This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Unwinding past main
- From: Randolph Chung <randolph at tausq dot org>
- To: gdb at sources dot redhat dot com
- Date: Tue, 2 Nov 2004 15:29:29 -0800
- Subject: Unwinding past main
- Reply-to: Randolph Chung <randolph at tausq dot org>
I'm seeing a stack unwinding problem on hppa. Seems like this should be
applicable to other targets too -- how do you solve this problem?
Take a simple test program:
====
int foo(void) { return 1; }
int main(void) { return foo(); }
====
gcc does some tail call optimizations on this (when compiled with -O2),
so that the generated code looks like:
00010518 <foo>:
10518: e8 40 c0 00 bv r0(rp)
1051c: 34 1c 00 02 ldi 1,ret0
00010520 <main>:
10520: 6b c2 3f d9 stw rp,-14(,sp)
10524: 37 de 00 80 ldo 40(sp),sp
10528: 4b c2 3f 59 ldw -54(,sp),rp
1052c: e8 1f 1f cd b,l 10518 <foo>,r0
10530: 37 de 3f 81 ldo -40(sp),sp
10534: 08 00 02 40 nop
doing a backtrace from foo results in an infinite loop :) I see some
code in gcc that tries to determine when we are in the main() function,
and stops the backtrace. But here, foo() returns directly to the caller
of main() (__libc_start_main on a glibc system), so we try to continue
to unwind through glibc and hit some asm bits that cannot be unwound
properly.
what is the "proper" way to handle this?
thanks,
randolph
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/