public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Willgerodt, Felix" <felix.willgerodt@intel.com>
To: Andrew Burgess <aburgess@redhat.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 1/1] gdb: Avoid warning for the jump command inside an inline function.
Date: Thu, 4 May 2023 08:10:58 +0000	[thread overview]
Message-ID: <MN2PR11MB45660949F623EA34AFE369AB8E6D9@MN2PR11MB4566.namprd11.prod.outlook.com> (raw)
In-Reply-To: <87o7ncawaj.fsf@redhat.com>

> -----Original Message-----
> From: Willgerodt, Felix
> Sent: Dienstag, 25. April 2023 16:40
> To: Andrew Burgess <aburgess@redhat.com>; gdb-
> patches@sourceware.org
> Subject: RE: [PATCH 1/1] gdb: Avoid warning for the jump command inside an
> inline function.
> 
> > -----Original Message-----
> > From: Andrew Burgess <aburgess@redhat.com>
> > Sent: Dienstag, 25. April 2023 16:09
> > To: Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org>; gdb-
> > patches@sourceware.org
> > Cc: Willgerodt, Felix <felix.willgerodt@intel.com>; Cristian Sandu
> > <cristian.sandu@intel.com>
> > Subject: Re: [PATCH 1/1] gdb: Avoid warning for the jump command inside
> > an inline function.
> >
> > Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org> writes:
> >
> > > When stopped inside an inline function, trying to jump to a different line
> > > of the same function currently results in a warning about jumping to
> > another
> > > function.  Fix this by taking inline functions into account.
> > >
> > > Before:
> > >   Breakpoint 1, function_inline (x=510) at jump-inline.cpp:22
> > >   22        a = a + x;             /* inline-funct */
> > >   (gdb) j 21
> > >   Line 21 is not in `function_inline(int)'.  Jump anyway? (y or n)
> > >
> > > After:
> > >   Breakpoint 2, function_inline (x=510) at jump-inline.cpp:22
> > >   22        a = a + x;            /* inline-funct */
> > >   (gdb) j 21
> > >   Continuing at 0x400679.
> > >
> > >   Breakpoint 1, function_inline (x=510) at jump-inline.cpp:21
> > >   21        a += 1020 + a;                /* increment-funct */
> > >
> > > This was regression-tested on X86-64 Linux.
> > >
> > > Co-Authored-by: Cristian Sandu <cristian.sandu@intel.com>
> > > ---
> > >  gdb/infcmd.c                           |  3 +-
> > >  gdb/testsuite/gdb.base/jump-inline.c   | 30 +++++++++++++++++
> > >  gdb/testsuite/gdb.base/jump-inline.exp | 45
> > ++++++++++++++++++++++++++
> > >  3 files changed, 77 insertions(+), 1 deletion(-)
> > >  create mode 100644 gdb/testsuite/gdb.base/jump-inline.c
> > >  create mode 100644 gdb/testsuite/gdb.base/jump-inline.exp
> > >
> > > diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> > > index fd88b8ca328..40414bc9260 100644
> > > --- a/gdb/infcmd.c
> > > +++ b/gdb/infcmd.c
> > > @@ -1091,7 +1091,8 @@ jump_command (const char *arg, int from_tty)
> > >
> > >    /* See if we are trying to jump to another function.  */
> > >    fn = get_frame_function (get_current_frame ());
> > > -  sfn = find_pc_function (sal.pc);
> > > +  sfn = find_pc_sect_containing_function (sal.pc,
> > > +					  find_pc_mapped_section (sal.pc));
> >
> > I had a read through the discussion about whether find_pc_function
> > should return inline functions or not.  I don't know the history of this
> > code, so I don't know if there's a reason why it does what it does, but
> > looking at how it's used, I know there are some places in GDB where
> > find_pc_function is used when it shouldn't be.
> >
> > For example in edit_command (cli-cmds.c) I'm pretty sure the use of
> > find_pc_function is incorrect -- GDB will print the name of the
> > containing function, but then open the editor on the inlined function.
> >
> > As was said elsewhere, the biggest problem here will be lack of
> > testing.  What is really needed is an audit of each use of
> > find_pc_function and to ensure that each use is hit with an inline
> > function and a non-inline function.  Until then I think it's hard to be
> > certain about whether find_pc_function can safely be changed or not.
> > But doing that is no small task.
> >
> > Given that, I'm inclined to think we should take the patch as
> > presented.  If anyone ever does get around to sorting out this corner of
> > GDB then it's easy enough to revert this code back to use
> > find_pc_function.
> >
> > I do have one minor nit though...
> >
> > >    if (fn != nullptr && sfn != fn)
> > >      {
> > >        if (!query (_("Line %d is not in `%s'.  Jump anyway? "), sal.line,
> > > diff --git a/gdb/testsuite/gdb.base/jump-inline.c
> > b/gdb/testsuite/gdb.base/jump-inline.c
> > > new file mode 100644
> > > index 00000000000..17447c2d557
> > > --- /dev/null
> > > +++ b/gdb/testsuite/gdb.base/jump-inline.c
> > > @@ -0,0 +1,30 @@
> > > +/* Copyright 2021-2023 Free Software Foundation, Inc.
> > > +
> > > +   This program is free software; you can redistribute it and/or modify
> > > +   it under the terms of the GNU General Public License as published by
> > > +   the Free Software Foundation; either version 2 of the License, or
> > > +   (at your option) any later version.
> > > +
> > > +   This program is distributed in the hope that it will be useful,
> > > +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > +   GNU General Public License for more details.
> > > +
> > > +   You should have received a copy of the GNU General Public License
> > > +   along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > */
> > > +
> > > +__attribute__((always_inline))
> > > +static void inline
> > > +function_inline (int x)
> > > +{
> > > +  int a = x;
> > > +  a += 1020 + a;		/* increment-funct. */
> > > +  a = a + x;			/* inline-funct. */
> > > +}
> > > +
> > > +int
> > > +main ()
> > > +{
> > > +  function_inline (510);
> > > +  return 0;			/* out-of-func. */
> > > +}
> > > diff --git a/gdb/testsuite/gdb.base/jump-inline.exp
> > b/gdb/testsuite/gdb.base/jump-inline.exp
> > > new file mode 100644
> > > index 00000000000..fef29fedb2f
> > > --- /dev/null
> > > +++ b/gdb/testsuite/gdb.base/jump-inline.exp
> > > @@ -0,0 +1,45 @@
> > > +# Copyright 2021-2023 Free Software Foundation, Inc.
> > > +
> > > +# This program is free software; you can redistribute it and/or modify
> > > +# it under the terms of the GNU General Public License as published by
> > > +# the Free Software Foundation; either version 3 of the License, or
> > > +# (at your option) any later version.
> > > +#
> > > +# This program is distributed in the hope that it will be useful,
> > > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > +# GNU General Public License for more details.
> > > +#
> > > +# You should have received a copy of the GNU General Public License
> > > +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > */
> > > +#
> > > +# Tests GDBs support for jump for inline functions.
> > > +
> > > +standard_testfile
> > > +
> > > +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
> > > +    return -1
> > > +}
> > > +
> > > +if { ![runto_main] } {
> > > +    untested "failed to run to main"
> >
> > This untested line is not needed.  runto_main will emit a FAIL if
> > anything goes wrong.
> 
> Right, I will remove it.
> 
> > Reviewed-By: Andrew Burgess <aburgess@redhat.com>
> >
> > Thanks,
> > Andrew
> 
> Thank you for your review and thorough feedback. I agree with your
> thoughts and conclusion.
> I am wondering though, as you gave me a reviewed-by but not an
> approved-by, should I wait a bit more or can I push this? I posted it originally
> in January and pinged a few times. So I tend to think that waiting more isn't
> worth it, but I am of course fine with doing that.
> 
> Thanks,
> Felix

*Pinging again after 10 days of no further comments*

Is it okay to push this with the untested line removed?

Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  parent reply	other threads:[~2023-05-04  8:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 15:19 Felix Willgerodt
2023-02-20 12:50 ` [PING] " Willgerodt, Felix
2023-03-06  9:03 ` Willgerodt, Felix
2023-03-16 15:08 ` Willgerodt, Felix
2023-03-17 10:13 ` Bruno Larsen
2023-03-17 12:56   ` Willgerodt, Felix
2023-03-17 13:33     ` Bruno Larsen
2023-03-21 14:05       ` Willgerodt, Felix
2023-03-21 14:44         ` Bruno Larsen
2023-04-11 13:08       ` Willgerodt, Felix
2023-04-24 14:28 ` [PING] " Willgerodt, Felix
2023-04-25 14:09 ` Andrew Burgess
2023-04-25 14:40   ` Willgerodt, Felix
2023-05-04  8:10   ` Willgerodt, Felix [this message]
2023-05-05 16:21     ` Andrew Burgess
2023-05-08  7:22       ` Willgerodt, Felix

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=MN2PR11MB45660949F623EA34AFE369AB8E6D9@MN2PR11MB4566.namprd11.prod.outlook.com \
    --to=felix.willgerodt@intel.com \
    --cc=aburgess@redhat.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).