1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008,
2 # 2009, 2010 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
24 # are we on a target board
29 set testfile "coremaker"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
37 # Create and source the file that provides information about the compiler
38 # used to compile the test case.
39 if [get_compiler_info ${binfile}] {
43 set corefile [core_find $binfile {coremmap.data}]
44 if {$corefile == ""} {
48 # Test that we can simply startup with a "-core=$corefile" command line arg
49 # and recognize that the core file is a valid, usable core file.
50 # To do this, we must shutdown the currently running gdb and restart
51 # with the -core args. We can't use gdb_start because it looks for
52 # the first gdb prompt, and the message we are looking for occurs
53 # before the first prompt.
55 # Another problem is that on some systems (solaris for example), there
56 # is apparently a limit on the length of a fully specified path to
57 # the coremaker executable, at about 80 chars. For this case, consider
58 # it a pass, but note that the program name is bad.
62 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile\n"
65 set oldtimeout $timeout
66 set timeout [expr "$timeout + 60"]
67 verbose "Timeout is now $timeout seconds" 2
68 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS -core=$corefile"
70 -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
71 fail "args: -core=[file tail $corefile] (couldn't find regs)"
73 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
74 pass "args: -core=[file tail $corefile]"
76 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
77 pass "args: -core=[file tail $corefile] (with bad program name)"
79 -re ".*registers from core file: File in wrong format.* $" {
80 fail "args: -core=[file tail $corefile] (could not read registers from core file)"
82 -re ".*$gdb_prompt $" { fail "args: -core=[file tail $corefile]" }
83 timeout { fail "(timeout) starting with -core" }
88 # Test that startup with both an executable file and -core argument.
89 # See previous comments above, they are still applicable.
95 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile\n"
99 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $binfile -core=$corefile";
101 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
102 pass "args: execfile -core=[file tail $corefile]"
104 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
105 pass "args: execfile -core=[file tail $corefile] (with bad program name)"
107 -re ".*registers from core file: File in wrong format.* $" {
108 fail "args: execfile -core=[file tail $corefile] (could not read registers from core file)"
110 -re ".*$gdb_prompt $" { fail "args: execfile -core=[file tail $corefile]" }
111 timeout { fail "(timeout) starting with -core" }
113 set timeout $oldtimeout
114 verbose "Timeout is now $timeout seconds" 2
118 # Now restart normally.
121 gdb_reinitialize_dir $srcdir/$subdir
124 # Test basic corefile recognition via core-file command.
126 send_gdb "core-file $corefile\n"
128 -re ".* program is being debugged already.*y or n. $" {
129 # gdb_load may connect us to a gdbserver.
133 -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
134 pass "core-file command"
136 -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
137 pass "core-file command (with bad program name)"
139 -re ".*registers from core file: File in wrong format.* $" {
140 fail "core-file command (could not read registers from core file)"
142 -re ".*$gdb_prompt $" { fail "core-file command" }
143 timeout { fail "(timeout) core-file command" }
146 # Test correct mapping of corefile sections by printing some variables.
148 gdb_test "print coremaker_data" "\\\$$decimal = 202"
149 gdb_test "print coremaker_bss" "\\\$$decimal = 10"
150 gdb_test "print coremaker_ro" "\\\$$decimal = 201"
152 gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
154 # Somehow we better test the ability to read the registers out of the core
155 # file correctly. I don't think the other tests do this.
157 gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
158 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
160 # Test ability to read mmap'd data
162 gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
163 setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
164 set test "accessing mmapped data in core file"
165 gdb_test_multiple "x/8bd buf2" "$test" {
166 -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
169 -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
170 fail "$test (mapping failed at runtime)"
172 -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
173 fail "$test (mapping address not found in core file)"
177 # test reinit_frame_cache
180 gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
182 gdb_test "core" "No core file now."