Commit | Line | Data |
---|---|---|
8710b709 MM |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | # | |
32d0add0 | 3 | # Copyright 2013-2015 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 | ||
20 | # check for btrace support | |
21 | if { [skip_btrace_tests] } { return -1 } | |
22 | ||
66849923 MM |
23 | # This test requires the compiler to generate a tail call. To guarantee that |
24 | # we always get one, we use an assembly source file. | |
25 | # | |
26 | # We use different assembly sources based on the target architecture. | |
27 | # | |
28 | # Luckily, they are similar enough that a single test script can handle | |
29 | # both. | |
8710b709 MM |
30 | set opts {} |
31 | if [info exists COMPILE] { | |
32 | # make check RUNTESTFLAGS="gdb.btrace/tailcall.exp COMPILE=1" | |
66849923 | 33 | standard_testfile tailcall.c |
8710b709 | 34 | lappend opts debug optimize=-O2 |
66849923 MM |
35 | } elseif {[istarget "x86_64-*-*"]} { |
36 | standard_testfile x86_64-tailcall.S | |
37 | } elseif {[istarget "i?86-*-*"]} { | |
38 | standard_testfile i686-tailcall.S | |
39 | } else { | |
8710b709 MM |
40 | verbose "Skipping ${testfile}." |
41 | return | |
42 | } | |
43 | ||
44 | if [prepare_for_testing tailcall.exp $testfile $srcfile $opts] { | |
45 | return -1 | |
46 | } | |
47 | if ![runto_main] { | |
48 | return -1 | |
49 | } | |
50 | ||
51 | # we want to see the full trace for this test | |
52 | gdb_test_no_output "set record function-call-history-size 0" | |
53 | ||
54 | # trace the call to foo | |
55 | gdb_test_no_output "record btrace" | |
66849923 | 56 | gdb_test "next 2" |
8710b709 MM |
57 | |
58 | # show the flat branch trace | |
59 | gdb_test "record function-call-history 1" [join [list \ | |
6e07b1d2 MM |
60 | "1\tmain" \ |
61 | "2\tfoo" \ | |
62 | "3\tbar" \ | |
63 | "4\tmain" \ | |
8710b709 MM |
64 | ] "\r\n"] "flat" |
65 | ||
66 | # show the branch trace with calls indented | |
67 | gdb_test "record function-call-history /c 1" [join [list \ | |
6e07b1d2 MM |
68 | "1\tmain" \ |
69 | "2\t foo" \ | |
70 | "3\t bar" \ | |
71 | "4\tmain" \ | |
8710b709 | 72 | ] "\r\n"] "indented" |
0b722aec MM |
73 | |
74 | # go into bar | |
66849923 | 75 | gdb_test "record goto 4" ".*bar \\(\\) at .*tailcall.c:24\r\n.*" |
0b722aec MM |
76 | |
77 | # check the backtrace | |
78 | gdb_test "backtrace" [join [list \ | |
66849923 MM |
79 | "#0.*bar \\(\\) at tailcall.c:24" \ |
80 | "#1.*foo \\(\\) at tailcall.c:29" \ | |
81 | "#2.*main \\(\\) at tailcall.c:37" \ | |
0b722aec MM |
82 | "Backtrace stopped: not enough registers or memory available to unwind further" \ |
83 | ] "\r\n"] | |
84 | ||
85 | # walk the backtrace | |
66849923 MM |
86 | gdb_test "up" "#1\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" "up to foo" |
87 | gdb_test "up" "#2\[^\r\n\]*main \\(\\) at tailcall.c:37\r\n.*" "up to main" | |
88 | gdb_test "down" "#1\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" "down to foo" | |
52834460 MM |
89 | |
90 | # test stepping into and out of tailcalls. | |
66849923 MM |
91 | gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" |
92 | gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at tailcall.c:24\r\n.*" | |
93 | gdb_test "reverse-finish" "\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" | |
94 | gdb_test "reverse-step" "\[^\r\n\]*main \\(\\) at tailcall.c:37\r\n.*" | |
95 | gdb_test "next" "\[^\r\n\]*38.*" | |
96 | gdb_test "reverse-next" "\[^\r\n\]*main \\(\\) at tailcall.c:37\r\n.*" | |
97 | gdb_test "step" "\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" | |
98 | gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" | |
99 | gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at tailcall.c:24\r\n.*" | |
100 | gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" |