From: Simon Marchi <simark@simark.ca>
To: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sourceware.org
Subject: Re: The 'cold' function attribute and GDB
Date: Wed, 01 May 2019 20:17:00 -0000 [thread overview]
Message-ID: <077aee8c-7bef-bad6-a6a1-e69f116cc18b@simark.ca> (raw)
In-Reply-To: <83wojaovbp.fsf@gnu.org>
On 2019-05-01 2:58 p.m., Eli Zaretskii wrote:
> If some functions in your program are declared with
> __attribute__((cold)), GCC generates local symbols of the form
> FOO.cold, where FOO is a function that has a code path which
> eventually calls one of the 'cold' functions. When GDB needs to show
> a backtrace or a stack frame inside one of these code paths, it shows
> FOO.cold as the name of the function. Here's a real-life example:
>
> Thread 1 received signal SIGTRAP, Trace/breakpoint trap.
> 0x76a63227 in KERNELBASE!DebugBreak () from C:\Windows\syswow64\KernelBase.dll
> (gdb) thread 1
> [Switching to thread 1 (Thread 7552.0x172c)]
> #0 0x76a63227 in KERNELBASE!DebugBreak ()
> from C:\Windows\syswow64\KernelBase.dll
> (gdb) up
> #1 0x012e7b89 in emacs_abort () at w32fns.c:10768
> 10768 DebugBreak ();
> (gdb)
> #2 0x012e1f3b in print_vectorlike.cold () at print.c:1824 <<<<<<<<<<<<<<<<
> 1824 emacs_abort ();
> (gdb) bt
> #0 0x76a63227 in KERNELBASE!DebugBreak ()
> from C:\Windows\syswow64\KernelBase.dll
> #1 0x012e7b89 in emacs_abort () at w32fns.c:10768
> #2 0x012e1f3b in print_vectorlike.cold () at print.c:1824 <<<<<<<<<<<<<<<<
> #3 0x011d2dec in print_object (obj=<optimized out>, printcharfun=XIL(0),
> escapeflag=true) at print.c:2150
The way this is written:
print_vectorlike.cold ()
makes me thing that GDB didn't find a full symbol (DWARF symbol) for this address, so
fell back on the nearest preceding minimal symbol (ELF symbol). I say this because it
lacks the arguments here, but it does accept some parameter in the code. If GDB had
found the full symbol, it should show the arguments, and the function name, print_vectorlike.
So I would inspect the DWARF info generated by gcc for the print_vectorlike function to
see what GDB is working with, it will be easier to know where to search.
In particular, how does the DWARF info describe the address range or ranges taken by
the print_vectorlike function? In an ideal world, if gcc generates two separate ranges
of instruction for this function (the hot path and the cold path), it should describe
it as two ranges in the entry for print_vectorlike. If so, it should be described with
a DW_AT_ranges attribute.
If you are not sure what to look for, try to find the debug info entry for print_vectorlike
and paste it here.
Also, which commit of GDB is this with? I recall some patches related to non-contiguous
address ranges not too long ago.
> There's a print_vectorlike function in Emacs, and it calls
> emacs_abort, which is declared 'cold' (because it is called in case of
> fatal errors and doesn't return).
>
> Since the 'cold' functions tend to be those that are called in case of
> some calamity, and since GDB is likely to be used to debug such
> calamities, and the user is likely to put breakpoint in such 'cold'
> functions precisely to catch these calamities, the above is not such a
> rare use case as far as real-life use of GDB goes.
>
> I think this display is confusing, but is there any reasonable way for
> GDB not to expose these symbols to the user?
I guess that it would be possible to handle specially minimal symbols named something.cold,
but it should not be necessary if we have good debug info and use it correctly, so I would
prefer not to go that route.
Simon
next prev parent reply other threads:[~2019-05-01 20:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-01 18:59 Eli Zaretskii
2019-05-01 20:17 ` Simon Marchi [this message]
2019-05-02 2:51 ` Kevin Buettner
2019-05-02 6:59 ` Eli Zaretskii
2019-05-02 7:26 ` Kevin Buettner
2019-05-02 15:27 ` Eli Zaretskii
2019-05-02 15:59 ` Kevin Buettner
2019-05-02 16:46 ` Eli Zaretskii
2019-05-02 18:08 ` Simon Marchi
2019-05-02 18:47 ` Eli Zaretskii
2019-05-02 18:55 ` Kevin Buettner
2019-05-02 19:32 ` Eli Zaretskii
2019-05-02 19:51 ` Kevin Buettner
2019-05-02 7:06 ` Eli Zaretskii
2019-05-02 7:38 ` Kevin Buettner
2019-05-02 15:23 ` Eli Zaretskii
2019-05-02 15:56 ` Kevin Buettner
2019-05-02 16:43 ` Eli Zaretskii
2019-05-02 18:25 ` Kevin Buettner
2019-05-02 18:52 ` Eli Zaretskii
2019-05-02 19:13 ` Kevin Buettner
2019-05-02 19:28 ` Eli Zaretskii
2019-05-02 19:45 ` Kevin Buettner
2019-05-02 19:56 ` Eli Zaretskii
2019-05-02 23:30 ` Kevin Buettner
2019-05-04 8:30 ` Eli Zaretskii
2019-05-05 20:04 ` Kevin Buettner
2019-05-06 15:33 ` Eli Zaretskii
2019-05-06 16:24 ` Kevin Buettner
2019-05-02 15:17 ` Eli Zaretskii
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=077aee8c-7bef-bad6-a6a1-e69f116cc18b@simark.ca \
--to=simark@simark.ca \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/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