1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 17:30:50 +00:00

Added dump of exports and imports

git-svn-id: svn://svn.cc65.org/cc65/trunk@240 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-07-30 21:02:44 +00:00
parent f91833caef
commit 3eabe5026f
3 changed files with 158 additions and 6 deletions

View File

@ -41,6 +41,7 @@
#include "objdefs.h"
#include "optdefs.h"
#include "segdefs.h"
#include "symdefs.h"
#include "xmalloc.h"
/* od65 */
@ -363,7 +364,7 @@ void DumpObjFiles (FILE* F, unsigned long Offset)
Count = Read8 (F);
printf (" Count:%27u\n", Count);
/* Read and print all options */
/* Read and print all files */
for (I = 0; I < Count; ++I) {
/* Read the data for one file */
@ -407,11 +408,11 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
/* Output a header */
printf (" Segments:\n");
/* Read the number of files and print it */
/* Read the number of segments and print it */
Count = Read8 (F);
printf (" Count:%27u\n", Count);
/* Read and print all options */
/* Read and print all segments */
for (I = 0; I < Count; ++I) {
/* Read the data for one segments */
@ -428,7 +429,7 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
case SEGTYPE_ABS: TypeDesc = "SEGTYPE_ABS"; break;
case SEGTYPE_ZP: TypeDesc = "SEGTYPE_ZP"; break;
case SEGTYPE_FAR: TypeDesc = "SEGTYPE_FAR"; break;
default: TypeDesc = "SEGTYPE_UNKNOWN"; break;
default: TypeDesc = "SEGTYPE_UNKNOWN"; break;
}
/* Print the header */
@ -462,3 +463,122 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
void DumpObjImports (FILE* F, unsigned long Offset)
/* Dump the imports in the 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.ImportOffs);
/* Output a header */
printf (" Imports:\n");
/* Read the number of imports and print it */
Count = Read16 (F);
printf (" Count:%27u\n", Count);
/* Read and print all imports */
for (I = 0; I < Count; ++I) {
const char* TypeDesc;
/* Read the data for one import */
unsigned char Type = Read8 (F);
char* Name = ReadMallocedStr (F);
unsigned Len = strlen (Name);
ReadFilePos (F, &Pos);
/* Get a description for the type */
switch (Type) {
case IMP_ZP: TypeDesc = "IMP_ZP"; break;
case IMP_ABS: TypeDesc = "IMP_ABS"; break;
default: TypeDesc = "IMP_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);
/* Free the Name */
xfree (Name);
}
}
void DumpObjExports (FILE* F, unsigned long Offset)
/* Dump the exports in the 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.ExportOffs);
/* Output a header */
printf (" Exports:\n");
/* Read the number of exports and print it */
Count = Read16 (F);
printf (" Count:%27u\n", Count);
/* Read and print all exports */
for (I = 0; I < Count; ++I) {
const char* TypeDesc;
/* Read the data for one export */
unsigned char Type = Read8 (F);
char* Name = ReadMallocedStr (F);
unsigned Len = strlen (Name);
if (Type & EXP_EXPR) {
SkipExpr (F);
} else {
(void) Read32 (F);
}
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);
/* Free the Name */
xfree (Name);
}
}

View File

@ -60,6 +60,12 @@ void DumpObjFiles (FILE* F, unsigned long Offset);
void DumpObjSegments (FILE* F, unsigned long Offset);
/* Dump the segments in the object file */
void DumpObjImports (FILE* F, unsigned long Offset);
/* Dump the imports in the object file */
void DumpObjExports (FILE* F, unsigned long Offset);
/* Dump the exports in the object file */
/* End of dump.h */

View File

@ -77,8 +77,10 @@ static void Usage (void)
" -V\t\t\tPrint the version number and exit\n"
"\n"
"Long options:\n"
" --dump-exports\tDump exported symbols\n"
" --dump-files\t\tDump the source files\n"
" --dump-header\t\tDump the object file header\n"
" --dump-imports\tDump imported symbols\n"
" --dump-options\tDump object file options\n"
" --dump-segments\tDump the segments in the file\n"
" --help\t\tHelp (this text)\n"
@ -88,6 +90,14 @@ static void Usage (void)
static void OptDumpExports (const char* Opt, const char* Arg)
/* Dump the exported symbols */
{
What |= D_EXPORTS;
}
static void OptDumpFiles (const char* Opt, const char* Arg)
/* Dump the source files */
{
@ -104,6 +114,14 @@ static void OptDumpHeader (const char* Opt, const char* Arg)
static void OptDumpImports (const char* Opt, const char* Arg)
/* Dump the imported symbols */
{
What |= D_IMPORTS;
}
static void OptDumpOptions (const char* Opt, const char* Arg)
/* Dump the object file options */
{
@ -178,11 +196,17 @@ static void DumpFile (const char* Name)
}
if (What & D_FILES) {
DumpObjFiles (F, 0);
}
}
if (What & D_SEGMENTS) {
DumpObjSegments (F, 0);
}
}
if (What & D_IMPORTS) {
DumpObjImports (F, 0);
}
if (What & D_EXPORTS) {
DumpObjExports (F, 0);
}
}
/* Close the file */
fclose (F);
@ -195,8 +219,10 @@ int main (int argc, char* argv [])
{
/* Program long options */
static const LongOpt OptTab[] = {
{ "--dump-exports", 0, OptDumpExports },
{ "--dump-files", 0, OptDumpFiles },
{ "--dump-header", 0, OptDumpHeader },
{ "--dump-imports", 0, OptDumpImports },
{ "--dump-options", 0, OptDumpOptions },
{ "--dump-segments", 0, OptDumpSegments },
{ "--help", 0, OptHelp },