1 /*****************************************************************************/
5 /* Main program of the od65 object file dump utility */
9 /* (C) 2000-2001 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 " -V\t\t\tPrint the version number and exit\n"
80 " --dump-all\t\tDump all object file information\n"
81 " --dump-dbgsyms\tDump debug symbols\n"
82 " --dump-exports\tDump exported symbols\n"
83 " --dump-files\t\tDump the source files\n"
84 " --dump-header\t\tDump the object file header\n"
85 " --dump-imports\tDump imported symbols\n"
86 " --dump-lineinfo\tDump line information\n"
87 " --dump-options\tDump object file options\n"
88 " --dump-segments\tDump the segments in the file\n"
89 " --help\t\tHelp (this text)\n"
90 " --version\t\tPrint the version number and exit\n",
96 static void OptDumpAll (const char* Opt attribute ((unused)),
97 const char* Arg attribute ((unused)))
98 /* Dump all object file information */
105 static void OptDumpDbgSyms (const char* Opt attribute ((unused)),
106 const char* Arg attribute ((unused)))
107 /* Dump debug symbols contained in the object file */
114 static void OptDumpExports (const char* Opt attribute ((unused)),
115 const char* Arg attribute ((unused)))
116 /* Dump the exported symbols */
123 static void OptDumpFiles (const char* Opt attribute ((unused)),
124 const char* Arg attribute ((unused)))
125 /* Dump the source files */
132 static void OptDumpHeader (const char* Opt attribute ((unused)),
133 const char* Arg attribute ((unused)))
134 /* Dump the object file header */
141 static void OptDumpImports (const char* Opt attribute ((unused)),
142 const char* Arg attribute ((unused)))
143 /* Dump the imported symbols */
150 static void OptDumpLineInfo (const char* Opt attribute ((unused)),
151 const char* Arg attribute ((unused)))
152 /* Dump the line infos */
159 static void OptDumpOptions (const char* Opt attribute ((unused)),
160 const char* Arg attribute ((unused)))
161 /* Dump the object file options */
168 static void OptDumpSegments (const char* Opt attribute ((unused)),
169 const char* Arg attribute ((unused)))
170 /* Dump the segments in the object file */
177 static void OptHelp (const char* Opt attribute ((unused)),
178 const char* Arg attribute ((unused)))
179 /* Print usage information and exit */
187 static void OptVersion (const char* Opt attribute ((unused)),
188 const char* Arg attribute ((unused)))
189 /* Print the assembler version */
192 "%s V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n",
193 ProgName, VER_MAJOR, VER_MINOR, VER_PATCH);
198 static void DumpFile (const char* Name)
199 /* Dump information from the named file */
203 /* Try to open the file */
204 FILE* F = fopen (Name, "rb");
206 Warning ("Cannot open `%s': %s", Name, strerror (errno));
209 /* Read the magic word */
212 /* Do we know this type of file? */
213 if (Magic != OBJ_MAGIC) {
216 printf ("%s: (no xo65 object file)\n", Name);
218 } else if (What == 0) {
220 /* Special handling if no info was requested */
221 printf ("%s: (no information requested)\n", Name);
225 /* Print the filename */
226 printf ("%s:\n", Name);
228 /* Check what to dump */
229 if (What & D_HEADER) {
230 DumpObjHeader (F, 0);
232 if (What & D_OPTIONS) {
233 DumpObjOptions (F, 0);
235 if (What & D_FILES) {
238 if (What & D_SEGMENTS) {
239 DumpObjSegments (F, 0);
241 if (What & D_IMPORTS) {
242 DumpObjImports (F, 0);
244 if (What & D_EXPORTS) {
245 DumpObjExports (F, 0);
247 if (What & D_DBGSYMS) {
248 DumpObjDbgSyms (F, 0);
250 if (What & D_LINEINFO) {
251 DumpObjLineInfo (F, 0);
261 int main (int argc, char* argv [])
262 /* Assembler main program */
264 /* Program long options */
265 static const LongOpt OptTab[] = {
266 { "--dump-all", 0, OptDumpAll },
267 { "--dump-dbgsyms", 0, OptDumpDbgSyms },
268 { "--dump-exports", 0, OptDumpExports },
269 { "--dump-files", 0, OptDumpFiles },
270 { "--dump-header", 0, OptDumpHeader },
271 { "--dump-imports", 0, OptDumpImports },
272 { "--dump-lineinfo", 0, OptDumpLineInfo },
273 { "--dump-options", 0, OptDumpOptions },
274 { "--dump-segments", 0, OptDumpSegments },
275 { "--help", 0, OptHelp },
276 { "--version", 0, OptVersion },
281 /* Initialize the cmdline module */
282 InitCmdLine (&argc, &argv, "od65");
284 /* Check the parameters */
286 while (I < ArgCount) {
288 /* Get the argument */
289 const char* Arg = ArgVec[I];
291 /* Check for an option */
292 if (Arg [0] == '-') {
296 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
304 OptDumpHeader (Arg, 0);
317 /* Filename. Dump it. */
326 /* Print a message if we did not process any files */
327 if (FilesProcessed == 0) {
328 fprintf (stderr, "%s: No input files\n", ProgName);