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 D129B3857400 for ; Fri, 17 Mar 2023 10:13:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D129B3857400 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=1679048026; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ahlyjaq1YfZIylBNFuCrpnwLhl66SRgQFZCZpgKNckQ=; b=J27d+fvkp7+XN8enRCSxTbcRqj9RNGiMgNQcmXu+//d866KwKNlg+wthZc1uwEF1hMTAa/ 7lPo7nR4HZvvW3niuY7Cc/zxvNi6UAqXqAFlrePufTRz9p1/FYz4LzVZvfU6QwdJP3FTHd Vy38g1Q+AFWaAw0JXkoN9Jp9RQHEt+E= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-183-d7bNK3p-O2eAQRlr6ZdK_A-1; Fri, 17 Mar 2023 06:13:45 -0400 X-MC-Unique: d7bNK3p-O2eAQRlr6ZdK_A-1 Received: by mail-ed1-f72.google.com with SMTP id h11-20020a0564020e8b00b004e59d4722a3so7172257eda.6 for ; Fri, 17 Mar 2023 03:13:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679048024; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ahlyjaq1YfZIylBNFuCrpnwLhl66SRgQFZCZpgKNckQ=; b=wcMFwCe6ikt9bRhHS+Spy/Ha0wr30Ub76mUZTmEkPhK7feuDbUEYa0SrLIYBJus69u oEGPB9GCVIZFVhl7RS9KcI5ynwsCtk8Pimg7wF4Kd3XkgYCi8SDwkEjgYfQJA3ZKRLzU g/tnznvAMY6MN1jUq+ijzKtZkSkpaYt+24KsI0X2XSINamzCxzA1fUCeHP4T5+he7Mht 2jnUgsFRi8G97Sqwnznfco4UnovWfgUMVvLb0F9FWsRa9z1f4BaUBj7I5JKBi01SYaMn lDk8ara2XsWbILVWSWE0n1CeEW3CMo5xbofcXO2tpQGLqGDEBgN8nslt5faPO4BD0T9k OkWg== X-Gm-Message-State: AO0yUKXUGUGdslAVZ4Fo2COWffqaLRKTyS98iXucVoaC+c0NNRPvC2dR TdKncSkiTB62i5yLSnwqPMS6SrOKZhp5jSVRUHSq92FlWIpwD/KX9WtWfwoCTiwud76nv2NIg90 XrpLjyRM8SjUY+XpN7//jfA== X-Received: by 2002:a17:906:a18e:b0:921:5cce:6599 with SMTP id s14-20020a170906a18e00b009215cce6599mr12577086ejy.41.1679048024342; Fri, 17 Mar 2023 03:13:44 -0700 (PDT) X-Google-Smtp-Source: AK7set8TREFOLOwxyspLW98kRgdb7WFyd+V8Xoz0mvAXSRq3NTN+iS2CYNS42YU0CwDQpS2oE69W3A== X-Received: by 2002:a17:906:a18e:b0:921:5cce:6599 with SMTP id s14-20020a170906a18e00b009215cce6599mr12577070ejy.41.1679048024000; Fri, 17 Mar 2023 03:13:44 -0700 (PDT) Received: from [192.168.0.45] (ip-94-112-225-44.bb.vodafone.cz. [94.112.225.44]) by smtp.gmail.com with ESMTPSA id fi9-20020a170906da0900b00931faf03db0sm518507ejb.27.2023.03.17.03.13.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Mar 2023 03:13:43 -0700 (PDT) Message-ID: <103d7434-d7ad-b03b-5724-d6f9d6846749@redhat.com> Date: Fri, 17 Mar 2023 11:13:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH 1/1] gdb: Avoid warning for the jump command inside an inline function. To: Felix Willgerodt , gdb-patches@sourceware.org Cc: Cristian Sandu References: <20230124151932.2471769-1-felix.willgerodt@intel.com> From: Bruno Larsen In-Reply-To: <20230124151932.2471769-1-felix.willgerodt@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: 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 > --- > 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 . */ > + > +__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"