This is the mail archive of the
mailing list for the GDB project.
Re: Doubt regarding a tail optimized code under ‘g db’
On Mon, May 18, 2009 at 11:13 PM, Paul Pluzhnikov
> On Mon, May 18, 2009 at 9:46 AM, Amit Saha <firstname.lastname@example.org> 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.
Yes. Yes. Now I remember. In the assembly code (I obtained by gcc
--S), I remember the CALL to only printf and scanf. So that explains
the behavior. Thanks!
Now, I will look into why the inlining takes place :)
Thanks a ton!
> Paul Pluzhnikov
IRC: cornucopic on #scheme, #lisp, #math, #linux
"Recursion is the basic iteration mechanism in Scheme"