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