Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Justin Paston-Cooper <paston.cooper@gmail.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb@sourceware.org
Subject: Re: Command to break before exiting stack frame?
Date: Sun, 17 Mar 2019 13:59:00 -0000	[thread overview]
Message-ID: <CAEndGgRAyz0gUrDJGooE+AMWuugdLD1Fcef5QYaqcgUAs9yeqw@mail.gmail.com> (raw)
In-Reply-To: <431d242053ca491be67a21d0d95b71a4@polymtl.ca>

I accidentally replied to Andreas's email without CCing the list.
Simon has addressed the jump issue. Does gcc emit jump tables when
optimisation options are not enabled anyway?

 On tail calls: I tested the behaviour of the "finish" command with a
tail-recursive function in following code, with the following gdb
commands:

------------------------------

static int f (int x);

int
main(void)
{
  f(5);
}

static int
f (int x)
{
  if (x == 0)
    {
      return 0;
    }
  else
    {
      return f(x - 1);
    }
}

------------------------------

break f
commands
finish
end

------------------------------

Given its documentation, I would have expected the "finish" command to
print the returned value at each tail call. It turns out that it
prints the returned value only for the f(0) call. I would similarly
expect a "break on exit" command to break on the exit of the frame in
which it is called even if a tail-recursion occurs. Is there a reason
that it doesn't? My first thought would be tail-call optimisation, but
in any case breaks on tail-calls of the function still work fine, and
when I disassembled the function, I saw that no tail-call optimisation
occurred in my case.

On the actual implementation of this command: Is the implementation of
such a feature feasible? If so, how much work would it take? I would
certainly be interested in helping, although I don't yet have any
experience with working on compilers/debuggers.


On Sun, 17 Mar 2019 at 00:23, Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
> On 2019-03-16 20:00, Andreas Schwab wrote:
> > On Mär 16 2019, Justin Paston-Cooper <paston.cooper@gmail.com> wrote:
> >
> >> I can't imagine that I am the first person to suggest or request this.
> >> Are
> >> there any architectural or practical reasons as to why this is might
> >> be
> >> difficult?
> >
> > There may not even be a place where the frame is exited in the current
> > function due to tail call.  Also, inline literal pools or jump tables
> > can result in false positives when searching for return insns.
> >
> > Andreas.
>
> I suppose that the list of all function exit points (regardless of
> whether it is a jump or real return) is an information that the compiler
> could theoretically produce and encode in the DWARF information?
>
> Simon


  reply	other threads:[~2019-03-17 13:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-16 23:15 Justin Paston-Cooper
2019-03-17  0:01 ` Andreas Schwab
2019-03-17  0:23   ` Simon Marchi
2019-03-17 13:59     ` Justin Paston-Cooper [this message]
2019-03-19 15:42       ` Tom Tromey
2019-03-19 20:44         ` Justin Paston-Cooper
2019-03-19 15:35     ` Tom Tromey

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=CAEndGgRAyz0gUrDJGooE+AMWuugdLD1Fcef5QYaqcgUAs9yeqw@mail.gmail.com \
    --to=paston.cooper@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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