public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: dtaylor@usendtaylorx2l.lss.emc.com
Cc: brobecker@adacore.com, gdb-patches@sourceware.org
Subject: Re: RFA bug fix -- x86-64 stabs and deprecated fp register
Date: Fri, 05 Dec 2014 13:38:00 -0000	[thread overview]
Message-ID: <201412051338.sB5Dcauf016922@glazunov.sibelius.xs4all.nl> (raw)
In-Reply-To: <16730.1417451430@usendtaylorx2l> (message from David Taylor on	Mon, 01 Dec 2014 11:30:30 -0500)

> Date: Mon, 01 Dec 2014 11:30:30 -0500
> From: David Taylor <dtaylor@usendtaylorx2l.lss.emc.com>
> 
> Joel Brobecker <brobecker@adacore.com> wrote:
> 
> > David,
> > 
> > On Fri, Nov 21, 2014 at 03:58:04PM -0500, David Taylor wrote:
> > > Sometimes when using STABS on x86-64 GNU/Linux, GDB does not know which
> > > register to use for the frame pointer and as a result offsets from the
> > > frame pointer are treated as absolute addresses rather than as
> > > offsets...
> > > 
> > > This patch provides a default for when the debug information doesn't
> > > specify which register to use.
> > > 
> > > We have seen this problem when debugging problems with a previous
> > > release of our software (I believe it was built with GCC 4.5.x, if that
> > > matters).
> > > 
> > > There were no regressions on x86-64 GNU/Linux.
> > > 
> > > 2014-11-21  David Taylor  <dtaylor@emc.com>
> > > 
> > > 	* amd64-tdep.c (amd64_init_abi): Set default frame pointer.
> > 
> > I don't think your patch is correct, as it is going to affect
> > the outcome of...
> > 
> >     (gdb) print $fp
> > 
> > ... for frameless functions compiled with DWARF2. See
> > std-regs.c:value_of_builtin_frame_fp_reg.
> > 
> > If we were to apply your patch, it would unconditionally print
> > the contents of the %rbp register as the result, which is not
> > what we've been printing so far.
> 
> For a frameless function, I would expect that $fp would be either
> <unavailable> or would be the frame pointer for the most recent function
> that had a frame or would just be %rbp.

We deprecated the concept of a frame pointer "register" more than a
decade ago.  There really isn't such a register on many architectures.
On amd64 %rbp is available for the compiler to use for whatever
purpose it sees fit.  Reintroducing a real frame pointer register in
the amd64-tdep.c code would be a mistake.  The
set_gdbarch_deprecated_fp_regnum() function has "deprecated" in its
name for a reason.

> Since a frameless function has no frame, I would consider any of the
> three to be reasonable.  I would also argue that it is an error to ask
> for the frame pointer of a frameless function, but that an error should
> not be thrown as the user shouldn't be expected to know that the
> function is frameless.

In GDB there always is a frame.  A frameless function is a function
that doesn't set up its own frame but re-uses the frame set up by its
parent.  So that matches "would be the frame pointer for the most
recent function that had a frame".

> But, my case is different from
> 
>     print $fp
> 
> .  It's more like:
> 
>     print foo
> 
> where the debug information says foo lives at $fp - 24.

The question here is how your debug format actually defines $fp here.
For DWARF2 this is reasonably well defined.  It has the concept of a
call frame address CFA and provides enough information to reconstruct
that address.  For STABS this isn't well defined.  Hopefully it
matches GDB's idea of "frame base", which is what $fp represents.

Few of us have really looked at the STABS code in GDB in the last
decae.  The mainstream Open Source world moved to DWARF2 long ago, and
there is a substantial amount of bitrot in the STABS-related code,
both on the producer (GCC) and consumer (GDB) side.  But judging from
what you write here:

> There are functions where the debug information (STABS) specifies an
> offset from the frame pointer, but does not specify which register is
> the frame pointer.  GDB currently decides to not use any register.  It
> treats the offset as an offset from zero -- put another way, it treats
> it as an absolute address.

This seems to suggest that the real bug is in GDB's STABS code.  It
should probably encode the address of your variable as being
LOC_LOCAL, in which case the address would be calculated as relative
to the "frame locals" address which for most architectures (including
amd64) is the same as "frame base".

...

> When I first posted this bug report and fix months ago, it drew zero
> responses.  (I noticed recently that it wasn't in so I sent another
> message.)  At that time I could have told you more.

The problem here is that by choosing to use STABS on amd64 for your
platform you're now so far behind the curve that there's basically
nobody around with enough knowledge to help you out.  All I can say to
you is that your suggested fix isn't the right approach.

  parent reply	other threads:[~2014-12-05 13:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-21 20:58 David Taylor
2014-11-30 15:20 ` Joel Brobecker
2014-11-30 18:59   ` Mark Kettenis
2014-12-01 16:42     ` David Taylor
2014-12-03  3:19       ` Joel Brobecker
2014-12-01 16:30   ` David Taylor
2014-12-03  3:50     ` Joel Brobecker
2014-12-03 17:31       ` Doug Evans
2014-12-04  3:20         ` Joel Brobecker
2014-12-05 13:38     ` Mark Kettenis [this message]
2014-12-03  3:43 ` Doug Evans

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=201412051338.sB5Dcauf016922@glazunov.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=brobecker@adacore.com \
    --cc=dtaylor@usendtaylorx2l.lss.emc.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).