This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH RFC] gdb.base/mips_pro.exp: accommodate tail call optimization
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [PATCH RFC] gdb.base/mips_pro.exp: accommodate tail call optimization
- From: Michael Elizabeth Chastain <chastain at cygnus dot com>
- Date: Mon, 20 Nov 2000 19:39:43 -0800
Here is a small patch to a test case in gdb/testsuite/gdb.base/mips_pro.exp .
Here is a snippet of C code from gdb.base/mips_pro.c:
int
top (int y)
{
return middle (y + 1);
}
Here is the generated C code from an older gcc:
(gdb) disass top
Dump of assembler code for function top:
0x804855c <top>: push %ebp
0x804855d <top+1>: mov %esp,%ebp
0x804855f <top+3>: mov 0x8(%ebp),%eax
0x8048562 <top+6>: inc %eax
0x8048563 <top+7>: push %eax
0x8048564 <top+8>: call 0x8048540 <middle>
0x8048569 <top+13>: mov %ebp,%esp
0x804856b <top+15>: pop %ebp
0x804856c <top+16>: ret
End of assembler dump.
And here is the generated C code from the sourceware gcc (today's
cvs version):
(gdb) disass top
Dump of assembler code for function top:
0x8048490 <top>: push %ebp
0x8048491 <top+1>: mov %esp,%ebp
0x8048493 <top+3>: sub $0x8,%esp
0x8048496 <top+6>: incl 0x8(%ebp)
0x8048499 <top+9>: mov %ebp,%esp
0x804849b <top+11>: pop %ebp
0x804849c <top+12>: jmp 0x8048460 <middle>
End of assembler dump.
I see that the older gcc uses a simple "call" instruction, but the
sourceware-cvs gcc optimizes the tail call to "jmp" instead.
This optimization is correct, but the test case does not know about it.
The test case does a stack backtrace and expects to see "top" on the
stack. Because of the tail call optimization, this is no longer true,
and the test case fails.
This patch does three things:
(1) Adds a comment with the warning messages from the original PR 3016,
which was filed in 1993. If we ever see these messages again,
I think having these comments will help.
(2) Removes setup_xfail for the hppa case. I have results from running
this test case on hppa1.1-hp-hpux10.20 which indicates that this
test is fine for this platform.
(3) The important part: changes the test case to accept a stack trace
of "middle -> main" as well as "middle -> top -> main". This fixes
the test failure.
Michael Elizabeth Chastain
<chastain@redhat.com>
"love without fear"
Index: gdb/testsuite/gdb.base/mips_pro.exp
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/testsuite/gdb.base/mips_pro.exp,v
retrieving revision 1.17
diff -c -3 -p -r1.17 mips_pro.exp
*** gdb/testsuite/gdb.base/mips_pro.exp 1999/06/25 23:58:09 1.17
--- gdb/testsuite/gdb.base/mips_pro.exp 2000/11/21 02:26:02
*************** gdb_load ${binfile}
*** 54,62 ****
if [runto middle] then {
# PR 3016
if {$gcc_compiled} then {
! setup_xfail "hppa*-*-*" "mips*-sgi-irix4*" "mips64*-*-elf"
}
! gdb_test "backtrace" "#0.*middle.*#1.*top.*#2.*main.*"
}
return 0
--- 54,75 ----
if [runto middle] then {
# PR 3016
+ # warning: Hit heuristic-fence-post without finding
+ # warning: enclosing function for pc 0x1006ead0
if {$gcc_compiled} then {
! setup_xfail "mips*-sgi-irix4*" "mips64*-*-elf"
}
! send_gdb "backtrace\n"
! gdb_expect {
! -re "#0.*middle.*#1.*top.*#2.*main.*" {
! pass "backtrace"
! }
! -re "#0.*middle.*#1.*main.*" {
! pass "backtrace"
! }
! timeout {
! fail "(timeout) backtrace"
! }
! }
}
return 0