public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bruno Larsen <blarsen@redhat.com>
To: Felix Willgerodt <felix.willgerodt@intel.com>,
	gdb-patches@sourceware.org
Cc: Cristian Sandu <cristian.sandu@intel.com>
Subject: Re: [PATCH 1/1] gdb: Avoid warning for the jump command inside an inline function.
Date: Fri, 17 Mar 2023 11:13:42 +0100	[thread overview]
Message-ID: <103d7434-d7ad-b03b-5724-d6f9d6846749@redhat.com> (raw)
In-Reply-To: <20230124151932.2471769-1-felix.willgerodt@intel.com>

On 24/01/2023 16:19, Felix Willgerodt via Gdb-patches wrote:
> 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));

Hi Felix,

Thanks for doing this, it is a good improvement, but I don't know if 
this is the best way to go about it. Is there a reason why 
find_pc_function should not return inlined functions?

I feel like most of the time we want to know the function, knowing if 
we're in an inlined one would be desirable, but I might be wrong. Does 
anyone know?

-- 
Cheers,
Bruno

>     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"
> +    return -1
> +}
> +
> +gdb_breakpoint [gdb_get_line_number "inline-funct"]
> +gdb_continue_to_breakpoint "inline-funct" ".*inline-funct.*"
> +
> +# Test jump to another function - main.
> +set out_func [gdb_get_line_number "out-of-func"]
> +gdb_test "jump $out_func" \
> +    "Not confirmed.*" \
> +    "aborted jump out of current function" \
> +    "Line $out_func is not in `function_inline.*'.  Jump anyway.*y or n. $" \
> +    "n"
> +
> +# Test jump in the same inline function.
> +set increment [gdb_get_line_number "increment-funct"]
> +gdb_breakpoint $increment
> +gdb_test "jump $increment" "Breakpoint .* at .*:$increment.*"
> +gdb_test "next" ".*inline-funct.*"
> +gdb_test "print a" "= 5100"


  parent reply	other threads:[~2023-03-17 10:13 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 [this message]
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
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=103d7434-d7ad-b03b-5724-d6f9d6846749@redhat.com \
    --to=blarsen@redhat.com \
    --cc=cristian.sandu@intel.com \
    --cc=felix.willgerodt@intel.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).