This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] infcall: Remove gdb_assert ($sp underflow)
On Fri, 26 Feb 2010 23:52:52 +0100, Daniel Jacobowitz wrote:
> On Fri, Feb 19, 2010 at 11:48:05PM +0100, Jan Kratochvil wrote:
> > Unaware how inconvenient is an intentional crash of the testcase on some
> > embedded/non-MMU systems.
>
> Maybe limit it at least by nosignals? It might still blow up uClinux
> testing, I don't know offhand if there are other crashy tests.
OK, used:
if {![target_info exists gdb,nosignals] && ![istarget "*-*-uclinux*"]} {
> > +foreach spval {0 -1} {
> > + set old_ldprefix $pf_prefix
> > + lappend pf_prefix "sp=$spval:"
> > +
> > + gdb_test {set $old_sp = $sp}
> > + gdb_test "set \$sp = $spval"
> > +
> > + gdb_test "call doubleit (1)"
> > +
> > + gdb_test {set $sp = $old_sp}
> > + set pf_prefix $old_ldprefix
> > +}
>
> Because these tests run more than once, please give them unique names.
The tests have been already producing:
PASS: gdb.base/callfuncs.exp: sp=0: set $old_sp = $sp
PASS: gdb.base/callfuncs.exp: sp=0: set $sp = 0
PASS: gdb.base/callfuncs.exp: sp=0: call doubleit (1)
PASS: gdb.base/callfuncs.exp: sp=0: set $sp = $old_sp
PASS: gdb.base/callfuncs.exp: sp=-1: set $old_sp = $sp
PASS: gdb.base/callfuncs.exp: sp=-1: set $sp = -1
PASS: gdb.base/callfuncs.exp: sp=-1: call doubleit (1)
PASS: gdb.base/callfuncs.exp: sp=-1: set $sp = $old_sp
But OK, made now the tests code more obvious:
PASS: gdb.base/callfuncs.exp: set $old_sp = $sp
PASS: gdb.base/callfuncs.exp: set $sp = 0
PASS: gdb.base/callfuncs.exp: sp == 0: call doubleit (1)
PASS: gdb.base/callfuncs.exp: set $sp = -1
PASS: gdb.base/callfuncs.exp: sp == -1: call doubleit (1)
PASS: gdb.base/callfuncs.exp: set $sp = $old_sp
Thanks,
Jan
gdb/
2010-02-27 Jan Kratochvil <jan.kratochvil@redhat.com>
* infcall.c (call_function_by_hand): Remove gdb_assert on sp and old_sp.
New comment.
gdb/testsuite/
2010-02-27 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/callfuncs.exp: New tests for $spval 0 and -1. Remove return.
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -518,10 +518,9 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
/* Stack grows up. */
sp = gdbarch_frame_align (gdbarch, old_sp + 1);
}
- gdb_assert ((gdbarch_inner_than (gdbarch, 1, 2)
- && sp <= old_sp)
- || (gdbarch_inner_than (gdbarch, 2, 1)
- && sp >= old_sp));
+ /* SP may have underflown address zero here from OLD_SP. Memory access
+ functions will probably fail in such case but that is a target's
+ problem. */
}
else
/* FIXME: cagney/2002-09-18: Hey, you loose!
--- a/gdb/testsuite/gdb.base/callfuncs.exp
+++ b/gdb/testsuite/gdb.base/callfuncs.exp
@@ -469,5 +469,17 @@ if {$old_reg_content == $new_reg_content} then {
fail "nested call dummies preserve register contents"
}
-return 0
+# GDB should not crash by internal error on $sp underflow during the inferior
+# call. It is OK it will stop on some: Cannot access memory at address 0x$hex.
+if {![target_info exists gdb,nosignals] && ![istarget "*-*-uclinux*"]} {
+ gdb_test {set $old_sp = $sp}
+
+ gdb_test {set $sp = 0}
+ gdb_test {sp == 0: call doubleit (1)}
+
+ gdb_test {set $sp = -1}
+ gdb_test {sp == -1: call doubleit (1)}
+
+ gdb_test {set $sp = $old_sp}
+}