]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2015-2024 Free Software Foundation, Inc. |
97a0c697 JK |
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 ability to load an elf64-i386 core file. The provided core file was | |
17 | # elf64-x8664 one but it got binary patched to i386: | |
18 | # Elf32_Ehdr.e_machine @0x12..0x13 | |
19 | # Elf64_Ehdr.e_machine @0x12..0x13 | |
20 | # #define EM_386 3 /* Intel 80386 */ | |
21 | # #define EM_X86_64 62 /* AMD x86-64 architecture */ | |
22 | # patch @0x12: 0x3E -> 0x03 | |
23 | ||
c7ccb471 | 24 | require {is_any_target "i?86-*-*" "x86_64-*-*"} |
acde2092 | 25 | |
97a0c697 JK |
26 | standard_testfile |
27 | ||
feb5926e | 28 | clean_restart |
775a3298 | 29 | |
feb5926e TV |
30 | set gnutargets [get_set_option_choices "set gnutarget"] |
31 | if { [lsearch -exact $gnutargets elf64-little] == -1 } { | |
32 | untested ".text is readable" | |
33 | return | |
97a0c697 JK |
34 | } |
35 | ||
36 | set corebz2file ${srcdir}/${subdir}/${testfile}.core.bz2 | |
97a0c697 JK |
37 | # Entry point of the original executable. |
38 | set address 0x400078 | |
39 | ||
24eb586f TV |
40 | set corefile [decompress_bz2 $corebz2file] |
41 | if { $corefile == "" } { | |
97a0c697 JK |
42 | untested "failed bzip2" |
43 | return -1 | |
44 | } | |
24eb586f | 45 | |
97a0c697 JK |
46 | file stat ${corefile} corestat |
47 | if {$corestat(size) != 102400} { | |
48 | untested "bzip2 produces invalid result" | |
49 | return -1 | |
50 | } | |
51 | ||
68f2478f TV |
52 | set corefile [gdb_remote_download host $corefile] |
53 | ||
13a66184 LM |
54 | # First check if this particular GDB supports i386, otherwise we should not |
55 | # expect the i386 core file to be loaded successfully. | |
feb5926e TV |
56 | set archs [get_set_option_choices "set architecture" "i386"] |
57 | set supports_arch_i386 [expr [lsearch -exact $archs i386] != -1] | |
13a66184 | 58 | |
97a0c697 JK |
59 | # Wrongly built GDB complains by: |
60 | # "..." is not a core dump: File format not recognized | |
61 | # As the provided test core has 64bit PRSTATUS i386 built GDB cannot parse it. | |
cfa68bae | 62 | # This is just a problem of the test case, real-world elf64-i386 file will have |
97a0c697 JK |
63 | # 32bit PRSTATUS. One cannot prepare elf64-i386 core file from elf32-i386 by |
64 | # objcopy as it corrupts the core file beyond all recognition. | |
775a3298 JK |
65 | # The output therefore does not matter much, just we should not get GDB |
66 | # internal error. | |
13a66184 LM |
67 | # |
68 | # If this particular GDB does not support i386, it is expected GDB will not | |
69 | # recognize the core file. If it does anyway, it should not crash. | |
70 | set test "load core file" | |
71 | gdb_test_multiple "core-file ${corefile}" $test { | |
72 | -re "no core file handler recognizes format.*\r\n$gdb_prompt $" { | |
73 | if { $supports_arch_i386 } { | |
74 | fail $test | |
75 | } else { | |
76 | pass $test | |
77 | untested ".text is readable (core file unrecognized)" | |
78 | return | |
79 | } | |
80 | } | |
81 | -re "\r\n$gdb_prompt $" { | |
82 | pass $test | |
83 | } | |
84 | } | |
97a0c697 | 85 | |
775a3298 JK |
86 | # Test if at least the core file segments memory has been loaded. |
87 | # https://bugzilla.redhat.com/show_bug.cgi?id=457187 | |
88 | gdb_test "x/bx $address" "\r\n\[ \t\]*$address:\[ \t\]*0xf4\[ \t\]*" ".text is readable" |