+cc65_segmentlist* cc65_get_segmentlist (cc65_dbginfo Handle)
+/* Return a list of all segments referenced in the debug information */
+{
+ DbgInfo* Info;
+ Collection* SegInfoByName;
+ cc65_segmentlist* D;
+ unsigned I;
+
+ /* Check the parameter */
+ assert (Handle != 0);
+
+ /* The handle is actually a pointer to a debug info struct */
+ Info = (DbgInfo*) Handle;
+
+ /* Get a pointer to the file list */
+ SegInfoByName = &Info->SegInfoByName;
+
+ /* Allocate memory for the data structure returned to the caller */
+ D = xmalloc (sizeof (*D) - sizeof (D->data[0]) +
+ CollCount (SegInfoByName) * sizeof (D->data[0]));
+
+ /* Fill in the data */
+ D->count = CollCount (SegInfoByName);
+ for (I = 0; I < CollCount (SegInfoByName); ++I) {
+
+ /* Get this item */
+ SegInfo* S = CollAt (SegInfoByName, I);
+
+ /* Copy the data */
+ D->data[I].name = S->SegName;
+ D->data[I].start = S->Start;
+ D->data[I].end = S->Start + S->Size - 1;
+ }
+
+ /* Return the result */
+ return D;
+}
+
+
+
+void cc65_free_segmentlist (cc65_dbginfo Handle, cc65_segmentlist* List)
+/* Free a file list returned by cc65_get_filelist() */
+{
+ /* Just for completeness, check the handle */
+ assert (Handle != 0);
+
+ /* Just free the memory */
+ xfree (List);
+}
+/* A list of segments with some information */
+typedef struct cc65_segmentlist cc65_segmentlist;
+struct cc65_segmentlist {
+ unsigned count; /* Number of data sets that follow */
+ struct {
+ const char* name; /* Name of the file */
+ cc65_addr start; /* Start address of segment */
+ cc65_addr end; /* End address of segment */
+ } data[1];
+};
+
+
+
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void cc65_free_filelist (cc65_dbginfo handle, cc65_filelist* list);
/* free a file list returned by cc65_get_filelist() */
+cc65_segmentlist* cc65_get_segmentlist (cc65_dbginfo handle);
+/* Return a list of all segments referenced in the debug information */
+
+void cc65_free_segmentlist (cc65_dbginfo handle, cc65_segmentlist* list);
+/* Free a file list returned by cc65_get_filelist() */
+
/* End of dbginfo.h */
int main (int argc, char** argv)
{
- const char* Input;
- cc65_dbginfo Info;
- cc65_filelist* Files;
- cc65_lineinfo* L;
- unsigned I;
- unsigned long Addr;
+ const char* Input;
+ cc65_dbginfo Info;
+ cc65_filelist* Files;
+ cc65_segmentlist* Segments;
+ cc65_lineinfo* L;
+ unsigned I;
+ unsigned long Addr;
/* Input file is argument */
}
cc65_free_filelist (Info, Files);
+ /* Output a list of segments */
+ printf ("Segments processed when linking:\n");
+ Segments = cc65_get_segmentlist (Info);
+ for (I = 0; I < Segments->count; ++I) {
+ printf (" %-20s $%06lX-$%06lX\n",
+ Segments->data[I].name,
+ (unsigned long) Segments->data[I].start,
+ (unsigned long) Segments->data[I].end);
+ }
+ cc65_free_segmentlist (Info, Segments);
+
/* Check one line */
printf ("Requesting line info for crt0.s(59):\n");
L = cc65_lineinfo_byname (Info, "crt0.s", 59);