]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Force elf headers in linux core dump
authorTom de Vries <tdevries@suse.de>
Fri, 23 Jan 2026 06:54:32 +0000 (07:54 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 23 Jan 2026 06:54:32 +0000 (07:54 +0100)
I've got a test setup consisting of a chromebook with a MediaTek MT8183
processor, running Debian userland with a custom kernel [1].

The custom kernel doesn't have CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS enabled,
and consequently the default coredump_filter is 0x23 instead of 0x33, in other
words bit 4 (which enables the dumping of ELF headers) is not set.

The testsuite relies on the dumping of ELF headers in core files to get the
build-ID of the executable and shared libraries, and consequently some
test-cases fail.

Fix this in core_find, by adding bit 4 in the coredump_filter, if necessary.

Fixes test-cases:
- gdb.base/corefile-exec-mismatch.exp
- gdb.base/corefile-find-exec.exp
- gdb.debuginfod/corefile-mapped-file.exp
- gdb.debuginfod/solib-with-soname.exp
- gdb.python/py-corefile.exp
- gdb.python/py-missing-objfile.exp

Tested on aarch64-linux.

Reviewed-By: Keith Seitz <keiths@redhat.com>
PR testsuite/33772
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33772

[1] https://github.com/hexdump0815/linux-mainline-mediatek-mt81xx-kernel

gdb/testsuite/lib/gdb.exp

index 7ac26f417ba80a5137a3369a16c6f69a261c650d..23fe3b3424a84bd1942d40754156b385e756b94e 100644 (file)
@@ -9771,8 +9771,23 @@ proc core_find {binfile {deletefiles {}} {arg ""} {output_file "/dev/null"}} {
     set found 0
     set coredir [standard_output_file coredir.[getpid]]
     file mkdir $coredir
+
+    set coredump_filter_cmd true
+    if {[istarget "*-linux*-*"]} {
+       # Bit 4, corresponding to "Dump ELF headers".  We need those to get
+       # the Build-ID of the exec from the core file.
+       set elf_headers_bit 0x10
+
+       set res 0x[exec cat /proc/self/coredump_filter]
+       if {($res & $elf_headers_bit) == 0} {
+           set res [expr {$res | $elf_headers_bit}]
+           set res 0x[format %x $res]
+           set coredump_filter_cmd "echo $res > /proc/self/coredump_filter"
+       }
+    }
+
     # tclint-disable command-args
-    catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >${output_file} 2>&1\""
+    catch "system \"(cd ${coredir}; ulimit -c unlimited; $coredump_filter_cmd; ${binfile} ${arg}; true) >${output_file} 2>&1\""
     #      remote_exec host "${binfile}"
     set binfile_basename [file tail $binfile]
     foreach i [list \