PR symtab/17559
authorDoug Evans <xdje42@gmail.com>
Sat, 15 Nov 2014 18:08:34 +0000 (10:08 -0800)
committerDoug Evans <xdje42@gmail.com>
Sat, 15 Nov 2014 18:08:34 +0000 (10:08 -0800)
Basically the problem is that "symtab" is ambiguous.
Is it the primary symtab (where we canonically think of
blockvectors as being stored) or is it for a specific file
(where each file's line table is stored) ?

gdb_disassembly wants the symtab that contains the line table
but is instead getting the primary symtab.

gdb/ChangeLog:

PR symtab/17559
* symtab.c (find_pc_line_symtab): New function.
* symtab.h (find_pc_line_symtab): Declare.
* disasm.c (gdb_disassembly): Call find_pc_line_symtab instead of
find_pc_symtab.
* tui/tui-disasm.c (tui_set_disassem_content): Ditto.
* tui/tui-hooks.c (tui_selected_frame_level_changed_hook): Ditto.
* tui/tui-source.c (tui_vertical_source_scroll): Ditto.
* tui/tui-win.c (make_visible_with_new_height): Ditto.
* tui/tui-winsource.c (tui_horizontal_source_scroll): Ditto.
(tui_display_main): Call find_pc_line_symtab instead of find_pc_line.

gdb/testsuite/ChangeLog:

PR symtab/17559
* gdb.base/line-symtabs.exp: New file.
* gdb.base/line-symtabs.c: New file.
* gdb.base/line-symtabs.h: New file.

13 files changed:
gdb/ChangeLog
gdb/disasm.c
gdb/symtab.c
gdb/symtab.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/line-symtabs.c [new file with mode: 0644]
gdb/testsuite/gdb.base/line-symtabs.exp [new file with mode: 0644]
gdb/testsuite/gdb.base/line-symtabs.h [new file with mode: 0644]
gdb/tui/tui-disasm.c
gdb/tui/tui-hooks.c
gdb/tui/tui-source.c
gdb/tui/tui-win.c
gdb/tui/tui-winsource.c

index 6198d5433c4d02789a56c9bfe58bed2fbb4a8062..6bd84c0467845c263d442d33b1de50a4d63dc568 100644 (file)
@@ -1,3 +1,17 @@
+2014-11-15  Doug Evans  <xdje42@gmail.com>
+
+       PR symtab/17559
+       * symtab.c (find_pc_line_symtab): New function.
+       * symtab.h (find_pc_line_symtab): Declare.
+       * disasm.c (gdb_disassembly): Call find_pc_line_symtab instead of
+       find_pc_symtab.
+       * tui/tui-disasm.c (tui_set_disassem_content): Ditto.
+       * tui/tui-hooks.c (tui_selected_frame_level_changed_hook): Ditto.
+       * tui/tui-source.c (tui_vertical_source_scroll): Ditto.
+       * tui/tui-win.c (make_visible_with_new_height): Ditto.
+       * tui/tui-winsource.c (tui_horizontal_source_scroll): Ditto.
+       (tui_display_main): Call find_pc_line_symtab instead of find_pc_line.
+
 2014-11-15  Doug Evans  <xdje42@gmail.com>
 
        * symtab.c (expand_symtab_containing_pc): Renamed from
index 6ff3793f2e76155376571a67d0657ac13f001412..365aa94f0994e832471cd37acdb110d0606a16df 100644 (file)
@@ -410,13 +410,12 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
   struct ui_file *stb = mem_fileopen ();
   struct cleanup *cleanups = make_cleanup_ui_file_delete (stb);
   struct disassemble_info di = gdb_disassemble_info (gdbarch, stb);
-  /* To collect the instruction outputted from opcodes.  */
-  struct symtab *symtab = NULL;
+  struct symtab *symtab;
   struct linetable_entry *le = NULL;
   int nlines = -1;
 
   /* Assume symtab is valid for whole PC range.  */
-  symtab = find_pc_symtab (low);
+  symtab = find_pc_line_symtab (low);
 
   if (symtab != NULL && symtab->linetable != NULL)
     {
index 4672ac31eabf2b53fddc6ccd3d3d19be699cdecd..d2146bb2a90ce39f5b41a1b425424ed347e882b6 100644 (file)
@@ -2431,6 +2431,19 @@ find_pc_line (CORE_ADDR pc, int notcurrent)
     pc = overlay_mapped_address (pc, section);
   return find_pc_sect_line (pc, section, notcurrent);
 }
+
+/* See symtab.h.  */
+
+struct symtab *
+find_pc_line_symtab (CORE_ADDR pc)
+{
+  struct symtab_and_line sal;
+
+  /* This always passes zero for NOTCURRENT to find_pc_line.
+     There are currently no callers that ever pass non-zero.  */
+  sal = find_pc_line (pc, 0);
+  return sal.symtab;
+}
 \f
 /* Find line number LINE in any symtab whose name is the same as
    SYMTAB.
index d69fbcfc32000e180c939ee6b8fe251b4cc02322..257d3be217606c873f1cc2d9189dd2e5c3dd82b4 100644 (file)
@@ -1271,6 +1271,10 @@ extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
 extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
                                                 struct obj_section *, int);
 
+/* Wrapper around find_pc_line to just return the symtab.  */
+
+extern struct symtab *find_pc_line_symtab (CORE_ADDR);
+
 /* Given a symtab and line number, return the pc there.  */
 
 extern int find_line_pc (struct symtab *, int, CORE_ADDR *);
index ce9c8192c0f5342e538486ad17d07a62fae06190..65687c011b765bf0dd22cfeaa8ddfc18f3dd0da9 100644 (file)
@@ -1,3 +1,10 @@
+2014-11-15  Doug Evans  <xdje42@gmail.com>
+
+       PR symtab/17559
+       * gdb.base/line-symtabs.exp: New file.
+       * gdb.base/line-symtabs.c: New file.
+       * gdb.base/line-symtabs.h: New file.
+
 2014-11-14  Yao Qi  <yao@codesourcery.com>
 
        * gdb.dwarf2/dw2-ifort-parameter.c: Remove inline asm.
diff --git a/gdb/testsuite/gdb.base/line-symtabs.c b/gdb/testsuite/gdb.base/line-symtabs.c
new file mode 100644 (file)
index 0000000..d21c711
--- /dev/null
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "line-symtabs.h"
+
+int
+main ()
+{
+  header_function ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/line-symtabs.exp b/gdb/testsuite/gdb.base/line-symtabs.exp
new file mode 100644 (file)
index 0000000..9bcbb92
--- /dev/null
@@ -0,0 +1,33 @@
+# Test handling of line symbol tables (non-primary symtabs).
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile .c line-symtabs.h
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    return -1
+}
+
+if ![runto_main] {
+    fail "Can't run to main"
+    return -1
+}
+
+# PR 17559: gdb_disassembly was using the wrong symtab lookup function.
+# It was expecting the symtab of the source file containing $pc,
+# instead it was getting the primary symtab of that compilation unit.
+gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here} $srcfile2]"
+gdb_continue_to_breakpoint "continue to breakpoint in header"
+gdb_test "disas /m" "break here.*End of assembler dump\\."
diff --git a/gdb/testsuite/gdb.base/line-symtabs.h b/gdb/testsuite/gdb.base/line-symtabs.h
new file mode 100644 (file)
index 0000000..7e19060
--- /dev/null
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int x;
+
+void
+header_function (void)
+{
+  x = 42; /* break here */
+}
index 1c89a14cfd9f30866342924cc39c98c5dcc9ed7b..88b14de31fdcc2202362b6b58064eaa4baa29722 100644 (file)
@@ -275,7 +275,7 @@ tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc)
 void
 tui_show_disassem (struct gdbarch *gdbarch, CORE_ADDR start_addr)
 {
-  struct symtab *s = find_pc_symtab (start_addr);
+  struct symtab *s = find_pc_line_symtab (start_addr);
   struct tui_win_info *win_with_focus = tui_win_with_focus ();
   struct tui_line_or_address val;
 
index 7db392a42711db37009c39214db665ba976bdc06..4c6e4504604e00657b1aac7bdd2372693781ac2b 100644 (file)
@@ -202,7 +202,7 @@ tui_selected_frame_level_changed_hook (int level)
     {
       struct symtab *s;
 
-      s = find_pc_symtab (pc);
+      s = find_pc_line_symtab (pc);
       /* elz: This if here fixes the problem with the pc not being
         displayed in the tui asm layout, with no debug symbols.  The
         value of s would be 0 here, and select_source_symtab would
index 7aceaa8e98992e986c222ef4bfafc7ec076d09dc..9842bb37e3a9411b1b14d461f887c94023b58b86 100644 (file)
@@ -357,7 +357,7 @@ tui_vertical_source_scroll (enum tui_scroll_direction scroll_direction,
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
 
       if (cursal.symtab == (struct symtab *) NULL)
-       s = find_pc_symtab (get_frame_pc (get_selected_frame (NULL)));
+       s = find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)));
       else
        s = cursal.symtab;
 
index 9c7a23f8b4968a568ee6e2100aefade1f5c691c5..d17a1e4741c8bbe4ffe520c57804d64f02e8dcd6 100644 (file)
@@ -1386,7 +1386,7 @@ make_visible_with_new_height (struct tui_win_info *win_info)
          struct frame_info *frame = deprecated_safe_get_selected_frame ();
          struct gdbarch *gdbarch = get_frame_arch (frame);
 
-         s = find_pc_symtab (get_frame_pc (frame));
+         s = find_pc_line_symtab (get_frame_pc (frame));
          if (win_info->generic.type == SRC_WIN)
            {
              line.loa = LOA_LINE;
index 171b1712bed2c8b0b191b033af079b39b6163e7c..48a95e4edcb822f2b877639943532b1706d07e87 100644 (file)
@@ -51,12 +51,12 @@ tui_display_main (void)
       tui_get_begin_asm_address (&gdbarch, &addr);
       if (addr != (CORE_ADDR) 0)
        {
-         struct symtab_and_line sal;
+         struct symtab *s;
 
          tui_update_source_windows_with_addr (gdbarch, addr);
-         sal = find_pc_line (addr, 0);
-          if (sal.symtab)
-             tui_update_locator_fullname (symtab_to_fullname (sal.symtab));
+         s = find_pc_line_symtab (addr);
+          if (s != NULL)
+             tui_update_locator_fullname (symtab_to_fullname (s));
           else
              tui_update_locator_fullname ("??");
        }
@@ -331,7 +331,7 @@ tui_horizontal_source_scroll (struct tui_win_info *win_info,
            = get_current_source_symtab_and_line ();
 
          if (cursal.symtab == NULL)
-           s = find_pc_symtab (get_frame_pc (get_selected_frame (NULL)));
+           s = find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)));
          else
            s = cursal.symtab;
        }
This page took 0.039051 seconds and 4 git commands to generate.