RFA/RFC: dump symtab and psymtab lists

Jim Blandy jimb@redhat.com
Mon Apr 7 23:41:00 GMT 2003


This patch adds two new commands, 'maint print symtabs' and 'maint
print psymtabs', that print out the full and partial symtab lists.
You can supply a regexp to match against the (p)symtab name to just
list a few.

The existing 'maint print symbols' and 'maint print psymbols' are
exhaustive, which is useful sometimes, but they produce so much output
that they're a pain to use when you just want to see what's up with
the symtab and psymtab lists themselves.

The output includes expressions you can cut-and-paste into GDB to get
a pointer to a specific symtab, psymtab, etc., and it's parenthesized
to make the Emacs balanced motion commands work usefully.  The
documentation includes examples.

(This includes a documentation change, which needs approval.)

gdb/ChangeLog:
2003-04-07  Jim Blandy  <jimb@redhat.com>

	* symmisc.c (maintenance_print_symtabs,
	maintenance_print_psymtabs): New functions.
	* maint.c (_initialize_maint_cmds): Add commands for the above.
	* symtab.h (maintenance_print_symtabs,
	maintenance_print_psymtabs): New declarations.
	* Makefile.in (symmisc.o): Update dependencies.

gdb/doc/ChangeLog:
2003-04-07  Jim Blandy  <jimb@redhat.com>

	* gdb.texinfo (Symbols): Document 'maint print symtabs' and 'maint
	print psymtabs'.

Index: gdb/symmisc.c
===================================================================
RCS file: /cvs/src/src/gdb/symmisc.c,v
retrieving revision 1.19
diff -c -r1.19 symmisc.c
*** gdb/symmisc.c	25 Feb 2003 21:36:20 -0000	1.19
--- gdb/symmisc.c	7 Apr 2003 23:35:27 -0000
***************
*** 33,38 ****
--- 33,39 ----
  #include "language.h"
  #include "bcache.h"
  #include "block.h"
+ #include "gdb_regex.h"
  
  #include "gdb_string.h"
  #include <readline/readline.h>
***************
*** 984,989 ****
--- 985,1129 ----
      dump_objfile (objfile);
    immediate_quit--;
  }
+ 
+ 
+ /* List all the symbol tables.  */
+ void
+ maintenance_print_symtabs (char *regexp, int from_tty)
+ {
+   struct objfile *objfile;
+ 
+   if (regexp)
+     re_comp (regexp);
+ 
+   ALL_OBJFILES (objfile)
+     {
+       struct symtab *symtab;
+       
+       /* We don't want to print anything for this objfile until we
+          actually find a symtab whose name matches.  */
+       int printed_objfile_start = 0;
+ 
+       ALL_OBJFILE_SYMTABS (objfile, symtab)
+         if (! regexp
+             || re_exec (symtab->filename))
+           {
+             if (! printed_objfile_start)
+               {
+                 printf_filtered ("{ objfile %s ", objfile->name);
+                 wrap_here ("  ");
+                 printf_filtered ("((struct objfile *) %p)\n", objfile);
+                 printed_objfile_start = 1;
+               }
+ 
+             printf_filtered ("  { symtab %s ", symtab->filename);
+             wrap_here ("    ");
+             printf_filtered ("((struct symtab *) %p)\n", symtab);
+             printf_filtered ("    dirname %s\n",
+                              symtab->dirname ? symtab->dirname : "(null)");
+             printf_filtered ("    fullname %s\n",
+                              symtab->fullname ? symtab->fullname : "(null)");
+             printf_filtered ("    blockvector ((struct blockvector *) %p)%s\n",
+                              symtab->blockvector,
+                              symtab->primary ? " (primary)" : "");
+             printf_filtered ("    debugformat %s\n", symtab->debugformat);
+             printf_filtered ("  }\n");
+           }
+ 
+       if (printed_objfile_start)
+         printf_filtered ("}\n");
+     }
+ }
+ 
+ 
+ /* List all the partial symbol tables.  */
+ void
+ maintenance_print_psymtabs (char *regexp, int from_tty)
+ {
+   struct objfile *objfile;
+ 
+   if (regexp)
+     re_comp (regexp);
+ 
+   ALL_OBJFILES (objfile)
+     {
+       struct partial_symtab *psymtab;
+ 
+       /* We don't want to print anything for this objfile until we
+          actually find a symtab whose name matches.  */
+       int printed_objfile_start = 0;
+ 
+       ALL_OBJFILE_PSYMTABS (objfile, psymtab)
+         if (! regexp
+             || re_exec (psymtab->filename))
+           {
+             if (! printed_objfile_start)
+               {
+                 printf_filtered ("{ objfile %s ", objfile->name);
+                 wrap_here ("  ");
+                 printf_filtered ("((struct objfile *) %p)\n", objfile);
+                 printed_objfile_start = 1;
+               }
+ 
+             printf_filtered ("  { psymtab %s ", psymtab->filename);
+             wrap_here ("    ");
+             printf_filtered ("((struct partial_symtab *) %p)\n", psymtab);
+             printf_filtered ("    readin %s\n",
+                              psymtab->readin ? "yes" : "no");
+             printf_filtered ("    fullname %s\n",
+                              psymtab->fullname ? psymtab->fullname : "(null)");
+             printf_filtered ("    text addresses ");
+             print_address_numeric (psymtab->textlow, 1, gdb_stdout);
+             printf_filtered (" -- ");
+             print_address_numeric (psymtab->texthigh, 1, gdb_stdout);
+             printf_filtered ("\n");
+             printf_filtered ("    globals ");
+             if (psymtab->n_global_syms)
+               {
+                 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
+                                  (psymtab->objfile->global_psymbols.list
+                                   + psymtab->globals_offset),
+                                  psymtab->n_global_syms);
+               }
+             else
+               printf_filtered ("(none)\n");
+             printf_filtered ("    statics ");
+             if (psymtab->n_static_syms)
+               {
+                 printf_filtered ("(* (struct partial_symbol **) %p @ %d)\n",
+                                  (psymtab->objfile->static_psymbols.list
+                                   + psymtab->statics_offset),
+                                  psymtab->n_static_syms);
+               }
+             else
+               printf_filtered ("(none)\n");
+             printf_filtered ("    dependencies ");
+             if (psymtab->number_of_dependencies)
+               {
+                 int i;
+ 
+                 printf_filtered ("{\n");
+                 for (i = 0; i < psymtab->number_of_dependencies; i++)
+                   {
+                     struct partial_symtab *dep = psymtab->dependencies[i];
+ 
+                     /* Note the string concatenation there --- no comma.  */
+                     printf_filtered ("      psymtab %s "
+                                      "((struct partial_symtab *) %p)\n",
+                                      dep->filename, dep);
+                   }
+                 printf_filtered ("    }\n");
+               }
+             else
+               printf_filtered ("(none)\n");
+             printf_filtered ("  }\n");
+           }
+ 
+       if (printed_objfile_start)
+         printf_filtered ("}\n");
+     }
+ }
+ 
  
  /* Check consistency of psymtabs and symtabs.  */
  
Index: gdb/maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.36
diff -c -r1.36 maint.c
*** gdb/maint.c	2 Apr 2003 03:02:46 -0000	1.36
--- gdb/maint.c	7 Apr 2003 23:35:26 -0000
***************
*** 810,815 ****
--- 810,828 ----
  	   "Print dump of current object file definitions.",
  	   &maintenanceprintlist);
  
+   add_cmd ("symtabs", class_maintenance, maintenance_print_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.",
+ 	   &maintenanceprintlist);
+ 
+   add_cmd ("psymtabs", class_maintenance, maintenance_print_psymtabs,
+ 	   "List the partial symbol tables for all object files.\n\
+ This does not include information about individual partial symbols,\n\
+ just the symbol table structures themselves.",
+ 	   &maintenanceprintlist);
+ 
    add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
  	   "Print statistics about internal gdb state.",
  	   &maintenanceprintlist);
Index: gdb/symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.65
diff -c -r1.65 symtab.h
*** gdb/symtab.h	3 Mar 2003 18:34:12 -0000	1.65
--- gdb/symtab.h	7 Apr 2003 23:35:30 -0000
***************
*** 1231,1236 ****
--- 1231,1240 ----
  
  void maintenance_print_objfiles (char *, int);
  
+ void maintenance_print_symtabs (char *, int);
+ 
+ void maintenance_print_psymtabs (char *, int);
+ 
  void maintenance_check_symtabs (char *, int);
  
  /* maint.c */
Index: gdb/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.360
diff -c -r1.360 Makefile.in
*** gdb/Makefile.in	6 Apr 2003 01:13:58 -0000	1.360
--- gdb/Makefile.in	7 Apr 2003 23:35:26 -0000
***************
*** 2254,2260 ****
  symmisc.o: symmisc.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(bfd_h) \
  	$(symfile_h) $(objfiles_h) $(breakpoint_h) $(command_h) \
  	$(gdb_obstack_h) $(language_h) $(bcache_h) $(gdb_string_h) \
! 	$(readline_h) $(block_h)
  symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \
  	$(frame_h) $(target_h) $(value_h) $(symfile_h) $(objfiles_h) \
  	$(gdbcmd_h) $(call_cmds_h) $(gdb_regex_h) $(expression_h) \
--- 2254,2260 ----
  symmisc.o: symmisc.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(bfd_h) \
  	$(symfile_h) $(objfiles_h) $(breakpoint_h) $(command_h) \
  	$(gdb_obstack_h) $(language_h) $(bcache_h) $(gdb_string_h) \
! 	$(readline_h) $(block_h) $(gdb_regex_h)
  symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \
  	$(frame_h) $(target_h) $(value_h) $(symfile_h) $(objfiles_h) \
  	$(gdbcmd_h) $(call_cmds_h) $(gdb_regex_h) $(expression_h) \
Index: gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.155
diff -c -r1.155 gdb.texinfo
*** gdb/doc/gdb.texinfo	2 Apr 2003 22:10:35 -0000	1.155
--- gdb/doc/gdb.texinfo	7 Apr 2003 23:35:46 -0000
***************
*** 9033,9039 ****
--- 9033,9095 ----
  required for each object file from which @value{GDBN} has read some symbols.
  @xref{Files, ,Commands to specify files}, for a discussion of how
  @value{GDBN} reads symbols (in the description of @code{symbol-file}).
+ 
+ @kindex maint print symtabs
+ @kindex maint print psymtabs
+ @cindex listing GDB's internal symbol tables
+ @cindex symbol tables, listing GDB's internal
+ @item maint print symtabs [@var{regexp}]
+ @itemx maint print psymtabs [@var{regexp}]
+ 
+ List the @code{struct symtab} or @code{struct partial_symtab}
+ structures whose names match @var{regexp}.  If @var{regexp} is not
+ given, list them all.  The output includes expressions which you can
+ copy into a @value{GDBN} debugging this one to examine a particular
+ structure in more detail.  For example:
+ 
+ @smallexample
+ (@value{GDBP}) maint print psymtabs dwarf2read
+ @{ objfile /home/gnu/build/gdb/gdb
+   ((struct objfile *) 0x82e69d0)
+   @{ psymtab /home/gnu/src/gdb/dwarf2read.c 
+     ((struct partial_symtab *) 0x8474b10)
+     readin no
+     fullname (null)
+     text addresses 0x814d3c8 -- 0x8158074
+     globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
+     statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
+     dependencies (none)
+   @}
+ @}
+ (@value{GDBP}) maint print symtabs
+ (@value{GDBP})
+ @end smallexample
+ @noindent
+ We see that there is one partial symbol table whose filename contains
+ the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
+ and we see that @value{GDBN} has not read in any symtabs yet at all.
+ If we set a breakpoint on a function, that will cause GDB to read the
+ symtab for the compilation unit containing that function:
+ 
+ @smallexample
+ (@value{GDBP}) break dwarf2_psymtab_to_symtab
+ Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
+ line 1574.
+ (@value{GDBP}) maint print symtabs
+ @{ objfile /home/gnu/build/gdb/gdb 
+   ((struct objfile *) 0x82e69d0)
+   @{ symtab /home/gnu/src/gdb/dwarf2read.c 
+     ((struct symtab *) 0x86c1f38)
+     dirname (null)
+     fullname (null)
+     blockvector ((struct blockvector *) 0x86c1bd0) (primary)
+     debugformat DWARF 2
+   @}
+ @}
+ (@value{GDBP}) 
+ @end smallexample
  @end table
+ 
  
  @node Altering
  @chapter Altering Execution



More information about the Gdb-patches mailing list