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