PR ld/12549
[binutils-gdb.git] / gdb / symmisc.c
index 3e9ca82d7e33a634cd57fd18162e3466ce8ae002..5fa4e4e0fbd03b86e5a505258f1c28f15ebf5291 100644 (file)
@@ -1,7 +1,6 @@
 /* Do various things to symbol tables (other than lookup), for GDB.
 
-   Copyright (C) 1986-2000, 2002-2004, 2007-2012 Free Software
-   Foundation, Inc.
+   Copyright (C) 1986-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -35,6 +34,9 @@
 #include "gdb_regex.h"
 #include "gdb_stat.h"
 #include "dictionary.h"
+#include "typeprint.h"
+#include "gdbcmd.h"
+#include "source.h"
 
 #include "gdb_string.h"
 #include "readline/readline.h"
@@ -92,7 +94,8 @@ print_symbol_bcache_statistics (void)
     printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
     print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
                              "partial symbol cache");
-    print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
+    print_bcache_statistics (objfile->per_bfd->macro_cache,
+                            "preprocessor macro cache");
     print_bcache_statistics (objfile->per_bfd->filename_cache,
                             "file name cache");
   }
@@ -154,7 +157,7 @@ print_objfile_statistics (void)
                     bcache_memory_used (psymbol_bcache_get_bcache
                                          (objfile->psymbol_cache)));
     printf_filtered (_("  Total memory used for macro cache: %d\n"),
-                    bcache_memory_used (objfile->macro_cache));
+                    bcache_memory_used (objfile->per_bfd->macro_cache));
     printf_filtered (_("  Total memory used for file name cache: %d\n"),
                     bcache_memory_used (objfile->per_bfd->filename_cache));
   }
@@ -183,7 +186,7 @@ dump_objfile (struct objfile *objfile)
           symtab != NULL;
           symtab = symtab->next)
        {
-         printf_filtered ("%s at ", symtab->filename);
+         printf_filtered ("%s at ", symtab_to_filename_for_display (symtab));
          gdb_print_host_address (symtab, gdb_stdout);
          printf_filtered (", ");
          if (symtab->objfile != objfile)
@@ -292,7 +295,8 @@ dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
   struct block *b;
   int depth;
 
-  fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
+  fprintf_filtered (outfile, "\nSymtab for file %s\n",
+                   symtab_to_filename_for_display (symtab));
   if (symtab->dirname)
     fprintf_filtered (outfile, "Compilation directory is %s\n",
                      symtab->dirname);
@@ -399,7 +403,7 @@ dump_symtab (struct objfile *objfile, struct symtab *symtab,
     dump_symtab_1 (objfile, symtab, outfile);
 }
 
-void
+static void
 maintenance_print_symbols (char *args, int from_tty)
 {
   char **argv;
@@ -441,7 +445,8 @@ maintenance_print_symbols (char *args, int from_tty)
   ALL_SYMTABS (objfile, s)
     {
       QUIT;
-      if (symname == NULL || filename_cmp (symname, s->filename) == 0)
+      if (symname == NULL
+         || filename_cmp (symname, symtab_to_filename_for_display (s)) == 0)
        dump_symtab (objfile, s, outfile);
     }
   do_cleanups (cleanups);
@@ -479,7 +484,8 @@ print_symbol (void *args)
     {
       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
        {
-         LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
+         LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
+                        &type_print_raw_options);
        }
       else
        {
@@ -489,7 +495,8 @@ print_symbol (void *args)
                     : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
                        ? "struct" : "union")),
                            SYMBOL_LINKAGE_NAME (symbol));
-         LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
+         LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth,
+                        &type_print_raw_options);
        }
       fprintf_filtered (outfile, ";\n");
     }
@@ -503,7 +510,8 @@ print_symbol (void *args)
          LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol),
                         outfile,
                         TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
-                        depth);
+                        depth,
+                        &type_print_raw_options);
          fprintf_filtered (outfile, "; ");
        }
       else
@@ -621,7 +629,7 @@ print_symbol (void *args)
   return 1;
 }
 
-void
+static void
 maintenance_print_msymbols (char *args, int from_tty)
 {
   char **argv;
@@ -650,7 +658,7 @@ maintenance_print_msymbols (char *args, int from_tty)
       /* If a second arg is supplied, it is a source file name to match on.  */
       if (argv[1] != NULL)
        {
-         symname = xfullpath (argv[1]);
+         symname = gdb_realpath (argv[1]);
          make_cleanup (xfree, symname);
          if (symname && stat (symname, &sym_st))
            perror_with_name (symname);
@@ -670,6 +678,7 @@ maintenance_print_msymbols (char *args, int from_tty)
       {
        QUIT;
        if (symname == NULL || (!stat (objfile->name, &obj_st)
+                               && sym_st.st_dev == obj_st.st_dev
                                && sym_st.st_ino == obj_st.st_ino))
          dump_msymbols (objfile, outfile);
       }
@@ -677,7 +686,7 @@ maintenance_print_msymbols (char *args, int from_tty)
   do_cleanups (cleanups);
 }
 
-void
+static void
 maintenance_print_objfiles (char *ignore, int from_tty)
 {
   struct program_space *pspace;
@@ -693,9 +702,9 @@ maintenance_print_objfiles (char *ignore, int from_tty)
       }
 }
 
-
 /* List all the symbol tables whose names match REGEXP (optional).  */
-void
+
+static void
 maintenance_info_symtabs (char *regexp, int from_tty)
 {
   struct program_space *pspace;
@@ -718,7 +727,7 @@ maintenance_info_symtabs (char *regexp, int from_tty)
          QUIT;
 
          if (! regexp
-             || re_exec (symtab->filename))
+             || re_exec (symtab_to_filename_for_display (symtab)))
            {
              if (! printed_objfile_start)
                {
@@ -729,7 +738,8 @@ maintenance_info_symtabs (char *regexp, int from_tty)
                  printed_objfile_start = 1;
                }
 
-             printf_filtered ("        { symtab %s ", symtab->filename);
+             printf_filtered ("        { symtab %s ",
+                              symtab_to_filename_for_display (symtab));
              wrap_here ("    ");
              printf_filtered ("((struct symtab *) %s)\n", 
                               host_address_to_string (symtab));
@@ -772,10 +782,34 @@ block_depth (struct block *block)
 \f
 
 /* Do early runtime initializations.  */
+
 void
 _initialize_symmisc (void)
 {
   std_in = stdin;
   std_out = stdout;
   std_err = stderr;
+
+  add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
+Print dump of current symbol definitions.\n\
+Entries in the full symbol table are dumped to file OUTFILE.\n\
+If a SOURCE file is specified, dump only that file's symbols."),
+          &maintenanceprintlist);
+
+  add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
+Print dump of current minimal symbol definitions.\n\
+Entries in the minimal symbol table are dumped to file OUTFILE.\n\
+If a SOURCE file is specified, dump only that file's minimal symbols."),
+          &maintenanceprintlist);
+
+  add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
+          _("Print dump of current object file definitions."),
+          &maintenanceprintlist);
+
+  add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
+List the full symbol tables for all object files.\n\
+This does not include information about individual symbols, blocks, or\n\
+linetables --- just the symbol table structures themselves.\n\
+With an argument REGEXP, list the symbol tables whose names that match that."),
+          &maintenanceinfolist);
 }