gcore.exp revision 1.6
1# Copyright 2002-2016 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# This file was written by Michael Snyder (msnyder@redhat.com) 17# This is a test for the gdb command "generate-core-file". 18 19 20standard_testfile 21 22if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { 23 untested $testfile.exp 24 return -1 25} 26 27if { ! [ runto_main ] } then { 28 untested gcore.exp 29 return -1 30} 31 32gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ 33 "set breakpoint at terminal_func" 34 35gdb_test "continue" "Breakpoint .* terminal_func.*" \ 36 "continue to terminal_func" 37 38set print_prefix ".\[0123456789\]* = " 39 40set pre_corefile_backtrace [capture_command_output "backtrace" ""] 41set pre_corefile_regs [capture_command_output "info registers" ""] 42set pre_corefile_allregs [capture_command_output "info all-reg" ""] 43set pre_corefile_sysregs [capture_command_output "info reg system" ""] 44set pre_corefile_static_array \ 45 [capture_command_output "print static_array" "$print_prefix"] 46set pre_corefile_uninit_array \ 47 [capture_command_output "print un_initialized_array" "$print_prefix"] 48set pre_corefile_heap_string \ 49 [capture_command_output "print heap_string" "$print_prefix"] 50set pre_corefile_local_array \ 51 [capture_command_output "print array_func::local_array" "$print_prefix"] 52set pre_corefile_extern_array \ 53 [capture_command_output "print extern_array" "$print_prefix"] 54 55set corefile [standard_output_file gcore.test] 56set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"] 57if {!$core_supported} { 58 return -1 59} 60 61# Now restart gdb and load the corefile. 62gdb_exit 63gdb_start 64gdb_reinitialize_dir $srcdir/$subdir 65gdb_load ${binfile} 66 67set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"] 68if { $core_loaded == -1 } { 69 # No use proceeding from here. 70 return 71} 72 73gdb_test_sequence "where" "where in corefile" { 74 "\[\r\n\]+#0 .* terminal_func \\(\\) at " 75 "\[\r\n\]+#1 .* array_func \\(\\) at " 76 "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " 77 "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " 78 "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " 79 "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " 80 "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " 81 "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " 82 "\[\r\n\]+#8 .* main \\(.*\\) at " 83} 84 85set post_corefile_regs [capture_command_output "info registers" ""] 86if ![string compare $pre_corefile_regs $post_corefile_regs] then { 87 pass "corefile restored general registers" 88} else { 89 fail "corefile restored general registers" 90} 91 92set post_corefile_allregs [capture_command_output "info all-reg" ""] 93if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { 94 pass "corefile restored all registers" 95} else { 96 fail "corefile restored all registers" 97} 98 99set post_corefile_sysregs [capture_command_output "info reg system" ""] 100if ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then { 101 pass "corefile restored system registers" 102} else { 103 fail "corefile restored system registers" 104} 105 106set post_corefile_extern_array \ 107 [capture_command_output "print extern_array" "$print_prefix"] 108if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { 109 pass "corefile restored extern array" 110} else { 111 fail "corefile restored extern array" 112} 113 114set post_corefile_static_array \ 115 [capture_command_output "print static_array" "$print_prefix"] 116if ![string compare $pre_corefile_static_array $post_corefile_static_array] { 117 pass "corefile restored static array" 118} else { 119 fail "corefile restored static array" 120} 121 122set post_corefile_uninit_array \ 123 [capture_command_output "print un_initialized_array" "$print_prefix"] 124if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { 125 pass "corefile restored un-initialized array" 126} else { 127 fail "corefile restored un-initialized array" 128} 129 130set post_corefile_heap_string \ 131 [capture_command_output "print heap_string" "$print_prefix"] 132if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { 133 pass "corefile restored heap array" 134} else { 135 fail "corefile restored heap array" 136} 137 138set post_corefile_local_array \ 139 [capture_command_output "print array_func::local_array" "$print_prefix"] 140if ![string compare $pre_corefile_local_array $post_corefile_local_array] { 141 pass "corefile restored stack array" 142} else { 143 fail "corefile restored stack array" 144} 145 146set post_corefile_backtrace [capture_command_output "backtrace" ""] 147if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { 148 pass "corefile restored backtrace" 149} else { 150 fail "corefile restored backtrace" 151} 152