binutils-gdb/gdb/testsuite/gdb.base/bt-selected-frame.exp
Andrew Burgess 45f25d6c83 gdb: Restore selected frame in print_frame_local_vars
PR gdb/23203 reports 'bt full' causing the currently selected frame to
change, this issue is fixed in this commit.

Add a new class scoped_restore_selected_frame that saves and restores
the selected frame.  Make use of this in print_frame_local_vars to
restore the selected frame on exit.

gdb/ChangeLog:

	PR gdb/23203
	* frame.c
	(scoped_restore_selected_frame::scoped_restore_selected_frame):
	Define.
	(scoped_restore_selected_frame::~scoped_restore_selected_frame):
	Define.
	* frame.h (class scoped_restore_selected_frame): New class.
	* stack.c (print_frame_local_vars): Remove catching and rethrowing
	of any exception, use scoped_restore_selected_frame to restore the
	frame instead.

gdb/testsuite/ChangeLog:

	PR gdb/23203
	* gdb.base/bt-selected-frame.c: New file.
	* gdb.base/bt-selected-frame.exp: New file.
	* lib/gdb.exp (get_current_frame_number): New function.
2018-05-24 18:01:31 +01:00

73 lines
1.9 KiB
Plaintext

# Copyright 2018 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Check that the selected stack frame doesn't change after a backtrace.
standard_testfile
if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
return -1
}
proc check_selected_frame_after_bt { bt_cmd stack_pattern } {
global binfile
clean_restart $binfile
with_test_prefix $bt_cmd {
if ![runto_main] then {
fail "can't run to main"
return 0
}
gdb_breakpoint "breakpt"
gdb_continue_to_breakpoint "breakpt"
# Visit each frame in the stack and ensure that the selected
# frame doesn't change after executing the backtrace command
# in BT_CMD.
foreach_with_prefix frame {0 1 2} {
if { $frame == 0 } {
gdb_assert {[get_current_frame_number] == $frame} \
"check frame"
} else {
gdb_test "frame $frame" "#$frame .*" "select frame"
}
gdb_test "$bt_cmd" $stack_pattern \
"perform backtrace command"
gdb_assert {[get_current_frame_number] == $frame} \
"check frame is still selected"
}
}
}
check_selected_frame_after_bt "bt" \
[multi_line \
"#0 \[^\n\r\]+" \
"#1 \[^\n\r\]+" \
"#2 \[^\n\r\]+"]
check_selected_frame_after_bt "bt full" \
[multi_line \
"#0 \[^\n\r\]+" \
"No locals\." \
"#1 \[^\n\r\]+" \
"No locals\." \
"#2 \[^\n\r\]+" \
"No locals\."]