From: Felix Willgerodt <felix.willgerodt@intel.com>
To: gdb-patches@sourceware.org
Cc: Felix Willgerodt <felix.willgerodt@intel.com>,
Cristian Sandu <cristian.sandu@intel.com>
Subject: [PATCH 1/1] gdb: Avoid warning for the jump command inside an inline function.
Date: Tue, 24 Jan 2023 16:19:32 +0100 [thread overview]
Message-ID: <20230124151932.2471769-1-felix.willgerodt@intel.com> (raw)
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));
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"
--
2.34.3
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
next reply other threads:[~2023-01-24 15:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-24 15:19 Felix Willgerodt [this message]
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
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=20230124151932.2471769-1-felix.willgerodt@intel.com \
--to=felix.willgerodt@intel.com \
--cc=cristian.sandu@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).