From 6272c9355600ee37e07b603bc1bcbf1d16ef58ee Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 8 Aug 2010 15:43:13 +0000 Subject: [PATCH] Allow access to segment information. git-svn-id: svn://svn.cc65.org/cc65/trunk@4796 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/dbginfo/dbginfo.c | 49 +++++++++++++++++++++++++++++++++++++++++++ src/dbginfo/dbginfo.h | 19 +++++++++++++++++ src/dbginfo/dbgtest.c | 24 +++++++++++++++------ 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/dbginfo/dbginfo.c b/src/dbginfo/dbginfo.c index c281a9236..cb46daad8 100644 --- a/src/dbginfo/dbginfo.c +++ b/src/dbginfo/dbginfo.c @@ -2376,6 +2376,55 @@ void cc65_free_filelist (cc65_dbginfo Handle, cc65_filelist* List) +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); +} diff --git a/src/dbginfo/dbginfo.h b/src/dbginfo/dbginfo.h index edb9dfed7..11c5ad084 100644 --- a/src/dbginfo/dbginfo.h +++ b/src/dbginfo/dbginfo.h @@ -101,6 +101,19 @@ struct cc65_filelist { +/* 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 */ /*****************************************************************************/ @@ -138,6 +151,12 @@ cc65_filelist* cc65_get_filelist (cc65_dbginfo handle); 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 */ diff --git a/src/dbginfo/dbgtest.c b/src/dbginfo/dbgtest.c index adb3cdb12..6d118b8c8 100644 --- a/src/dbginfo/dbgtest.c +++ b/src/dbginfo/dbgtest.c @@ -63,12 +63,13 @@ static void Usage (void) 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 */ @@ -93,6 +94,17 @@ int main (int argc, char** argv) } 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); -- 2.39.5