22ccdc894e2cd8baacf6d07ddf45e292d2c709b9
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.arch / i386-biarch-core.exp
1 # Copyright 2015-2021 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 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
24 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
25 verbose "Skipping i386 biarch core test."
26 return
27 }
28
29 standard_testfile
30
31 gdb_exit
32 gdb_start
33 gdb_reinitialize_dir $srcdir/$subdir
34
35 set test "complete set gnutarget"
36 gdb_test_multiple "complete set gnutarget " $test {
37 -re "set gnutarget elf64-little\r\n(.*\r\n)?$gdb_prompt $" {
38 pass $test
39 }
40 -re "\r\n$gdb_prompt $" {
41 pass $test
42 untested ".text is readable"
43 return
44 }
45 }
46
47 set corebz2file ${srcdir}/${subdir}/${testfile}.core.bz2
48 set corefile [standard_output_file ${testfile}.core]
49 # Entry point of the original executable.
50 set address 0x400078
51
52 if {[catch "system \"bzip2 -dc ${corebz2file} >${corefile}\""] != 0} {
53 untested "failed bzip2"
54 return -1
55 }
56 file stat ${corefile} corestat
57 if {$corestat(size) != 102400} {
58 untested "bzip2 produces invalid result"
59 return -1
60 }
61
62 # First check if this particular GDB supports i386, otherwise we should not
63 # expect the i386 core file to be loaded successfully.
64 set supports_arch_i386 1
65 set test "complete set architecture i386"
66 gdb_test_multiple $test $test {
67 -re "\r\nset architecture i386\r\n(.*\r\n)?$gdb_prompt $" {
68 }
69 -re "\r\n$gdb_prompt $" {
70 set supports_arch_i386 0
71 }
72 }
73
74 # Wrongly built GDB complains by:
75 # "..." is not a core dump: File format not recognized
76 # As the provided test core has 64bit PRSTATUS i386 built GDB cannot parse it.
77 # This is just a problem of the test case, real-world elf64-i386 file will have
78 # 32bit PRSTATUS. One cannot prepare elf64-i386 core file from elf32-i386 by
79 # objcopy as it corrupts the core file beyond all recognition.
80 # The output therefore does not matter much, just we should not get GDB
81 # internal error.
82 #
83 # If this particular GDB does not support i386, it is expected GDB will not
84 # recognize the core file. If it does anyway, it should not crash.
85 set test "load core file"
86 gdb_test_multiple "core-file ${corefile}" $test {
87 -re "no core file handler recognizes format.*\r\n$gdb_prompt $" {
88 if { $supports_arch_i386 } {
89 fail $test
90 } else {
91 pass $test
92 untested ".text is readable (core file unrecognized)"
93 return
94 }
95 }
96 -re "\r\n$gdb_prompt $" {
97 pass $test
98 }
99 }
100
101 # Test if at least the core file segments memory has been loaded.
102 # https://bugzilla.redhat.com/show_bug.cgi?id=457187
103 gdb_test "x/bx $address" "\r\n\[ \t\]*$address:\[ \t\]*0xf4\[ \t\]*" ".text is readable"
This page took 0.03094 seconds and 3 git commands to generate.