Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Amit Saha <amitsaha.in@gmail.com>
To: Paul Pluzhnikov <ppluzhnikov@google.com>
Cc: gdb@sourceware.org
Subject: Re: Doubt regarding a tail optimized code under ‘gdb’
Date: Tue, 19 May 2009 02:48:00 -0000	[thread overview]
Message-ID: <547db2260905181948l123e42c2v4c63fa6ee589a5b4@mail.gmail.com> (raw)
In-Reply-To: <8ac60eac0905181043i46a817d6nbb9a31f7c22d497d@mail.gmail.com>

Hello Paul,

On Mon, May 18, 2009 at 11:13 PM, Paul Pluzhnikov
<ppluzhnikov@google.com> wrote:
> 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.

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!

Best,
Amit


>
> Cheers,
> --
> Paul Pluzhnikov
>



-- 
Journal: http://amitksaha.wordpress.com
IRC: cornucopic on #scheme, #lisp, #math, #linux

"Recursion is the basic iteration mechanism in Scheme"
--- http://c2.com/cgi/wiki?TailRecursion


      reply	other threads:[~2009-05-19  2:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 16:47 Amit Saha
2009-05-18 17:43 ` Paul Pluzhnikov
2009-05-19  2:48   ` Amit Saha [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=547db2260905181948l123e42c2v4c63fa6ee589a5b4@mail.gmail.com \
    --to=amitsaha.in@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=ppluzhnikov@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox