From b4967d359fa1574acddc85e66377d3ec8d6cdb41 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 11 Aug 2011 17:11:45 +0000 Subject: [PATCH] Output spans to the debug info file. git-svn-id: svn://svn.cc65.org/cc65/trunk@5152 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/dbgfile.c | 13 +++++++++---- src/ld65/scopes.c | 15 ++++++++++++--- src/ld65/span.c | 47 +++++++++++++++++++++++++++++++++++++++++++--- src/ld65/span.h | 7 +++++++ 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/ld65/dbgfile.c b/src/ld65/dbgfile.c index 20c64a1ec..a9df4ffff 100644 --- a/src/ld65/dbgfile.c +++ b/src/ld65/dbgfile.c @@ -47,6 +47,7 @@ #include "lineinfo.h" #include "scopes.h" #include "segments.h" +#include "span.h" @@ -102,17 +103,18 @@ void CreateDbgFile (void) /* Output version information */ fprintf (F, "version\tmajor=2,minor=0\n"); - /* Output a line with the item numbers so the debug info module is able + /* Output a line with the item numbers so the debug info module is able * to preallocate the required memory. */ fprintf ( F, - "info\tlib=%u,mod=%u,seg=%u,file=%u,scope=%u\n", + "info\tlib=%u,file=%u,mod=%u,scope=%u,seg=%u,span=%u\n", + FileInfoCount (), LibraryCount (), ObjDataCount (), + ScopeCount (), SegmentCount (), - FileInfoCount (), - ScopeCount () + SpanCount () ); /* Assign the ids to the items */ @@ -133,6 +135,9 @@ void CreateDbgFile (void) /* Output line info */ PrintDbgLineInfo (F); + /* Output spans */ + PrintDbgSpans (F); + /* Output symbols */ PrintDbgSyms (F); diff --git a/src/ld65/scopes.c b/src/ld65/scopes.c index e548fcad5..775e89fea 100644 --- a/src/ld65/scopes.c +++ b/src/ld65/scopes.c @@ -89,7 +89,7 @@ Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id) S->LabelId = ReadVar (F); } - /* Read the segment ranges for this scope */ + /* Read the spans for this scope */ ReadSpans (&S->Spans, F, Obj); /* Return the new Scope */ @@ -120,7 +120,7 @@ unsigned ScopeCount (void) void PrintDbgScopes (FILE* F) /* Output the scopes to a debug info file */ { - unsigned I, J; + unsigned I, J, K; /* Print scopes from all modules we have linked into the output file */ for (I = 0; I < CollCount (&ObjDataList); ++I) { @@ -152,7 +152,7 @@ void PrintDbgScopes (FILE* F) GetObjFileName (O), S->Type); } - /* Print the size if available */ + /* Print the size if available */ if (S->Size != 0) { fprintf (F, ",size=%lu", S->Size); } @@ -164,6 +164,15 @@ void PrintDbgScopes (FILE* F) if (SCOPE_HAS_LABEL (S->Flags)) { fprintf (F, ",sym=%u", O->SymBaseId + S->LabelId); } + /* Print the list of spans for this scope */ + if (CollCount (&S->Spans) > 0) { + const Span* SP = CollConstAt (&S->Spans, 0); + fprintf (F, ",span=%u", SP->Id); + for (K = 1; K < CollCount (&S->Spans); ++K) { + SP = CollConstAt (&S->Spans, K); + fprintf (F, "+%u", SP->Id); + } + } /* Terminate the output line */ fputc ('\n', F); diff --git a/src/ld65/span.c b/src/ld65/span.c index f1bf280c3..69d0f4d43 100644 --- a/src/ld65/span.c +++ b/src/ld65/span.c @@ -36,7 +36,7 @@ /* common */ #include "xmalloc.h" -/* ld65 */ +/* ld65 */ #include "fileio.h" #include "objdata.h" #include "segments.h" @@ -45,7 +45,18 @@ /*****************************************************************************/ -/* Code */ +/* Data */ +/*****************************************************************************/ + + + +/* List of all spans */ +static Collection SpanList = STATIC_COLLECTION_INITIALIZER; + + + +/*****************************************************************************/ +/* Code */ /*****************************************************************************/ @@ -57,12 +68,16 @@ Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size) Span* S = xmalloc (sizeof (*S)); /* Initialize the fields */ + S->Id = CollCount (&SpanList); S->Seg = Seg; S->Offs = Offs; S->Size = Size; + /* Remember this span in the global list */ + CollAppend (&SpanList, S); + /* Return the result */ - return S; + return S; } @@ -161,3 +176,29 @@ void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs, +unsigned SpanCount (void) +/* Return the total number of spans */ +{ + return CollCount (&SpanList); +} + + + +void PrintDbgSpans (FILE* F) +/* Output the spans to a debug info file */ +{ + /* Walk over all spans */ + unsigned I; + for (I = 0; I < CollCount (&SpanList); ++I) { + + /* Get this span */ + const Span* S = CollAtUnchecked (&SpanList, I); + + /* Output the data */ + fprintf (F, "span\tid=%u,seg=%u,start=%lu,size=%lu\n", + S->Id, S->Seg->Id, S->Offs, S->Size); + } +} + + + diff --git a/src/ld65/span.h b/src/ld65/span.h index 82c7cf81b..d307b5564 100644 --- a/src/ld65/span.h +++ b/src/ld65/span.h @@ -64,6 +64,7 @@ struct Segment; typedef struct Span Span; struct Span { + unsigned Id; /* Id of the span */ struct Segment* Seg; /* Segment of this span */ unsigned long Offs; /* Offset of span within segment */ unsigned long Size; /* Size of span */ @@ -95,6 +96,12 @@ void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs, * possible - merge it with adjacent ones that already exist. */ +unsigned SpanCount (void); +/* Return the total number of spans */ + +void PrintDbgSpans (FILE* F); +/* Output the spans to a debug info file */ + /* End of span.h */ -- 2.39.5