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