Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@redhat.com>
To: Donn Terry <donnte@microsoft.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: Single step vs. "tail recursion" optimization
Date: Thu, 07 Nov 2002 17:04:00 -0000	[thread overview]
Message-ID: <3DCB0D9B.2010601@redhat.com> (raw)
In-Reply-To: <FE465D8F724E3F4F811D067203A214AE06D7B45B@red-msg-08.redmond.corp.microsoft.com>

> While debugging gdb, I ran across a really nasty little issue: the gcc
> guys (for the "bleeding edge", at least) have generated an optimization
> such that if the last thing in function x is a function call to y, it
> will short circut the return from x, and set things up so it returns
> directly from y.  (A special case of tail recursion optimizations.)
> 
> If you try to n (or s) over that, the debugged program runs away because
> gdb doesn't know about that magic.  The real example is
> regcache_raw_read, which ends in a memcpy.  Instead of jsr-ing to the
> memcpy and then returning, it fiddles with the stack and jmps to memcpy.
> Is this a known issue, and is it being worked, or have I just run across
> something
> new to worry about?

Sounds both new, and, er, painful.  GDB would be, er, what would gdb be 
doing?

Lets see.

The memcpy() probably doesn't have debug info and hence GDB will try to 
step over it, just like for a next.  This would explain why both 
step/next give the same behavior.

With a next, GDB steps into the first instruction of the function, 
extracts saved return address, sets a breakpoint on that, and then free 
runs the target.  Perhaphs set a breakpoint on 
i386_saved_pc_after_call() and see how well it is doing.

Can I suggest also trying a tail recursion case where there is debug 
info for both the caller and the callee?  Step and next should behave 
differently.

> (This is on Interix (x86, obviously from the code below) with a gcc
> that's less than
> a week old.  I have no idea how long it might actually have been this
> way.  I doubt
> the problem is actually unique to the x86 as this is a very general
> optimization.)

Andrew



  reply	other threads:[~2002-11-08  1:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-07 11:18 Donn Terry
2002-11-07 17:04 ` Andrew Cagney [this message]
2002-11-08 11:43 ` Michael Snyder
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
2002-11-13  9:52 Donn Terry

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=3DCB0D9B.2010601@redhat.com \
    --to=ac131313@redhat.com \
    --cc=donnte@microsoft.com \
    --cc=gdb-patches@sources.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