1 /*****************************************************************************/
5 /* Main program of the od65 object file dump utility */
9 /* (C) 2000-2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
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 */
73 printf ("Usage: %s [options] file [options] [file]\n"
75 " -h\t\t\tHelp (this text)\n"
76 " -H\t\t\tDump the object file header\n"
77 " -S\t\t\tDump segments sizes\n"
78 " -V\t\t\tPrint the version number and exit\n"
81 " --dump-all\t\tDump all object file information\n"
82 " --dump-dbgsyms\tDump debug symbols\n"
83 " --dump-exports\tDump exported symbols\n"
84 " --dump-files\t\tDump the source files\n"
85 " --dump-header\t\tDump the object file header\n"
86 " --dump-imports\tDump imported symbols\n"
87 " --dump-lineinfo\tDump line information\n"
88 " --dump-options\tDump object file options\n"
89 " --dump-segments\tDump the segments in the file\n"
90 " --dump-segsize\tDump segments sizes\n"
91 " --help\t\tHelp (this text)\n"
92 " --version\t\tPrint the version number and exit\n",
98 static void OptDumpAll (const char* Opt attribute ((unused)),
99 const char* Arg attribute ((unused)))
100 /* Dump all object file information */
107 static void OptDumpDbgSyms (const char* Opt attribute ((unused)),
108 const char* Arg attribute ((unused)))
109 /* Dump debug symbols contained in the object file */
116 static void OptDumpExports (const char* Opt attribute ((unused)),
117 const char* Arg attribute ((unused)))
118 /* Dump the exported symbols */
125 static void OptDumpFiles (const char* Opt attribute ((unused)),
126 const char* Arg attribute ((unused)))
127 /* Dump the source files */
134 static void OptDumpHeader (const char* Opt attribute ((unused)),
135 const char* Arg attribute ((unused)))
136 /* Dump the object file header */
143 static void OptDumpImports (const char* Opt attribute ((unused)),
144 const char* Arg attribute ((unused)))
145 /* Dump the imported symbols */
152 static void OptDumpLineInfo (const char* Opt attribute ((unused)),
153 const char* Arg attribute ((unused)))
154 /* Dump the line infos */
161 static void OptDumpOptions (const char* Opt attribute ((unused)),
162 const char* Arg attribute ((unused)))
163 /* Dump the object file options */
170 static void OptDumpScopes (const char* Opt attribute ((unused)),
171 const char* Arg attribute ((unused)))
172 /* Dump the scopes in the object file */
179 static void OptDumpSegments (const char* Opt attribute ((unused)),
180 const char* Arg attribute ((unused)))
181 /* Dump the segments in the object file */
188 static void OptDumpSegSize (const char* Opt attribute ((unused)),
189 const char* Arg attribute ((unused)))
190 /* Dump the segments in the object file */
197 static void OptHelp (const char* Opt attribute ((unused)),
198 const char* Arg attribute ((unused)))
199 /* Print usage information and exit */
207 static void OptVersion (const char* Opt attribute ((unused)),
208 const char* Arg attribute ((unused)))
209 /* Print the assembler version */
212 "%s V%s - (C) Copyright 2000-2011, Ullrich von Bassewitz\n",
213 ProgName, GetVersionAsString ());
218 static void DumpFile (const char* Name)
219 /* Dump information from the named file */
223 /* Try to open the file */
224 FILE* F = fopen (Name, "rb");
226 Error ("Cannot open `%s': %s", Name, strerror (errno));
229 /* Read the magic word */
232 /* Do we know this type of file? */
233 if (Magic != OBJ_MAGIC) {
236 printf ("%s: (no xo65 object file)\n", Name);
238 } else if (What == 0) {
240 /* Special handling if no info was requested */
241 printf ("%s: (no information requested)\n", Name);
245 /* Print the filename */
246 printf ("%s:\n", Name);
248 /* Check what to dump */
249 if (What & D_HEADER) {
250 DumpObjHeader (F, 0);
252 if (What & D_OPTIONS) {
253 DumpObjOptions (F, 0);
255 if (What & D_FILES) {
258 if (What & D_SEGMENTS) {
259 DumpObjSegments (F, 0);
261 if (What & D_IMPORTS) {
262 DumpObjImports (F, 0);
264 if (What & D_EXPORTS) {
265 DumpObjExports (F, 0);
267 if (What & D_DBGSYMS) {
268 DumpObjDbgSyms (F, 0);
270 if (What & D_LINEINFO) {
271 DumpObjLineInfo (F, 0);
273 if (What & D_SCOPES) {
274 DumpObjScopes (F, 0);
276 if (What & D_SEGSIZE) {
277 DumpObjSegSize (F, 0);
287 int main (int argc, char* argv [])
288 /* Assembler main program */
290 /* Program long options */
291 static const LongOpt OptTab[] = {
292 { "--dump-all", 0, OptDumpAll },
293 { "--dump-dbgsyms", 0, OptDumpDbgSyms },
294 { "--dump-exports", 0, OptDumpExports },
295 { "--dump-files", 0, OptDumpFiles },
296 { "--dump-header", 0, OptDumpHeader },
297 { "--dump-imports", 0, OptDumpImports },
298 { "--dump-lineinfo", 0, OptDumpLineInfo },
299 { "--dump-options", 0, OptDumpOptions },
300 { "--dump-scopes", 0, OptDumpScopes },
301 { "--dump-segments", 0, OptDumpSegments },
302 { "--dump-segsize", 0, OptDumpSegSize },
303 { "--help", 0, OptHelp },
304 { "--version", 0, OptVersion },
309 /* Initialize the cmdline module */
310 InitCmdLine (&argc, &argv, "od65");
312 /* Check the parameters */
314 while (I < ArgCount) {
316 /* Get the argument */
317 const char* Arg = ArgVec[I];
319 /* Check for an option */
320 if (Arg [0] == '-') {
324 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
332 OptDumpHeader (Arg, 0);
336 OptDumpSegSize (Arg, 0);
349 /* Filename. Dump it. */
358 /* Print a message if we did not process any files */
359 if (FilesProcessed == 0) {
360 fprintf (stderr, "%s: No input files\n", ProgName);