From 89dccd5a23e12f83bcb09da5968206522e2a2d92 Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 31 Jul 2000 22:21:37 +0000 Subject: [PATCH] Added dump of debug symbols and output of values for the exports, in those cases where the export is a constant. git-svn-id: svn://svn.cc65.org/cc65/trunk@246 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/od65/dump.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++-- src/od65/dump.h | 3 ++ src/od65/main.c | 19 +++++++++-- 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/od65/dump.c b/src/od65/dump.c index 0c3d743d4..67708e8e7 100644 --- a/src/od65/dump.c +++ b/src/od65/dump.c @@ -546,7 +546,9 @@ void DumpObjExports (FILE* F, unsigned long Offset) /* Read and print all exports */ for (I = 0; I < Count; ++I) { - const char* TypeDesc; + unsigned long Value = 0; + int HaveValue; + const char* TypeDesc; /* Read the data for one export */ unsigned char Type = Read8 (F); @@ -554,8 +556,10 @@ void DumpObjExports (FILE* F, unsigned long Offset) unsigned Len = strlen (Name); if (Type & EXP_EXPR) { SkipExpr (F); + HaveValue = 0; } else { - (void) Read32 (F); + Value = Read32 (F); + HaveValue = 1; } ReadFilePos (F, &Pos); @@ -574,6 +578,86 @@ void DumpObjExports (FILE* F, unsigned long Offset) /* Print the data */ printf (" Type:%22s0x%02X (%s)\n", "", Type, TypeDesc); printf (" Name:%*s\"%s\"\n", 24-Len, "", Name); + if (HaveValue) { + printf (" Value:%15s0x%08lX (%lu)\n", "", Value, Value); + } + + /* Free the Name */ + xfree (Name); + } +} + + + +void DumpObjDbgSyms (FILE* F, unsigned long Offset) +/* Dump the debug symbols from an object file */ +{ + ObjHeader H; + unsigned Count; + unsigned I; + FilePos Pos; + + /* Seek to the header position */ + FileSeek (F, Offset); + + /* Read the header */ + ReadObjHeader (F, &H); + + /* Seek to the start of the options */ + FileSeek (F, Offset + H.DbgSymOffs); + + /* Output a header */ + printf (" Debug symbols:\n"); + + /* Check if the object file was compiled with debug info */ + if ((H.Flags & OBJ_FLAGS_DBGINFO) == 0) { + /* Print that there no debug symbols and bail out */ + printf (" Count:%27u\n", 0); + return; + } + + /* Read the number of exports and print it */ + Count = Read16 (F); + printf (" Count:%27u\n", Count); + + /* Read and print all debug symbols */ + for (I = 0; I < Count; ++I) { + + unsigned long Value = 0; + int HaveValue; + const char* TypeDesc; + + /* Read the data for one symbol */ + unsigned char Type = Read8 (F); + char* Name = ReadMallocedStr (F); + unsigned Len = strlen (Name); + if (Type & EXP_EXPR) { + SkipExpr (F); + HaveValue = 0; + } else { + Value = Read32 (F); + HaveValue = 1; + } + ReadFilePos (F, &Pos); + + /* Get a description for the type */ + switch (Type) { + case EXP_ABS|EXP_CONST: TypeDesc = "EXP_ABS,EXP_CONST"; break; + case EXP_ZP|EXP_CONST: TypeDesc = "EXP_ZP,EXP_CONST"; break; + case EXP_ABS|EXP_EXPR: TypeDesc = "EXP_ABS,EXP_EXPR"; break; + case EXP_ZP|EXP_EXPR: TypeDesc = "EXP_ZP,EXP_EXPR"; break; + default: TypeDesc = "EXP_UNKNOWN"; break; + } + + /* Print the header */ + printf (" Index:%27u\n", I); + + /* Print the data */ + printf (" Type:%22s0x%02X (%s)\n", "", Type, TypeDesc); + printf (" Name:%*s\"%s\"\n", 24-Len, "", Name); + if (HaveValue) { + printf (" Value:%15s0x%08lX (%lu)\n", "", Value, Value); + } /* Free the Name */ xfree (Name); diff --git a/src/od65/dump.h b/src/od65/dump.h index aee984216..d35417b9c 100644 --- a/src/od65/dump.h +++ b/src/od65/dump.h @@ -66,6 +66,9 @@ void DumpObjImports (FILE* F, unsigned long Offset); void DumpObjExports (FILE* F, unsigned long Offset); /* Dump the exports in the object file */ +void DumpObjDbgSyms (FILE* F, unsigned long Offset); +/* Dump the debug symbols from an object file */ + /* End of dump.h */ diff --git a/src/od65/main.c b/src/od65/main.c index b7383c8dd..9387e2640 100644 --- a/src/od65/main.c +++ b/src/od65/main.c @@ -77,7 +77,8 @@ static void Usage (void) " -V\t\t\tPrint the version number and exit\n" "\n" "Long options:\n" - " --dump-all\t\tDump all object file information\n" + " --dump-all\t\tDump all object file information\n" + " --dump-dbgsyms\tDump debug symbols\n" " --dump-exports\tDump exported symbols\n" " --dump-files\t\tDump the source files\n" " --dump-header\t\tDump the object file header\n" @@ -99,6 +100,14 @@ static void OptDumpAll (const char* Opt, const char* Arg) +static void OptDumpDbgSyms (const char* Opt, const char* Arg) +/* Dump debug symbols contained in the object file */ +{ + What |= D_DBGSYMS; +} + + + static void OptDumpExports (const char* Opt, const char* Arg) /* Dump the exported symbols */ { @@ -215,6 +224,9 @@ static void DumpFile (const char* Name) if (What & D_EXPORTS) { DumpObjExports (F, 0); } + if (What & D_DBGSYMS) { + DumpObjDbgSyms (F, 0); + } } /* Close the file */ @@ -228,9 +240,10 @@ int main (int argc, char* argv []) { /* Program long options */ static const LongOpt OptTab[] = { - { "--dump-all", 0, OptDumpAll }, + { "--dump-all", 0, OptDumpAll }, + { "--dump-dbgsyms", 0, OptDumpDbgSyms }, { "--dump-exports", 0, OptDumpExports }, - { "--dump-files", 0, OptDumpFiles }, + { "--dump-files", 0, OptDumpFiles }, { "--dump-header", 0, OptDumpHeader }, { "--dump-imports", 0, OptDumpImports }, { "--dump-options", 0, OptDumpOptions }, -- 2.39.5