home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / symmisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  20.7 KB  |  818 lines

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