This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Doubt regarding a tail optimized code under ‘g db’


On Mon, May 18, 2009 at 9:46 AM, Amit Saha <amitsaha.in@gmail.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.

Cheers,
-- 
Paul Pluzhnikov


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]