| 1 | # Copyright 2010-2012 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 | |
| 17 | if { ![istarget i?86-*-linux*] && ![istarget x86_64-*-linux* ] } { |
| 18 | verbose "Skipping system register gcore tests." |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | set testfile "system-gcore" |
| 23 | set srcfile gcore.c |
| 24 | set binfile ${objdir}/${subdir}/${testfile} |
| 25 | |
| 26 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 27 | untested system-gcore.exp |
| 28 | return -1 |
| 29 | } |
| 30 | |
| 31 | # Start with a fresh gdb. |
| 32 | |
| 33 | gdb_exit |
| 34 | gdb_start |
| 35 | gdb_reinitialize_dir $srcdir/$subdir |
| 36 | gdb_load ${binfile} |
| 37 | |
| 38 | # Does this gdb support gcore? |
| 39 | send_gdb "help gcore\n" |
| 40 | gdb_expect { |
| 41 | -re "Undefined command: .gcore.*$gdb_prompt $" { |
| 42 | # gcore command not supported -- nothing to test here. |
| 43 | unsupported "gdb does not support gcore on this target" |
| 44 | return -1; |
| 45 | } |
| 46 | -re "Save a core file .*$gdb_prompt $" { |
| 47 | pass "help gcore" |
| 48 | } |
| 49 | -re ".*$gdb_prompt $" { |
| 50 | fail "help gcore" |
| 51 | } |
| 52 | timeout { |
| 53 | fail "help gcore (timeout)" |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if { ! [ runto_main ] } then { |
| 58 | untested system-gcore.exp |
| 59 | return -1 |
| 60 | } |
| 61 | |
| 62 | proc capture_command_output { command prefix } { |
| 63 | global gdb_prompt |
| 64 | global expect_out |
| 65 | |
| 66 | set output_string "" |
| 67 | gdb_test_multiple "$command" "capture_command_output for $command" { |
| 68 | -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { |
| 69 | set output_string $expect_out(1,string) |
| 70 | } |
| 71 | } |
| 72 | return $output_string |
| 73 | } |
| 74 | |
| 75 | gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ |
| 76 | "set breakpoint at terminal_func" |
| 77 | |
| 78 | gdb_test "continue" "Breakpoint .* terminal_func.*" \ |
| 79 | "continue to terminal_func" |
| 80 | |
| 81 | set print_prefix ".\[0123456789\]* = " |
| 82 | |
| 83 | set pre_corefile_backtrace [capture_command_output "backtrace" ""] |
| 84 | set pre_corefile_regs [capture_command_output "info registers" ""] |
| 85 | set pre_corefile_allregs [capture_command_output "info all-reg" ""] |
| 86 | set pre_corefile_sysregs [capture_command_output "info reg system" ""] |
| 87 | set pre_corefile_static_array \ |
| 88 | [capture_command_output "print static_array" "$print_prefix"] |
| 89 | set pre_corefile_uninit_array \ |
| 90 | [capture_command_output "print un_initialized_array" "$print_prefix"] |
| 91 | set pre_corefile_heap_string \ |
| 92 | [capture_command_output "print heap_string" "$print_prefix"] |
| 93 | set pre_corefile_local_array \ |
| 94 | [capture_command_output "print array_func::local_array" "$print_prefix"] |
| 95 | set pre_corefile_extern_array \ |
| 96 | [capture_command_output "print extern_array" "$print_prefix"] |
| 97 | |
| 98 | set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/gcore.test" \ |
| 99 | "save a corefile"] |
| 100 | |
| 101 | if {!$core_supported} { |
| 102 | return -1 |
| 103 | } |
| 104 | |
| 105 | # Now restart gdb and load the corefile. |
| 106 | gdb_exit |
| 107 | gdb_start |
| 108 | gdb_reinitialize_dir $srcdir/$subdir |
| 109 | gdb_load ${binfile} |
| 110 | |
| 111 | send_gdb "core ${objdir}/${subdir}/gcore.test\n" |
| 112 | gdb_expect { |
| 113 | -re ".* is not a core dump:.*$gdb_prompt $" { |
| 114 | fail "re-load generated corefile (bad file format)" |
| 115 | # No use proceeding from here. |
| 116 | return; |
| 117 | } |
| 118 | -re ".*: No such file or directory.*$gdb_prompt $" { |
| 119 | fail "re-load generated corefile (file not found)" |
| 120 | # No use proceeding from here. |
| 121 | return; |
| 122 | } |
| 123 | -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { |
| 124 | fail "re-load generated corefile (incomplete note section)" |
| 125 | } |
| 126 | -re "Core was generated by .*$gdb_prompt $" { |
| 127 | pass "re-load generated corefile" |
| 128 | } |
| 129 | -re ".*$gdb_prompt $" { |
| 130 | fail "re-load generated corefile" |
| 131 | } |
| 132 | timeout { |
| 133 | fail "re-load generated corefile (timeout)" |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | gdb_test_sequence "where" "where in corefile" { |
| 138 | "\[\r\n\]+#0 .* terminal_func \\(\\) at " |
| 139 | "\[\r\n\]+#1 .* array_func \\(\\) at " |
| 140 | "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " |
| 141 | "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " |
| 142 | "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " |
| 143 | "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " |
| 144 | "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " |
| 145 | "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " |
| 146 | "\[\r\n\]+#8 .* main \\(.*\\) at " |
| 147 | } |
| 148 | |
| 149 | set post_corefile_regs [capture_command_output "info registers" ""] |
| 150 | if ![string compare $pre_corefile_regs $post_corefile_regs] then { |
| 151 | pass "corefile restored general registers" |
| 152 | } else { |
| 153 | fail "corefile restored general registers" |
| 154 | } |
| 155 | |
| 156 | set post_corefile_allregs [capture_command_output "info all-reg" ""] |
| 157 | if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { |
| 158 | pass "corefile restored all registers" |
| 159 | } else { |
| 160 | fail "corefile restored all registers" |
| 161 | } |
| 162 | |
| 163 | set post_corefile_sysregs [capture_command_output "info reg system" ""] |
| 164 | if ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then { |
| 165 | pass "corefile restored system registers" |
| 166 | } else { |
| 167 | fail "corefile restored system registers" |
| 168 | } |
| 169 | |
| 170 | set post_corefile_extern_array \ |
| 171 | [capture_command_output "print extern_array" "$print_prefix"] |
| 172 | if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { |
| 173 | pass "corefile restored extern array" |
| 174 | } else { |
| 175 | fail "corefile restored extern array" |
| 176 | } |
| 177 | |
| 178 | set post_corefile_static_array \ |
| 179 | [capture_command_output "print static_array" "$print_prefix"] |
| 180 | if ![string compare $pre_corefile_static_array $post_corefile_static_array] { |
| 181 | pass "corefile restored static array" |
| 182 | } else { |
| 183 | fail "corefile restored static array" |
| 184 | } |
| 185 | |
| 186 | set post_corefile_uninit_array \ |
| 187 | [capture_command_output "print un_initialized_array" "$print_prefix"] |
| 188 | if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { |
| 189 | pass "corefile restored un-initialized array" |
| 190 | } else { |
| 191 | fail "corefile restored un-initialized array" |
| 192 | } |
| 193 | |
| 194 | set post_corefile_heap_string \ |
| 195 | [capture_command_output "print heap_string" "$print_prefix"] |
| 196 | if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { |
| 197 | pass "corefile restored heap array" |
| 198 | } else { |
| 199 | fail "corefile restored heap array" |
| 200 | } |
| 201 | |
| 202 | set post_corefile_local_array \ |
| 203 | [capture_command_output "print array_func::local_array" "$print_prefix"] |
| 204 | if ![string compare $pre_corefile_local_array $post_corefile_local_array] { |
| 205 | pass "corefile restored stack array" |
| 206 | } else { |
| 207 | fail "corefile restored stack array" |
| 208 | } |
| 209 | |
| 210 | set post_corefile_backtrace [capture_command_output "backtrace" ""] |
| 211 | if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { |
| 212 | pass "corefile restored backtrace" |
| 213 | } else { |
| 214 | fail "corefile restored backtrace" |
| 215 | } |