aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/bt-selected-frame.exp
blob: c454f4c9a115d2379ff1353a15e41c011c0b1efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright 2018-2021 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 { [build_executable "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\."]