Commit | Line | Data |
---|---|---|
8710b709 MM |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | # | |
61baf725 | 3 | # Copyright 2013-2017 Free Software Foundation, Inc. |
8710b709 MM |
4 | # |
5 | # Contributed by Intel Corp. <markus.t.metzger@intel.com> | |
6 | # | |
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. | |
11 | # | |
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. | |
16 | # | |
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/>. | |
19 | ||
b5ac99b0 MM |
20 | if { [skip_btrace_tests] } { |
21 | unsupported "target does not support record-btrace" | |
22 | return -1 | |
23 | } | |
8710b709 | 24 | |
66849923 MM |
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. | |
8710b709 MM |
32 | set opts {} |
33 | if [info exists COMPILE] { | |
34 | # make check RUNTESTFLAGS="gdb.btrace/tailcall.exp COMPILE=1" | |
66849923 | 35 | standard_testfile tailcall.c |
8710b709 | 36 | lappend opts debug optimize=-O2 |
e0461dbb MM |
37 | } elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} { |
38 | if {[is_amd64_regs_target]} { | |
39 | standard_testfile x86_64-tailcall.S | |
40 | } else { | |
41 | standard_testfile i686-tailcall.S | |
42 | } | |
66849923 | 43 | } else { |
b5ac99b0 | 44 | unsupported "target architecture not supported" |
e0461dbb | 45 | return -1 |
8710b709 MM |
46 | } |
47 | ||
5b362f04 | 48 | if [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] { |
8710b709 MM |
49 | return -1 |
50 | } | |
51 | if ![runto_main] { | |
b5ac99b0 | 52 | untested "failed to run to main" |
8710b709 MM |
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 the call to foo | |
60 | gdb_test_no_output "record btrace" | |
66849923 | 61 | gdb_test "next 2" |
8710b709 MM |
62 | |
63 | # show the flat branch trace | |
3c724c8c | 64 | gdb_test "record function-call-history 1" [multi_line \ |
6e07b1d2 MM |
65 | "1\tmain" \ |
66 | "2\tfoo" \ | |
67 | "3\tbar" \ | |
68 | "4\tmain" \ | |
3c724c8c | 69 | ] "flat" |
8710b709 MM |
70 | |
71 | # show the branch trace with calls indented | |
3c724c8c | 72 | gdb_test "record function-call-history /c 1" [multi_line \ |
6e07b1d2 MM |
73 | "1\tmain" \ |
74 | "2\t foo" \ | |
75 | "3\t bar" \ | |
76 | "4\tmain" \ | |
3c724c8c | 77 | ] "indented" |
0b722aec MM |
78 | |
79 | # go into bar | |
66849923 | 80 | gdb_test "record goto 4" ".*bar \\(\\) at .*tailcall.c:24\r\n.*" |
0b722aec MM |
81 | |
82 | # check the backtrace | |
3c724c8c | 83 | gdb_test "backtrace" [multi_line \ |
66849923 MM |
84 | "#0.*bar \\(\\) at tailcall.c:24" \ |
85 | "#1.*foo \\(\\) at tailcall.c:29" \ | |
86 | "#2.*main \\(\\) at tailcall.c:37" \ | |
0b722aec | 87 | "Backtrace stopped: not enough registers or memory available to unwind further" \ |
3c724c8c | 88 | ] |
0b722aec MM |
89 | |
90 | # walk the backtrace | |
66849923 MM |
91 | gdb_test "up" "#1\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" "up to foo" |
92 | gdb_test "up" "#2\[^\r\n\]*main \\(\\) at tailcall.c:37\r\n.*" "up to main" | |
93 | gdb_test "down" "#1\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" "down to foo" | |
52834460 MM |
94 | |
95 | # test stepping into and out of tailcalls. | |
66849923 MM |
96 | gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" |
97 | gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at tailcall.c:24\r\n.*" | |
98 | gdb_test "reverse-finish" "\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" | |
99 | gdb_test "reverse-step" "\[^\r\n\]*main \\(\\) at tailcall.c:37\r\n.*" | |
100 | gdb_test "next" "\[^\r\n\]*38.*" | |
101 | gdb_test "reverse-next" "\[^\r\n\]*main \\(\\) at tailcall.c:37\r\n.*" | |
102 | gdb_test "step" "\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" | |
103 | gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" | |
104 | gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at tailcall.c:24\r\n.*" | |
105 | gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" |