From 8c39874daac6bf3f3a2d1e8052276f2f6aea5849 Mon Sep 17 00:00:00 2001 From: uz Date: Sat, 7 Aug 2010 12:46:12 +0000 Subject: [PATCH] Some changes in debug info generation. git-svn-id: svn://svn.cc65.org/cc65/trunk@4788 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/dbginfo.c | 15 ++++++------ src/ld65/fileinfo.c | 14 ++++++++--- src/ld65/fileinfo.h | 15 ++++++------ src/ld65/fragment.c | 1 + src/ld65/fragment.h | 1 + src/ld65/lineinfo.c | 59 ++++++++++++++++++++++++--------------------- src/ld65/lineinfo.h | 13 +++++----- src/ld65/segments.c | 12 ++++++--- src/ld65/segments.h | 9 ++++--- 9 files changed, 80 insertions(+), 59 deletions(-) diff --git a/src/ld65/dbginfo.c b/src/ld65/dbginfo.c index ddf4320b6..98227790b 100644 --- a/src/ld65/dbginfo.c +++ b/src/ld65/dbginfo.c @@ -37,12 +37,13 @@ #include "dbginfo.h" #include "fileinfo.h" #include "lineinfo.h" +#include "segments.h" #include "spool.h" /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -55,8 +56,9 @@ void PrintDbgInfo (ObjData* O, FILE* F) /* Output the files section */ for (I = 0; I < CollCount (&O->Files); ++I) { const FileInfo* FI = CollConstAt (&O->Files, I); - fprintf (F, "file\t\"%s\",size=%lu,mtime=0x%08lX\n", - GetString (FI->Name), FI->Size, FI->MTime); + fprintf (F, + "file\tid=%u,name=\"%s\",size=%lu,mtime=0x%08lX\n", + FI->Id, GetString (FI->Name), FI->Size, FI->MTime); } /* Output the line infos */ @@ -76,10 +78,9 @@ void PrintDbgInfo (ObjData* O, FILE* F) /* Print it */ fprintf (F, - "line\t\"%s\",line=%lu,range=0x%06lX-0x%06lX", - GetString (LI->File->Name), - LI->Pos.Line, - R->Offs, R->Offs + R->Size - 1); + "line\tfile=%u,line=%lu,segment=%u,range=0x%06lX-0x%06lX", + LI->File->Id, LI->Pos.Line, R->Seg->Id, + R->Offs, R->Offs + R->Size - 1); } /* Terminate the line */ diff --git a/src/ld65/fileinfo.c b/src/ld65/fileinfo.c index 58b5826b1..7965d574f 100644 --- a/src/ld65/fileinfo.c +++ b/src/ld65/fileinfo.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@cc65.org */ +/* (C) 2001-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -51,9 +51,15 @@ static FileInfo* NewFileInfo (void) /* Allocate and initialize a new FileInfo struct and return it */ { + /* We will assign file info ids in increasing order of creation */ + static unsigned Id = 0; + /* Allocate memory */ FileInfo* FI = xmalloc (sizeof (FileInfo)); + /* Initialize stuff */ + FI->Id = Id++; + /* Return the new struct */ return FI; } diff --git a/src/ld65/fileinfo.h b/src/ld65/fileinfo.h index 4d2d423ba..8ebee7972 100644 --- a/src/ld65/fileinfo.h +++ b/src/ld65/fileinfo.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@cc65.org */ +/* (C) 2001-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -57,9 +57,10 @@ typedef struct FileInfo FileInfo; struct FileInfo { - unsigned Name; /* File name index */ - unsigned long MTime; /* Time of last modification */ - unsigned long Size; /* Size of the file */ + unsigned Name; /* File name index */ + unsigned long MTime; /* Time of last modification */ + unsigned long Size; /* Size of the file */ + unsigned Id; /* Id of file for debug info */ }; diff --git a/src/ld65/fragment.c b/src/ld65/fragment.c index c3f902c75..3dfbceb91 100644 --- a/src/ld65/fragment.c +++ b/src/ld65/fragment.c @@ -71,6 +71,7 @@ Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S) /* Initialize the data */ F->Next = 0; F->Obj = 0; + F->Sec = S; F->Size = Size; F->Expr = 0; F->LineInfos = EmptyCollection; diff --git a/src/ld65/fragment.h b/src/ld65/fragment.h index 94e40656b..24ebc3e19 100644 --- a/src/ld65/fragment.h +++ b/src/ld65/fragment.h @@ -67,6 +67,7 @@ typedef struct Fragment Fragment; struct Fragment { Fragment* Next; /* Next fragment in list */ struct ObjData* Obj; /* Source of fragment */ + struct Section* Sec; /* Section for this fragment */ unsigned Size; /* Size of data/expression */ struct ExprNode* Expr; /* Expression if FRAG_EXPR */ Collection LineInfos; /* Line info for this fragment */ diff --git a/src/ld65/lineinfo.c b/src/ld65/lineinfo.c index 2b5eba78f..bbdc3548e 100644 --- a/src/ld65/lineinfo.c +++ b/src/ld65/lineinfo.c @@ -52,13 +52,14 @@ -static CodeRange* NewCodeRange (unsigned long Offs, unsigned long Size) +static CodeRange* NewCodeRange (Segment* Seg, unsigned long Offs, unsigned long Size) /* Create and return a new CodeRange struct */ { /* Allocate memory */ CodeRange* R = xmalloc (sizeof (CodeRange)); /* Initialize the fields */ + R->Seg = Seg; R->Offs = Offs; R->Size = Size; @@ -102,7 +103,8 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O) -static void AddCodeRange (LineInfo* LI, unsigned long Offs, unsigned long Size) +static void AddCodeRange (LineInfo* LI, Segment* Seg, unsigned long Offs, + unsigned long Size) /* Add a range of code to this line */ { unsigned I; @@ -117,34 +119,35 @@ static void AddCodeRange (LineInfo* LI, unsigned long Offs, unsigned long Size) */ for (I = 0; I < CollCount (CodeRanges); ++I) { CodeRange* R = CollAtUnchecked (CodeRanges, I); - if (Offs < R->Offs) { - - /* Got the insert position */ - if (Offs + Size == R->Offs) { - /* Merge the two */ - R->Offs = Offs; - R->Size += Size; - } else { - /* Insert a new entry */ - CollInsert (CodeRanges, NewCodeRange (Offs, Size), I); - } - - /* Done */ - return; - - } else if (R->Offs + R->Size == Offs) { - - /* This is the regular case. Merge the two. */ - R->Size += Size; - - /* Done */ - return; - - } + /* Must be same segment */ + if (R->Seg == Seg) { + if (Offs < R->Offs) { + + /* Got the insert position */ + if (Offs + Size == R->Offs) { + /* Merge the two */ + R->Offs = Offs; + R->Size += Size; + } else { + /* Insert a new entry */ + CollInsert (CodeRanges, NewCodeRange (Seg, Offs, Size), I); + } + + /* Done */ + return; + + } else if (R->Offs + R->Size == Offs) { + /* This is the regular case. Merge the two. */ + R->Size += Size; + + /* Done */ + return; + } + } } /* We must append an entry */ - CollAppend (CodeRanges, NewCodeRange (Offs, Size)); + CollAppend (CodeRanges, NewCodeRange (Seg, Offs, Size)); } @@ -170,7 +173,7 @@ void RelocLineInfo (Segment* S) /* Add the range for this fragment to all line infos */ for (I = 0; I < CollCount (&Frag->LineInfos); ++I) { - AddCodeRange (CollAt (&Frag->LineInfos, I), Offs, Frag->Size); + AddCodeRange (CollAt (&Frag->LineInfos, I), S, Offs, Frag->Size); } /* Update the offset */ diff --git a/src/ld65/lineinfo.h b/src/ld65/lineinfo.h index 7ef66d6d4..f47fa44a9 100644 --- a/src/ld65/lineinfo.h +++ b/src/ld65/lineinfo.h @@ -65,18 +65,19 @@ struct Segment; typedef struct CodeRange CodeRange; struct CodeRange { - unsigned long Offs; - unsigned long Size; + struct Segment* Seg; /* Segment of this code range */ + unsigned long Offs; /* Offset of code range */ + unsigned long Size; /* Size of code range */ }; typedef struct LineInfo LineInfo; struct LineInfo { - struct FileInfo* File; /* File struct for this line */ - FilePos Pos; /* File position */ - Collection Fragments; /* Fragments for this line */ - Collection CodeRanges; /* Code ranges for this line */ + struct FileInfo* File; /* File struct for this line */ + FilePos Pos; /* File position */ + Collection Fragments; /* Fragments for this line */ + Collection CodeRanges; /* Code ranges for this line */ }; diff --git a/src/ld65/segments.c b/src/ld65/segments.c index 249ef2817..9d3627113 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -103,7 +103,12 @@ static Segment* NewSegment (unsigned Name, unsigned char AddrSize) S->Relocatable = 0; S->Dumped = 0; - /* Insert the segment into the segment list */ + /* Insert the segment into the segment list and assign the segment id */ + if (SegRoot == 0) { + S->Id = 0; + } else { + S->Id = SegRoot->Id + 1; + } S->List = SegRoot; SegRoot = S; ++SegCount; @@ -656,8 +661,9 @@ void PrintDbgSegments (FILE* F) if (S->Size > 0) { /* Print the segment data */ - fprintf (F, "segment\t\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s\n", - GetString (S->Name), S->PC, S->Size, + fprintf (F, + "segment\tid=%u,name=\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s\n", + S->Id, GetString (S->Name), S->PC, S->Size, AddrSizeToStr (S->AddrSize), S->ReadOnly? "ro" : "rw"); } diff --git a/src/ld65/segments.h b/src/ld65/segments.h index aca4bf6ad..6e5f628ed 100644 --- a/src/ld65/segments.h +++ b/src/ld65/segments.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2003 Ullrich von Bassewitz */ -/* Römerstraße 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2010, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -55,6 +55,7 @@ typedef struct Segment Segment; struct Segment { unsigned Name; /* Name index of the segment */ + unsigned Id; /* Segment id for debug info */ Segment* Next; /* Hash list */ Segment* List; /* List of all segments */ struct Section* SecRoot; /* Section list */ -- 2.39.5