Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>,
	Simon Marchi <simon.marchi@polymtl.ca>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH][gdb/symtab] Ignore cold clones
Date: Tue, 1 Jun 2021 15:23:41 +0200	[thread overview]
Message-ID: <bca55d40-a4e3-0dd9-4069-6275ce56d1ef@suse.de> (raw)
In-Reply-To: <AM8PR10MB470872B58F078FD0332C25B2E43F9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM>

On 5/31/21 6:54 PM, Bernd Edlinger wrote:
> On 5/31/21 4:59 PM, Tom de Vries wrote:
>> On 5/31/21 4:26 PM, Simon Marchi wrote:
>>> On 2021-05-31 10:15 a.m., Tom de Vries wrote:
>>>> Hi,
>>>>
>>>> Consider the test-case contained in this patch, compiled for c using gcc-10:
>>>> ...
>>>> $ gcc-10 -x c src/gdb/testsuite/gdb.cp/cold-clone.cc -O2 -g -Wall -Wextra
>>>> ...
>>>>
>>>> When setting a breakpoint on foo, we get one breakpoint location:
>>>> ...
>>>> $ gdb -q -batch a.out -ex "b foo"
>>>> Breakpoint 1 at 0x400560: file cold-clone.cc, line 28.
>>>> ...
>>>>
>>>> However, when we compile for c++ instead, we get two breakpoint locations:
>>>> ...
>>>> $ gdb -q -batch a.out -ex "b foo" -ex "info break"
>>>> Breakpoint 1 at 0x400430: foo. (2 locations)
>>>> Num  Type        Disp Enb Address            What
>>>> 1    breakpoint  keep y   <MULTIPLE>
>>>> 1.1                   y   0x0000000000400430 in foo() at cold-clone.cc:30
>>>> 1.2                   y   0x0000000000400560 in foo() at cold-clone.cc:28
>>>> ...
>>>>
>>>> The additional breakpoint location at 0x400430 corresponds to the cold clone:
>>>> ...
>>>> $ nm a.out | grep foo
>>>> 0000000000400560 t _ZL3foov
>>>> 0000000000400430 t _ZL3foov.cold
>>>> ...
>>>> which demangled looks like this:
>>>> ...
>>>> $ nm -C a.out | grep foo
>>>> 0000000000400560 t foo()
>>>> 0000000000400430 t foo() [clone .cold]
>>>> ...
>>>>
>>>> [ Or, in the case of the cc1 mentioned in PR23710:
>>>> ...
>>>> $ nm cc1 | grep do_rpo_vn.*cold
>>>> 000000000058659d t \
>>>>   _ZL9do_rpo_vnP8functionP8edge_defP11bitmap_headbb.cold.138
>>>> $ nm -C cc1 | grep do_rpo_vn.*cold
>>>> 000000000058659d t \
>>>>   do_rpo_vn(function*, edge_def*, bitmap_head*, bool, bool) [clone .cold.138]
>>>> ... ]
>>>>
>>>> The cold clone is a part of the function that is split off from the rest of
>>>> the function because it's considered cold (not frequently executed).  So while
>>>> the symbol points to code that is part of a function, it doesn't point to a
>>>> function entry, so the desirable behaviour for "break foo" is to ignore this
>>>> symbol.
>>>>
>>>> When compiling for c, the symbol "foo.cold" is entered as minimal symbol
>>>> with the search name "foo.cold", and the lookup using "foo" fails to find that
>>>> symbol.
>>>>
>>>> But when compiling for c++, the symbol "foo.cold" is entered as minimal symbol
>>>> with both the mangled and demangled name, and for the demangled name
>>>> "foo() [clone .cold]" we get the search name "foo" (because
>>>> cp_search_name_hash stops hashing at '('), and the lookup using "foo" succeeds.
>>>>
>>>> Fix this by recognizing the cold clone suffix and returning false for such a
>>>> minimal symbol in msymbol_is_function.
>>>>
>>>> Tested on x86_64-linux.
>>>>
>>>> Any comments?
>>>
>>> Is this related to
>>>
>>> https://sourceware.org/pipermail/gdb-patches/2021-May/179371.html
>>>
>>
>> Yes, it looks like both attempt to fix the same PR, thanks for the pointer.
>>
>> At first glance, that one doesn't handle symbol
>> "_ZL9do_rpo_vnP8functionP8edge_defP11bitmap_headbb.cold.138".
>>
> 
> Is this symbol from gcc?

Yes (as you found out by now).

And looking at the DW_AT_producer it's generated by gcc-9 flto:
...
DW_AT_producer    : GNU C++14 9.0.0 20180925 (experimental) [trunk
revision 259470] -mtune=generic -march=x86-64 -g -O2 -fno-PIE
-flto=jobserver -frandom-seed=1 -fno-exceptions -fno-rtti
-fasynchronous-unwind-tables
...

> I never saw this kind of mangled symbol.
> 
> TBH, I was not sure if I should handle foo$cold or __foo_cold. 
> In theory there may be targets where the assembler does not like ".",
> then gcc would emit foo$cold
> If neither "." nor "$" is acceptable then gcc would emit __foo_cold
> but I was not sure if such targets do really exist.
> 

Yeah, good point.

Well, there's nvptx for example, but that one doesn't have upstream gdb
support.  Anyway, it might be that this is dealt with somehow in the
demangler, I'm not sure.  So I don't think it makes sense to try to fix
this until we see proof that it's actually broken.

Thanks,
- Tom

      parent reply	other threads:[~2021-06-01 13:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31 14:15 Tom de Vries
2021-05-31 14:26 ` Simon Marchi via Gdb-patches
2021-05-31 14:59   ` Tom de Vries
2021-05-31 16:54     ` Bernd Edlinger
2021-06-01  5:18       ` Bernd Edlinger
2021-06-01 11:33         ` Tom de Vries
2021-06-01 13:23       ` Tom de Vries [this message]

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=bca55d40-a4e3-0dd9-4069-6275ce56d1ef@suse.de \
    --to=tdevries@suse.de \
    --cc=bernd.edlinger@hotmail.de \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.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