Avoid "text file busy" in dw2-using-debug-str.exp
[binutils-gdb.git] / gdb / testsuite / gdb.btrace / tailcall.exp
blob198cfa988ddbebfce28f7749d821d3aac3e9b754
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2024 Free Software Foundation, Inc.
5 # Contributed by Intel Corp. <markus.t.metzger@intel.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 require allow_btrace_tests
22 # This test requires the compiler to generate a tail call.  To guarantee that
23 # we always get one, we use an assembly source file.
25 # We use different assembly sources based on the target architecture.
27 # Luckily, they are similar enough that a single test script can handle
28 # both.
29 set opts {}
30 if [info exists COMPILE] {
31     # make check RUNTESTFLAGS="gdb.btrace/tailcall.exp COMPILE=1"
32     standard_testfile tailcall.c
33     lappend opts debug optimize=-O2
34 } elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
35         if {[is_amd64_regs_target]} {
36                 standard_testfile x86_64-tailcall.S
37         } else {
38                 standard_testfile i686-tailcall.S
39         }
40 } else {
41     unsupported "target architecture not supported"
42     return -1
45 if [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] {
46     return -1
48 if ![runto_main] {
49     return -1
52 # When GDB prints the file for a stop location, it may print the full path
53 # depending on what information the compiler added.  This regexp allows for
54 # that path to be present, but does not require it.
55 set optional_filepath {[^\n]*}
57 # we want to see the full trace for this test
58 gdb_test_no_output "set record function-call-history-size 0"
60 # trace the call to foo
61 gdb_test_no_output "record btrace"
62 gdb_test "next 2"
64 # show the flat branch trace
65 gdb_test "record function-call-history 1" [multi_line \
66   "1\tmain" \
67   "2\tfoo" \
68   "3\tbar" \
69   "4\tmain" \
70   ] "flat"
72 # show the branch trace with calls indented
73 gdb_test "record function-call-history /c 1" [multi_line \
74   "1\tmain" \
75   "2\t  foo" \
76   "3\t    bar" \
77   "4\tmain" \
78   ] "indented"
80 # go into bar
81 gdb_test "record goto 4" ".*bar \\(\\) at ${optional_filepath}tailcall.c:24\r\n.*"
83 # check the backtrace
84 gdb_test "backtrace" [multi_line \
85   "#0.*bar \\(\\) at ${optional_filepath}tailcall.c:24" \
86   "#1.*foo \\(\\) at ${optional_filepath}tailcall.c:29" \
87   "#2.*main \\(\\) at ${optional_filepath}tailcall.c:37" \
88   "Backtrace stopped: not enough registers or memory available to unwind further" \
89   ]
91 # walk the backtrace
92 gdb_test "up" "#1\[^\r\n\]*foo \\(\\) at ${optional_filepath}tailcall.c:29\r\n.*" "up to foo"
93 gdb_test "up" "#2\[^\r\n\]*main \\(\\) at ${optional_filepath}tailcall.c:37\r\n.*" "up to main"
94 gdb_test "down" "#1\[^\r\n\]*foo \\(\\) at ${optional_filepath}tailcall.c:29\r\n.*" "down to foo"
96 # test stepping into and out of tailcalls.
97 gdb_test "finish" "\[^\r\n\]*main \\(\\) at ${optional_filepath}tailcall.c:38\r\n.*" \
98     "finish.1"
99 gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at ${optional_filepath}tailcall.c:24\r\n.*" \
100     "reverse-step.1"
101 gdb_test "reverse-finish" "\[^\r\n\]*foo \\(\\) at ${optional_filepath}tailcall.c:29\r\n.*" \
102     "reverse-finish.1"
103 gdb_test "reverse-step" "\[^\r\n\]*main \\(\\) at ${optional_filepath}tailcall.c:37\r\n.*" \
104     "reverse-step.2"
105 gdb_test "next" "\[^\r\n\]*38.*" \
106     "next.1"
107 gdb_test "reverse-next" "\[^\r\n\]*main \\(\\) at ${optional_filepath}tailcall.c:37\r\n.*" \
108     "reverse-next.1"
109 gdb_test "step" "\[^\r\n\]*foo \\(\\) at ${optional_filepath}tailcall.c:29\r\n.*" \
110     "step.1"
111 gdb_test "finish" "\[^\r\n\]*main \\(\\) at ${optional_filepath}tailcall.c:38\r\n.*" \
112     "finish.2"
113 gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at ${optional_filepath}tailcall.c:24\r\n.*" \
114     "reverse-step.3"
115 gdb_test "finish" "\[^\r\n\]*main \\(\\) at ${optional_filepath}tailcall.c:38\r\n.*" \
116     "finish.3"