From: Andrew Cagney <ac131313@redhat.com>
To: Donn Terry <donnte@microsoft.com>
Cc: Michael Snyder <msnyder@redhat.com>, gdb-patches@sources.redhat.com
Subject: Re: Single step vs. "tail recursion" optimization
Date: Wed, 13 Nov 2002 19:44:00 -0000 [thread overview]
Message-ID: <3DD31C0D.4050207@redhat.com> (raw)
In-Reply-To: <FE465D8F724E3F4F811D067203A214AE06D7B61A@red-msg-08.redmond.corp.microsoft.com>
> (I'm sorry to have to be the messenger on this one...)
>
> Here's a mini testcase. I've also attached the resulting .s files for
> -O2 and -O3.
> Shudder. Andrew's speculation about s not working because there were no
> symbols
> is correct. S-ing works until the call to getpid().
>
> I haven't actually tried to figure out why gdb isn't doing it right in
> that case
> because there's actually something potentially even uglier going on in
> the -O3 case.
> This is something that the "management" of gdb and the "management" of
> gcc are going
> to have to take on and resolve as either "no, you can't sanely debug
> -O3" or "we need
> some help from the compiler to sort this one out". (And if the latter,
> then the same
> help may be useful with the -O2 case!) (I haven't seen this addressed,
> but I could
> easily have missed it.)
GDB's going to have to learn to do something with -O3, even if it isn't
very sane :-)
> Note that in the case of -O3, foo() and bar() are NEVER actually called
> from main,
> but rather getpid() is called directly. (Note also the reordering of the
> functions.)
> (Seeing that this sort of optimization is pretty compellingly needed for
> C++ code,
> "don't do that" seems an unlikely outcome.)
Anyway, here's a wild guess:
- gdb stepi's into getpid() (or what ever the tail recursive function
is) - detects this because its no longer in foo()
- gdb calls saved_pc_after_call() and gets an address in main, sets
tempoary breakpoint at that address.
I think, if this isn't happening, GCC will have by definition, screwed
up the stack frame. The stack, for getpid() and hence GDB, has to
appear like it was called from main() so getpid() will correctly return
there.
- gdb resumes target
- getpid() returns, hits breakpoint in main, but the logic there (hmm,
Elena's `until' post) doesn't realise that its exited the function /
block in question.
- gdb resumes target, target exits
I think you can see this by either setting a breakpoint on
saved_pc_after_call() or by watching the target traffic (set debug
target 1?).
Andrew
next prev parent reply other threads:[~2002-11-14 3:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-08 13:57 Donn Terry
2002-11-08 15:11 ` Michael Snyder
2002-11-13 9:43 ` Jim Blandy
2002-11-13 19:44 ` Andrew Cagney [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-11-13 9:52 Donn Terry
2002-11-07 11:18 Donn Terry
2002-11-07 17:04 ` Andrew Cagney
2002-11-08 11:43 ` Michael Snyder
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=3DD31C0D.4050207@redhat.com \
--to=ac131313@redhat.com \
--cc=donnte@microsoft.com \
--cc=gdb-patches@sources.redhat.com \
--cc=msnyder@redhat.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