gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / symmisc.c
CommitLineData
c906108c 1/* Do various things to symbol tables (other than lookup), for GDB.
af5f3db6 2
6aba47ca 3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
0fb0cc75 4 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2007, 2008, 2009
6aba47ca 5 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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"
04ea0df1 30#include "gdb_obstack.h"
60250e8b 31#include "exceptions.h"
c906108c
SS
32#include "language.h"
33#include "bcache.h"
fe898f56 34#include "block.h"
44ea7b70 35#include "gdb_regex.h"
07318b29 36#include "gdb_stat.h"
de4f826b 37#include "dictionary.h"
c906108c
SS
38
39#include "gdb_string.h"
dbda9972 40#include "readline/readline.h"
c906108c
SS
41
42#ifndef DEV_TTY
43#define DEV_TTY "/dev/tty"
44#endif
45
46/* Unfortunately for debugging, stderr is usually a macro. This is painful
47 when calling functions that take FILE *'s from the debugger.
48 So we make a variable which has the same value and which is accessible when
49 debugging GDB with itself. Because stdin et al need not be constants,
50 we initialize them in the _initialize_symmisc function at the bottom
51 of the file. */
52FILE *std_in;
53FILE *std_out;
54FILE *std_err;
55
56/* Prototypes for local functions */
57
d9fcf2fb
JM
58static void dump_symtab (struct objfile *, struct symtab *,
59 struct ui_file *);
c906108c 60
d9fcf2fb
JM
61static void dump_psymtab (struct objfile *, struct partial_symtab *,
62 struct ui_file *);
c906108c 63
d9fcf2fb 64static void dump_msymbols (struct objfile *, struct ui_file *);
c906108c 65
a14ed312 66static void dump_objfile (struct objfile *);
c906108c 67
a14ed312 68static int block_depth (struct block *);
c906108c 69
5af949e3
UW
70static void print_partial_symbols (struct gdbarch *,
71 struct partial_symbol **, int,
d9fcf2fb 72 char *, struct ui_file *);
c906108c 73
a14ed312 74void _initialize_symmisc (void);
c906108c 75
c5aa993b
JM
76struct print_symbol_args
77 {
5af949e3 78 struct gdbarch *gdbarch;
c5aa993b
JM
79 struct symbol *symbol;
80 int depth;
d9fcf2fb 81 struct ui_file *outfile;
c5aa993b 82 };
c906108c 83
4efb68b1 84static int print_symbol (void *);
c906108c 85\f
c906108c 86/* Free all the storage associated with the struct symtab <- S.
f73634e5
DE
87 Note that some symtabs have contents that all live inside one big block of
88 memory, and some share the contents of another symbol table and so you
89 should not free the contents on their behalf (except sometimes the
90 linetable, which maybe per symtab even when the rest is not).
c906108c
SS
91 It is s->free_code that says which alternative to use. */
92
93void
aa1ee363 94free_symtab (struct symtab *s)
c906108c 95{
52f0bd74
AC
96 int i, n;
97 struct blockvector *bv;
c906108c
SS
98
99 switch (s->free_code)
100 {
101 case free_nothing:
102 /* All the contents are part of a big block of memory (an obstack),
c5aa993b
JM
103 and some other symtab is in charge of freeing that block.
104 Therefore, do nothing. */
c906108c
SS
105 break;
106
c906108c 107 case free_linetable:
de4f826b 108 /* Everything will be freed either by our `free_func'
c5aa993b
JM
109 or by some other symtab, except for our linetable.
110 Free that now. */
c906108c 111 if (LINETABLE (s))
2dc74dc1 112 xfree (LINETABLE (s));
c906108c
SS
113 break;
114 }
115
116 /* If there is a single block of memory to free, free it. */
de4f826b
DC
117 if (s->free_func != NULL)
118 s->free_func (s);
c906108c
SS
119
120 /* Free source-related stuff */
c5aa993b 121 if (s->line_charpos != NULL)
2dc74dc1 122 xfree (s->line_charpos);
c5aa993b 123 if (s->fullname != NULL)
2dc74dc1 124 xfree (s->fullname);
c5aa993b 125 if (s->debugformat != NULL)
2dc74dc1
AC
126 xfree (s->debugformat);
127 xfree (s);
c906108c
SS
128}
129
c906108c 130void
fba45db2 131print_symbol_bcache_statistics (void)
c906108c 132{
6c95b8df 133 struct program_space *pspace;
c906108c
SS
134 struct objfile *objfile;
135
136 immediate_quit++;
6c95b8df
PA
137 ALL_PSPACES (pspace)
138 ALL_PSPACE_OBJFILES (pspace, objfile)
c5aa993b 139 {
a3f17187 140 printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
af5f3db6 141 print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
d4ce0d3f 142 print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
10abe6bf 143 print_bcache_statistics (objfile->filename_cache, "file name cache");
c5aa993b 144 }
c906108c
SS
145 immediate_quit--;
146}
147
148void
fba45db2 149print_objfile_statistics (void)
c906108c 150{
6c95b8df 151 struct program_space *pspace;
c906108c 152 struct objfile *objfile;
c4f90d87
JM
153 struct symtab *s;
154 struct partial_symtab *ps;
155 int i, linetables, blockvectors;
c906108c
SS
156
157 immediate_quit++;
6c95b8df
PA
158 ALL_PSPACES (pspace)
159 ALL_PSPACE_OBJFILES (pspace, objfile)
c5aa993b 160 {
a3f17187 161 printf_filtered (_("Statistics for '%s':\n"), objfile->name);
c5aa993b 162 if (OBJSTAT (objfile, n_stabs) > 0)
a3f17187 163 printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
c5aa993b
JM
164 OBJSTAT (objfile, n_stabs));
165 if (OBJSTAT (objfile, n_minsyms) > 0)
a3f17187 166 printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
c5aa993b
JM
167 OBJSTAT (objfile, n_minsyms));
168 if (OBJSTAT (objfile, n_psyms) > 0)
a3f17187 169 printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
c5aa993b
JM
170 OBJSTAT (objfile, n_psyms));
171 if (OBJSTAT (objfile, n_syms) > 0)
a3f17187 172 printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
c5aa993b
JM
173 OBJSTAT (objfile, n_syms));
174 if (OBJSTAT (objfile, n_types) > 0)
a3f17187 175 printf_filtered (_(" Number of \"types\" defined: %d\n"),
c5aa993b 176 OBJSTAT (objfile, n_types));
c4f90d87
JM
177 i = 0;
178 ALL_OBJFILE_PSYMTABS (objfile, ps)
179 {
180 if (ps->readin == 0)
181 i++;
182 }
a3f17187 183 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
c4f90d87
JM
184 i = linetables = blockvectors = 0;
185 ALL_OBJFILE_SYMTABS (objfile, s)
186 {
187 i++;
188 if (s->linetable != NULL)
189 linetables++;
190 if (s->primary == 1)
191 blockvectors++;
192 }
a3f17187
AC
193 printf_filtered (_(" Number of symbol tables: %d\n"), i);
194 printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
c4f90d87 195 linetables);
a3f17187 196 printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
c4f90d87
JM
197 blockvectors);
198
c5aa993b 199 if (OBJSTAT (objfile, sz_strtab) > 0)
a3f17187 200 printf_filtered (_(" Space used by a.out string tables: %d\n"),
c5aa993b 201 OBJSTAT (objfile, sz_strtab));
a3f17187 202 printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
4a146b47 203 obstack_memory_used (&objfile->objfile_obstack));
a3f17187 204 printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
af5f3db6 205 bcache_memory_used (objfile->psymbol_cache));
a3f17187 206 printf_filtered (_(" Total memory used for macro cache: %d\n"),
af5f3db6 207 bcache_memory_used (objfile->macro_cache));
10abe6bf
TT
208 printf_filtered (_(" Total memory used for file name cache: %d\n"),
209 bcache_memory_used (objfile->filename_cache));
c5aa993b 210 }
c906108c
SS
211 immediate_quit--;
212}
213
c5aa993b 214static void
fba45db2 215dump_objfile (struct objfile *objfile)
c906108c
SS
216{
217 struct symtab *symtab;
218 struct partial_symtab *psymtab;
219
c5aa993b 220 printf_filtered ("\nObject file %s: ", objfile->name);
c906108c 221 printf_filtered ("Objfile at ");
d4f3574e 222 gdb_print_host_address (objfile, gdb_stdout);
c906108c 223 printf_filtered (", bfd at ");
d4f3574e 224 gdb_print_host_address (objfile->obfd, gdb_stdout);
c906108c
SS
225 printf_filtered (", %d minsyms\n\n",
226 objfile->minimal_symbol_count);
227
c5aa993b 228 if (objfile->psymtabs)
c906108c
SS
229 {
230 printf_filtered ("Psymtabs:\n");
c5aa993b 231 for (psymtab = objfile->psymtabs;
c906108c 232 psymtab != NULL;
c5aa993b 233 psymtab = psymtab->next)
c906108c
SS
234 {
235 printf_filtered ("%s at ",
c5aa993b 236 psymtab->filename);
d4f3574e 237 gdb_print_host_address (psymtab, gdb_stdout);
c906108c 238 printf_filtered (", ");
c5aa993b 239 if (psymtab->objfile != objfile)
c906108c
SS
240 {
241 printf_filtered ("NOT ON CHAIN! ");
242 }
243 wrap_here (" ");
244 }
245 printf_filtered ("\n\n");
246 }
247
c5aa993b 248 if (objfile->symtabs)
c906108c
SS
249 {
250 printf_filtered ("Symtabs:\n");
c5aa993b 251 for (symtab = objfile->symtabs;
c906108c
SS
252 symtab != NULL;
253 symtab = symtab->next)
254 {
c5aa993b 255 printf_filtered ("%s at ", symtab->filename);
d4f3574e 256 gdb_print_host_address (symtab, gdb_stdout);
c906108c 257 printf_filtered (", ");
c5aa993b 258 if (symtab->objfile != objfile)
c906108c
SS
259 {
260 printf_filtered ("NOT ON CHAIN! ");
261 }
262 wrap_here (" ");
263 }
264 printf_filtered ("\n\n");
265 }
266}
267
268/* Print minimal symbols from this objfile. */
c5aa993b
JM
269
270static void
fba45db2 271dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
c906108c 272{
5af949e3 273 struct gdbarch *gdbarch = get_objfile_arch (objfile);
c906108c
SS
274 struct minimal_symbol *msymbol;
275 int index;
276 char ms_type;
c5aa993b
JM
277
278 fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
279 if (objfile->minimal_symbol_count == 0)
c906108c
SS
280 {
281 fprintf_filtered (outfile, "No minimal symbols found.\n");
282 return;
283 }
3567439c
DJ
284 index = 0;
285 ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
c906108c 286 {
714835d5
UW
287 struct obj_section *section = SYMBOL_OBJ_SECTION (msymbol);
288
712f90be 289 switch (MSYMBOL_TYPE (msymbol))
c906108c 290 {
c5aa993b
JM
291 case mst_unknown:
292 ms_type = 'u';
293 break;
294 case mst_text:
295 ms_type = 'T';
296 break;
297 case mst_solib_trampoline:
298 ms_type = 'S';
299 break;
300 case mst_data:
301 ms_type = 'D';
302 break;
303 case mst_bss:
304 ms_type = 'B';
305 break;
306 case mst_abs:
307 ms_type = 'A';
308 break;
309 case mst_file_text:
310 ms_type = 't';
311 break;
312 case mst_file_data:
313 ms_type = 'd';
314 break;
315 case mst_file_bss:
316 ms_type = 'b';
317 break;
318 default:
319 ms_type = '?';
320 break;
c906108c
SS
321 }
322 fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
5af949e3
UW
323 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msymbol)),
324 outfile);
3567439c 325 fprintf_filtered (outfile, " %s", SYMBOL_LINKAGE_NAME (msymbol));
714835d5 326 if (section)
c906108c
SS
327 fprintf_filtered (outfile, " section %s",
328 bfd_section_name (objfile->obfd,
714835d5 329 section->the_bfd_section));
c906108c
SS
330 if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
331 {
332 fprintf_filtered (outfile, " %s", SYMBOL_DEMANGLED_NAME (msymbol));
333 }
c906108c
SS
334 if (msymbol->filename)
335 fprintf_filtered (outfile, " %s", msymbol->filename);
c906108c 336 fputs_filtered ("\n", outfile);
3567439c 337 index++;
c906108c 338 }
c5aa993b 339 if (objfile->minimal_symbol_count != index)
c906108c 340 {
8a3fe4f8 341 warning (_("internal error: minimal symbol count %d != %d"),
c5aa993b 342 objfile->minimal_symbol_count, index);
c906108c
SS
343 }
344 fprintf_filtered (outfile, "\n");
345}
346
347static void
fba45db2
KB
348dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
349 struct ui_file *outfile)
c906108c 350{
5af949e3 351 struct gdbarch *gdbarch = get_objfile_arch (objfile);
c906108c
SS
352 int i;
353
354 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
c5aa993b 355 psymtab->filename);
c906108c 356 fprintf_filtered (outfile, "(object ");
d4f3574e 357 gdb_print_host_address (psymtab, outfile);
c906108c
SS
358 fprintf_filtered (outfile, ")\n\n");
359 fprintf_unfiltered (outfile, " Read from object file %s (",
c5aa993b 360 objfile->name);
d4f3574e 361 gdb_print_host_address (objfile, outfile);
c906108c
SS
362 fprintf_unfiltered (outfile, ")\n");
363
c5aa993b 364 if (psymtab->readin)
c906108c
SS
365 {
366 fprintf_filtered (outfile,
c5aa993b 367 " Full symtab was read (at ");
d4f3574e 368 gdb_print_host_address (psymtab->symtab, outfile);
c906108c 369 fprintf_filtered (outfile, " by function at ");
4efb68b1 370 gdb_print_host_address (psymtab->read_symtab, outfile);
c906108c
SS
371 fprintf_filtered (outfile, ")\n");
372 }
373
374 fprintf_filtered (outfile, " Relocate symbols by ");
375 for (i = 0; i < psymtab->objfile->num_sections; ++i)
376 {
377 if (i != 0)
378 fprintf_filtered (outfile, ", ");
379 wrap_here (" ");
5af949e3
UW
380 fputs_filtered (paddress (gdbarch,
381 ANOFFSET (psymtab->section_offsets, i)),
ed49a04f 382 outfile);
c906108c
SS
383 }
384 fprintf_filtered (outfile, "\n");
385
386 fprintf_filtered (outfile, " Symbols cover text addresses ");
5af949e3 387 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
c906108c 388 fprintf_filtered (outfile, "-");
5af949e3 389 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
c906108c
SS
390 fprintf_filtered (outfile, "\n");
391 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
c5aa993b
JM
392 psymtab->number_of_dependencies);
393 for (i = 0; i < psymtab->number_of_dependencies; i++)
c906108c
SS
394 {
395 fprintf_filtered (outfile, " %d ", i);
d4f3574e 396 gdb_print_host_address (psymtab->dependencies[i], outfile);
c906108c 397 fprintf_filtered (outfile, " %s\n",
c5aa993b 398 psymtab->dependencies[i]->filename);
c906108c 399 }
c5aa993b 400 if (psymtab->n_global_syms > 0)
c906108c 401 {
5af949e3
UW
402 print_partial_symbols (gdbarch,
403 objfile->global_psymbols.list
c5aa993b
JM
404 + psymtab->globals_offset,
405 psymtab->n_global_syms, "Global", outfile);
c906108c 406 }
c5aa993b 407 if (psymtab->n_static_syms > 0)
c906108c 408 {
5af949e3
UW
409 print_partial_symbols (gdbarch,
410 objfile->static_psymbols.list
c5aa993b
JM
411 + psymtab->statics_offset,
412 psymtab->n_static_syms, "Static", outfile);
c906108c
SS
413 }
414 fprintf_filtered (outfile, "\n");
415}
416
c5aa993b 417static void
44b164c5
JB
418dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
419 struct ui_file *outfile)
c906108c 420{
5af949e3 421 struct gdbarch *gdbarch = get_objfile_arch (objfile);
de4f826b
DC
422 int i;
423 struct dict_iterator iter;
c906108c 424 int len, blen;
de4f826b 425 struct linetable *l;
c906108c 426 struct blockvector *bv;
e88c90f2 427 struct symbol *sym;
de4f826b 428 struct block *b;
c906108c
SS
429 int depth;
430
431 fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
432 if (symtab->dirname)
433 fprintf_filtered (outfile, "Compilation directory is %s\n",
434 symtab->dirname);
435 fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
d4f3574e 436 gdb_print_host_address (objfile, outfile);
c906108c
SS
437 fprintf_filtered (outfile, ")\n");
438 fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
439
440 /* First print the line table. */
441 l = LINETABLE (symtab);
442 if (l)
443 {
444 fprintf_filtered (outfile, "\nLine table:\n\n");
445 len = l->nitems;
446 for (i = 0; i < len; i++)
447 {
448 fprintf_filtered (outfile, " line %d at ", l->item[i].line);
5af949e3 449 fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile);
c906108c
SS
450 fprintf_filtered (outfile, "\n");
451 }
452 }
453 /* Now print the block info, but only for primary symtabs since we will
454 print lots of duplicate info otherwise. */
c5aa993b 455 if (symtab->primary)
c906108c
SS
456 {
457 fprintf_filtered (outfile, "\nBlockvector:\n\n");
458 bv = BLOCKVECTOR (symtab);
459 len = BLOCKVECTOR_NBLOCKS (bv);
460 for (i = 0; i < len; i++)
461 {
462 b = BLOCKVECTOR_BLOCK (bv, i);
463 depth = block_depth (b) * 2;
464 print_spaces (depth, outfile);
465 fprintf_filtered (outfile, "block #%03d, object at ", i);
d4f3574e 466 gdb_print_host_address (b, outfile);
c906108c
SS
467 if (BLOCK_SUPERBLOCK (b))
468 {
469 fprintf_filtered (outfile, " under ");
d4f3574e 470 gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
c906108c 471 }
261397f8
DJ
472 /* drow/2002-07-10: We could save the total symbols count
473 even if we're using a hashtable, but nothing else but this message
474 wants it. */
de4f826b
DC
475 fprintf_filtered (outfile, ", %d syms/buckets in ",
476 dict_size (BLOCK_DICT (b)));
5af949e3 477 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile);
c906108c 478 fprintf_filtered (outfile, "..");
5af949e3 479 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile);
c906108c
SS
480 if (BLOCK_FUNCTION (b))
481 {
3567439c
DJ
482 fprintf_filtered (outfile, ", function %s",
483 SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
484 if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
485 {
486 fprintf_filtered (outfile, ", %s",
c5aa993b 487 SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
488 }
489 }
c906108c 490 fprintf_filtered (outfile, "\n");
261397f8
DJ
491 /* Now print each symbol in this block (in no particular order, if
492 we're using a hashtable). */
de4f826b 493 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c
SS
494 {
495 struct print_symbol_args s;
5af949e3 496 s.gdbarch = gdbarch;
e88c90f2 497 s.symbol = sym;
c906108c
SS
498 s.depth = depth + 1;
499 s.outfile = outfile;
500 catch_errors (print_symbol, &s, "Error printing symbol:\n",
5c3ce3f7 501 RETURN_MASK_ERROR);
c906108c
SS
502 }
503 }
504 fprintf_filtered (outfile, "\n");
505 }
506 else
507 {
508 fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
509 }
510}
511
44b164c5
JB
512static void
513dump_symtab (struct objfile *objfile, struct symtab *symtab,
514 struct ui_file *outfile)
515{
44b164c5
JB
516 /* Set the current language to the language of the symtab we're dumping
517 because certain routines used during dump_symtab() use the current
969107c5
EZ
518 language to print an image of the symbol. We'll restore it later.
519 But use only real languages, not placeholders. */
520 if (symtab->language != language_unknown
521 && symtab->language != language_auto)
522 {
523 enum language saved_lang;
524
525 saved_lang = set_language (symtab->language);
44b164c5 526
969107c5 527 dump_symtab_1 (objfile, symtab, outfile);
44b164c5 528
969107c5
EZ
529 set_language (saved_lang);
530 }
531 else
532 dump_symtab_1 (objfile, symtab, outfile);
44b164c5
JB
533}
534
c906108c 535void
fba45db2 536maintenance_print_symbols (char *args, int from_tty)
c906108c
SS
537{
538 char **argv;
d9fcf2fb 539 struct ui_file *outfile;
c906108c
SS
540 struct cleanup *cleanups;
541 char *symname = NULL;
542 char *filename = DEV_TTY;
543 struct objfile *objfile;
544 struct symtab *s;
545
546 dont_repeat ();
547
548 if (args == NULL)
549 {
8a3fe4f8
AC
550 error (_("\
551Arguments missing: an output file name and an optional symbol file name"));
c906108c 552 }
d1a41061 553 argv = gdb_buildargv (args);
7a292a7a 554 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
555
556 if (argv[0] != NULL)
557 {
558 filename = argv[0];
559 /* If a second arg is supplied, it is a source file name to match on */
560 if (argv[1] != NULL)
561 {
562 symname = argv[1];
563 }
564 }
565
566 filename = tilde_expand (filename);
b8c9b27d 567 make_cleanup (xfree, filename);
c5aa993b 568
c906108c
SS
569 outfile = gdb_fopen (filename, FOPEN_WT);
570 if (outfile == 0)
571 perror_with_name (filename);
d9fcf2fb 572 make_cleanup_ui_file_delete (outfile);
c906108c
SS
573
574 immediate_quit++;
575 ALL_SYMTABS (objfile, s)
6314a349 576 if (symname == NULL || strcmp (symname, s->filename) == 0)
c5aa993b 577 dump_symtab (objfile, s, outfile);
c906108c
SS
578 immediate_quit--;
579 do_cleanups (cleanups);
580}
581
582/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
583 far to indent. ARGS is really a struct print_symbol_args *, but is
584 declared as char * to get it past catch_errors. Returns 0 for error,
585 1 for success. */
586
587static int
4efb68b1 588print_symbol (void *args)
c906108c 589{
5af949e3 590 struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
c5aa993b
JM
591 struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
592 int depth = ((struct print_symbol_args *) args)->depth;
d9fcf2fb 593 struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
714835d5 594 struct obj_section *section = SYMBOL_OBJ_SECTION (symbol);
c906108c
SS
595
596 print_spaces (depth, outfile);
176620f1 597 if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN)
c906108c 598 {
de5ad195 599 fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol));
5af949e3
UW
600 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
601 outfile);
714835d5 602 if (section)
c906108c 603 fprintf_filtered (outfile, " section %s\n",
714835d5
UW
604 bfd_section_name (section->the_bfd_section->owner,
605 section->the_bfd_section));
c906108c
SS
606 else
607 fprintf_filtered (outfile, "\n");
608 return 1;
609 }
176620f1 610 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
c906108c
SS
611 {
612 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
613 {
614 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
615 }
616 else
617 {
618 fprintf_filtered (outfile, "%s %s = ",
c5aa993b
JM
619 (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
620 ? "enum"
621 : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
622 ? "struct" : "union")),
3567439c 623 SYMBOL_LINKAGE_NAME (symbol));
c906108c
SS
624 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
625 }
626 fprintf_filtered (outfile, ";\n");
627 }
628 else
629 {
630 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
631 fprintf_filtered (outfile, "typedef ");
632 if (SYMBOL_TYPE (symbol))
633 {
634 /* Print details of types, except for enums where it's clutter. */
de5ad195 635 LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
c906108c
SS
636 outfile,
637 TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
638 depth);
639 fprintf_filtered (outfile, "; ");
640 }
641 else
de5ad195 642 fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol));
c906108c
SS
643
644 switch (SYMBOL_CLASS (symbol))
645 {
646 case LOC_CONST:
647 fprintf_filtered (outfile, "const %ld (0x%lx)",
648 SYMBOL_VALUE (symbol),
649 SYMBOL_VALUE (symbol));
650 break;
651
652 case LOC_CONST_BYTES:
653 {
654 unsigned i;
655 struct type *type = check_typedef (SYMBOL_TYPE (symbol));
656 fprintf_filtered (outfile, "const %u hex bytes:",
657 TYPE_LENGTH (type));
658 for (i = 0; i < TYPE_LENGTH (type); i++)
659 fprintf_filtered (outfile, " %02x",
c5aa993b 660 (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
c906108c
SS
661 }
662 break;
663
664 case LOC_STATIC:
665 fprintf_filtered (outfile, "static at ");
5af949e3
UW
666 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
667 outfile);
714835d5 668 if (section)
c906108c 669 fprintf_filtered (outfile, " section %s",
714835d5
UW
670 bfd_section_name (section->the_bfd_section->owner,
671 section->the_bfd_section));
c906108c
SS
672 break;
673
c906108c 674 case LOC_REGISTER:
2a2d4dc3
AS
675 if (SYMBOL_IS_ARGUMENT (symbol))
676 fprintf_filtered (outfile, "parameter register %ld",
677 SYMBOL_VALUE (symbol));
678 else
679 fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
c906108c
SS
680 break;
681
682 case LOC_ARG:
683 fprintf_filtered (outfile, "arg at offset 0x%lx",
684 SYMBOL_VALUE (symbol));
685 break;
686
c906108c
SS
687 case LOC_REF_ARG:
688 fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
689 break;
690
c906108c
SS
691 case LOC_REGPARM_ADDR:
692 fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
693 break;
694
695 case LOC_LOCAL:
696 fprintf_filtered (outfile, "local at offset 0x%lx",
697 SYMBOL_VALUE (symbol));
698 break;
699
c906108c
SS
700 case LOC_TYPEDEF:
701 break;
702
703 case LOC_LABEL:
704 fprintf_filtered (outfile, "label at ");
5af949e3
UW
705 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
706 outfile);
714835d5 707 if (section)
c906108c 708 fprintf_filtered (outfile, " section %s",
714835d5
UW
709 bfd_section_name (section->the_bfd_section->owner,
710 section->the_bfd_section));
c906108c
SS
711 break;
712
713 case LOC_BLOCK:
714 fprintf_filtered (outfile, "block object ");
d4f3574e 715 gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
c906108c 716 fprintf_filtered (outfile, ", ");
5af949e3
UW
717 fputs_filtered (paddress (gdbarch,
718 BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
ed49a04f 719 outfile);
c906108c 720 fprintf_filtered (outfile, "..");
5af949e3
UW
721 fputs_filtered (paddress (gdbarch,
722 BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))),
ed49a04f 723 outfile);
714835d5 724 if (section)
c906108c 725 fprintf_filtered (outfile, " section %s",
714835d5
UW
726 bfd_section_name (section->the_bfd_section->owner,
727 section->the_bfd_section));
c906108c
SS
728 break;
729
4c2df51b 730 case LOC_COMPUTED:
4c2df51b
DJ
731 fprintf_filtered (outfile, "computed at runtime");
732 break;
733
c906108c
SS
734 case LOC_UNRESOLVED:
735 fprintf_filtered (outfile, "unresolved");
736 break;
737
738 case LOC_OPTIMIZED_OUT:
739 fprintf_filtered (outfile, "optimized out");
740 break;
741
c5aa993b 742 default:
c906108c
SS
743 fprintf_filtered (outfile, "botched symbol class %x",
744 SYMBOL_CLASS (symbol));
745 break;
746 }
747 }
748 fprintf_filtered (outfile, "\n");
749 return 1;
750}
751
752void
fba45db2 753maintenance_print_psymbols (char *args, int from_tty)
c906108c
SS
754{
755 char **argv;
d9fcf2fb 756 struct ui_file *outfile;
c906108c
SS
757 struct cleanup *cleanups;
758 char *symname = NULL;
759 char *filename = DEV_TTY;
760 struct objfile *objfile;
761 struct partial_symtab *ps;
762
763 dont_repeat ();
764
765 if (args == NULL)
766 {
8a3fe4f8 767 error (_("print-psymbols takes an output file name and optional symbol file name"));
c906108c 768 }
d1a41061 769 argv = gdb_buildargv (args);
7a292a7a 770 cleanups = make_cleanup_freeargv (argv);
c906108c
SS
771
772 if (argv[0] != NULL)
773 {
774 filename = argv[0];
775 /* If a second arg is supplied, it is a source file name to match on */
776 if (argv[1] != NULL)
777 {
778 symname = argv[1];
779 }
780 }
781
782 filename = tilde_expand (filename);
b8c9b27d 783 make_cleanup (xfree, filename);
c5aa993b 784
c906108c
SS
785 outfile = gdb_fopen (filename, FOPEN_WT);
786 if (outfile == 0)
787 perror_with_name (filename);
d9fcf2fb 788 make_cleanup_ui_file_delete (outfile);
c906108c
SS
789
790 immediate_quit++;
791 ALL_PSYMTABS (objfile, ps)
6314a349 792 if (symname == NULL || strcmp (symname, ps->filename) == 0)
c5aa993b 793 dump_psymtab (objfile, ps, outfile);
c906108c
SS
794 immediate_quit--;
795 do_cleanups (cleanups);
796}
797
798static void
5af949e3
UW
799print_partial_symbols (struct gdbarch *gdbarch,
800 struct partial_symbol **p, int count, char *what,
fba45db2 801 struct ui_file *outfile)
c906108c
SS
802{
803 fprintf_filtered (outfile, " %s partial symbols:\n", what);
804 while (count-- > 0)
805 {
3567439c 806 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
c906108c
SS
807 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
808 {
809 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
810 }
811 fputs_filtered (", ", outfile);
176620f1 812 switch (SYMBOL_DOMAIN (*p))
c906108c 813 {
176620f1
EZ
814 case UNDEF_DOMAIN:
815 fputs_filtered ("undefined domain, ", outfile);
c906108c 816 break;
176620f1 817 case VAR_DOMAIN:
c906108c
SS
818 /* This is the usual thing -- don't print it */
819 break;
176620f1
EZ
820 case STRUCT_DOMAIN:
821 fputs_filtered ("struct domain, ", outfile);
c906108c 822 break;
176620f1
EZ
823 case LABEL_DOMAIN:
824 fputs_filtered ("label domain, ", outfile);
c906108c
SS
825 break;
826 default:
176620f1 827 fputs_filtered ("<invalid domain>, ", outfile);
c906108c
SS
828 break;
829 }
830 switch (SYMBOL_CLASS (*p))
831 {
832 case LOC_UNDEF:
833 fputs_filtered ("undefined", outfile);
834 break;
835 case LOC_CONST:
836 fputs_filtered ("constant int", outfile);
837 break;
838 case LOC_STATIC:
839 fputs_filtered ("static", outfile);
840 break;
c906108c
SS
841 case LOC_REGISTER:
842 fputs_filtered ("register", outfile);
843 break;
844 case LOC_ARG:
845 fputs_filtered ("pass by value", outfile);
846 break;
847 case LOC_REF_ARG:
848 fputs_filtered ("pass by reference", outfile);
849 break;
c906108c
SS
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;
c906108c
SS
868 case LOC_UNRESOLVED:
869 fputs_filtered ("unresolved", outfile);
870 break;
871 case LOC_OPTIMIZED_OUT:
872 fputs_filtered ("optimized out", outfile);
873 break;
4c2df51b 874 case LOC_COMPUTED:
4c2df51b
DJ
875 fputs_filtered ("computed at runtime", outfile);
876 break;
c906108c
SS
877 default:
878 fputs_filtered ("<invalid location>", outfile);
879 break;
880 }
881 fputs_filtered (", ", outfile);
5af949e3 882 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
c906108c
SS
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;
6c95b8df 896 struct program_space *pspace;
c906108c
SS
897 struct objfile *objfile;
898
07318b29
CV
899 struct stat sym_st, obj_st;
900
c906108c
SS
901 dont_repeat ();
902
903 if (args == NULL)
904 {
8a3fe4f8 905 error (_("print-msymbols takes an output file name and optional symbol file name"));
c906108c 906 }
d1a41061 907 argv = gdb_buildargv (args);
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 {
07318b29
CV
916 symname = xfullpath (argv[1]);
917 make_cleanup (xfree, symname);
918 if (symname && stat (symname, &sym_st))
919 perror_with_name (symname);
c906108c
SS
920 }
921 }
922
923 filename = tilde_expand (filename);
b8c9b27d 924 make_cleanup (xfree, filename);
c5aa993b 925
c906108c
SS
926 outfile = gdb_fopen (filename, FOPEN_WT);
927 if (outfile == 0)
928 perror_with_name (filename);
d9fcf2fb 929 make_cleanup_ui_file_delete (outfile);
c906108c
SS
930
931 immediate_quit++;
6c95b8df
PA
932 ALL_PSPACES (pspace)
933 ALL_PSPACE_OBJFILES (pspace, objfile)
934 if (symname == NULL
935 || (!stat (objfile->name, &obj_st) && sym_st.st_ino == obj_st.st_ino))
936 dump_msymbols (objfile, outfile);
c906108c
SS
937 immediate_quit--;
938 fprintf_filtered (outfile, "\n\n");
939 do_cleanups (cleanups);
940}
941
942void
fba45db2 943maintenance_print_objfiles (char *ignore, int from_tty)
c906108c 944{
6c95b8df 945 struct program_space *pspace;
c906108c
SS
946 struct objfile *objfile;
947
948 dont_repeat ();
949
950 immediate_quit++;
6c95b8df
PA
951 ALL_PSPACES (pspace)
952 ALL_PSPACE_OBJFILES (pspace, objfile)
953 dump_objfile (objfile);
c906108c
SS
954 immediate_quit--;
955}
956
44ea7b70 957
5e7b2f39 958/* List all the symbol tables whose names match REGEXP (optional). */
44ea7b70 959void
5e7b2f39 960maintenance_info_symtabs (char *regexp, int from_tty)
44ea7b70 961{
6c95b8df 962 struct program_space *pspace;
44ea7b70
JB
963 struct objfile *objfile;
964
965 if (regexp)
966 re_comp (regexp);
967
6c95b8df
PA
968 ALL_PSPACES (pspace)
969 ALL_PSPACE_OBJFILES (pspace, objfile)
44ea7b70
JB
970 {
971 struct symtab *symtab;
972
973 /* We don't want to print anything for this objfile until we
974 actually find a symtab whose name matches. */
975 int printed_objfile_start = 0;
976
977 ALL_OBJFILE_SYMTABS (objfile, symtab)
8a498d38
DE
978 {
979 QUIT;
980
981 if (! regexp
982 || re_exec (symtab->filename))
983 {
984 if (! printed_objfile_start)
985 {
986 printf_filtered ("{ objfile %s ", objfile->name);
987 wrap_here (" ");
a74ce742
PM
988 printf_filtered ("((struct objfile *) %s)\n",
989 host_address_to_string (objfile));
8a498d38
DE
990 printed_objfile_start = 1;
991 }
992
993 printf_filtered (" { symtab %s ", symtab->filename);
994 wrap_here (" ");
a74ce742
PM
995 printf_filtered ("((struct symtab *) %s)\n",
996 host_address_to_string (symtab));
8a498d38
DE
997 printf_filtered (" dirname %s\n",
998 symtab->dirname ? symtab->dirname : "(null)");
999 printf_filtered (" fullname %s\n",
1000 symtab->fullname ? symtab->fullname : "(null)");
a74ce742
PM
1001 printf_filtered (" blockvector ((struct blockvector *) %s)%s\n",
1002 host_address_to_string (symtab->blockvector),
8a498d38 1003 symtab->primary ? " (primary)" : "");
a74ce742
PM
1004 printf_filtered (" linetable ((struct linetable *) %s)\n",
1005 host_address_to_string (symtab->linetable));
8a498d38
DE
1006 printf_filtered (" debugformat %s\n", symtab->debugformat);
1007 printf_filtered (" }\n");
1008 }
1009 }
44ea7b70
JB
1010
1011 if (printed_objfile_start)
1012 printf_filtered ("}\n");
1013 }
1014}
1015
1016
5e7b2f39 1017/* List all the partial symbol tables whose names match REGEXP (optional). */
44ea7b70 1018void
5e7b2f39 1019maintenance_info_psymtabs (char *regexp, int from_tty)
44ea7b70 1020{
6c95b8df 1021 struct program_space *pspace;
44ea7b70
JB
1022 struct objfile *objfile;
1023
1024 if (regexp)
1025 re_comp (regexp);
1026
6c95b8df
PA
1027 ALL_PSPACES (pspace)
1028 ALL_PSPACE_OBJFILES (pspace, objfile)
44ea7b70 1029 {
5af949e3 1030 struct gdbarch *gdbarch = get_objfile_arch (objfile);
44ea7b70
JB
1031 struct partial_symtab *psymtab;
1032
1033 /* We don't want to print anything for this objfile until we
1034 actually find a symtab whose name matches. */
1035 int printed_objfile_start = 0;
1036
1037 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
8a498d38
DE
1038 {
1039 QUIT;
1040
1041 if (! regexp
1042 || re_exec (psymtab->filename))
1043 {
1044 if (! printed_objfile_start)
1045 {
1046 printf_filtered ("{ objfile %s ", objfile->name);
1047 wrap_here (" ");
a74ce742
PM
1048 printf_filtered ("((struct objfile *) %s)\n",
1049 host_address_to_string (objfile));
8a498d38
DE
1050 printed_objfile_start = 1;
1051 }
1052
1053 printf_filtered (" { psymtab %s ", psymtab->filename);
1054 wrap_here (" ");
a74ce742
PM
1055 printf_filtered ("((struct partial_symtab *) %s)\n",
1056 host_address_to_string (psymtab));
1057
8a498d38
DE
1058 printf_filtered (" readin %s\n",
1059 psymtab->readin ? "yes" : "no");
1060 printf_filtered (" fullname %s\n",
1061 psymtab->fullname ? psymtab->fullname : "(null)");
1062 printf_filtered (" text addresses ");
5af949e3
UW
1063 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1064 gdb_stdout);
8a498d38 1065 printf_filtered (" -- ");
5af949e3
UW
1066 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1067 gdb_stdout);
8a498d38
DE
1068 printf_filtered ("\n");
1069 printf_filtered (" globals ");
1070 if (psymtab->n_global_syms)
1071 {
dfc3cd0e
PM
1072 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1073 host_address_to_string (psymtab->objfile->global_psymbols.list
8a498d38
DE
1074 + psymtab->globals_offset),
1075 psymtab->n_global_syms);
1076 }
1077 else
1078 printf_filtered ("(none)\n");
1079 printf_filtered (" statics ");
1080 if (psymtab->n_static_syms)
1081 {
dfc3cd0e
PM
1082 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1083 host_address_to_string (psymtab->objfile->static_psymbols.list
8a498d38
DE
1084 + psymtab->statics_offset),
1085 psymtab->n_static_syms);
1086 }
1087 else
1088 printf_filtered ("(none)\n");
1089 printf_filtered (" dependencies ");
1090 if (psymtab->number_of_dependencies)
1091 {
1092 int i;
1093
1094 printf_filtered ("{\n");
1095 for (i = 0; i < psymtab->number_of_dependencies; i++)
1096 {
1097 struct partial_symtab *dep = psymtab->dependencies[i];
1098
1099 /* Note the string concatenation there --- no comma. */
1100 printf_filtered (" psymtab %s "
a74ce742
PM
1101 "((struct partial_symtab *) %s)\n",
1102 dep->filename,
1103 host_address_to_string (dep));
8a498d38
DE
1104 }
1105 printf_filtered (" }\n");
1106 }
1107 else
1108 printf_filtered ("(none)\n");
1109 printf_filtered (" }\n");
1110 }
1111 }
44ea7b70
JB
1112
1113 if (printed_objfile_start)
1114 printf_filtered ("}\n");
1115 }
1116}
1117
1118
c906108c
SS
1119/* Check consistency of psymtabs and symtabs. */
1120
1121void
fba45db2 1122maintenance_check_symtabs (char *ignore, int from_tty)
c906108c 1123{
52f0bd74
AC
1124 struct symbol *sym;
1125 struct partial_symbol **psym;
1126 struct symtab *s = NULL;
1127 struct partial_symtab *ps;
c906108c 1128 struct blockvector *bv;
52f0bd74
AC
1129 struct objfile *objfile;
1130 struct block *b;
c906108c
SS
1131 int length;
1132
1133 ALL_PSYMTABS (objfile, ps)
c5aa993b 1134 {
5af949e3 1135 struct gdbarch *gdbarch = get_objfile_arch (objfile);
c5aa993b
JM
1136 s = PSYMTAB_TO_SYMTAB (ps);
1137 if (s == NULL)
1138 continue;
1139 bv = BLOCKVECTOR (s);
1140 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1141 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1142 length = ps->n_static_syms;
1143 while (length--)
1144 {
3567439c 1145 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
176620f1 1146 NULL, SYMBOL_DOMAIN (*psym));
c5aa993b
JM
1147 if (!sym)
1148 {
1149 printf_filtered ("Static symbol `");
3567439c 1150 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
c5aa993b
JM
1151 printf_filtered ("' only found in ");
1152 puts_filtered (ps->filename);
1153 printf_filtered (" psymtab\n");
1154 }
1155 psym++;
1156 }
1157 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1158 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1159 length = ps->n_global_syms;
1160 while (length--)
1161 {
3567439c 1162 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
176620f1 1163 NULL, SYMBOL_DOMAIN (*psym));
c5aa993b
JM
1164 if (!sym)
1165 {
1166 printf_filtered ("Global symbol `");
3567439c 1167 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
c5aa993b
JM
1168 printf_filtered ("' only found in ");
1169 puts_filtered (ps->filename);
1170 printf_filtered (" psymtab\n");
1171 }
1172 psym++;
1173 }
1174 if (ps->texthigh < ps->textlow)
1175 {
1176 printf_filtered ("Psymtab ");
1177 puts_filtered (ps->filename);
1178 printf_filtered (" covers bad range ");
5af949e3 1179 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
c5aa993b 1180 printf_filtered (" - ");
5af949e3 1181 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
c5aa993b 1182 printf_filtered ("\n");
c906108c 1183 continue;
c5aa993b
JM
1184 }
1185 if (ps->texthigh == 0)
1186 continue;
1187 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1188 {
1189 printf_filtered ("Psymtab ");
1190 puts_filtered (ps->filename);
1191 printf_filtered (" covers ");
5af949e3 1192 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
c5aa993b 1193 printf_filtered (" - ");
5af949e3 1194 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
c5aa993b 1195 printf_filtered (" but symtab covers only ");
5af949e3 1196 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
c5aa993b 1197 printf_filtered (" - ");
5af949e3 1198 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
c5aa993b
JM
1199 printf_filtered ("\n");
1200 }
1201 }
c906108c 1202}
c906108c 1203\f
c5aa993b 1204
c906108c
SS
1205/* Return the nexting depth of a block within other blocks in its symtab. */
1206
1207static int
fba45db2 1208block_depth (struct block *block)
c906108c 1209{
52f0bd74 1210 int i = 0;
c5aa993b 1211 while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
c906108c
SS
1212 {
1213 i++;
1214 }
1215 return i;
1216}
c906108c 1217\f
c5aa993b 1218
c906108c
SS
1219/* Increase the space allocated for LISTP, which is probably
1220 global_psymbols or static_psymbols. This space will eventually
1221 be freed in free_objfile(). */
1222
1223void
aa1ee363 1224extend_psymbol_list (struct psymbol_allocation_list *listp,
fba45db2 1225 struct objfile *objfile)
c906108c
SS
1226{
1227 int new_size;
1228 if (listp->size == 0)
1229 {
1230 new_size = 255;
1231 listp->list = (struct partial_symbol **)
7936743b 1232 xmalloc (new_size * sizeof (struct partial_symbol *));
c906108c
SS
1233 }
1234 else
1235 {
1236 new_size = listp->size * 2;
1237 listp->list = (struct partial_symbol **)
0efffb96
AC
1238 xrealloc ((char *) listp->list,
1239 new_size * sizeof (struct partial_symbol *));
c906108c
SS
1240 }
1241 /* Next assumes we only went one over. Should be good if
1242 program works correctly */
1243 listp->next = listp->list + listp->size;
1244 listp->size = new_size;
1245}
1246
1247
1248/* Do early runtime initializations. */
1249void
fba45db2 1250_initialize_symmisc (void)
c906108c 1251{
c5aa993b 1252 std_in = stdin;
c906108c
SS
1253 std_out = stdout;
1254 std_err = stderr;
1255}
This page took 1.254478 seconds and 4 git commands to generate.