keiths / rpms / gdb

Forked from rpms/gdb 3 days ago
Clone
7d64017
http://sourceware.org/ml/gdb-patches/2010-02/msg00515.html
7d64017
Subject: [patch] infcall: Remove gdb_assert ($sp overflow)
7d64017
7d64017
Hi,
7d64017
7d64017
set $sp=0
7d64017
call something()
7d64017
->
7d64017
../../gdb/infcall.c:521: internal-error: call_function_by_hand: Assertion
7d64017
`(gdbarch_inner_than (gdbarch, 1, 2) && sp <= old_sp) || (gdbarch_inner_than
7d64017
(gdbarch, 2, 1) && sp >= old_sp)' failed.
7d64017
7d64017
as $sp - frame == 0xffffsmth which is not lower than $sp.
7d64017
7d64017
It must not be gdb_assert().  It can be an error() but I left it just to do:
7d64017
	(gdb) set $sp=0
7d64017
	(gdb) call doubleit (1)
7d64017
	Cannot access memory at address 0xffffffffffffff78
7d64017
	(gdb) set $sp=-1
7d64017
	(gdb) call doubleit (1)
7d64017
	Cannot access memory at address 0xffffffffffffff68
7d64017
7d64017
Unaware how inconvenient is an intentional crash of the testcase on some
7d64017
embedded/non-MMU systems.
7d64017
No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu.
7d64017
7d64017
7d64017
Thanks,
7d64017
Jan
7d64017
7d64017
7d64017
gdb/
7d64017
2010-02-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
7d64017
7d64017
	* infcall.c (call_function_by_hand): Remove gdb_assert on sp and old_sp.
7d64017
	New comment.
7d64017
7d64017
gdb/testsuite/
7d64017
2010-02-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
7d64017
7d64017
	* gdb.base/callfuncs.exp: New tests for $spval 0 and -1.  Remove return.
7d64017
7d64017
--- a/gdb/infcall.c
7d64017
+++ b/gdb/infcall.c
7d64017
@@ -518,10 +518,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
7d64017
 	      /* Stack grows up.  */
7d64017
 	      sp = gdbarch_frame_align (gdbarch, old_sp + 1);
7d64017
 	  }
7d64017
-	gdb_assert ((gdbarch_inner_than (gdbarch, 1, 2)
7d64017
-		    && sp <= old_sp)
7d64017
-		    || (gdbarch_inner_than (gdbarch, 2, 1)
7d64017
-		       && sp >= old_sp));
7d64017
+	/* SP may have overflown address zero here from OLD_SP.  Memory access
7d64017
+	   functions will probably fail in such case but that is a target's
7d64017
+	   problem.  */
7d64017
       }
7d64017
     else
7d64017
       /* FIXME: cagney/2002-09-18: Hey, you loose!
7d64017
--- a/gdb/testsuite/gdb.base/callfuncs.exp
7d64017
+++ b/gdb/testsuite/gdb.base/callfuncs.exp
7d64017
@@ -469,5 +469,18 @@ if {$old_reg_content == $new_reg_content} then {
7d64017
     fail "nested call dummies preserve register contents"
7d64017
 }
7d64017
 
7d64017
-return 0
7d64017
+# GDB should not crash by internal error on $sp overflow during the inferior
7d64017
+# call.  It is OK it will stop on some: Cannot access memory at address 0x$hex.
7d64017
 
7d64017
+foreach spval {0 -1} {
7d64017
+    set old_ldprefix $pf_prefix
7d64017
+    lappend pf_prefix "sp=$spval:"
7d64017
+
7d64017
+    gdb_test {set $old_sp = $sp}
7d64017
+    gdb_test "set \$sp = $spval"
7d64017
+
7d64017
+    gdb_test "call doubleit (1)"
7d64017
+
7d64017
+    gdb_test {set $sp = $old_sp}
7d64017
+    set pf_prefix $old_ldprefix
7d64017
+}
7d64017