From 2f75733e43257a3ef4a0b598e08f17cfc9500c73 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 4 Aug 2011 15:58:54 +0000 Subject: [PATCH] Rearrange debug info output. Add scopes to the debug info. git-svn-id: svn://svn.cc65.org/cc65/trunk@5117 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/dbgfile.c | 26 +++++---- src/ld65/dbginfo.c | 111 --------------------------------------- src/ld65/dbginfo.h | 66 ----------------------- src/ld65/dbgsyms.c | 39 ++++++-------- src/ld65/dbgsyms.h | 2 +- src/ld65/fileinfo.c | 32 ++++++++++- src/ld65/fileinfo.h | 3 ++ src/ld65/lineinfo.c | 53 +++++++++++++++++++ src/ld65/lineinfo.h | 3 ++ src/ld65/make/gcc.mak | 1 - src/ld65/make/watcom.mak | 1 - src/ld65/objfile.c | 2 +- src/ld65/scopes.c | 43 +++++++++++++++ 13 files changed, 163 insertions(+), 219 deletions(-) delete mode 100644 src/ld65/dbginfo.c delete mode 100644 src/ld65/dbginfo.h diff --git a/src/ld65/dbgfile.c b/src/ld65/dbgfile.c index 30d8bd1fd..1b369169c 100644 --- a/src/ld65/dbgfile.c +++ b/src/ld65/dbgfile.c @@ -39,10 +39,12 @@ /* ld65 */ #include "dbgfile.h" -#include "dbginfo.h" #include "dbgsyms.h" #include "error.h" +#include "fileinfo.h" #include "global.h" +#include "lineinfo.h" +#include "scopes.h" #include "segments.h" @@ -56,8 +58,6 @@ void CreateDbgFile (void) /* Create a debug info file */ { - unsigned I; - /* Open the debug info file */ FILE* F = fopen (DbgFileName, "w"); if (F == 0) { @@ -67,22 +67,20 @@ void CreateDbgFile (void) /* Output version information */ fprintf (F, "version\tmajor=1,minor=2\n"); - /* Clear the debug sym table (used to detect duplicates) */ - ClearDbgSymTable (); - /* Output the segment info */ PrintDbgSegments (F); - /* Print line infos from all modules we have linked into the output file */ - for (I = 0; I < CollCount (&ObjDataList); ++I) { + /* Output files */ + PrintDbgFileInfo (F); - /* Get the object file */ - ObjData* O = CollAtUnchecked (&ObjDataList, I); + /* Output line info */ + PrintDbgLineInfo (F); - /* Output debug info */ - PrintDbgInfo (O, F); - PrintDbgSyms (O, F); - } + /* Output symbols */ + PrintDbgSyms (F); + + /* Output scopes */ + PrintDbgScopes (F); /* Close the file */ if (fclose (F) != 0) { diff --git a/src/ld65/dbginfo.c b/src/ld65/dbginfo.c deleted file mode 100644 index 7dca2fef9..000000000 --- a/src/ld65/dbginfo.c +++ /dev/null @@ -1,111 +0,0 @@ -/*****************************************************************************/ -/* */ -/* dbginfo.c */ -/* */ -/* Debug info handling for the ld65 linker */ -/* */ -/* */ -/* */ -/* (C) 2001-2011, Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ -/* */ -/* */ -/* This software is provided 'as-is', without any expressed or implied */ -/* warranty. In no event will the authors be held liable for any damages */ -/* arising from the use of this software. */ -/* */ -/* Permission is granted to anyone to use this software for any purpose, */ -/* including commercial applications, and to alter it and redistribute it */ -/* freely, subject to the following restrictions: */ -/* */ -/* 1. The origin of this software must not be misrepresented; you must not */ -/* claim that you wrote the original software. If you use this software */ -/* in a product, an acknowledgment in the product documentation would be */ -/* appreciated but is not required. */ -/* 2. Altered source versions must be plainly marked as such, and must not */ -/* be misrepresented as being the original software. */ -/* 3. This notice may not be removed or altered from any source */ -/* distribution. */ -/* */ -/*****************************************************************************/ - - - -/* common */ -#include "lidefs.h" - -/* ld65 */ -#include "dbginfo.h" -#include "fileinfo.h" -#include "lineinfo.h" -#include "segments.h" -#include "spool.h" - - - -/*****************************************************************************/ -/* Code */ -/*****************************************************************************/ - - - -void PrintDbgInfo (ObjData* O, FILE* F) -/* Print the debug info into a file */ -{ - unsigned I, J; - - /* Output the files section */ - for (I = 0; I < CollCount (&O->Files); ++I) { - FileInfo* FI = CollAt (&O->Files, I); - if (!FI->Dumped) { - fprintf (F, - "file\tid=%u,name=\"%s\",size=%lu,mtime=0x%08lX\n", - FI->Id, GetString (FI->Name), FI->Size, FI->MTime); - FI->Dumped = 1; - } - } - - /* Output the line infos */ - for (I = 0; I < CollCount (&O->LineInfos); ++I) { - - /* Get this line info */ - const LineInfo* LI = CollConstAt (&O->LineInfos, I); - - /* Get the line info type and count */ - unsigned Type = LI_GET_TYPE (LI->Type); - unsigned Count = LI_GET_COUNT (LI->Type); - - /* Get a pointer to the spans */ - const Collection* Spans = &LI->Spans; - - /* Spans */ - for (J = 0; J < CollCount (Spans); ++J) { - - /* Get this code range */ - const Span* S = CollConstAt (Spans, J); - - /* Print it */ - fprintf (F, - "line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX", - LI->File->Id, GetSourceLine (LI), S->Seg->Id, - S->Offs, S->Offs + S->Size - 1); - - /* Print type if not LI_TYPE_ASM and count if not zero */ - if (Type != LI_TYPE_ASM) { - fprintf (F, ",type=%u", Type); - } - if (Count != 0) { - fprintf (F, ",count=%u", Count); - } - - /* Terminate line */ - fputc ('\n', F); - - } - } -} - - - diff --git a/src/ld65/dbginfo.h b/src/ld65/dbginfo.h deleted file mode 100644 index 5c88370d4..000000000 --- a/src/ld65/dbginfo.h +++ /dev/null @@ -1,66 +0,0 @@ -/*****************************************************************************/ -/* */ -/* dbginfo.h */ -/* */ -/* Debug info handling for the ld65 linker */ -/* */ -/* */ -/* */ -/* (C) 2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@cc65.org */ -/* */ -/* */ -/* This software is provided 'as-is', without any expressed or implied */ -/* warranty. In no event will the authors be held liable for any damages */ -/* arising from the use of this software. */ -/* */ -/* Permission is granted to anyone to use this software for any purpose, */ -/* including commercial applications, and to alter it and redistribute it */ -/* freely, subject to the following restrictions: */ -/* */ -/* 1. The origin of this software must not be misrepresented; you must not */ -/* claim that you wrote the original software. If you use this software */ -/* in a product, an acknowledgment in the product documentation would be */ -/* appreciated but is not required. */ -/* 2. Altered source versions must be plainly marked as such, and must not */ -/* be misrepresented as being the original software. */ -/* 3. This notice may not be removed or altered from any source */ -/* distribution. */ -/* */ -/*****************************************************************************/ - - - -#ifndef DBGINFO_H -#define DBGINFO_H - - - -#include - -/* ld65 */ -#include "objdata.h" - - - -/*****************************************************************************/ -/* Code */ -/*****************************************************************************/ - - - -void PrintDbgInfo (ObjData* O, FILE* F); -/* Print the debug info into a file */ - - - -/* End of dbginfo.h */ - -#endif - - - - - diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index a9c6ede28..cf68714c8 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -67,7 +67,7 @@ static DbgSym* DbgSymPool[256]; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -205,32 +205,30 @@ long GetDbgSymVal (const DbgSym* D) -void PrintDbgSyms (ObjData* O, FILE* F) +void PrintDbgSyms (FILE* F) /* Print the debug symbols in a debug file */ { - unsigned I; + unsigned I, J; - /* Walk through all debug symbols in this module */ - for (I = 0; I < CollCount (&O->DbgSyms); ++I) { + for (I = 0; I < CollCount (&ObjDataList); ++I) { - long Val; + /* Get the object file */ + const ObjData* O = CollAtUnchecked (&ObjDataList, I); - /* Get the next debug symbol */ - DbgSym* S = CollAt (&O->DbgSyms, I); + /* Walk through all debug symbols in this module */ + for (J = 0; J < CollCount (&O->DbgSyms); ++J) { - /* Get the symbol value */ - Val = GetDbgSymVal (S); + long Val; + SegExprDesc D; - /* Lookup this symbol in the table. If it is found in the table, it was - * already written to the file, so don't emit it twice. If it is not in - * the table, insert and output it. - */ - if (GetDbgSym (S, Val) == 0) { + /* Get the next debug symbol */ + const DbgSym* S = CollConstAt (&O->DbgSyms, J); - SegExprDesc D; + /* Get the symbol value */ + Val = GetDbgSymVal (S); - /* Emit the base data for the entry */ - fprintf (F, + /* Emit the base data for the entry */ + fprintf (F, "sym\tname=\"%s\",value=0x%lX,addrsize=%s,type=%s", GetString (S->Name), Val, @@ -252,10 +250,7 @@ void PrintDbgSyms (ObjData* O, FILE* F) /* Terminate the output line */ fputc ('\n', F); - - /* Insert the symbol into the table */ - InsertDbgSym (S, Val); - } + } } } diff --git a/src/ld65/dbgsyms.h b/src/ld65/dbgsyms.h index e1b0aef23..18027e6ff 100644 --- a/src/ld65/dbgsyms.h +++ b/src/ld65/dbgsyms.h @@ -96,7 +96,7 @@ void ClearDbgSymTable (void); * or debug labels the first time. */ -void PrintDbgSyms (ObjData* O, FILE* F); +void PrintDbgSyms (FILE* F); /* Print the debug symbols in a debug file */ void PrintDbgSymLabels (ObjData* O, FILE* F); diff --git a/src/ld65/fileinfo.c b/src/ld65/fileinfo.c index 7bf4e1d55..d48280447 100644 --- a/src/ld65/fileinfo.c +++ b/src/ld65/fileinfo.c @@ -2,7 +2,7 @@ /* */ /* fileinfo.c */ /* */ -/* sOURCE FILE INFO STRUCTURE */ +/* Source file info structure */ /* */ /* */ /* */ @@ -40,6 +40,8 @@ /* ld65 */ #include "fileio.h" #include "fileinfo.h" +#include "objdata.h" +#include "spool.h" @@ -110,7 +112,7 @@ static FileInfo* NewFileInfo (void) FileInfo* FI = xmalloc (sizeof (FileInfo)); /* Initialize stuff */ - FI->Id = Id++; + FI->Id = Id++; FI->Dumped = 0; /* Return the new struct */ @@ -180,3 +182,29 @@ FileInfo* ReadFileInfo (FILE* F, ObjData* O) +void PrintDbgFileInfo (FILE* F) +/* Output the file info to a debug info file */ +{ + unsigned I, J; + + /* Print file infos from all modules we have linked into the output file */ + for (I = 0; I < CollCount (&ObjDataList); ++I) { + + /* Get the object file */ + ObjData* O = CollAtUnchecked (&ObjDataList, I); + + /* Output the files section */ + for (J = 0; J < CollCount (&O->Files); ++J) { + FileInfo* FI = CollAt (&O->Files, J); + if (!FI->Dumped) { + fprintf (F, + "file\tid=%u,name=\"%s\",size=%lu,mtime=0x%08lX\n", + FI->Id, GetString (FI->Name), FI->Size, FI->MTime); + FI->Dumped = 1; + } + } + } +} + + + diff --git a/src/ld65/fileinfo.h b/src/ld65/fileinfo.h index 1cd4fef92..a4499d83d 100644 --- a/src/ld65/fileinfo.h +++ b/src/ld65/fileinfo.h @@ -75,6 +75,9 @@ struct FileInfo { FileInfo* ReadFileInfo (FILE* F, ObjData* O); /* Read a file info from a file and return it */ +void PrintDbgFileInfo (FILE* F); +/* Output the file info to a debug info file */ + /* End of fileinfo.h */ diff --git a/src/ld65/lineinfo.c b/src/ld65/lineinfo.c index 219dcf1cc..63b764e6a 100644 --- a/src/ld65/lineinfo.c +++ b/src/ld65/lineinfo.c @@ -204,4 +204,57 @@ void RelocLineInfo (Segment* S) +void PrintDbgLineInfo (FILE* F) +/* Output the line infos to a debug info file */ +{ + unsigned I, J, K; + + /* Print line infos from all modules we have linked into the output file */ + for (I = 0; I < CollCount (&ObjDataList); ++I) { + + /* Get the object file */ + const ObjData* O = CollAtUnchecked (&ObjDataList, I); + + /* Output the line infos */ + for (J = 0; J < CollCount (&O->LineInfos); ++J) { + + /* Get this line info */ + const LineInfo* LI = CollConstAt (&O->LineInfos, J); + + /* Get the line info type and count */ + unsigned Type = LI_GET_TYPE (LI->Type); + unsigned Count = LI_GET_COUNT (LI->Type); + + /* Get a pointer to the spans */ + const Collection* Spans = &LI->Spans; + + /* Spans */ + for (K = 0; K < CollCount (Spans); ++K) { + + /* Get this code range */ + const Span* S = CollConstAt (Spans, K); + + /* Print it */ + fprintf (F, + "line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX", + LI->File->Id, GetSourceLine (LI), S->Seg->Id, + S->Offs, S->Offs + S->Size - 1); + + /* Print type if not LI_TYPE_ASM and count if not zero */ + if (Type != LI_TYPE_ASM) { + fprintf (F, ",type=%u", Type); + } + if (Count != 0) { + fprintf (F, ",count=%u", Count); + } + + /* Terminate line */ + fputc ('\n', F); + + } + } + } +} + + diff --git a/src/ld65/lineinfo.h b/src/ld65/lineinfo.h index bc7106eff..efe013990 100644 --- a/src/ld65/lineinfo.h +++ b/src/ld65/lineinfo.h @@ -171,6 +171,9 @@ INLINE unsigned long GetSourceLineFromList (const Collection* LineInfos) GetSourceLine ((const LineInfo*) CollConstAt ((LineInfos), 0)) #endif +void PrintDbgLineInfo (FILE* F); +/* Output the line infos to a debug info file */ + /* End of lineinfo.h */ diff --git a/src/ld65/make/gcc.mak b/src/ld65/make/gcc.mak index 89bce8d4c..9e071f685 100644 --- a/src/ld65/make/gcc.mak +++ b/src/ld65/make/gcc.mak @@ -36,7 +36,6 @@ OBJS = asserts.o \ condes.o \ config.o \ dbgfile.o \ - dbginfo.o \ dbgsyms.o \ error.o \ exports.o \ diff --git a/src/ld65/make/watcom.mak b/src/ld65/make/watcom.mak index 37a8e6fc6..cbad1d803 100644 --- a/src/ld65/make/watcom.mak +++ b/src/ld65/make/watcom.mak @@ -67,7 +67,6 @@ OBJS = asserts.obj \ condes.obj \ config.obj \ dbgfile.obj \ - dbginfo.obj \ dbgsyms.obj \ error.obj \ exports.obj \ diff --git a/src/ld65/objfile.c b/src/ld65/objfile.c index 5eb60c5e7..8b85e2cfa 100644 --- a/src/ld65/objfile.c +++ b/src/ld65/objfile.c @@ -276,7 +276,7 @@ void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O) CollGrow (&O->Scopes, ScopeCount); for (I = 0; I < ScopeCount; ++I) { CollAppend (&O->Scopes, ReadScope (F, O, I)); - } + } } diff --git a/src/ld65/scopes.c b/src/ld65/scopes.c index 106bd46a9..0bf3f881b 100644 --- a/src/ld65/scopes.c +++ b/src/ld65/scopes.c @@ -41,6 +41,7 @@ #include "fileio.h" #include "scopes.h" #include "span.h" +#include "spool.h" @@ -116,3 +117,45 @@ void ResolveScopes (ObjData* Obj) +void PrintDbgScopes (FILE* F) +/* Output the scopes to a debug info file */ +{ + unsigned I, J; + + /* Print scopes from all modules we have linked into the output file */ + unsigned BaseId = 0; + for (I = 0; I < CollCount (&ObjDataList); ++I) { + + /* Get the object file */ + ObjData* O = CollAtUnchecked (&ObjDataList, I); + + /* Output the scopes for this object file */ + for (J = 0; J < CollCount (&O->Scopes); ++J) { + const Scope* S = CollConstAt (&O->Scopes, J); + + fprintf (F, + "scope\tid=%u,name=\"%s\",type=%u", + BaseId + S->Id, + GetString (S->Name), + S->Type); + + /* Print the size if available */ + if (S->Size != 0) { + fprintf (F, ",size=%lu", S->Size); + } + /* Print parent if available */ + if (S->Parent.Scope) { + fprintf (F, ",parent=%u", BaseId + S->Parent.Scope->Id); + } + + /* Terminate the output line */ + fputc ('\n', F); + } + + /* Increment scope base id */ + BaseId += CollCount (&O->Scopes); + } +} + + + -- 2.39.5