From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by sourceware.org (Postfix) with ESMTPS id C7B9B3858D28 for ; Tue, 24 Jan 2023 15:20:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7B9B3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674573635; x=1706109635; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=auf7b4w63NzVmS3At5kOvgaOOlv+fLyVdpN5fYG92JQ=; b=P7+wryZZFyLyDYHwFbeeAJocZUZBNBHGXj8kRjRFHwpNXtaEltfmg5LL g//VD3tqKpfpB+Z023tMdRbh4WnHCOGA2Lw3SHJZGog13fv+UL87uMOgb ETzDs54Ny6NNQJOztcJOUhD8dBwwBeZiLnVw4jmg/p8Fpc9LAQ8d7EQTk oK9yZX5VaLr64sLWSSOGAN/3GASQ6ECB04JQGE0nO9BIRFIbrooEakphi EK8pK8m7mhan6JUZuOpuKmygTmZq5QuqTE/zhRNIEfvNGlqrm+tkH657N yO4nPEqdfQsAKagsfaOjk1di6V9EyerOfdt42DZwiKwWpgM1zWjV5c84c g==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="353593892" X-IronPort-AV: E=Sophos;i="5.97,242,1669104000"; d="scan'208";a="353593892" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2023 07:20:34 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="730715294" X-IronPort-AV: E=Sophos;i="5.97,242,1669104000"; d="scan'208";a="730715294" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.92]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2023 07:20:33 -0800 From: Felix Willgerodt To: gdb-patches@sourceware.org Cc: Felix Willgerodt , Cristian Sandu Subject: [PATCH 1/1] gdb: Avoid warning for the jump command inside an inline function. Date: Tue, 24 Jan 2023 16:19:32 +0100 Message-Id: <20230124151932.2471769-1-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,TXREP,T_SPF_TEMPERROR,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- 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 . */ + +__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 . */ +# +# 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 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