1# Copyright 2004-2015 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 test is to check that a frame's "info frame", especially the 17# saved registers list, doesn't change while that frame isn't current. 18 19# It uses the program savedregs.c to construct a somewhat warped 20# backtrace (contains both signal and dummy frames) and then, at each 21# step checks that non-inner frames have consistent "info frame" 22# output. Note that a frame's "info frame" can only be captured after 23# it is non-current (made a call, interrupted, ...), this is because 24# instructions executed to perform the call may affect "info frame" 25# output. 26 27if [target_info exists gdb,nosignals] { 28 verbose "Skipping savedregs.exp because of nosignals." 29 continue 30} 31 32 33standard_testfile .c 34 35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 36 untested "Couldn't compile ${module}.c" 37 return -1 38} 39 40# get things started 41clean_restart ${binfile} 42 43# Advance to main 44if { ![runto_main] } { 45 gdb_suppress_tests 46} 47 48proc process_saved_regs { current inner outer } { 49 global gdb_prompt 50 global expect_out 51 global saved_regs 52 53 # Skip the CURRENT frame. 54 55 set level 1 56 57 # Run over the list of INNER frames capturing the "info frame" 58 # output for each. Both dummy and sigtramp frames need to be 59 # handled specially: they do not yet have correct function names; 60 # and for dummy frames won't have saved registers. If there's a 61 # problem, fail but capture the output anyway, hopefully later 62 # "info frame" requests for that same frame will at least fail in 63 # a consistent manner (stops propogated fails). 64 65 foreach func $inner { 66 set saved_regs($func) "error" 67 set test "Get $func info frame" 68 # Both dummy and sigtramp frames have problems. 69 switch $func { 70 dummy { 71 # Dummy frame's do not have saved registers, and do 72 # not print <dummy>. 73 set pat "Stack frame at .*" 74 } 75 sigtramp { 76 # Sigtramp frames don't yet print <signal trampoline>. 77 set pat "Stack frame at .* Saved registers:.*" 78 } 79 default { 80 set pat "Stack frame at .* in $func .* Saved registers:.*" 81 } 82 } 83 # If the "info frame" barf, capture the output anyway so that 84 # it does not cascade further failures. 85 gdb_test_multiple "info frame $level" "$test" { 86 -re "($pat)$gdb_prompt " { 87 set saved_regs($func) "$expect_out(1,string)" 88 pass "$test" 89 } 90 -re "(Stack frame at .*)$gdb_prompt " { 91 set saved_regs($func) "$expect_out(1,string)" 92 fail "$test" 93 } 94 -re "(Cannot access .*)$gdb_prompt " { 95 set saved_regs($func) "$expect_out(1,string)" 96 fail "$test" 97 } 98 } 99 incr level 100 } 101 102 # Now iterate through the list of OUTER frames checking that the 103 # "info frame" output from each still matches what was captured 104 # during an early query. To avoid cascading failures, checking is 105 # abandoned after the first failure. The assumption is that, 106 # since frames outer to the botched frame rely on the botched 107 # frame's info, those more outer frames are also botched. Besides 108 # we've got the failure we're after. 109 110 set ok 1 111 foreach func $outer { 112 set test [concat "Check $func info frame; stack contains" \ 113 $current $inner $outer] 114 if $ok { 115 set ok 0 116 set pat [string_to_regexp "$saved_regs($func)"] 117 gdb_test_multiple "info frame $level" "$test" { 118 -re "$pat$gdb_prompt " { 119 pass "$test" 120 set ok 1 121 } 122 } 123 } { 124 pass "$test (skipped)" 125 } 126 incr level 127 } 128} 129 130 131# Continue to the signal thrower, capture main's saved-reg info. 132gdb_test "advance thrower" "thrower .* at .*" 133process_saved_regs thrower { main } { } 134 135# Continue to the signal catcher, check main's saved-reg info, capture 136# catcher's saved-reg info. 137gdb_test "handle SIGSEGV pass print nostop" 138gdb_test "handle SIGILL pass print nostop" 139gdb_test "advance catcher" "catcher .* at .*" 140process_saved_regs catcher { sigtramp thrower } { main } 141 142# Breakpoint at and call the caller function, saved-regs of main and 143# catcher, capture caller's registers. 144gdb_test "break caller" 145gdb_test "call caller (1,2,3,4,5,6,7,8)" 146process_saved_regs caller { dummy catcher } { sigtramp thrower main } 147 148# Run to callee, again check everything. 149gdb_test "advance callee" "callee .* at .*" 150process_saved_regs callee { caller } { dummy catcher sigtramp thrower main } 151