164562Sgshapiro# Copyright 2002-2020 Free Software Foundation, Inc. 264562Sgshapiro 364562Sgshapiro# This program is free software; you can redistribute it and/or modify 464562Sgshapiro# it under the terms of the GNU General Public License as published by 564562Sgshapiro# the Free Software Foundation; either version 3 of the License, or 664562Sgshapiro# (at your option) any later version. 764562Sgshapiro# 864562Sgshapiro# This program is distributed in the hope that it will be useful, 964562Sgshapiro# but WITHOUT ANY WARRANTY; without even the implied warranty of 1064562Sgshapiro# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1164562Sgshapiro# GNU General Public License for more details. 1290792Sgshapiro# 1390792Sgshapiro# You should have received a copy of the GNU General Public License 1490792Sgshapiro# along with this program. If not, see <http://www.gnu.org/licenses/>. 1564562Sgshapiro 1690792Sgshapiro# This file was written by Michael Snyder (msnyder@redhat.com) 1764562Sgshapiro# This is a test for the gdb command "generate-core-file". 1890792Sgshapiro 1990792Sgshapiro 2090792Sgshapirostandard_testfile 2164562Sgshapiro 2290792Sgshapiroif {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 2390792Sgshapiro return -1 2490792Sgshapiro} 2590792Sgshapiro 2690792Sgshapiroif { ! [ runto_main ] } then { 2790792Sgshapiro untested "couldn't run to main" 2890792Sgshapiro return -1 2990792Sgshapiro} 3090792Sgshapiro 3190792Sgshapirogdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ 3290792Sgshapiro "set breakpoint at terminal_func" 3390792Sgshapiro 3464562Sgshapirogdb_test "continue" "Breakpoint .* terminal_func.*" \ 3564562Sgshapiro "continue to terminal_func" 3664562Sgshapiro 3764562Sgshapiroset print_prefix ".\[0123456789\]* = " 3864562Sgshapiro 3964562Sgshapiroset pre_corefile_backtrace [capture_command_output "backtrace" ""] 4064562Sgshapiroset pre_corefile_regs [capture_command_output "info registers" ""] 4164562Sgshapiroset pre_corefile_allregs [capture_command_output "info all-reg" ""] 4290792Sgshapiroset pre_corefile_sysregs [capture_command_output "info reg system" ""] 4364562Sgshapiroset pre_corefile_static_array \ 4464562Sgshapiro [capture_command_output "print static_array" "$print_prefix"] 4564562Sgshapiroset pre_corefile_uninit_array \ 4664562Sgshapiro [capture_command_output "print un_initialized_array" "$print_prefix"] 4764562Sgshapiroset pre_corefile_heap_string \ 4890792Sgshapiro [capture_command_output "print heap_string" "$print_prefix"] 4990792Sgshapiroset pre_corefile_local_array \ 5064562Sgshapiro [capture_command_output "print array_func::local_array" "$print_prefix"] 5164562Sgshapiroset pre_corefile_extern_array \ 5264562Sgshapiro [capture_command_output "print extern_array" "$print_prefix"] 5364562Sgshapiro 5464562Sgshapiroset corefile [standard_output_file gcore.test] 5564562Sgshapiroset core_supported [gdb_gcore_cmd "$corefile" "save a corefile"] 5664562Sgshapiroif {!$core_supported} { 5773188Sgshapiro return -1 5873188Sgshapiro} 5973188Sgshapiro 6073188Sgshapiro# Now restart gdb and load the corefile. 6164562Sgshapirogdb_exit 6273188Sgshapirogdb_start 6364562Sgshapirogdb_reinitialize_dir $srcdir/$subdir 6464562Sgshapirogdb_load ${binfile} 6564562Sgshapiro 6664562Sgshapiroset core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"] 6764562Sgshapiroif { $core_loaded == -1 } { 6864562Sgshapiro # No use proceeding from here. 6964562Sgshapiro return 7064562Sgshapiro} 7164562Sgshapiro 7280785Sgshapirogdb_test_sequence "where" "where in corefile" { 7364562Sgshapiro "\[\r\n\]+#0 .* terminal_func \\(\\) at " 7464562Sgshapiro "\[\r\n\]+#1 .* array_func \\(\\) at " 7564562Sgshapiro "\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " 7664562Sgshapiro "\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " 7764562Sgshapiro "\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " 7864562Sgshapiro "\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " 7980785Sgshapiro "\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " 8064562Sgshapiro "\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " 8164562Sgshapiro "\[\r\n\]+#8 .* main \\(.*\\) at " 8264562Sgshapiro} 8364562Sgshapiro 8464562Sgshapiroset post_corefile_regs [capture_command_output "info registers" ""] 8564562Sgshapiroif ![string compare $pre_corefile_regs $post_corefile_regs] then { 8664562Sgshapiro pass "corefile restored general registers" 8764562Sgshapiro} else { 8864562Sgshapiro fail "corefile restored general registers" 8966494Sgshapiro} 9090792Sgshapiro 9166494Sgshapiroset post_corefile_allregs [capture_command_output "info all-reg" ""] 9264562Sgshapiroif ![string compare $pre_corefile_allregs $post_corefile_allregs] then { 9380785Sgshapiro pass "corefile restored all registers" 9464562Sgshapiro} else { 9564562Sgshapiro fail "corefile restored all registers" 9690792Sgshapiro} 9780785Sgshapiro 9880785Sgshapiroset post_corefile_sysregs [capture_command_output "info reg system" ""] 9980785Sgshapiroif ![string compare $pre_corefile_sysregs $post_corefile_sysregs] then { 10080785Sgshapiro pass "corefile restored system registers" 10180785Sgshapiro} else { 10264562Sgshapiro fail "corefile restored system registers" 10364562Sgshapiro} 10480785Sgshapiro 10580785Sgshapiroset post_corefile_extern_array \ 10664562Sgshapiro [capture_command_output "print extern_array" "$print_prefix"] 10790792Sgshapiroif ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { 10864562Sgshapiro pass "corefile restored extern array" 10964562Sgshapiro} else { 11064562Sgshapiro fail "corefile restored extern array" 11166494Sgshapiro} 11277349Sgshapiro 11377349Sgshapiroset post_corefile_static_array \ 11464562Sgshapiro [capture_command_output "print static_array" "$print_prefix"] 11566494Sgshapiroif ![string compare $pre_corefile_static_array $post_corefile_static_array] { 11666494Sgshapiro pass "corefile restored static array" 11766494Sgshapiro} else { 11866494Sgshapiro fail "corefile restored static array" 11966494Sgshapiro} 12066494Sgshapiro 12166494Sgshapiroset post_corefile_uninit_array \ 12266494Sgshapiro [capture_command_output "print un_initialized_array" "$print_prefix"] 12366494Sgshapiroif ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { 12464562Sgshapiro pass "corefile restored un-initialized array" 12564562Sgshapiro} else { 12664562Sgshapiro fail "corefile restored un-initialized array" 12764562Sgshapiro} 12864562Sgshapiro 12964562Sgshapiroset post_corefile_heap_string \ 13064562Sgshapiro [capture_command_output "print heap_string" "$print_prefix"] 13164562Sgshapiroif ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { 13264562Sgshapiro pass "corefile restored heap array" 13364562Sgshapiro} else { 13464562Sgshapiro fail "corefile restored heap array" 13564562Sgshapiro} 13664562Sgshapiro 13764562Sgshapiroset post_corefile_local_array \ 13864562Sgshapiro [capture_command_output "print array_func::local_array" "$print_prefix"] 13964562Sgshapiroif ![string compare $pre_corefile_local_array $post_corefile_local_array] { 14064562Sgshapiro pass "corefile restored stack array" 14164562Sgshapiro} else { 14264562Sgshapiro fail "corefile restored stack array" 14364562Sgshapiro} 14464562Sgshapiro 14564562Sgshapiroset post_corefile_backtrace [capture_command_output "backtrace" ""] 14664562Sgshapiroif ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { 14764562Sgshapiro pass "corefile restored backtrace" 14864562Sgshapiro} else { 14964562Sgshapiro fail "corefile restored backtrace" 15064562Sgshapiro} 15164562Sgshapiro