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