This is the mail archive of the gdb-patches@sourceware.org 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]

[patch] Fix backtraces on p_vaddr != p_paddr


Hi,

there was bugreport on IRC that in some case GDB displays "??" instead of
function name.  This is because it has:
	Program Headers:
	  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
	  LOAD           0x001000 0x00100000 0x00100000 0x01397 0x01397 RWE 0x1000
	  LOAD           0x003000 0xc0102000 0x00102000 0x04260 0x04260 RWE 0x1000

with VirtAddr != PhysAddr reportedly for GRUB.  insert_section_p then
considers sections there overlays and by default does not resolve them.

I believe with default overlay_debugging == ovly_off it should not consider
VirtAddr != PhysAddr to be an overlay indication, PhysAddr was intended more
for flash loaders etc. than overlays anyway.

I believe with overlay_debugging == ovly_off GDB just should normally follow
VirtAddrs, possibly clashing overlay sections but that is correct.  Since the
original discussion update_section_map no longer crashes on overlapping
sections anyway, the original discussion is around the post:
	Re: [patch] Speed up find_pc_section
	http://sourceware.org/ml/gdb-patches/2009-08/msg00326.html

No regressions on {x86_64,x86_64-m32,i686}-fedora16pre-linux-gnu.
Well, I am expert in neither flash loading nor overlays.

#0  ?? () at ../arch/i386/machine/cpu_asm.S:38
->
#0  cpu_load_gdt () at ../arch/i386/machine/cpu_asm.S:38


Thanks,
Jan


gdb/
2011-08-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* objfiles.c (insert_section_p): Require for overlays also
	OVERLAY_DEBUGGING.
	(objfiles_changed_all_pspaces): New function.
	* objfiles.h (objfiles_changed_all_pspaces): New declaration.
	* symfile.c (overlay_auto_command, overlay_manual_command)
	(overlay_off_command): Call on change objfiles_changed_all_pspaces.

Gdb/testsuite/
2011-08-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.arch/i386-physaddr.S: New file.
	* gdb.arch/i386-physaddr.exp: New file.
	* gdb.arch/i386-physaddr.ld: New file.

--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1123,7 +1123,7 @@ insert_section_p (const struct bfd *abfd,
 {
   const bfd_vma lma = bfd_section_lma (abfd, section);
 
-  if (lma != 0 && lma != bfd_section_vma (abfd, section)
+  if (overlay_debugging && lma != 0 && lma != bfd_section_vma (abfd, section)
       && (bfd_get_file_flags (abfd) & BFD_IN_MEMORY) == 0)
     /* This is an overlay section.  IN_MEMORY check is needed to avoid
        discarding sections from the "system supplied DSO" (aka vdso)
@@ -1496,6 +1496,24 @@ objfiles_changed (void)
   get_objfile_pspace_data (current_program_space)->objfiles_changed_p = 1;
 }
 
+/* Call objfiles_changed for each program_space.  */
+
+void
+objfiles_changed_all_pspaces (void)
+{
+  struct program_space *ss;
+  struct cleanup *old_chain;
+
+  old_chain = save_current_program_space ();
+  ALL_PSPACES (ss)
+  {
+    set_current_program_space (ss);
+    objfiles_changed ();
+  }
+
+  do_cleanups (old_chain);
+}
+
 /* Close ABFD, and warn if that fails.  */
 
 int
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -488,6 +488,8 @@ extern int have_full_symbols (void);
 
 extern void objfiles_changed (void);
 
+extern void objfiles_changed_all_pspaces (void);
+
 /* This operation deletes all objfile entries that represent solibs that
    weren't explicitly loaded by the user, via e.g., the add-symbol-file
    command.  */
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3222,6 +3222,8 @@ unmap_overlay_command (char *args, int from_tty)
 static void
 overlay_auto_command (char *args, int from_tty)
 {
+  if (overlay_debugging == ovly_off)
+    objfiles_changed_all_pspaces ();
   overlay_debugging = ovly_auto;
   enable_overlay_breakpoints ();
   if (info_verbose)
@@ -3235,6 +3237,8 @@ overlay_auto_command (char *args, int from_tty)
 static void
 overlay_manual_command (char *args, int from_tty)
 {
+  if (overlay_debugging == ovly_off)
+    objfiles_changed_all_pspaces ();
   overlay_debugging = ovly_on;
   disable_overlay_breakpoints ();
   if (info_verbose)
@@ -3248,6 +3252,8 @@ overlay_manual_command (char *args, int from_tty)
 static void
 overlay_off_command (char *args, int from_tty)
 {
+  if (overlay_debugging != ovly_off)
+    objfiles_changed_all_pspaces ();
   overlay_debugging = ovly_off;
   disable_overlay_breakpoints ();
   if (info_verbose)
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-physaddr.S
@@ -0,0 +1,36 @@
+/* Copyright 2011 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/>.
+
+   This file is part of the gdb testsuite.  */
+
+_start:	.globl	_start
+	nop
+	nop
+	call	func
+	nop
+	.size	_start, . - _start
+
+/* Workaround GDB internal error.  */
+_dl_debug_state:	.globl _dl_debug_state
+	nop
+	.size	_dl_debug_state, . - _dl_debug_state
+
+	.section	.text.b,"",@progbits
+func:	.globl	func
+	int3
+	int3
+	.size	func, . - func
+
+	.section	.note.GNU-stack,"",@progbits
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-physaddr.exp
@@ -0,0 +1,83 @@
+# Copyright 2011 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/>.
+
+if {(![istarget "x86_64-*-*"] && ![istarget "i?86-*-*"]) || ![is_ilp32_target] } then {
+    verbose "Skipping i386-physaddr test."
+    return
+}
+
+set testfile "i386-physaddr"
+set ldfile ${srcdir}/${subdir}/${testfile}.ld
+set srcfile ${testfile}.S
+set executable ${testfile}
+set binfile ${objdir}/${subdir}/${executable}
+
+# If we're using a stub, breakpoints at the entry point will not trigger.
+# See also the comment in break-entry.exp.
+
+if [target_info exists use_gdb_stub] {
+    untested ${testfile}.exp
+    return
+}
+
+# default_target_compile would otherwise add "-lm" making the testcase
+# dependent on whether the system libraries are already prelinked.
+# prelink: Could not set /lib64/libm-2.11.1.so owner or mode: Operation not permitted
+proc compile {} {
+    global srcdir subdir srcfile binfile ldfile
+    return [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list "additional_flags=-static -nostdlib -Wl,-T,${ldfile}"]]
+}
+set board [target_info name]
+if [board_info $board exists mathlib] {
+    set mathlib [board_info $dest mathlib]
+    set_board_info mathlib ""
+    set err [compile]
+    set_board_info mathlib $mathlib
+} else {
+    set_board_info mathlib ""
+    set err [compile]
+    unset_board_info mathlib
+}
+if {$err != ""} {
+    untested ${testfile}.exp
+    return -1
+}
+
+clean_restart $executable
+
+set test "info addr _DYNAMIC"
+gdb_test_multiple $test $test {
+    -re "No symbol \"_DYNAMIC\" in current context\\.\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "Symbol \"_DYNAMIC\" is at 0x\[0-9a-f\]+ .*\r\n$gdb_prompt $" {
+	# Some systems may have default -pie with inappropriate startup code.
+	xfail $test
+	untested ${testfile}.exp
+	return -1
+    }
+}
+
+if ![runto func] then {
+    return -1
+}
+
+gdb_test "frame" {#0  0x08049000 in func \(\)} "overlay default"
+
+gdb_test "overlay manual"
+gdb_test "frame" {#0  0x08049000 in \?\? \(\)} "overlay manual"
+
+gdb_test "overlay off"
+gdb_test "frame" {#0  0x08049000 in func \(\)} "overlay off"
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-physaddr.ld
@@ -0,0 +1,29 @@
+/* Copyright 2011 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/>.
+
+   This file is part of the gdb testsuite.  */
+
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+OUTPUT_ARCH(i386)
+ENTRY(_start)
+SECTIONS
+{
+  . = 0x8048000;
+  .text : { *(.text) }
+  . = 0x8049000;
+  .text.b : AT(0xa049000) { *(.text.b) }
+  .note.GNU-stack : { *(.note.GNU-stack) }
+}
+


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