This is the mail archive of the
mailing list for the GDB project.
Re: Doubt regarding a tail optimized code under ‘g db’
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: Amit Saha <amitsaha dot in at gmail dot com>
- Cc: gdb at sourceware dot org
- Date: Mon, 18 May 2009 10:43:08 -0700
- Subject: Re: Doubt regarding a tail optimized code under ‘g db’
- References: <firstname.lastname@example.org>
On Mon, May 18, 2009 at 9:46 AM, Amit Saha <email@example.com> wrote:
> Out of sheer curiosity, I tried to run a tail optimised code under
> 'gdb'. Consider a tail recursive factorial implementation in C:
Debugging optimized code is tricky; you need to know what you are doing
and know how to read disassembly :-)
> I place a breakpoint in 'factorial' and I run the above under 'gdb'.
> The breakpoint is never hit. Assuming that its tail call optimised (I
> have compiled it using gcc -O2), it should hit the breakpoint, at
> least once. I get the final result without hitting any breakpoint.
I can reproduce this with gcc-4.3.1 on i386, but not with gcc-4.4.0.
This doesn't have anything to do with tail-recursion though: gcc-4.3.1
simply inlines factorial() into main: looking at disassembly, the only
CALLs from main are to scanf and printf. Compiling with -fno-inline makes
it work as expected under gcc-4.3.1 as well.