Re: question about why gdb needs executable's binary

Jan Kratochvil <[email protected]> Thu, 14 Mar 2019 22:45:55 +0100
Newsgroups gmane.comp.gdb.devel,gmane.comp.gdb.general
Message-ID <[email protected]>
On Wed, 13 Mar 2019 15:24:50 +0100, Jirka Koutn=C3=BD wrote:
> I was wondering why does gdb still need the executable's binary as well?
> Is there some additional information retrieved from the executable?

Yes, without the main executable GDB cannot find the list of shared librari=
es.


> PT_NOTE contains address ranges and shared libraries names as well,

NT_FILE is a recent feature and GDB can only produce it, GDB cannot read it.
GDB also cannot read /proc/PID/maps to recognize the list of shared librari=
es.


> What is the missing bit of information there?

To find the list of mapped shared libraries GDB needs to read DT_DEBUG which
is located in DYNAMIC segment of the main executable.

GDB can read also "_r_debug" but for that it needs to know ld.so which is
a mapped shared library so that is a chicked-and-egg problem.


eu-stack can do these:

With main executable:
$ eu-stack --core=3Dsleep.core
PID 1886638 - core
TID 1886638:
#0  0x00007f37e04707f8 __nanosleep
#1  0x000055a9557f28d7 rpl_nanosleep
#2  0x000055a9557f26b0 xnanosleep
#3  0x000055a9557ef7c8 main
#4  0x00007f37e03cb413 __libc_start_main
#5  0x000055a9557ef89e _start

Without main executable:
$ eu-stack --core=3Dsleep.core2
PID 1886638 - core
TID 1886638:
#0  0x00007f37e04707f8 __nanosleep
#1  0x000055a9557f28d7
eu-stack: dwfl_thread_getframes tid 1886638 at 0x55a9557f28d6 in /usr/bin/s=
leep: Callback returned failure

Just that eu-stack does not contain heuristics for unwinding frames with
missing unwind information (.eh_frame/.debug_frame) and so if a frame is
generated from the main executable it gives up for further unwinding.


Jan