1 /*****************************************************************************/
5 /* Main program of the od65 object file dump utility */
9 /* (C) 2000-2002 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
60 static unsigned FilesProcessed = 0;
64 /*****************************************************************************/
66 /*****************************************************************************/
70 static void Usage (void)
71 /* Print usage information and exit */
74 "Usage: %s [options] file [options] [file]\n"
76 " -h\t\t\tHelp (this text)\n"
77 " -H\t\t\tDump the object file header\n"
78 " -S\t\t\tDump segments sizes\n"
79 " -V\t\t\tPrint the version number and exit\n"
82 " --dump-all\t\tDump all object file information\n"
83 " --dump-dbgsyms\tDump debug symbols\n"
84 " --dump-exports\tDump exported symbols\n"
85 " --dump-files\t\tDump the source files\n"
86 " --dump-header\t\tDump the object file header\n"
87 " --dump-imports\tDump imported symbols\n"
88 " --dump-lineinfo\tDump line information\n"
89 " --dump-options\tDump object file options\n"
90 " --dump-segments\tDump the segments in the file\n"
91 " --dump-segsize\tDump segments sizes\n"
92 " --help\t\tHelp (this text)\n"
93 " --version\t\tPrint the version number and exit\n",
99 static void OptDumpAll (const char* Opt attribute ((unused)),
100 const char* Arg attribute ((unused)))
101 /* Dump all object file information */
108 static void OptDumpDbgSyms (const char* Opt attribute ((unused)),
109 const char* Arg attribute ((unused)))
110 /* Dump debug symbols contained in the object file */
117 static void OptDumpExports (const char* Opt attribute ((unused)),
118 const char* Arg attribute ((unused)))
119 /* Dump the exported symbols */
126 static void OptDumpFiles (const char* Opt attribute ((unused)),
127 const char* Arg attribute ((unused)))
128 /* Dump the source files */
135 static void OptDumpHeader (const char* Opt attribute ((unused)),
136 const char* Arg attribute ((unused)))
137 /* Dump the object file header */
144 static void OptDumpImports (const char* Opt attribute ((unused)),
145 const char* Arg attribute ((unused)))
146 /* Dump the imported symbols */
153 static void OptDumpLineInfo (const char* Opt attribute ((unused)),
154 const char* Arg attribute ((unused)))
155 /* Dump the line infos */
162 static void OptDumpOptions (const char* Opt attribute ((unused)),
163 const char* Arg attribute ((unused)))
164 /* Dump the object file options */
171 static void OptDumpSegments (const char* Opt attribute ((unused)),
172 const char* Arg attribute ((unused)))
173 /* Dump the segments in the object file */
180 static void OptDumpSegSize (const char* Opt attribute ((unused)),
181 const char* Arg attribute ((unused)))
182 /* Dump the segments in the object file */
189 static void OptHelp (const char* Opt attribute ((unused)),
190 const char* Arg attribute ((unused)))
191 /* Print usage information and exit */
199 static void OptVersion (const char* Opt attribute ((unused)),
200 const char* Arg attribute ((unused)))
201 /* Print the assembler version */
204 "%s V%u.%u.%u - (C) Copyright 2000-2002 Ullrich von Bassewitz\n",
205 ProgName, VER_MAJOR, VER_MINOR, VER_PATCH);
210 static void DumpFile (const char* Name)
211 /* Dump information from the named file */
215 /* Try to open the file */
216 FILE* F = fopen (Name, "rb");
218 Error ("Cannot open `%s': %s", Name, strerror (errno));
221 /* Read the magic word */
224 /* Do we know this type of file? */
225 if (Magic != OBJ_MAGIC) {
228 printf ("%s: (no xo65 object file)\n", Name);
230 } else if (What == 0) {
232 /* Special handling if no info was requested */
233 printf ("%s: (no information requested)\n", Name);
237 /* Print the filename */
238 printf ("%s:\n", Name);
240 /* Check what to dump */
241 if (What & D_HEADER) {
242 DumpObjHeader (F, 0);
244 if (What & D_OPTIONS) {
245 DumpObjOptions (F, 0);
247 if (What & D_FILES) {
250 if (What & D_SEGMENTS) {
251 DumpObjSegments (F, 0);
253 if (What & D_IMPORTS) {
254 DumpObjImports (F, 0);
256 if (What & D_EXPORTS) {
257 DumpObjExports (F, 0);
259 if (What & D_DBGSYMS) {
260 DumpObjDbgSyms (F, 0);
262 if (What & D_LINEINFO) {
263 DumpObjLineInfo (F, 0);
265 if (What & D_SEGSIZE) {
266 DumpObjSegSize (F, 0);
276 int main (int argc, char* argv [])
277 /* Assembler main program */
279 /* Program long options */
280 static const LongOpt OptTab[] = {
281 { "--dump-all", 0, OptDumpAll },
282 { "--dump-dbgsyms", 0, OptDumpDbgSyms },
283 { "--dump-exports", 0, OptDumpExports },
284 { "--dump-files", 0, OptDumpFiles },
285 { "--dump-header", 0, OptDumpHeader },
286 { "--dump-imports", 0, OptDumpImports },
287 { "--dump-lineinfo", 0, OptDumpLineInfo },
288 { "--dump-options", 0, OptDumpOptions },
289 { "--dump-segments", 0, OptDumpSegments },
290 { "--dump-segsize", 0, OptDumpSegSize },
291 { "--help", 0, OptHelp },
292 { "--version", 0, OptVersion },
297 /* Initialize the cmdline module */
298 InitCmdLine (&argc, &argv, "od65");
300 /* Check the parameters */
302 while (I < ArgCount) {
304 /* Get the argument */
305 const char* Arg = ArgVec[I];
307 /* Check for an option */
308 if (Arg [0] == '-') {
312 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
320 OptDumpHeader (Arg, 0);
324 OptDumpSegSize (Arg, 0);
337 /* Filename. Dump it. */
346 /* Print a message if we did not process any files */
347 if (FilesProcessed == 0) {
348 fprintf (stderr, "%s: No input files\n", ProgName);