public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: Bruno Larsen <blarsen@redhat.com>
Subject: Re: [PATCHv3] gdb/c++: fix handling of breakpoints on @plt symbols
Date: Sun, 12 Feb 2023 06:22:45 +0000	[thread overview]
Message-ID: <875yc7v1vu.fsf@redhat.com> (raw)
In-Reply-To: <c9315691-00e3-b84f-206e-891876db8fb7@simark.ca>

Simon Marchi <simark@simark.ca> writes:

>> 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 <http://www.gnu.org/licenses/>.  */
>> +
>> +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:

I removed the 'extern' and added an extra check that we hit the expected
breakpoint, then pushed this patch.

Thanks,
Andrew

>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>
>> 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


  reply	other threads:[~2023-02-12  6:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20 13:55 [PATCH] " Andrew Burgess
2023-01-20 11:48 ` [PATCHv2] " Andrew Burgess
2023-01-30 15:13   ` Andrew Burgess
2023-02-08  9:36   ` Bruno Larsen
2023-02-10 19:09     ` Andrew Burgess
2023-02-13  9:31       ` Bruno Larsen
2023-02-08 22:22   ` Simon Marchi
2023-02-10 19:10     ` Andrew Burgess
2023-02-10 19:03   ` [PATCHv3] " Andrew Burgess
2023-02-10 20:51     ` Simon Marchi
2023-02-12  6:22       ` Andrew Burgess [this message]
2023-02-13 14:14       ` Tom Tromey

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=875yc7v1vu.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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).