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