]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: New maint info line-table command.
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 21 Jan 2016 10:03:32 +0000 (11:03 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 11 Mar 2016 22:48:21 +0000 (22:48 +0000)
Add a new command 'maint info line-table' to display the contents of
GDB's internal line table structure.  Useful when trying to understand
problems (within gdb) relating to line tables.

gdb/ChangeLog:

* symmisc.c (maintenance_info_line_tables): New function.
(maintenance_print_one_line_table): New function.
(_initialize_symmisc): Register 'maint info line-table' command.
* NEWS: Mention new command.

gdb/doc/ChangeLog:

* gdb.texinfo (Symbols): Document new 'maint info line-table'
command.

gdb/testsuite/ChangeLog:

* gdb.base/maint.exp: New tests for 'maint info line-table'.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/symmisc.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/maint.exp

index febe9608b8eaad7f92fb342c31915c2f73bf9c91..6eeb1e2eedc8648383b5b049abc80385ef9b506d 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * symmisc.c (maintenance_info_line_tables): New function.
+       (maintenance_print_one_line_table): New function.
+       (_initialize_symmisc): Register 'maint info line-table' command.
+       * NEWS: Mention new command.
+
 2016-03-11  Marcin Koƛcielnicki  <koriakin@0x04.net>
 
        * s390-linux-tdep.c (s390_ax_pseudo_register_collect): New function.
index 55b56b0c64a37ed57ec8551c14eed62a1af7d88f..928f70c55e75e4d0c20384743e1fbc03fecf05a9 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -31,6 +31,9 @@ skip -rfunction regular-expression
   glob-style file names and regular expressions for function names.
   Additionally, a file spec and a function spec may now be combined.
 
+maint info line-table REGEXP
+  Display the contents of GDB's internal line table data struture.
+
 *** Changes in GDB 7.11
 
 * GDB now supports debugging kernel-based threads on FreeBSD.
index 3a98647682246a5213d429a9cf9df30d42bafd91..3d49085ed7d2d6a8cb1bdf7b866ed553f1b8cd4e 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.texinfo (Symbols): Document new 'maint info line-table'
+       command.
+
 2016-03-10  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdb.texinfo (Convenience Functions): Document $_as_string.
index 0b249f401fdd66a4c9aa46b8c090f77a20e5035b..bf7df3557af92c27a636e32a45a85bbb5a7753c4 100644 (file)
@@ -17175,6 +17175,15 @@ line 1574.
 (@value{GDBP})
 @end smallexample
 
+@kindex maint info line-table
+@cindex listing @value{GDBN}'s internal line tables
+@cindex line tables, listing @value{GDBN}'s internal
+@item maint info line-table @r{[} @var{regexp} @r{]}
+
+List the @code{struct linetable} from all @code{struct symtab}
+instances whose name matches @var{regexp}.  If @var{regexp} is not
+given, list the @code{struct linetable} from all @code{struct symtab}.
+
 @kindex maint set symbol-cache-size
 @cindex symbol cache size
 @item maint set symbol-cache-size @var{size}
index 69b7e8e088720c07618748f20f203fe797c36f7f..88daf09ec33ac2b27ad63b61c967be50c8b83670 100644 (file)
@@ -949,6 +949,90 @@ block_depth (struct block *block)
 }
 \f
 
+/* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a
+   single line table.  */
+
+static int
+maintenance_print_one_line_table (struct symtab *symtab, void *data)
+{
+  struct linetable *linetable;
+  struct objfile *objfile;
+
+  objfile = symtab->compunit_symtab->objfile;
+  printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
+                  objfile_name (objfile),
+                  host_address_to_string (objfile));
+  printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"),
+                  host_address_to_string (symtab->compunit_symtab));
+  printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"),
+                  symtab_to_fullname (symtab),
+                  host_address_to_string (symtab));
+  linetable = SYMTAB_LINETABLE (symtab);
+  printf_filtered (_("linetable: ((struct linetable *) %s):\n"),
+                  host_address_to_string (linetable));
+
+  if (linetable == NULL)
+    printf_filtered (_("No line table.\n"));
+  else if (linetable->nitems <= 0)
+    printf_filtered (_("Line table has no lines.\n"));
+  else
+    {
+      int i;
+
+      /* Leave space for 6 digits of index and line number.  After that the
+        tables will just not format as well.  */
+      printf_filtered (_("%-6s %6s %s\n"),
+                      _("INDEX"), _("LINE"), _("ADDRESS"));
+
+      for (i = 0; i < linetable->nitems; ++i)
+       {
+         struct linetable_entry *item;
+         struct cleanup *row_cleanup;
+
+         item = &linetable->item [i];
+         printf_filtered (_("%-6d %6d %s\n"), i, item->line,
+                          core_addr_to_string (item->pc));
+       }
+    }
+
+  return 0;
+}
+
+/* Implement the 'maint info line-table' command.  */
+
+static void
+maintenance_info_line_tables (char *regexp, int from_tty)
+{
+  struct program_space *pspace;
+  struct objfile *objfile;
+
+  dont_repeat ();
+
+  if (regexp != NULL)
+    re_comp (regexp);
+
+  ALL_PSPACES (pspace)
+    ALL_PSPACE_OBJFILES (pspace, objfile)
+    {
+      struct compunit_symtab *cust;
+      struct symtab *symtab;
+
+      ALL_OBJFILE_COMPUNITS (objfile, cust)
+       {
+         ALL_COMPUNIT_FILETABS (cust, symtab)
+           {
+             QUIT;
+
+             if (regexp == NULL
+                 || re_exec (symtab_to_filename_for_display (symtab)))
+               maintenance_print_one_line_table (symtab, NULL);
+           }
+       }
+    }
+}
+
+\f
+
 /* Do early runtime initializations.  */
 
 void
@@ -982,6 +1066,12 @@ linetables --- just the symbol table structures themselves.\n\
 With an argument REGEXP, list the symbol tables with matching names."),
           &maintenanceinfolist);
 
+  add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\
+List the contents of all line tables, from all symbol tables.\n\
+With an argument REGEXP, list just the line tables for the symbol\n\
+tables with matching names."),
+          &maintenanceinfolist);
+
   add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
           _("\
 Check consistency of currently expanded symtabs."),
index 411081cd1515a0ec17d678fe57d998ed620964bd..625359f1710a9168281a40ce5e9bdca4ae3198fa 100644 (file)
@@ -1,3 +1,7 @@
+2016-03-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.base/maint.exp: New tests for 'maint info line-table'.
+
 2016-03-10  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdb.python/py-as-string.exp: New file.
index 79924a7cdeff34b50ff5ac171f5e1d6161731339..f926c8b7bec9941e423d6a99394c52958aafa64f 100644 (file)
@@ -471,6 +471,26 @@ gdb_test "maint" \
     "\"maintenance\" must be followed by the name of a maintenance command\\.\r\nList.*unambiguous\\..*" \
     "maint w/o args"
 
+gdb_test "maint info line-table" \
+    "symtab: \[^\n\r\]+${srcfile}.*\\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX.*LINE.*ADDRESS.*" \
+    "maint info line-table w/o a file name"
+
+gdb_test "maint info line-table ${srcfile}" \
+    "symtab: \[^\n\r\]+${srcfile}.*INDEX.*LINE.*ADDRESS.*" \
+    "maint info line-table with filename of current symtab"
+
+gdb_test_no_output "maint info line-table ${srcfile2}" \
+    "maint info line-table with filename of symtab that is not currently expanded"
+
+gdb_test_no_output "maint expand-symtabs"
+
+gdb_test "maint info line-table ${srcfile2}" \
+    "symtab: \[^\n\r\]+${srcfile2}.*INDEX.*LINE.*ADDRESS.*" \
+    "maint info line-table with filename of symtab that is not current"
+
+gdb_test_no_output "maint info line-table xxx.c" \
+    "maint info line-table with invalid filename"
+
 set timeout $oldtimeout
 
 #============test help on maint commands