]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.btrace/tailcall-only.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.btrace / tailcall-only.exp
1 # This testcase is part of GDB, the GNU debugger.
2 #
3 # Copyright 2016-2024 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 #
19 # This is a variant of tailcall.exp where the entire trace contains only tail
20 # calls. This used to cause a crash in get_frame_type.
21 #
22
23 require allow_btrace_tests
24
25 # This test requires the compiler to generate a tail call. To guarantee that
26 # we always get one, we use an assembly source file.
27 #
28 # We use different assembly sources based on the target architecture.
29 #
30 # Luckily, they are similar enough that a single test script can handle
31 # both.
32 set opts {}
33 if [info exists COMPILE] {
34 # make check RUNTESTFLAGS="gdb.btrace/tailcall-only.exp COMPILE=1"
35 standard_testfile tailcall-only.c
36 lappend opts debug optimize=-O2
37 } elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
38 if {[is_amd64_regs_target]} {
39 standard_testfile x86_64-tailcall-only.S
40 } else {
41 standard_testfile i686-tailcall-only.S
42 }
43 } else {
44 unsupported "target architecture not supported"
45 return -1
46 }
47
48 if [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] {
49 return -1
50 }
51
52 if ![runto_main] {
53 return -1
54 }
55
56 # we want to see the full trace for this test
57 gdb_test_no_output "set record function-call-history-size 0"
58
59 # trace foo
60 gdb_test "step" ".*" "prepare for recording"
61 gdb_test_no_output "record btrace"
62 gdb_test "stepi 4" ".*" "record branch trace"
63
64 # for debugging
65 gdb_test "info record" ".*"
66
67 # show the branch trace with calls indented
68 gdb_test "record function-call-history /c 1" [multi_line \
69 "1\tfoo" \
70 "2\t foo_1" \
71 "3\t bar" \
72 "4\t bar_1"
73 ] "function-call-history"
74
75 # We can step
76 gdb_test "record goto begin" ".*foo.*"
77 gdb_test "stepi" ".*foo_1.*" "step into foo_1"
78 gdb_test "step" ".*bar.*" "step into bar"
79 gdb_test "stepi" ".*bar_1.*" "step into bar_1"
80
81 # We can neither finish nor return.
82 gdb_test "finish" "Cannot find the caller frame.*"
83 gdb_test_multiple "return" "return" {
84 -re "Make .* return now.*y or n. $" {
85 send_gdb "y\n"
86 exp_continue
87 }
88 -re "Cannot find the caller frame.*$gdb_prompt $" {
89 pass "return"
90 }
91 }
92
93 # But we can reverse-finish
94 gdb_test "reverse-finish" ".*bar.*"
95 gdb_test "reverse-step" ".*foo_1.*"
96
97 # Info frame isn't useful but doesn't crash as it used to.
98 gdb_test "up" ".*foo.*"
99 gdb_test "info frame" ".*"