From: Tom de Vries Date: Fri, 23 Jan 2026 06:54:32 +0000 (+0100) Subject: [gdb/testsuite] Force elf headers in linux core dump X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=735f4a98b10acf42907eac2bb022ed47095f70e6;p=thirdparty%2Fbinutils-gdb.git [gdb/testsuite] Force elf headers in linux core dump 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 PR testsuite/33772 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33772 [1] https://github.com/hexdump0815/linux-mainline-mediatek-mt81xx-kernel --- diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 7ac26f417ba..23fe3b3424a 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -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 \