Dear Maintainer,
and some more digging with the help of rr-debugger led me to the
functions svr4_relocate_main_executable/exec_set_section_address
in gdb.
The latter gets not called in the valgrind core case,
because the vgcore file lacks an ".auxv" section,
which does exist inside a regular core:
$ objdump -x core
...
Sections:
Idx Name Size VMA LMA File off
Algn
...
5 .auxv 00000140 0000000000000000 0000000000000000 000007b8 2**3
CONTENTS
So I came up with attached patch for valgrind
that adds the ".auxv" section to the vgcore
and with such a vgcore gdb is able to show
the proper source line and shared library information.
(This patch still contains some informational debug printfs.)
Kind regards,
Bernhard
gdb backtrace, where the ".auxv" sections is searched:
868 section = bfd_get_section_by_name (core_bfd, ".auxv");
(rr) bt
#0 core_target::xfer_partial (this=0x563cec758120, object=TARGET_OBJECT_AUXV,
annex=0x0, readbuf=0x563cec79d540 "\240Sa[J\177", writebuf=0x0, offset=0,
len=4096, xfered_len=0x7fff66a72fc8) at /build/gdb-Nav6Es/gdb-10.1/gdb/corelow.c:868
#1 0x0000563cebeee1be in target_xfer_partial (ops=0x563cec758120,
object=TARGET_OBJECT_AUXV, annex=0x0, readbuf=0x563cec79d540 "\240Sa[J\177",
writebuf=0x0, offset=0, len=<optimized out>, xfered_len=0x7fff66a72fc8) at
/build/gdb-Nav6Es/gdb-10.1/gdb/target.c:1160
#2 0x0000563cebef0863 in target_read_partial (xfered_len=0x7fff66a72fc8,
len=4096, offset=0, buf=<optimized out>, annex=0x0, object=TARGET_OBJECT_AUXV,
ops=0x563cec758120) at /build/gdb-Nav6Es/gdb-10.1/gdb/target.c:1387
#3 target_read_alloc_1<unsigned char> (ops=ops@entry=0x563cec758120,
object=object@entry=TARGET_OBJECT_AUXV, annex=annex@entry=0x0) at
/build/gdb-Nav6Es/gdb-10.1/gdb/target.c:1722
#4 0x0000563cebeeff6a in target_read_alloc (ops=ops@entry=0x563cec758120,
object=object@entry=TARGET_OBJECT_AUXV, annex=annex@entry=0x0) at
/build/gdb-Nav6Es/gdb-10.1/gdb/target.c:1751
#5 0x0000563cebc30630 in get_auxv_inferior_data (ops=0x563cec758120) at
/build/gdb-Nav6Es/gdb-10.1/gdb/auxv.c:368
#6 0x0000563cebc30c69 in target_auxv_search (ops=<optimized out>,
match=match@entry=9, valp=valp@entry=0x7fff66a73158) at
/build/gdb-Nav6Es/gdb-10.1/gdb/auxv.c:382
#7 0x0000563cebe97881 in svr4_exec_displacement (displacementp=<synthetic
pointer>) at /build/gdb-Nav6Es/gdb-10.1/gdb/solib-svr4.c:2577
#8 svr4_relocate_main_executable () at
/build/gdb-Nav6Es/gdb-10.1/gdb/solib-svr4.c:2960
...
Description: Add auxiliary vector to vgcore files
This enables gdb to get relocation and load debug information.
Author: Bernhard Übelacker <bernha...@mailbox.org>
Bug-Debian: https://bugs.debian.org/993018
Forwarded: no
Last-Update: 2021-09-13
--- valgrind-3.16.1.orig/coregrind/m_coredump/coredump-elf.c
+++ valgrind-3.16.1/coregrind/m_coredump/coredump-elf.c
@@ -730,6 +730,19 @@ void make_elf_coredump(ThreadId tid, con
/* Second, work out their layout */
phdrs = VG_(malloc)("coredump-elf.mec.1", sizeof(*phdrs) * num_phdrs);
+ /* Auxiliary vector, from coregrind/m_gdbserver/server.c */
+ UWord *client_auxv = VG_(client_auxv);
+ unsigned int client_auxv_len = 0;
+ while (*client_auxv != 0) {
+ client_auxv++;
+ client_auxv++;
+ client_auxv_len += 2 * sizeof(UWord);
+ }
+ client_auxv_len += 2 * sizeof(UWord);
+ client_auxv = VG_(client_auxv);
+ VG_(umsg)("Adding NT_AUXV. %p/%u\n", client_auxv, client_auxv_len);
+ add_note(¬elist, "CORE", NT_AUXV, client_auxv, client_auxv_len);
+
/* Add details for all threads except the one that faulted */
for(i = 1; i < VG_N_THREADS; i++) {
--- valgrind-3.16.1.orig/coregrind/m_initimg/initimg-linux.c
+++ valgrind-3.16.1/coregrind/m_initimg/initimg-linux.c
@@ -674,6 +674,7 @@ Addr setup_client_stack( void* init_sp,
break;
case AT_ENTRY:
+ VG_(printf)("AT_ENTRY=%lx auxv=%p info=%p client_auxv=%p\n", info->entry, auxv, info, *client_auxv);
auxv->u.a_val = info->entry;
break;