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