PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/freebsd/contrib/gdb/gdb/symmisc.c

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