Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2019-2022 Free Software Foundation, Inc. |
57e5e645 SDJ |
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 | ||
24 | standard_testfile "normal.c" | |
25 | ||
26 | # This test is Linux x86_64 only. | |
27 | if { ![istarget *-*-linux*] } { | |
28 | untested "$testfile.exp" | |
29 | return -1 | |
30 | } | |
31 | if { ![istarget "x86_64-*-*"] || ![is_lp64_target] } { | |
32 | untested "$testfile.exp" | |
33 | return -1 | |
34 | } | |
35 | ||
36 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { | |
37 | return -1 | |
38 | } | |
39 | ||
40 | if { ![runto_main] } { | |
41 | untested "could not run to main" | |
42 | return -1 | |
43 | } | |
44 | ||
45 | # First we need to generate a corefile. | |
46 | set corefilename "[standard_output_file gcore.test]" | |
47 | if { ![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). | |
55 | if { [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 | ||
5e6741a1 TV |
61 | set binfile_re (?:[string_to_regexp $binfile]|\\\[(?:exe|pie)\\\]) |
62 | if { [regexp "^${hex}\\+${hex} \[a-f0-9\]+@${hex}.*$binfile_re$" $line] } { | |
57e5e645 SDJ |
63 | pass "$test" |
64 | } else { | |
65 | fail "$test" | |
66 | } | |
67 | } else { | |
68 | verbose -log "Could not execute eu-unstrip program" | |
69 | untested "$testfile.exp" | |
70 | } |