From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EB0533858D33 for ; Tue, 25 Apr 2023 14:09:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB0533858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682431753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZZQ+9FlLbOyDf8q/KWNPmk6+8uVxuwu2cSjFpU8rn48=; b=g+SGca2E9ivWxrj+dA8gfw4Sl33dgysU7qcs1j2zZ1XC8Z1tLL7vswWq+9zm2W1P6cplsP IMIKigcWshm7nYG1f5/wRce/Ui5ONCN3gK6XSmf0eNzzSRFYww2BxP5Gi4WZaEF5QGWCYJ vLA9w9UzTEStG2pWTgVpiecDDFNnZhk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-pOqPN846Oqeyzjg2MaBCIw-1; Tue, 25 Apr 2023 10:09:11 -0400 X-MC-Unique: pOqPN846Oqeyzjg2MaBCIw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f17afcf99cso21461655e9.2 for ; Tue, 25 Apr 2023 07:09:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682431750; x=1685023750; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZZQ+9FlLbOyDf8q/KWNPmk6+8uVxuwu2cSjFpU8rn48=; b=jvqs/XQhvTaH6q6ujQ3QVXiOCQ4QknexYXdH4+GVFhgPpD0FoMlARudMlch6IqSTIi OqStDG6nrlf9w0ObVEHgXWnFD87D+2pwHBLzzeypPGfl3YQ/gxKxXWCtlp4RP3+Ef1eX ziQ2wJBoN9qfa5tC9AQimBV3YM5guXRx7nqEumppkgC3jmMDO6EjfN9qcYZfPOBF7F9L 4J9pLt19RbeQpEoD6uZ7GY3FTp2PN/owyrr/PUcE/xaQc9rPIHELnYhlLEEyb2+Dfyyx /wWYrI0eJLqkb2Z1JMXbYmCzIgOdkOCcr/6dF8HuQuvJBJBUe9831DeTaeDSrRc6Zewr BHyQ== X-Gm-Message-State: AAQBX9dbfjEhcyL6kC73wl0JQj0PqhRgJA7/npicY3np8YgrD5P6pJAe Ty2Mwv+g+rhAHCtTQSTY4WIdhwgx4bS8wnpAxWVjXm2XwE1rOyJKRmIaiSRkTl3ciDHtCvvsJw4 EqWzbj1yHak0+6IFS5R8YivUDK/5q9eUULkuRSk15prk2jeqJW+ScDMjhI11IF00kIJWPtb7Tpl yto6KpGA== X-Received: by 2002:a05:600c:3657:b0:3f1:6f52:74d with SMTP id y23-20020a05600c365700b003f16f52074dmr10137073wmq.39.1682431750504; Tue, 25 Apr 2023 07:09:10 -0700 (PDT) X-Google-Smtp-Source: AKy350bLrNrs7VLB+mbgL9UcQXt1GePofE/EVHnFkPw+dv6LZy5JueSPRPl1VP0IjfWO2QJyw5ZZUQ== X-Received: by 2002:a05:600c:3657:b0:3f1:6f52:74d with SMTP id y23-20020a05600c365700b003f16f52074dmr10137050wmq.39.1682431750094; Tue, 25 Apr 2023 07:09:10 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id x2-20020a5d60c2000000b002de9a0b0a20sm13134143wrt.113.2023.04.25.07.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 07:09:09 -0700 (PDT) From: Andrew Burgess To: Felix Willgerodt via Gdb-patches , gdb-patches@sourceware.org Cc: Felix Willgerodt , Cristian Sandu Subject: Re: [PATCH 1/1] gdb: Avoid warning for the jump command inside an inline function. In-Reply-To: <20230124151932.2471769-1-felix.willgerodt@intel.com> References: <20230124151932.2471769-1-felix.willgerodt@intel.com> Date: Tue, 25 Apr 2023 15:09:08 +0100 Message-ID: <87o7ncawaj.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 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_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: Felix Willgerodt via Gdb-patches 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 > --- > 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 . */ > + > +__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" This untested line is not needed. runto_main will emit a FAIL if anything goes wrong. Reviewed-By: Andrew Burgess Thanks, Andrew > + 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