From: cuz Date: Fri, 15 Aug 2003 10:59:22 +0000 (+0000) Subject: More debug infos X-Git-Tag: V2.12.0~1416 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f3e0d3fbb13a724f88d2127e8d9107d883de2a11;p=cc65 More debug infos git-svn-id: svn://svn.cc65.org/cc65/trunk@2320 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index 12d13a83d..44c066094 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -35,7 +35,7 @@ #include -/* common */ +/* common */ #include "check.h" #include "symdefs.h" #include "xmalloc.h" @@ -60,7 +60,7 @@ /* We will collect all debug symbols in the following array and remove * duplicates before outputing them. */ -static DbgSym* DbgSymPool [256]; +static DbgSym* DbgSymPool[256]; @@ -139,20 +139,17 @@ static void InsertDbgSym (DbgSym* D, long Val) DbgSym* ReadDbgSym (FILE* F, ObjData* O) /* Read a debug symbol from a file, insert and return it */ { - unsigned char Type; - DbgSym* D; - /* Read the type */ - Type = Read8 (F); + unsigned char Type = Read8 (F); /* Create a new debug symbol */ - D = NewDbgSym (Type, O); + DbgSym* D = NewDbgSym (Type, O); /* Read and assign the name */ D->Name = MakeGlobalStringId (O, ReadVar (F)); /* Read the value */ - if (IS_EXP_EXPR (Type)) { + if (IS_EXP_EXPR (D->Type)) { D->Expr = ReadExpr (F, O); } else { D->Expr = LiteralExpr (Read32 (F), O); @@ -167,6 +164,23 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* O) +static void ClearDbgSymTable (void) +/* Clear the debug symbol table */ +{ + unsigned I; + for (I = 0; I < sizeof (DbgSymPool) / sizeof (DbgSymPool[0]); ++I) { + DbgSym* Sym = DbgSymPool[I]; + DbgSymPool[I] = 0; + while (Sym) { + DbgSym* NextSym = Sym->Next; + Sym->Next = 0; + Sym = NextSym; + } + } +} + + + long GetDbgSymVal (DbgSym* D) /* Get the value of this symbol */ { @@ -176,19 +190,69 @@ long GetDbgSymVal (DbgSym* D) +void PrintDbgSyms (ObjData* O, FILE* F) +/* Print the debug symbols in a debug file */ +{ + unsigned I; + + /* Clear the debug sym table */ + ClearDbgSymTable (); + + /* Walk through all debug symbols in this module */ + for (I = 0; I < O->DbgSymCount; ++I) { + + long Val; + + /* Get the next debug symbol */ + DbgSym* D = O->DbgSyms [I]; + + /* Get the symbol value */ + Val = GetDbgSymVal (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 (D, Val) == 0) { + + /* Emit the debug file line */ + fprintf (F, + "sym\t\"%s\", 0x%02X, 0x%08lX\n", + GetString (D->Name), + D->Type, + Val); + + /* Insert the symbol into the table */ + InsertDbgSym (D, Val); + } + } +} + + + void PrintDbgSymLabels (ObjData* O, FILE* F) /* Print the debug symbols in a VICE label file */ { unsigned I; + /* Clear the debug sym table */ + ClearDbgSymTable (); + /* Walk through all debug symbols in this module */ for (I = 0; I < O->DbgSymCount; ++I) { + long Val; + /* Get the next debug symbol */ DbgSym* D = O->DbgSyms [I]; + /* Emit this symbol only if it is a label (ignore equates) */ + if (IS_EXP_EQUATE (D->Type)) { + continue; + } + /* Get the symbol value */ - long Val = GetDbgSymVal (D); + Val = GetDbgSymVal (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 diff --git a/src/ld65/dbgsyms.h b/src/ld65/dbgsyms.h index 5483116fe..250b50bd5 100644 --- a/src/ld65/dbgsyms.h +++ b/src/ld65/dbgsyms.h @@ -81,6 +81,9 @@ DbgSym* ReadDbgSym (FILE* F, ObjData* Obj); long GetDbgSymVal (DbgSym* D); /* Get the value of this symbol */ +void PrintDbgSyms (ObjData* O, FILE* F); +/* Print the debug symbols in a debug file */ + void PrintDbgSymLabels (ObjData* O, FILE* F); /* Print the debug symbols in a VICE label file */ diff --git a/src/ld65/main.c b/src/ld65/main.c index 7e2f4cf7e..146b0db78 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -106,7 +106,7 @@ static void Usage (void) "Long options:\n" " --cfg-path path\tSpecify a config file search path\n" " --config name\t\tUse linker config file\n" - " --dbgfile name\t\tGenerate debug information\n" + " --dbgfile name\tGenerate debug information\n" " --dump-config name\tDump a builtin configuration\n" " --help\t\tHelp (this text)\n" " --lib file\t\tLink this library\n" diff --git a/src/ld65/mapfile.c b/src/ld65/mapfile.c index 071b11318..5fcba2b99 100644 --- a/src/ld65/mapfile.c +++ b/src/ld65/mapfile.c @@ -149,7 +149,7 @@ void CreateLabelFile (void) /* Close the file */ if (fclose (F) != 0) { - Error ("Error closing map file `%s': %s", LabelFileName, strerror (errno)); + Error ("Error closing label file `%s': %s", LabelFileName, strerror (errno)); } } @@ -163,7 +163,7 @@ void CreateDbgFile (void) /* Open the debug info file */ FILE* F = fopen (DbgFileName, "w"); if (F == 0) { - Error ("Cannot create label file `%s': %s", DbgFileName, strerror (errno)); + Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno)); } /* Print line infos from all modules we have linked into the output file */ @@ -174,11 +174,12 @@ void CreateDbgFile (void) /* Output debug info */ PrintDbgInfo (O, F); + PrintDbgSyms (O, F); } /* Close the file */ if (fclose (F) != 0) { - Error ("Error closing map file `%s': %s", DbgFileName, strerror (errno)); + Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno)); } }