1 | /* $Id: $ */
|
---|
2 | /** @file
|
---|
3 | * kDbgDump - Debug Info Dumper.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
8 | *
|
---|
9 | * This file is part of kLIBC.
|
---|
10 | *
|
---|
11 | * kLIBC is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kLIBC is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kLIBC; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include <k/kDbg.h>
|
---|
31 | #include <string.h>
|
---|
32 | #include <stdio.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*******************************************************************************
|
---|
36 | * Global Variables *
|
---|
37 | *******************************************************************************/
|
---|
38 | /** @name Options
|
---|
39 | * @{ */
|
---|
40 | static int g_fGlobalSyms = 1;
|
---|
41 | static int g_fPrivateSyms = 1;
|
---|
42 | static int g_fLineNumbers = 0;
|
---|
43 | /** @} */
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Dumps one file.
|
---|
48 | *
|
---|
49 | * @returns main exit status.
|
---|
50 | * @param pszFile The file to dump (path to it).
|
---|
51 | */
|
---|
52 | static int DumpFile(const char *pszFile)
|
---|
53 | {
|
---|
54 | PKDBGMOD pDbgMod;
|
---|
55 | int rc = kDbgModuleOpen(&pDbgMod, pszFile, NULL);
|
---|
56 | if (rc)
|
---|
57 | {
|
---|
58 | printf("kDbgDump: error: kDbgModuleOpen('%s',) failed with rc=%d.\n", pszFile, rc);
|
---|
59 | return 1;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Prints the version number
|
---|
70 | * @return 0
|
---|
71 | */
|
---|
72 | static int ShowVersion()
|
---|
73 | {
|
---|
74 | printf("kDbgDump v0.0.1\n");
|
---|
75 | return 0;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Prints the program syntax.
|
---|
81 | *
|
---|
82 | * @returns 1
|
---|
83 | * @param argv0 The program name.
|
---|
84 | */
|
---|
85 | static int ShowSyntax(const char *argv0)
|
---|
86 | {
|
---|
87 | ShowVersion();
|
---|
88 | printf("syntax: %s [options] <files>\n"
|
---|
89 | "\n",
|
---|
90 | argv0);
|
---|
91 | return 1;
|
---|
92 | }
|
---|
93 |
|
---|
94 | int main(int argc, char **argv)
|
---|
95 | {
|
---|
96 | int rcRet = 0;
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * Parse arguments.
|
---|
100 | */
|
---|
101 | int fArgsDone = 0;
|
---|
102 | for (int i = 1; i < argc; i++)
|
---|
103 | {
|
---|
104 | const char *psz = argv[i];
|
---|
105 |
|
---|
106 | if (!fArgsDone && psz[0] == '-' && psz[1])
|
---|
107 | {
|
---|
108 | /* convert long option to short. */
|
---|
109 | if (*++psz == '-')
|
---|
110 | {
|
---|
111 | psz++;
|
---|
112 | if (!*psz) /* -- */
|
---|
113 | {
|
---|
114 | fArgsDone = 1;
|
---|
115 | continue;
|
---|
116 | }
|
---|
117 | if (!strcmp(psz, "line-numbers"))
|
---|
118 | psz = "l";
|
---|
119 | else if (!strcmp(psz, "no-line-numbers"))
|
---|
120 | psz = "L";
|
---|
121 | else if (!strcmp(psz, "global-syms") || !strcmp(psz, "public-syms"))
|
---|
122 | psz = "g";
|
---|
123 | else if (!strcmp(psz, "no-global-syms") || !strcmp(psz, "no-public-syms"))
|
---|
124 | psz = "G";
|
---|
125 | else if (!strcmp(psz, "privat-syms") || !strcmp(psz, "local-syms"))
|
---|
126 | psz = "p";
|
---|
127 | else if (!strcmp(psz, "no-privat-syms") || !strcmp(psz, "no-local-syms"))
|
---|
128 | psz = "P";
|
---|
129 | else if (!strcmp(psz, "version"))
|
---|
130 | psz = "v";
|
---|
131 | else if (!strcmp(psz, "help"))
|
---|
132 | psz = "h";
|
---|
133 | else
|
---|
134 | {
|
---|
135 | fprintf(stderr, "%s: syntax error: unknown option '--%s'\n", argv[0], psz);
|
---|
136 | return 1;
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | /* eat short options. */
|
---|
141 | while (*psz)
|
---|
142 | switch (*psz++)
|
---|
143 | {
|
---|
144 | case 'l': g_fLineNumbers = 1; break;
|
---|
145 | case 'L': g_fLineNumbers = 0; break;
|
---|
146 | case 'p': g_fPrivateSyms = 1; break;
|
---|
147 | case 'P': g_fPrivateSyms = 0; break;
|
---|
148 | case 'g': g_fGlobalSyms = 1; break;
|
---|
149 | case 'G': g_fGlobalSyms = 0; break;
|
---|
150 | case '?':
|
---|
151 | case 'H':
|
---|
152 | case 'h': return ShowSyntax(argv[0]);
|
---|
153 | case 'v': return ShowVersion();
|
---|
154 | default:
|
---|
155 | fprintf(stderr, "%s: syntax error: unknown option '-%c'.\n", argv[0], psz[-1]);
|
---|
156 | return 1;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | else
|
---|
160 | {
|
---|
161 | /* Dump does it's own bitching if something goes wrong. */
|
---|
162 | int rc = DumpFile(psz);
|
---|
163 | if (rc && !rcRet)
|
---|
164 | rc = rcRet;
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | return rcRet;
|
---|
169 | }
|
---|
170 |
|
---|