From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 679A03858414 for ; Fri, 10 Feb 2023 20:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 679A03858414 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.192] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 150601E0D3; Fri, 10 Feb 2023 15:51:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1676062282; bh=98qjVRhTt5ps4go9Ld+FLbeh4SeOHXL3Hh72nK/iXyA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=VVw/Ef6DJ2fpSnz9Pd7M9Jd2gzqgVP2q7l1ynPW0PGRrlbZZNRlrPZeZhRYD3zb4y RM4ZNblQd24c3zPXfYjnUXVDBoTDH7Qo234b5VdaH88Db8sYiC75MkaRjA8Li1kEMH aOmRQSblDjjMbZOBb1XAeMW55apHbiGomuB2A+fY= Message-ID: Date: Fri, 10 Feb 2023 15:51:21 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCHv3] gdb/c++: fix handling of breakpoints on @plt symbols Content-Language: fr To: Andrew Burgess , gdb-patches@sourceware.org Cc: Bruno Larsen References: <29e560fd9c94874f0839924fa25557a7e8418ad3.1674215225.git.aburgess@redhat.com> <1e9534288b91692c94af288b12659b107ac590c8.1676055649.git.aburgess@redhat.com> From: Simon Marchi In-Reply-To: <1e9534288b91692c94af288b12659b107ac590c8.1676055649.git.aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,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: > diff --git a/gdb/testsuite/gdb.cp/breakpoint-shlib-func-lib.cc b/gdb/testsuite/gdb.cp/breakpoint-shlib-func-lib.cc > new file mode 100644 > index 00000000000..7219f7c5a23 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/breakpoint-shlib-func-lib.cc > @@ -0,0 +1,21 @@ > +/* Copyright 2022-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 . */ > + > +extern int foo (); I don't think this extern declaration is needed. > +# The breakpoint should now be showing in `foo` for real. > +gdb_test "info breakpoints" \ > + "\r\n$decimal\\s+\[^\r\n\]+ in foo\\(\\) at \[^\r\n\]+\r\n.*" \ > + "check breakpoints after starting the inferior" > + > +# Now we can delete the breakpoints. > +delete_breakpoints > + > +# And recreate the foo breakpoint, we should only get one location, > +# the actual location. > +gdb_test "break foo" "Breakpoint $decimal at \[^\r\n\]+" \ > + "recreate foo breakpoint" > + > +# Check the breakpoint was recreated correctly. > +gdb_test "info breakpoints" \ > + "\r\n$decimal\\s+\[^\r\n\]+ in foo\\(\\) at \[^\r\n\]+" \ > + "check breakpoints after recreation" For completeness, you could maybe resume and confirm you are stopped at foo (and not foo@plt). Otherwise, it all LGTM: Approved-By: Simon Marchi > diff --git a/gdb/utils.c b/gdb/utils.c > index 95adbe58e4a..76c0df36a80 100644 > --- a/gdb/utils.c > +++ b/gdb/utils.c > @@ -2402,7 +2402,31 @@ strncmp_iw_with_mode (const char *string1, const char *string2, > return 0; > } > else > - return (*string1 != '\0' && *string1 != '('); > + { > + if (*string1 == '(') > + { > + int p_count = 0; > + > + do > + { > + if (*string1 == '(') > + ++p_count; > + else if (*string1 == ')') > + --p_count; > + ++string1; > + } > + while (*string1 != '\0' && p_count > 0); > + > + /* There maybe things like 'const' after the parameters, > + which we do want to ignore. However, if there's an '@' > + then this likely indicates something like '@plt' which we > + should not ignore. */ > + return *string1 == '@'; > + } > + > + return *string1 == '\0' ? 0 : 1; > + } Not really relevant for your patch but... just chatting. I don't know if it would be really inefficient, but reading this function, I dream of some util function that would parse a demangled C++ function symbol into some structured type (listing the namespaces, name, abi tags, parameters, whether it is const or not, etc). It would then be much easier to work on that, rather than doing everything string-based. Simon