1# Copyright 2019-2020 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# Test whether GDB's gcore/generate-core-file command can dump memory 17# mappings with ELF headers, containing a build-id note. 18# 19# Due to the fact that we don't have an easy way to process a corefile 20# and look for specific notes using GDB/dejagnu, we rely on an 21# external tool, eu-unstrip, to verify if the corefile contains 22# build-ids. 23 24standard_testfile "normal.c" 25 26# This test is Linux x86_64 only. 27if { ![istarget *-*-linux*] } { 28 untested "$testfile.exp" 29 return -1 30} 31if { ![istarget "x86_64-*-*"] || ![is_lp64_target] } { 32 untested "$testfile.exp" 33 return -1 34} 35 36if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { 37 return -1 38} 39 40if { ![runto_main] } { 41 untested "could not run to main" 42 return -1 43} 44 45# First we need to generate a corefile. 46set corefilename "[standard_output_file gcore.test]" 47if { ![gdb_gcore_cmd "$corefilename" "save corefile"] } { 48 verbose -log "Could not save corefile" 49 untested "$testfile.exp" 50 return -1 51} 52 53# Determine if GDB dumped the mapping containing the build-id. This 54# is done by invoking an external program (eu-unstrip). 55if { [catch "exec [gdb_find_eu-unstrip] -n --core $corefilename" output] == 0 } { 56 set line [lindex [split $output "\n"] 0] 57 set test "gcore dumped mapping with build-id" 58 59 verbose -log "First line of eu-unstrip: $line" 60 61 if { [regexp "^${hex}\\+${hex} \[a-f0-9\]+@${hex}.*[string_to_regexp $binfile]$" $line] } { 62 pass "$test" 63 } else { 64 fail "$test" 65 } 66} else { 67 verbose -log "Could not execute eu-unstrip program" 68 untested "$testfile.exp" 69} 70