From 85e36f2ea54eccd29f962a79de04e956c8d1767e Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 25 Nov 2002 17:32:16 +0000 Subject: [PATCH] Add capability to dump just the segment sizes git-svn-id: svn://svn.cc65.org/cc65/trunk@1647 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/od65/dump.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++- src/od65/dump.h | 5 ++++- src/od65/global.h | 9 ++++---- src/od65/main.c | 26 ++++++++++++++++++++--- 4 files changed, 85 insertions(+), 9 deletions(-) diff --git a/src/od65/dump.c b/src/od65/dump.c index 431ced527..0d2dadaeb 100644 --- a/src/od65/dump.c +++ b/src/od65/dump.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2001 Ullrich von Bassewitz */ +/* (C) 2000-2002 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ /* EMail: uz@cc65.org */ @@ -744,4 +744,56 @@ void DumpObjLineInfo (FILE* F, unsigned long Offset) +void DumpObjSegSize (FILE* F, unsigned long Offset) +/* Dump the sizes of the segment in the object file */ +{ + ObjHeader H; + unsigned Count; + + /* Seek to the header position */ + FileSeek (F, Offset); + + /* Read the header */ + ReadObjHeader (F, &H); + + /* Seek to the start of the segments */ + FileSeek (F, Offset + H.SegOffs); + + /* Output a header */ + printf (" Segment sizes:\n"); + + /* Read the number of segments */ + Count = ReadVar (F); + + /* Read and print the sizes of all segments */ + while (Count--) { + + /* Read the data for one segments */ + char* Name = ReadStr (F); + unsigned Len = strlen (Name); + unsigned long Size = Read32 (F); + + /* Skip alignment and type */ + (void) Read8 (F); + (void) Read8 (F); + + /* Print the size for this segment */ + printf (" %s:%*s%6lu\n", Name, 24-Len, "", Size); + + /* Free the Name */ + xfree (Name); + + /* Skip the fragments for this segment, counting them */ + while (Size > 0) { + unsigned FragSize = SkipFragment (F); + if (FragSize > Size) { + /* OOPS - file data invalid */ + Error ("Invalid fragment data - file corrupt!"); + } + Size -= FragSize; + } + } +} + + diff --git a/src/od65/dump.h b/src/od65/dump.h index 96a65f725..43d96a7e1 100644 --- a/src/od65/dump.h +++ b/src/od65/dump.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2001 Ullrich von Bassewitz */ +/* (C) 2000-2002 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ /* EMail: uz@cc65.org */ @@ -72,6 +72,9 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset); void DumpObjLineInfo (FILE* F, unsigned long Offset); /* Dump the line infos from an object file */ +void DumpObjSegSize (FILE* F, unsigned long Offset); +/* Dump the sizes of the segment in the object file */ + /* End of dump.h */ diff --git a/src/od65/global.h b/src/od65/global.h index 702e5691a..09eab2c11 100644 --- a/src/od65/global.h +++ b/src/od65/global.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2000-2002 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@musoftware.de */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -52,6 +52,7 @@ #define D_EXPORTS 0x0020U /* Dump exported symbols */ #define D_DBGSYMS 0x0040U /* Dump debug symbols */ #define D_LINEINFO 0x0080U /* Dump line infos */ +#define D_SEGSIZE 0x0100U /* Dump segment sizes */ #define D_ALL 0xFFFFU /* Dump anything */ diff --git a/src/od65/main.c b/src/od65/main.c index d3171f776..a79bc0bd0 100644 --- a/src/od65/main.c +++ b/src/od65/main.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2001 Ullrich von Bassewitz */ +/* (C) 2000-2002 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ /* EMail: uz@cc65.org */ @@ -74,6 +74,8 @@ static void Usage (void) "Usage: %s [options] file [options] [file]\n" "Short options:\n" " -h\t\t\tHelp (this text)\n" + " -H\t\t\tDump the object file header\n" + " -S\t\t\tDump segments sizes\n" " -V\t\t\tPrint the version number and exit\n" "\n" "Long options:\n" @@ -86,6 +88,7 @@ static void Usage (void) " --dump-lineinfo\tDump line information\n" " --dump-options\tDump object file options\n" " --dump-segments\tDump the segments in the file\n" + " --dump-segsize\tDump segments sizes\n" " --help\t\tHelp (this text)\n" " --version\t\tPrint the version number and exit\n", ProgName); @@ -174,6 +177,15 @@ static void OptDumpSegments (const char* Opt attribute ((unused)), +static void OptDumpSegSize (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Dump the segments in the object file */ +{ + What |= D_SEGSIZE; +} + + + static void OptHelp (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Print usage information and exit */ @@ -250,6 +262,9 @@ static void DumpFile (const char* Name) if (What & D_LINEINFO) { DumpObjLineInfo (F, 0); } + if (What & D_SEGSIZE) { + DumpObjSegSize (F, 0); + } } /* Close the file */ @@ -272,8 +287,9 @@ int main (int argc, char* argv []) { "--dump-lineinfo", 0, OptDumpLineInfo }, { "--dump-options", 0, OptDumpOptions }, { "--dump-segments", 0, OptDumpSegments }, - { "--help", 0, OptHelp }, - { "--version", 0, OptVersion }, + { "--dump-segsize", 0, OptDumpSegSize }, + { "--help", 0, OptHelp }, + { "--version", 0, OptVersion }, }; unsigned I; @@ -304,6 +320,10 @@ int main (int argc, char* argv []) OptDumpHeader (Arg, 0); break; + case 'S': + OptDumpSegSize (Arg, 0); + break; + case 'V': OptVersion (Arg, 0); break; -- 2.39.5