keiths / rpms / gdb

Forked from rpms/gdb 11 days ago
Clone
b048379
2006-10-30  Jan Kratochvil  <jan.kratochvil@redhat.com>
b048379
b048379
	* gdb/minsyms.c (lookup_minimal_symbol_by_pc_section): Handle
b048379
	overlapping non-zero sized functions (for glibc `__nanosleep').
b048379
b048379
2006-10-30  Jan Kratochvil  <jan.kratochvil@redhat.com>
b048379
b048379
	* gdb.arch/i386-size-overlap.c, gdb.arch/i386-size-overlap.exp: New
b048379
	file, provide nested (overlapping) functions for the PC resolving.
b048379
b048379
aefb0e1
Index: ./gdb/minsyms.c
aefb0e1
===================================================================
aefb0e1
--- ./gdb/minsyms.c	17 Oct 2006 20:17:44 -0000	1.47
aefb0e1
+++ ./gdb/minsyms.c	30 Oct 2006 12:41:26 -0000
aefb0e1
@@ -511,6 +511,29 @@ lookup_minimal_symbol_by_pc_section (COR
aefb0e1
 		      continue;
aefb0e1
 		    }
b048379
 
b048379
+		  /* We are behind the current symbol's size.
b048379
+		     Try the previous symbol - if it is non-zero sized one it
b048379
+		     may overlap the current one and reach our PC.
b048379
+		     It occurs for GNU/Linux glibc `__nanosleep' overlapping
b048379
+		     later `__nanosleep_nocancel' with PC at 0077ec66:
b048379
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
b048379
+  7247: 0077ec20   124 FUNC    WEAK   DEFAULT   11 __nanosleep
b048379
+  4651: 0077ec2a    32 FUNC    LOCAL  DEFAULT   11 __nanosleep_nocancel
b048379
+		     Test `gdb.arch/i386-size' + `gdb.arch/i386-unwind'.
b048379
+		     Limit it only for the overlapping cases as we could harm
b048379
+		     the zero-sized symbols detection logic around.
b048379
+		     */
aefb0e1
+		  if (hi > 0
aefb0e1
+		      && MSYMBOL_SIZE (&msymbol[hi]) != 0
aefb0e1
+		      && pc >= (SYMBOL_VALUE_ADDRESS (&msymbol[hi])
aefb0e1
+				+ MSYMBOL_SIZE (&msymbol[hi]))
aefb0e1
+		      && pc < (SYMBOL_VALUE_ADDRESS (&msymbol[hi - 1])
aefb0e1
+			       + MSYMBOL_SIZE (&msymbol[hi - 1])))
aefb0e1
+		    {
aefb0e1
+		      hi--;
aefb0e1
+		      continue;
aefb0e1
+		    }
aefb0e1
+
aefb0e1
 		  /* Otherwise, this symbol must be as good as we're going
aefb0e1
 		     to get.  */
aefb0e1
 		  break;
b048379
Index: ./gdb/testsuite/gdb.arch/i386-size-overlap.c
b048379
===================================================================
b048379
--- /dev/null	1 Jan 1970 00:00:00 -0000
b048379
+++ ./gdb/testsuite/gdb.arch/i386-size-overlap.c	30 Oct 2006 12:41:35 -0000
b048379
@@ -0,0 +1,53 @@
b048379
+/* Overlapping symbol sizes test program.
b048379
+
b048379
+   Copyright 2006 Free Software Foundation, Inc.
b048379
+
b048379
+   This file is part of GDB.
b048379
+
b048379
+   This program is free software; you can redistribute it and/or modify
b048379
+   it under the terms of the GNU General Public License as published by
b048379
+   the Free Software Foundation; either version 2 of the License, or
b048379
+   (at your option) any later version.
b048379
+   
b048379
+   This program is distributed in the hope that it will be useful,
b048379
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b048379
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b048379
+   GNU General Public License for more details.
b048379
+   
b048379
+   You should have received a copy of the GNU General Public License
b048379
+   along with this program; if not, write to the Free Software
b048379
+   Foundation, Inc., 59 Temple Place - Suite 330,
b048379
+   Boston, MA 02111-1307, USA.  */
b048379
+
b048379
+#ifdef SYMBOL_PREFIX
b048379
+#define SYMBOL(str)	SYMBOL_PREFIX #str
b048379
+#else
b048379
+#define SYMBOL(str)	#str
b048379
+#endif
b048379
+
b048379
+void
b048379
+trap (void)
b048379
+{
b048379
+  asm ("int $0x03");
b048379
+}
b048379
+
b048379
+/* Jump from a function with its symbol size set, to a function
b048379
+   named by a local label.  GDB should report the `main' function
b048379
+   even for the rest, after the global `inner' ends.  */
b048379
+
b048379
+asm(".text\n"
b048379
+    "    .align 8\n"
b048379
+    "    .globl " SYMBOL (main) "\n"
b048379
+    SYMBOL (main) ":\n"
b048379
+    "    pushl %ebp\n"
b048379
+    "    mov   %esp, %ebp\n"
b048379
+    "    call  .Lfunc\n"
b048379
+    "    ret\n"
b048379
+    SYMBOL (inner) ":\n"
b048379
+    "    ret\n"
b048379
+    "    .size " SYMBOL (inner) ", .-" SYMBOL (inner) "\n"
b048379
+    ".Lfunc:\n"
b048379
+    "    pushl %ebp\n"
b048379
+    "    mov   %esp, %ebp\n"
b048379
+    "    call  " SYMBOL (trap) "\n"
b048379
+    "    .size " SYMBOL (main) ", .-" SYMBOL (main) "\n");
aefb0e1
Index: gdb/testsuite/gdb.arch/i386-size-overlap.exp
b048379
===================================================================
b048379
RCS file: gdb/testsuite/gdb.arch/i386-size-overlap.exp
aefb0e1
diff -N ./gdb/testsuite/gdb.arch/i386-size-overlap.exp
b048379
--- /dev/null	1 Jan 1970 00:00:00 -0000
b048379
+++ ./gdb/testsuite/gdb.arch/i386-size-overlap.exp	30 Oct 2006 12:41:35 -0000
b048379
@@ -0,0 +1,79 @@
b048379
+# Copyright 2006 Free Software Foundation, Inc.
b048379
+
b048379
+# This program is free software; you can redistribute it and/or modify
b048379
+# it under the terms of the GNU General Public License as published by
b048379
+# the Free Software Foundation; either version 2 of the License, or
b048379
+# (at your option) any later version.
b048379
+#
b048379
+# This program is distributed in the hope that it will be useful,
b048379
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b048379
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b048379
+# GNU General Public License for more details.
b048379
+#
b048379
+# You should have received a copy of the GNU General Public License
b048379
+# along with this program; if not, write to the Free Software
b048379
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
b048379
+
b048379
+# Please email any bugs, comments, and/or additions to this file to:
b048379
+# bug-gdb@gnu.org
b048379
+
b048379
+# This file is part of the gdb testsuite.
b048379
+
b048379
+if $tracelevel {
b048379
+    strace $tracelevel
b048379
+}
b048379
+
b048379
+# Test that GDB can handle overlapping sizes of symbols.
b048379
+
b048379
+if ![istarget "i?86-*-*"] then {
b048379
+    verbose "Skipping i386 unwinder tests."
b048379
+    return
b048379
+}
b048379
+
b048379
+set testfile "i386-size-overlap"
b048379
+set srcfile ${testfile}.c
b048379
+set binfile ${objdir}/${subdir}/${testfile}
b048379
+
b048379
+# some targets have leading underscores on assembly symbols.
b048379
+# TODO: detect this automatically
b048379
+set additional_flags ""
b048379
+if [istarget "i?86-*-cygwin*"] then {
b048379
+  set additional_flags "additional_flags=-DSYMBOL_PREFIX=\"_\""
b048379
+}
b048379
+
b048379
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
b048379
+	  executable [list debug $additional_flags]] != "" } {
b048379
+    untested "i386-size"
b048379
+    return -1
b048379
+}
b048379
+
b048379
+gdb_exit
b048379
+gdb_start
b048379
+gdb_reinitialize_dir $srcdir/$subdir
b048379
+gdb_load ${binfile}
b048379
+
b048379
+# We use gdb_run_cmd so this stands a chance to work for remote
b048379
+# targets too.
b048379
+gdb_run_cmd
b048379
+
b048379
+gdb_expect {
b048379
+    -re "Program received signal SIGTRAP.*$gdb_prompt $" {
b048379
+	pass "run past main"
b048379
+    }
b048379
+    -re ".*$gdb_prompt $" {
b048379
+	fail "run past main"
b048379
+    }
b048379
+    timeout {
b048379
+	fail "run past main (timeout)"
b048379
+    }
b048379
+}
b048379
+
b048379
+set message "backtrace shows the outer function"
b048379
+gdb_test_multiple "backtrace 10" $message {
b048379
+    -re "#1\[ \t]*$hex in inner.*$gdb_prompt $" {
b048379
+	fail $message
b048379
+    }
b048379
+    -re "#1\[ \t]*$hex in main.*$gdb_prompt $" {
b048379
+	pass $message
b048379
+    }
b048379
+}