]>
Commit | Line | Data |
---|---|---|
7e258d18 | 1 | /* Do various things to symbol tables (other than lookup), for GDB. |
2b576293 C |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
4a35d6e9 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
4a35d6e9 FF |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
4a35d6e9 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
4a35d6e9 FF |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 20 | |
bd5635a1 | 21 | #include "defs.h" |
bd5635a1 | 22 | #include "symtab.h" |
318bf84f | 23 | #include "gdbtypes.h" |
4a35d6e9 FF |
24 | #include "bfd.h" |
25 | #include "symfile.h" | |
d630b615 | 26 | #include "objfiles.h" |
bd5635a1 RP |
27 | #include "breakpoint.h" |
28 | #include "command.h" | |
7e258d18 | 29 | #include "obstack.h" |
51b57ded | 30 | #include "language.h" |
bd5635a1 | 31 | |
2b576293 | 32 | #include "gdb_string.h" |
318bf84f FF |
33 | |
34 | #ifndef DEV_TTY | |
35 | #define DEV_TTY "/dev/tty" | |
36 | #endif | |
37 | ||
018ab14f PS |
38 | /* Unfortunately for debugging, stderr is usually a macro. This is painful |
39 | when calling functions that take FILE *'s from the debugger. | |
40 | So we make a variable which has the same value and which is accessible when | |
41 | debugging GDB with itself. Because stdin et al need not be constants, | |
42 | we initialize them in the _initialize_symmisc function at the bottom | |
43 | of the file. */ | |
44 | FILE *std_in; | |
45 | FILE *std_out; | |
46 | FILE *std_err; | |
d630b615 | 47 | |
318bf84f FF |
48 | /* Prototypes for local functions */ |
49 | ||
d630b615 | 50 | static void |
833e0d94 | 51 | dump_symtab PARAMS ((struct objfile *, struct symtab *, GDB_FILE *)); |
318bf84f | 52 | |
d630b615 | 53 | static void |
833e0d94 | 54 | dump_psymtab PARAMS ((struct objfile *, struct partial_symtab *, GDB_FILE *)); |
318bf84f | 55 | |
d630b615 | 56 | static void |
833e0d94 | 57 | dump_msymbols PARAMS ((struct objfile *, GDB_FILE *)); |
318bf84f | 58 | |
d630b615 FF |
59 | static void |
60 | dump_objfile PARAMS ((struct objfile *)); | |
318bf84f | 61 | |
318bf84f FF |
62 | static int |
63 | block_depth PARAMS ((struct block *)); | |
64 | ||
65 | static void | |
833e0d94 | 66 | print_partial_symbol PARAMS ((struct partial_symbol *, int, char *, GDB_FILE *)); |
318bf84f | 67 | |
13bd9622 JK |
68 | struct print_symbol_args { |
69 | struct symbol *symbol; | |
70 | int depth; | |
833e0d94 | 71 | GDB_FILE *outfile; |
13bd9622 JK |
72 | }; |
73 | ||
74 | static int print_symbol PARAMS ((char *)); | |
318bf84f | 75 | |
318bf84f FF |
76 | static void |
77 | free_symtab_block PARAMS ((struct objfile *, struct block *)); | |
78 | ||
bd5635a1 | 79 | \f |
bd5635a1 RP |
80 | /* Free a struct block <- B and all the symbols defined in that block. */ |
81 | ||
82 | static void | |
318bf84f FF |
83 | free_symtab_block (objfile, b) |
84 | struct objfile *objfile; | |
bd5635a1 RP |
85 | struct block *b; |
86 | { | |
87 | register int i, n; | |
88 | n = BLOCK_NSYMS (b); | |
89 | for (i = 0; i < n; i++) | |
90 | { | |
318bf84f | 91 | mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i))); |
d630b615 | 92 | mfree (objfile -> md, (PTR) BLOCK_SYM (b, i)); |
bd5635a1 | 93 | } |
d630b615 | 94 | mfree (objfile -> md, (PTR) b); |
bd5635a1 RP |
95 | } |
96 | ||
97 | /* Free all the storage associated with the struct symtab <- S. | |
98 | Note that some symtabs have contents malloc'ed structure by structure, | |
99 | while some have contents that all live inside one big block of memory, | |
100 | and some share the contents of another symbol table and so you should | |
101 | not free the contents on their behalf (except sometimes the linetable, | |
102 | which maybe per symtab even when the rest is not). | |
103 | It is s->free_code that says which alternative to use. */ | |
104 | ||
029981e2 | 105 | void |
bd5635a1 RP |
106 | free_symtab (s) |
107 | register struct symtab *s; | |
108 | { | |
109 | register int i, n; | |
110 | register struct blockvector *bv; | |
bd5635a1 RP |
111 | |
112 | switch (s->free_code) | |
113 | { | |
114 | case free_nothing: | |
029981e2 | 115 | /* All the contents are part of a big block of memory (an obstack), |
bd5635a1 RP |
116 | and some other symtab is in charge of freeing that block. |
117 | Therefore, do nothing. */ | |
118 | break; | |
119 | ||
120 | case free_contents: | |
121 | /* Here all the contents were malloc'ed structure by structure | |
122 | and must be freed that way. */ | |
123 | /* First free the blocks (and their symbols. */ | |
124 | bv = BLOCKVECTOR (s); | |
125 | n = BLOCKVECTOR_NBLOCKS (bv); | |
126 | for (i = 0; i < n; i++) | |
318bf84f | 127 | free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i)); |
bd5635a1 | 128 | /* Free the blockvector itself. */ |
d630b615 | 129 | mfree (s -> objfile -> md, (PTR) bv); |
bd5635a1 RP |
130 | /* Also free the linetable. */ |
131 | ||
132 | case free_linetable: | |
133 | /* Everything will be freed either by our `free_ptr' | |
7e258d18 | 134 | or by some other symtab, except for our linetable. |
bd5635a1 | 135 | Free that now. */ |
7e258d18 | 136 | if (LINETABLE (s)) |
d630b615 | 137 | mfree (s -> objfile -> md, (PTR) LINETABLE (s)); |
bd5635a1 RP |
138 | break; |
139 | } | |
140 | ||
141 | /* If there is a single block of memory to free, free it. */ | |
318bf84f FF |
142 | if (s -> free_ptr != NULL) |
143 | mfree (s -> objfile -> md, s -> free_ptr); | |
bd5635a1 RP |
144 | |
145 | /* Free source-related stuff */ | |
318bf84f | 146 | if (s -> line_charpos != NULL) |
d630b615 | 147 | mfree (s -> objfile -> md, (PTR) s -> line_charpos); |
318bf84f FF |
148 | if (s -> fullname != NULL) |
149 | mfree (s -> objfile -> md, s -> fullname); | |
d630b615 | 150 | mfree (s -> objfile -> md, (PTR) s); |
bd5635a1 | 151 | } |
bd5635a1 | 152 | |
a8a69e63 FF |
153 | #if MAINTENANCE_CMDS |
154 | ||
d630b615 FF |
155 | static void |
156 | dump_objfile (objfile) | |
318bf84f | 157 | struct objfile *objfile; |
bd5635a1 | 158 | { |
318bf84f FF |
159 | struct symtab *symtab; |
160 | struct partial_symtab *psymtab; | |
bd5635a1 | 161 | |
318bf84f | 162 | printf_filtered ("\nObject file %s: ", objfile -> name); |
833e0d94 JK |
163 | printf_filtered ("Objfile at "); |
164 | gdb_print_address (objfile, gdb_stdout); | |
165 | printf_filtered (", bfd at "); | |
166 | gdb_print_address (objfile->obfd, gdb_stdout); | |
167 | printf_filtered (", %d minsyms\n\n", | |
168 | objfile->minimal_symbol_count); | |
bd5635a1 | 169 | |
318bf84f FF |
170 | if (objfile -> psymtabs) |
171 | { | |
172 | printf_filtered ("Psymtabs:\n"); | |
173 | for (psymtab = objfile -> psymtabs; | |
174 | psymtab != NULL; | |
175 | psymtab = psymtab -> next) | |
176 | { | |
833e0d94 JK |
177 | printf_filtered ("%s at ", |
178 | psymtab -> filename); | |
5e678752 | 179 | gdb_print_address (psymtab, gdb_stdout); |
833e0d94 | 180 | printf_filtered (", "); |
318bf84f FF |
181 | if (psymtab -> objfile != objfile) |
182 | { | |
183 | printf_filtered ("NOT ON CHAIN! "); | |
184 | } | |
185 | wrap_here (" "); | |
186 | } | |
187 | printf_filtered ("\n\n"); | |
188 | } | |
7e258d18 | 189 | |
318bf84f FF |
190 | if (objfile -> symtabs) |
191 | { | |
192 | printf_filtered ("Symtabs:\n"); | |
193 | for (symtab = objfile -> symtabs; | |
194 | symtab != NULL; | |
195 | symtab = symtab->next) | |
196 | { | |
833e0d94 | 197 | printf_filtered ("%s at ", symtab -> filename); |
5e678752 | 198 | gdb_print_address (symtab, gdb_stdout); |
833e0d94 | 199 | printf_filtered (", "); |
318bf84f FF |
200 | if (symtab -> objfile != objfile) |
201 | { | |
202 | printf_filtered ("NOT ON CHAIN! "); | |
203 | } | |
204 | wrap_here (" "); | |
205 | } | |
206 | printf_filtered ("\n\n"); | |
207 | } | |
318bf84f FF |
208 | } |
209 | ||
d630b615 FF |
210 | /* Print minimal symbols from this objfile. */ |
211 | ||
212 | static void | |
213 | dump_msymbols (objfile, outfile) | |
318bf84f | 214 | struct objfile *objfile; |
833e0d94 | 215 | GDB_FILE *outfile; |
318bf84f | 216 | { |
318bf84f FF |
217 | struct minimal_symbol *msymbol; |
218 | int index; | |
219 | char ms_type; | |
bd5635a1 | 220 | |
d630b615 | 221 | fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name); |
018ab14f PS |
222 | if (objfile -> minimal_symbol_count == 0) |
223 | { | |
224 | fprintf_filtered (outfile, "No minimal symbols found.\n"); | |
225 | return; | |
226 | } | |
d630b615 | 227 | for (index = 0, msymbol = objfile -> msymbols; |
2e4964ad | 228 | SYMBOL_NAME (msymbol) != NULL; msymbol++, index++) |
318bf84f | 229 | { |
d630b615 | 230 | switch (msymbol -> type) |
318bf84f | 231 | { |
d630b615 FF |
232 | case mst_unknown: |
233 | ms_type = 'u'; | |
234 | break; | |
235 | case mst_text: | |
018ab14f | 236 | ms_type = 'T'; |
d630b615 | 237 | break; |
2b576293 C |
238 | case mst_solib_trampoline: |
239 | ms_type = 'S'; | |
240 | break; | |
d630b615 | 241 | case mst_data: |
018ab14f | 242 | ms_type = 'D'; |
d630b615 FF |
243 | break; |
244 | case mst_bss: | |
018ab14f | 245 | ms_type = 'B'; |
d630b615 FF |
246 | break; |
247 | case mst_abs: | |
018ab14f PS |
248 | ms_type = 'A'; |
249 | break; | |
250 | case mst_file_text: | |
251 | ms_type = 't'; | |
252 | break; | |
253 | case mst_file_data: | |
254 | ms_type = 'd'; | |
255 | break; | |
256 | case mst_file_bss: | |
257 | ms_type = 'b'; | |
d630b615 FF |
258 | break; |
259 | default: | |
260 | ms_type = '?'; | |
261 | break; | |
318bf84f | 262 | } |
833e0d94 | 263 | fprintf_filtered (outfile, "[%2d] %c %#10lx %s", index, ms_type, |
2e4964ad | 264 | SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol)); |
7532cf10 | 265 | if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL) |
2e4964ad FF |
266 | { |
267 | fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol)); | |
268 | } | |
2b576293 C |
269 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING |
270 | if (msymbol->filename) | |
271 | fprintf_filtered (outfile, " %s", msymbol->filename); | |
272 | #endif | |
2e4964ad | 273 | fputs_filtered ("\n", outfile); |
d630b615 FF |
274 | } |
275 | if (objfile -> minimal_symbol_count != index) | |
276 | { | |
277 | warning ("internal error: minimal symbol count %d != %d", | |
278 | objfile -> minimal_symbol_count, index); | |
318bf84f | 279 | } |
d630b615 | 280 | fprintf_filtered (outfile, "\n"); |
318bf84f | 281 | } |
bd5635a1 | 282 | |
d630b615 FF |
283 | static void |
284 | dump_psymtab (objfile, psymtab, outfile) | |
318bf84f FF |
285 | struct objfile *objfile; |
286 | struct partial_symtab *psymtab; | |
833e0d94 | 287 | GDB_FILE *outfile; |
318bf84f | 288 | { |
f5d6b0c5 | 289 | int i; |
bd5635a1 | 290 | |
d630b615 FF |
291 | fprintf_filtered (outfile, "\nPartial symtab for source file %s ", |
292 | psymtab -> filename); | |
2b576293 | 293 | fprintf_filtered (outfile, "(object "); |
833e0d94 JK |
294 | gdb_print_address (psymtab, outfile); |
295 | fprintf_filtered (outfile, ")\n\n"); | |
296 | fprintf_unfiltered (outfile, " Read from object file %s (", | |
297 | objfile -> name); | |
298 | gdb_print_address (objfile, outfile); | |
299 | fprintf_unfiltered (outfile, ")\n"); | |
300 | ||
d630b615 | 301 | if (psymtab -> readin) |
bd5635a1 | 302 | { |
d630b615 | 303 | fprintf_filtered (outfile, |
833e0d94 JK |
304 | " Full symtab was read (at "); |
305 | gdb_print_address (psymtab->symtab, outfile); | |
306 | fprintf_filtered (outfile, " by function at "); | |
2b576293 | 307 | gdb_print_address ((PTR)psymtab->read_symtab, outfile); |
833e0d94 JK |
308 | fprintf_filtered (outfile, ")\n"); |
309 | } | |
310 | ||
311 | fprintf_filtered (outfile, " Relocate symbols by "); | |
312 | for (i = 0; i < psymtab->objfile->num_sections; ++i) | |
313 | { | |
2b576293 C |
314 | if (i != 0) |
315 | fprintf_filtered (outfile, ", "); | |
833e0d94 | 316 | wrap_here (" "); |
2b576293 C |
317 | print_address_numeric (ANOFFSET (psymtab->section_offsets, i), |
318 | 1, | |
319 | outfile); | |
318bf84f | 320 | } |
2b576293 | 321 | fprintf_filtered (outfile, "\n"); |
2670f34d | 322 | |
833e0d94 | 323 | fprintf_filtered (outfile, " Symbols cover text addresses "); |
2b576293 | 324 | print_address_numeric (psymtab->textlow, 1, outfile); |
833e0d94 | 325 | fprintf_filtered (outfile, "-"); |
2b576293 | 326 | print_address_numeric (psymtab->texthigh, 1, outfile); |
833e0d94 | 327 | fprintf_filtered (outfile, "\n"); |
d630b615 FF |
328 | fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n", |
329 | psymtab -> number_of_dependencies); | |
f5d6b0c5 PS |
330 | for (i = 0; i < psymtab -> number_of_dependencies; i++) |
331 | { | |
833e0d94 JK |
332 | fprintf_filtered (outfile, " %d ", i); |
333 | gdb_print_address (psymtab -> dependencies[i], outfile); | |
334 | fprintf_filtered (outfile, " %s\n", | |
f5d6b0c5 PS |
335 | psymtab -> dependencies[i] -> filename); |
336 | } | |
d630b615 FF |
337 | if (psymtab -> n_global_syms > 0) |
338 | { | |
339 | print_partial_symbol (objfile -> global_psymbols.list | |
340 | + psymtab -> globals_offset, | |
341 | psymtab -> n_global_syms, "Global", outfile); | |
342 | } | |
343 | if (psymtab -> n_static_syms > 0) | |
344 | { | |
345 | print_partial_symbol (objfile -> static_psymbols.list | |
346 | + psymtab -> statics_offset, | |
347 | psymtab -> n_static_syms, "Static", outfile); | |
348 | } | |
349 | fprintf_filtered (outfile, "\n"); | |
318bf84f | 350 | } |
7e258d18 | 351 | |
d630b615 FF |
352 | static void |
353 | dump_symtab (objfile, symtab, outfile) | |
318bf84f FF |
354 | struct objfile *objfile; |
355 | struct symtab *symtab; | |
833e0d94 | 356 | GDB_FILE *outfile; |
318bf84f | 357 | { |
318bf84f FF |
358 | register int i, j; |
359 | int len, blen; | |
360 | register struct linetable *l; | |
361 | struct blockvector *bv; | |
362 | register struct block *b; | |
363 | int depth; | |
7e258d18 | 364 | |
833e0d94 JK |
365 | fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename); |
366 | fprintf_filtered (outfile, "Read from object file %s (", objfile->name); | |
367 | gdb_print_address (objfile, outfile); | |
368 | fprintf_filtered (outfile, ")\n"); | |
369 | fprintf_filtered (outfile, "Language: %s\n", language_str (symtab -> language)); | |
370 | ||
d630b615 FF |
371 | /* First print the line table. */ |
372 | l = LINETABLE (symtab); | |
833e0d94 JK |
373 | if (l) |
374 | { | |
375 | fprintf_filtered (outfile, "\nLine table:\n\n"); | |
376 | len = l->nitems; | |
377 | for (i = 0; i < len; i++) | |
378 | { | |
379 | fprintf_filtered (outfile, " line %d at ", l->item[i].line); | |
2b576293 | 380 | print_address_numeric (l->item[i].pc, 1, outfile); |
833e0d94 JK |
381 | fprintf_filtered (outfile, "\n"); |
382 | } | |
383 | } | |
d630b615 | 384 | /* Now print the block info. */ |
833e0d94 | 385 | fprintf_filtered (outfile, "\nBlockvector:\n\n"); |
d630b615 FF |
386 | bv = BLOCKVECTOR (symtab); |
387 | len = BLOCKVECTOR_NBLOCKS (bv); | |
388 | for (i = 0; i < len; i++) | |
318bf84f | 389 | { |
d630b615 FF |
390 | b = BLOCKVECTOR_BLOCK (bv, i); |
391 | depth = block_depth (b) * 2; | |
392 | print_spaces (depth, outfile); | |
833e0d94 JK |
393 | fprintf_filtered (outfile, "block #%03d (object ", i); |
394 | gdb_print_address (b, outfile); | |
395 | fprintf_filtered (outfile, ") "); | |
396 | fprintf_filtered (outfile, "["); | |
2b576293 | 397 | print_address_numeric (BLOCK_START (b), 1, outfile); |
833e0d94 | 398 | fprintf_filtered (outfile, ".."); |
2b576293 | 399 | print_address_numeric (BLOCK_END (b), 1, outfile); |
833e0d94 | 400 | fprintf_filtered (outfile, "]"); |
d630b615 | 401 | if (BLOCK_SUPERBLOCK (b)) |
833e0d94 JK |
402 | { |
403 | fprintf_filtered (outfile, " (under "); | |
404 | gdb_print_address (BLOCK_SUPERBLOCK (b), outfile); | |
405 | fprintf_filtered (outfile, ")"); | |
406 | } | |
d630b615 | 407 | if (BLOCK_FUNCTION (b)) |
2e4964ad | 408 | { |
833e0d94 | 409 | fprintf_filtered (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b))); |
7532cf10 | 410 | if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL) |
2e4964ad | 411 | { |
833e0d94 | 412 | fprintf_filtered (outfile, " %s", |
2e4964ad FF |
413 | SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b))); |
414 | } | |
415 | } | |
a8a69e63 | 416 | if (BLOCK_GCC_COMPILED(b)) |
833e0d94 | 417 | fprintf_filtered (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b)); |
2b576293 | 418 | fprintf_filtered (outfile, "\n"); |
d630b615 FF |
419 | blen = BLOCK_NSYMS (b); |
420 | for (j = 0; j < blen; j++) | |
bd5635a1 | 421 | { |
13bd9622 JK |
422 | struct print_symbol_args s; |
423 | s.symbol = BLOCK_SYM (b, j); | |
424 | s.depth = depth + 1; | |
425 | s.outfile = outfile; | |
426 | catch_errors (print_symbol, &s, "Error printing symbol:\n", | |
427 | RETURN_MASK_ERROR); | |
bd5635a1 | 428 | } |
318bf84f | 429 | } |
833e0d94 | 430 | fprintf_filtered (outfile, "\n"); |
318bf84f | 431 | } |
bd5635a1 | 432 | |
a8a69e63 FF |
433 | void |
434 | maintenance_print_symbols (args, from_tty) | |
318bf84f FF |
435 | char *args; |
436 | int from_tty; | |
437 | { | |
438 | char **argv; | |
833e0d94 | 439 | GDB_FILE *outfile; |
318bf84f FF |
440 | struct cleanup *cleanups; |
441 | char *symname = NULL; | |
442 | char *filename = DEV_TTY; | |
d630b615 FF |
443 | struct objfile *objfile; |
444 | struct symtab *s; | |
318bf84f FF |
445 | |
446 | dont_repeat (); | |
447 | ||
448 | if (args == NULL) | |
449 | { | |
2b576293 C |
450 | error ("\ |
451 | Arguments missing: an output file name and an optional symbol file name"); | |
318bf84f FF |
452 | } |
453 | else if ((argv = buildargv (args)) == NULL) | |
454 | { | |
455 | nomem (0); | |
456 | } | |
457 | cleanups = make_cleanup (freeargv, (char *) argv); | |
458 | ||
459 | if (argv[0] != NULL) | |
460 | { | |
461 | filename = argv[0]; | |
462 | /* If a second arg is supplied, it is a source file name to match on */ | |
463 | if (argv[1] != NULL) | |
464 | { | |
465 | symname = argv[1]; | |
466 | } | |
bd5635a1 RP |
467 | } |
468 | ||
318bf84f FF |
469 | filename = tilde_expand (filename); |
470 | make_cleanup (free, filename); | |
471 | ||
833e0d94 | 472 | outfile = gdb_fopen (filename, FOPEN_WT); |
318bf84f FF |
473 | if (outfile == 0) |
474 | perror_with_name (filename); | |
475 | make_cleanup (fclose, (char *) outfile); | |
476 | ||
477 | immediate_quit++; | |
d630b615 | 478 | ALL_SYMTABS (objfile, s) |
2e4964ad | 479 | if (symname == NULL || (STREQ (symname, s -> filename))) |
d630b615 | 480 | dump_symtab (objfile, s, outfile); |
bd5635a1 RP |
481 | immediate_quit--; |
482 | do_cleanups (cleanups); | |
483 | } | |
484 | ||
13bd9622 JK |
485 | /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how |
486 | far to indent. ARGS is really a struct print_symbol_args *, but is | |
996ccb30 JK |
487 | declared as char * to get it past catch_errors. Returns 0 for error, |
488 | 1 for success. */ | |
13bd9622 JK |
489 | |
490 | static int | |
491 | print_symbol (args) | |
492 | char *args; | |
bd5635a1 | 493 | { |
13bd9622 JK |
494 | struct symbol *symbol = ((struct print_symbol_args *)args)->symbol; |
495 | int depth = ((struct print_symbol_args *)args)->depth; | |
833e0d94 | 496 | GDB_FILE *outfile = ((struct print_symbol_args *)args)->outfile; |
13bd9622 | 497 | |
bd5635a1 RP |
498 | print_spaces (depth, outfile); |
499 | if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE) | |
500 | { | |
833e0d94 | 501 | fprintf_filtered (outfile, "label %s at ", SYMBOL_SOURCE_NAME (symbol)); |
2b576293 | 502 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile); |
833e0d94 | 503 | fprintf_filtered (outfile, "\n"); |
996ccb30 | 504 | return 1; |
bd5635a1 RP |
505 | } |
506 | if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE) | |
507 | { | |
833e0d94 | 508 | if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol))) |
bd5635a1 | 509 | { |
a8a69e63 | 510 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth); |
bd5635a1 RP |
511 | } |
512 | else | |
513 | { | |
833e0d94 | 514 | fprintf_filtered (outfile, "%s %s = ", |
bd5635a1 RP |
515 | (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM |
516 | ? "enum" | |
517 | : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT | |
518 | ? "struct" : "union")), | |
519 | SYMBOL_NAME (symbol)); | |
a8a69e63 | 520 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth); |
bd5635a1 | 521 | } |
833e0d94 | 522 | fprintf_filtered (outfile, ";\n"); |
bd5635a1 RP |
523 | } |
524 | else | |
525 | { | |
526 | if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) | |
833e0d94 | 527 | fprintf_filtered (outfile, "typedef "); |
bd5635a1 RP |
528 | if (SYMBOL_TYPE (symbol)) |
529 | { | |
d630b615 | 530 | /* Print details of types, except for enums where it's clutter. */ |
018ab14f PS |
531 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol), |
532 | outfile, | |
a8a69e63 FF |
533 | TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM, |
534 | depth); | |
833e0d94 | 535 | fprintf_filtered (outfile, "; "); |
bd5635a1 RP |
536 | } |
537 | else | |
833e0d94 | 538 | fprintf_filtered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol)); |
bd5635a1 RP |
539 | |
540 | switch (SYMBOL_CLASS (symbol)) | |
541 | { | |
542 | case LOC_CONST: | |
833e0d94 JK |
543 | fprintf_filtered (outfile, "const %ld (0x%lx),", |
544 | SYMBOL_VALUE (symbol), | |
545 | SYMBOL_VALUE (symbol)); | |
bd5635a1 RP |
546 | break; |
547 | ||
548 | case LOC_CONST_BYTES: | |
833e0d94 | 549 | fprintf_filtered (outfile, "const %u hex bytes:", |
bd5635a1 RP |
550 | TYPE_LENGTH (SYMBOL_TYPE (symbol))); |
551 | { | |
552 | unsigned i; | |
553 | for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++) | |
833e0d94 | 554 | fprintf_filtered (outfile, " %02x", |
bd5635a1 | 555 | (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]); |
833e0d94 | 556 | fprintf_filtered (outfile, ","); |
bd5635a1 RP |
557 | } |
558 | break; | |
559 | ||
560 | case LOC_STATIC: | |
833e0d94 | 561 | fprintf_filtered (outfile, "static at "); |
2b576293 | 562 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1,outfile); |
833e0d94 | 563 | fprintf_filtered (outfile, ","); |
bd5635a1 RP |
564 | break; |
565 | ||
566 | case LOC_REGISTER: | |
833e0d94 | 567 | fprintf_filtered (outfile, "register %ld,", SYMBOL_VALUE (symbol)); |
bd5635a1 RP |
568 | break; |
569 | ||
570 | case LOC_ARG: | |
833e0d94 JK |
571 | fprintf_filtered (outfile, "arg at offset 0x%lx,", |
572 | SYMBOL_VALUE (symbol)); | |
bd5635a1 RP |
573 | break; |
574 | ||
575 | case LOC_LOCAL_ARG: | |
833e0d94 | 576 | fprintf_filtered (outfile, "arg at offset 0x%lx from fp,", |
13bd9622 JK |
577 | SYMBOL_VALUE (symbol)); |
578 | break; | |
bd5635a1 RP |
579 | |
580 | case LOC_REF_ARG: | |
833e0d94 | 581 | fprintf_filtered (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol)); |
bd5635a1 RP |
582 | break; |
583 | ||
584 | case LOC_REGPARM: | |
833e0d94 | 585 | fprintf_filtered (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol)); |
bd5635a1 RP |
586 | break; |
587 | ||
018ab14f | 588 | case LOC_REGPARM_ADDR: |
833e0d94 | 589 | fprintf_filtered (outfile, "address parameter register %ld,", SYMBOL_VALUE (symbol)); |
018ab14f PS |
590 | break; |
591 | ||
bd5635a1 | 592 | case LOC_LOCAL: |
833e0d94 JK |
593 | fprintf_filtered (outfile, "local at offset 0x%lx,", |
594 | SYMBOL_VALUE (symbol)); | |
13bd9622 JK |
595 | break; |
596 | ||
597 | case LOC_BASEREG: | |
833e0d94 | 598 | fprintf_filtered (outfile, "local at 0x%lx from register %d", |
13bd9622 JK |
599 | SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol)); |
600 | break; | |
601 | ||
602 | case LOC_BASEREG_ARG: | |
833e0d94 | 603 | fprintf_filtered (outfile, "arg at 0x%lx from register %d,", |
13bd9622 | 604 | SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol)); |
bd5635a1 RP |
605 | break; |
606 | ||
607 | case LOC_TYPEDEF: | |
608 | break; | |
609 | ||
610 | case LOC_LABEL: | |
833e0d94 | 611 | fprintf_filtered (outfile, "label at "); |
2b576293 | 612 | print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile); |
bd5635a1 RP |
613 | break; |
614 | ||
615 | case LOC_BLOCK: | |
833e0d94 JK |
616 | fprintf_filtered (outfile, "block (object "); |
617 | gdb_print_address (SYMBOL_BLOCK_VALUE (symbol), outfile); | |
618 | fprintf_filtered (outfile, ") starting at "); | |
619 | print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)), | |
2b576293 | 620 | 1, |
833e0d94 JK |
621 | outfile); |
622 | fprintf_filtered (outfile, ","); | |
bd5635a1 RP |
623 | break; |
624 | ||
018ab14f | 625 | case LOC_OPTIMIZED_OUT: |
833e0d94 | 626 | fprintf_filtered (outfile, "optimized out"); |
018ab14f PS |
627 | break; |
628 | ||
bd5635a1 | 629 | default: |
833e0d94 JK |
630 | fprintf_filtered (outfile, "botched symbol class %x", |
631 | SYMBOL_CLASS (symbol)); | |
bd5635a1 RP |
632 | break; |
633 | } | |
634 | } | |
833e0d94 | 635 | fprintf_filtered (outfile, "\n"); |
996ccb30 | 636 | return 1; |
bd5635a1 RP |
637 | } |
638 | ||
a8a69e63 FF |
639 | void |
640 | maintenance_print_psymbols (args, from_tty) | |
318bf84f FF |
641 | char *args; |
642 | int from_tty; | |
4a35d6e9 | 643 | { |
318bf84f | 644 | char **argv; |
833e0d94 | 645 | GDB_FILE *outfile; |
4a35d6e9 | 646 | struct cleanup *cleanups; |
318bf84f FF |
647 | char *symname = NULL; |
648 | char *filename = DEV_TTY; | |
d630b615 FF |
649 | struct objfile *objfile; |
650 | struct partial_symtab *ps; | |
4a35d6e9 | 651 | |
318bf84f | 652 | dont_repeat (); |
4a35d6e9 | 653 | |
318bf84f FF |
654 | if (args == NULL) |
655 | { | |
a8a69e63 | 656 | error ("print-psymbols takes an output file name and optional symbol file name"); |
318bf84f FF |
657 | } |
658 | else if ((argv = buildargv (args)) == NULL) | |
659 | { | |
660 | nomem (0); | |
661 | } | |
662 | cleanups = make_cleanup (freeargv, (char *) argv); | |
663 | ||
664 | if (argv[0] != NULL) | |
665 | { | |
666 | filename = argv[0]; | |
667 | /* If a second arg is supplied, it is a source file name to match on */ | |
668 | if (argv[1] != NULL) | |
669 | { | |
670 | symname = argv[1]; | |
671 | } | |
672 | } | |
7e258d18 | 673 | |
4a35d6e9 FF |
674 | filename = tilde_expand (filename); |
675 | make_cleanup (free, filename); | |
676 | ||
833e0d94 | 677 | outfile = gdb_fopen (filename, FOPEN_WT); |
4a35d6e9 FF |
678 | if (outfile == 0) |
679 | perror_with_name (filename); | |
318bf84f | 680 | make_cleanup (fclose, outfile); |
4a35d6e9 | 681 | |
4a35d6e9 | 682 | immediate_quit++; |
d630b615 | 683 | ALL_PSYMTABS (objfile, ps) |
2e4964ad | 684 | if (symname == NULL || (STREQ (symname, ps -> filename))) |
d630b615 | 685 | dump_psymtab (objfile, ps, outfile); |
4a35d6e9 FF |
686 | immediate_quit--; |
687 | do_cleanups (cleanups); | |
688 | } | |
689 | ||
690 | static void | |
691 | print_partial_symbol (p, count, what, outfile) | |
318bf84f FF |
692 | struct partial_symbol *p; |
693 | int count; | |
694 | char *what; | |
833e0d94 | 695 | GDB_FILE *outfile; |
4a35d6e9 | 696 | { |
4a35d6e9 FF |
697 | |
698 | fprintf_filtered (outfile, " %s partial symbols:\n", what); | |
699 | while (count-- > 0) | |
700 | { | |
2e4964ad | 701 | fprintf_filtered (outfile, " `%s'", SYMBOL_NAME(p)); |
7532cf10 | 702 | if (SYMBOL_DEMANGLED_NAME (p) != NULL) |
2e4964ad FF |
703 | { |
704 | fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (p)); | |
705 | } | |
706 | fputs_filtered (", ", outfile); | |
4a35d6e9 FF |
707 | switch (SYMBOL_NAMESPACE (p)) |
708 | { | |
709 | case UNDEF_NAMESPACE: | |
710 | fputs_filtered ("undefined namespace, ", outfile); | |
711 | break; | |
712 | case VAR_NAMESPACE: | |
713 | /* This is the usual thing -- don't print it */ | |
714 | break; | |
715 | case STRUCT_NAMESPACE: | |
716 | fputs_filtered ("struct namespace, ", outfile); | |
717 | break; | |
718 | case LABEL_NAMESPACE: | |
719 | fputs_filtered ("label namespace, ", outfile); | |
720 | break; | |
721 | default: | |
722 | fputs_filtered ("<invalid namespace>, ", outfile); | |
723 | break; | |
724 | } | |
725 | switch (SYMBOL_CLASS (p)) | |
726 | { | |
727 | case LOC_UNDEF: | |
728 | fputs_filtered ("undefined", outfile); | |
729 | break; | |
730 | case LOC_CONST: | |
731 | fputs_filtered ("constant int", outfile); | |
732 | break; | |
733 | case LOC_STATIC: | |
734 | fputs_filtered ("static", outfile); | |
735 | break; | |
736 | case LOC_REGISTER: | |
737 | fputs_filtered ("register", outfile); | |
738 | break; | |
739 | case LOC_ARG: | |
740 | fputs_filtered ("pass by value", outfile); | |
741 | break; | |
742 | case LOC_REF_ARG: | |
743 | fputs_filtered ("pass by reference", outfile); | |
744 | break; | |
745 | case LOC_REGPARM: | |
746 | fputs_filtered ("register parameter", outfile); | |
747 | break; | |
018ab14f PS |
748 | case LOC_REGPARM_ADDR: |
749 | fputs_filtered ("register address parameter", outfile); | |
750 | break; | |
4a35d6e9 FF |
751 | case LOC_LOCAL: |
752 | fputs_filtered ("stack parameter", outfile); | |
753 | break; | |
754 | case LOC_TYPEDEF: | |
755 | fputs_filtered ("type", outfile); | |
756 | break; | |
757 | case LOC_LABEL: | |
758 | fputs_filtered ("label", outfile); | |
759 | break; | |
760 | case LOC_BLOCK: | |
761 | fputs_filtered ("function", outfile); | |
762 | break; | |
763 | case LOC_CONST_BYTES: | |
764 | fputs_filtered ("constant bytes", outfile); | |
765 | break; | |
766 | case LOC_LOCAL_ARG: | |
767 | fputs_filtered ("shuffled arg", outfile); | |
768 | break; | |
018ab14f PS |
769 | case LOC_OPTIMIZED_OUT: |
770 | fputs_filtered ("optimized out", outfile); | |
771 | break; | |
4a35d6e9 FF |
772 | default: |
773 | fputs_filtered ("<invalid location>", outfile); | |
774 | break; | |
775 | } | |
776 | fputs_filtered (", ", outfile); | |
833e0d94 JK |
777 | /* FIXME-32x64: Need to use SYMBOL_VALUE_ADDRESS, etc.; this |
778 | could be 32 bits when some of the other fields in the union | |
779 | are 64. */ | |
780 | fprintf_filtered (outfile, "0x%lx\n", SYMBOL_VALUE (p)); | |
4a35d6e9 FF |
781 | p++; |
782 | } | |
783 | } | |
784 | ||
a8a69e63 FF |
785 | void |
786 | maintenance_print_msymbols (args, from_tty) | |
318bf84f FF |
787 | char *args; |
788 | int from_tty; | |
789 | { | |
790 | char **argv; | |
833e0d94 | 791 | GDB_FILE *outfile; |
318bf84f FF |
792 | struct cleanup *cleanups; |
793 | char *filename = DEV_TTY; | |
794 | char *symname = NULL; | |
d630b615 | 795 | struct objfile *objfile; |
bd5635a1 | 796 | |
318bf84f FF |
797 | dont_repeat (); |
798 | ||
799 | if (args == NULL) | |
800 | { | |
a8a69e63 | 801 | error ("print-msymbols takes an output file name and optional symbol file name"); |
318bf84f FF |
802 | } |
803 | else if ((argv = buildargv (args)) == NULL) | |
804 | { | |
805 | nomem (0); | |
806 | } | |
807 | cleanups = make_cleanup (freeargv, argv); | |
808 | ||
809 | if (argv[0] != NULL) | |
810 | { | |
811 | filename = argv[0]; | |
812 | /* If a second arg is supplied, it is a source file name to match on */ | |
813 | if (argv[1] != NULL) | |
814 | { | |
815 | symname = argv[1]; | |
816 | } | |
817 | } | |
818 | ||
819 | filename = tilde_expand (filename); | |
820 | make_cleanup (free, filename); | |
821 | ||
833e0d94 | 822 | outfile = gdb_fopen (filename, FOPEN_WT); |
318bf84f FF |
823 | if (outfile == 0) |
824 | perror_with_name (filename); | |
825 | make_cleanup (fclose, outfile); | |
826 | ||
827 | immediate_quit++; | |
d630b615 | 828 | ALL_OBJFILES (objfile) |
2e4964ad | 829 | if (symname == NULL || (STREQ (symname, objfile -> name))) |
d630b615 | 830 | dump_msymbols (objfile, outfile); |
318bf84f FF |
831 | immediate_quit--; |
832 | fprintf_filtered (outfile, "\n\n"); | |
833 | do_cleanups (cleanups); | |
834 | } | |
835 | ||
a8a69e63 FF |
836 | void |
837 | maintenance_print_objfiles (ignore, from_tty) | |
d630b615 FF |
838 | char *ignore; |
839 | int from_tty; | |
bd5635a1 | 840 | { |
d630b615 FF |
841 | struct objfile *objfile; |
842 | ||
318bf84f FF |
843 | dont_repeat (); |
844 | ||
845 | immediate_quit++; | |
d630b615 FF |
846 | ALL_OBJFILES (objfile) |
847 | dump_objfile (objfile); | |
318bf84f | 848 | immediate_quit--; |
bd5635a1 | 849 | } |
a8a69e63 | 850 | |
2b576293 C |
851 | /* Check consistency of psymtabs and symtabs. */ |
852 | ||
853 | void | |
854 | maintenance_check_symtabs (ignore, from_tty) | |
855 | char *ignore; | |
856 | int from_tty; | |
857 | { | |
858 | register struct symbol *sym; | |
859 | register struct partial_symbol *psym; | |
860 | register struct symtab *s = NULL; | |
861 | register struct partial_symtab *ps; | |
862 | struct blockvector *bv; | |
863 | register struct objfile *objfile; | |
864 | register struct block *b; | |
865 | int length; | |
866 | ||
867 | ALL_PSYMTABS (objfile, ps) | |
868 | { | |
869 | s = PSYMTAB_TO_SYMTAB(ps); | |
870 | if (s == NULL) | |
871 | continue; | |
872 | bv = BLOCKVECTOR (s); | |
873 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
874 | psym = ps->objfile->static_psymbols.list + ps->statics_offset; | |
875 | length = ps->n_static_syms; | |
876 | while (length--) | |
877 | { | |
878 | sym = lookup_block_symbol (b, SYMBOL_NAME (psym), | |
879 | SYMBOL_NAMESPACE (psym)); | |
880 | if (!sym) | |
881 | { | |
882 | printf_filtered ("Static symbol `"); | |
883 | puts_filtered (SYMBOL_NAME (psym)); | |
884 | printf_filtered ("' only found in "); | |
885 | puts_filtered (ps->filename); | |
886 | printf_filtered (" psymtab\n"); | |
887 | } | |
888 | psym++; | |
889 | } | |
890 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
891 | psym = ps->objfile->global_psymbols.list + ps->globals_offset; | |
892 | length = ps->n_global_syms; | |
893 | while (length--) | |
894 | { | |
895 | sym = lookup_block_symbol (b, SYMBOL_NAME (psym), | |
896 | SYMBOL_NAMESPACE (psym)); | |
897 | if (!sym) | |
898 | { | |
899 | printf_filtered ("Global symbol `"); | |
900 | puts_filtered (SYMBOL_NAME (psym)); | |
901 | printf_filtered ("' only found in "); | |
902 | puts_filtered (ps->filename); | |
903 | printf_filtered (" psymtab\n"); | |
904 | } | |
905 | psym++; | |
906 | } | |
907 | if (ps->texthigh < ps->textlow) | |
908 | { | |
909 | printf_filtered ("Psymtab "); | |
910 | puts_filtered (ps->filename); | |
911 | printf_filtered (" covers bad range "); | |
912 | print_address_numeric (ps->textlow, 1, stdout); | |
913 | printf_filtered (" - "); | |
914 | print_address_numeric (ps->texthigh, 1, stdout); | |
915 | printf_filtered ("\n"); | |
916 | continue; | |
917 | } | |
918 | if (ps->texthigh == 0) | |
919 | continue; | |
920 | if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b)) | |
921 | { | |
922 | printf_filtered ("Psymtab "); | |
923 | puts_filtered (ps->filename); | |
924 | printf_filtered (" covers "); | |
925 | print_address_numeric (ps->textlow, 1, stdout); | |
926 | printf_filtered (" - "); | |
927 | print_address_numeric (ps->texthigh, 1, stdout); | |
928 | printf_filtered (" but symtab covers only "); | |
929 | print_address_numeric (BLOCK_START (b), 1, stdout); | |
930 | printf_filtered (" - "); | |
931 | print_address_numeric (BLOCK_END (b), 1, stdout); | |
932 | printf_filtered ("\n"); | |
933 | } | |
934 | } | |
935 | } | |
936 | ||
bd5635a1 | 937 | \f |
318bf84f | 938 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
7e258d18 | 939 | |
318bf84f FF |
940 | static int |
941 | block_depth (block) | |
942 | struct block *block; | |
7e258d18 | 943 | { |
318bf84f | 944 | register int i = 0; |
a8a69e63 FF |
945 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
946 | { | |
947 | i++; | |
948 | } | |
318bf84f | 949 | return i; |
7e258d18 PB |
950 | } |
951 | ||
a8a69e63 FF |
952 | #endif /* MAINTENANCE_CMDS */ |
953 | ||
318bf84f | 954 | \f |
346168a2 JG |
955 | /* Increase the space allocated for LISTP, which is probably |
956 | global_psymbol_list or static_psymbol_list. This space will eventually | |
957 | be freed in free_objfile(). */ | |
7e258d18 PB |
958 | |
959 | void | |
318bf84f | 960 | extend_psymbol_list (listp, objfile) |
7e258d18 | 961 | register struct psymbol_allocation_list *listp; |
318bf84f | 962 | struct objfile *objfile; |
7e258d18 PB |
963 | { |
964 | int new_size; | |
965 | if (listp->size == 0) | |
966 | { | |
967 | new_size = 255; | |
968 | listp->list = (struct partial_symbol *) | |
318bf84f | 969 | xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol)); |
7e258d18 PB |
970 | } |
971 | else | |
972 | { | |
973 | new_size = listp->size * 2; | |
974 | listp->list = (struct partial_symbol *) | |
318bf84f FF |
975 | xmrealloc (objfile -> md, (char *) listp->list, |
976 | new_size * sizeof (struct partial_symbol)); | |
7e258d18 PB |
977 | } |
978 | /* Next assumes we only went one over. Should be good if | |
979 | program works correctly */ | |
980 | listp->next = listp->list + listp->size; | |
981 | listp->size = new_size; | |
982 | } | |
018ab14f PS |
983 | |
984 | ||
985 | /* Do early runtime initializations. */ | |
986 | void | |
987 | _initialize_symmisc () | |
988 | { | |
989 | std_in = stdin; | |
990 | std_out = stdout; | |
991 | std_err = stderr; | |
992 | } |