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