This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA/RFC: dump symtab and psymtab lists


Andrew Cagney <ac131313 at redhat dot com> writes:
> > Could you suggest a way I can provide the utility I need, without
> > introducing an unnecessary inconsistency?  I'm not sure what you're
> > looking for.
> 
> Some level of consistency with the rest of the CLI (which isn't easy).
> 
> > How about 'maint print symtabs [-matching REGEXP] [outfile]'?
> 
> maint grep <table> <expression>
> maint search <table> <expression>

Okay, here's a revised patch that calls them "maint list {,p}symtab".

Perhaps commands that produce so much output that they need to be able
to send it to a file should be renamed to "maint dump"?

gdb/ChangeLog:
2003-04-10  Jim Blandy  <jimb at redhat dot com>

	* symmisc.c: #include "gdb_regex.h".
	(maintenance_list_symtabs, maintenance_list_psymtabs): New
	functions.
	* maint.c (maintenance_list_command): New function.
	(_initialize_maint_cmds): Register the above as commands.
	* symtab.h (maintenance_list_symtabs,
	maintenance_list_psymtabs): New declarations.
	* cli/cli-cmds.c (maintenancelistlist): New variable.
	(init_cmd_lists): Initialize it.
	* cli/cli-cmds.h (maintenancelistlist): New declaration.
	* gdbcmd.h (maintenancelistlist): New declaration.
	* Makefile.in (symmisc.o): Update dependencies.

gdb/doc/ChangeLog:
2003-04-09  Jim Blandy  <jimb at redhat dot com>

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

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	10 Apr 2003 20:21:00 -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/gdbcmd.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbcmd.h,v
retrieving revision 1.8
diff -c -r1.8 gdbcmd.h
*** gdb/gdbcmd.h	17 Jan 2002 22:15:17 -0000	1.8
--- gdb/gdbcmd.h	10 Apr 2003 20:21:00 -0000
***************
*** 98,103 ****
--- 98,107 ----
  
  extern struct cmd_list_element *maintenanceprintlist;
  
+ /* Chain containing all defined "maintenance list" subcommands. */
+ 
+ extern struct cmd_list_element *maintenancelistlist;
+ 
  extern struct cmd_list_element *setprintlist;
  
  extern struct cmd_list_element *showprintlist;
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	10 Apr 2003 20:21:01 -0000
***************
*** 434,439 ****
--- 434,451 ----
    help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
  }
  
+ /* The "maintenance list" command is defined as a prefix, with
+    allow_unknown 0.  Therefore, its own definition is called only for
+    "maintenance print" with no args.  */
+ 
+ /* ARGSUSED */
+ static void
+ maintenance_list_command (char *arg, int from_tty)
+ {
+   printf_unfiltered ("\"maintenance list\" must be followed by the name of a list command.\n");
+   help_list (maintenancelistlist, "maintenance list ", -1, gdb_stdout);
+ }
+ 
  /* The "maintenance translate-address" command converts a section and address
     to a symbol.  This can be called in two ways:
     maintenance translate-address <secname> <addr>
***************
*** 732,737 ****
--- 744,754 ----
  		  &maintenanceprintlist, "maintenance print ", 0,
  		  &maintenancelist);
  
+   add_prefix_cmd ("list", class_maintenance, maintenance_list_command,
+ 		  "Maintenance command for listing GDB internal state.",
+ 		  &maintenancelistlist, "maintenance list ", 0,
+ 		  &maintenancelist);
+ 
    add_prefix_cmd ("set", class_maintenance, maintenance_set_cmd, "\
  Set GDB internal variables used by the GDB maintainer.\n\
  Configure variables internal to GDB that aid in GDB's maintenance",
***************
*** 809,814 ****
--- 826,844 ----
    add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
  	   "Print dump of current object file definitions.",
  	   &maintenanceprintlist);
+ 
+   add_cmd ("symtabs", class_maintenance, maintenance_list_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.",
+ 	   &maintenancelistlist);
+ 
+   add_cmd ("psymtabs", class_maintenance, maintenance_list_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.",
+ 	   &maintenancelistlist);
  
    add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
  	   "Print statistics about internal gdb state.",
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	10 Apr 2003 20:21:02 -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_list_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_list_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/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	10 Apr 2003 20:21:03 -0000
***************
*** 1231,1236 ****
--- 1231,1240 ----
  
  void maintenance_print_objfiles (char *, int);
  
+ void maintenance_list_symtabs (char *, int);
+ 
+ void maintenance_list_psymtabs (char *, int);
+ 
  void maintenance_check_symtabs (char *, int);
  
  /* maint.c */
Index: gdb/cli/cli-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
retrieving revision 1.28
diff -c -r1.28 cli-cmds.c
*** gdb/cli/cli-cmds.c	20 Feb 2003 17:17:25 -0000	1.28
--- gdb/cli/cli-cmds.c	10 Apr 2003 20:21:03 -0000
***************
*** 171,176 ****
--- 171,180 ----
  
  struct cmd_list_element *maintenanceprintlist;
  
+ /* Chain containing all defined "maintenance list" subcommands. */
+ 
+ struct cmd_list_element *maintenancelistlist;
+ 
  struct cmd_list_element *setprintlist;
  
  struct cmd_list_element *showprintlist;
***************
*** 1032,1037 ****
--- 1036,1042 ----
    maintenancelist = NULL;
    maintenanceinfolist = NULL;
    maintenanceprintlist = NULL;
+   maintenancelistlist = NULL;
    setprintlist = NULL;
    showprintlist = NULL;
    setchecklist = NULL;
Index: gdb/cli/cli-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-cmds.h,v
retrieving revision 1.3
diff -c -r1.3 cli-cmds.h
*** gdb/cli/cli-cmds.h	23 Feb 2002 20:12:13 -0000	1.3
--- gdb/cli/cli-cmds.h	10 Apr 2003 20:21:03 -0000
***************
*** 87,92 ****
--- 87,96 ----
  
  extern struct cmd_list_element *maintenanceprintlist;
  
+ /* Chain containing all defined "maintenance list" subcommands. */
+ 
+ extern struct cmd_list_element *maintenancelistlist;
+ 
  extern struct cmd_list_element *setprintlist;
  
  extern struct cmd_list_element *showprintlist;
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	10 Apr 2003 20:21:21 -0000
***************
*** 9033,9039 ****
--- 9033,9097 ----
  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 list symtabs
+ @kindex maint list psymtabs
+ @cindex listing @value{GDBN}'s internal symbol tables
+ @cindex symbol tables, listing @value{GDBN}'s internal
+ @cindex full symbol tables, listing @value{GDBN}'s internal
+ @cindex partial symbol tables, listing @value{GDBN}'s internal
+ @item maint list symtabs @r{[} @var{regexp} @r{]}
+ @itemx maint list psymtabs @r{[} @var{regexp} @r{]}
+ 
+ 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 list 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 list 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 @value{GDBN} 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 list 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]