Commit | Line | Data |
---|---|---|
066ce621 MM |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | # | |
618f726f | 3 | # Copyright 2013-2016 Free Software Foundation, Inc. |
066ce621 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 | # The "record goto" command jumps to a specific instruction in the execution |
24 | # trace. To guarantee that we always get the same execution trace, we use | |
25 | # an assembly source file. | |
26 | # | |
27 | # We use different assembly sources based on the target architecture. | |
28 | # | |
29 | # Luckily, they are similar enough that a single test script can handle | |
30 | # both. | |
066ce621 MM |
31 | set opts {} |
32 | if [info exists COMPILE] { | |
33 | # make check RUNTESTFLAGS="gdb.btrace/record_goto.exp COMPILE=1" | |
34 | standard_testfile record_goto.c | |
35 | lappend opts debug | |
66849923 MM |
36 | } elseif {[istarget "x86_64-*-*"]} { |
37 | standard_testfile x86_64-record_goto.S | |
38 | } elseif {[istarget "i?86-*-*"]} { | |
39 | standard_testfile i686-record_goto.S | |
40 | } else { | |
066ce621 | 41 | verbose "Skipping ${testfile}." |
66849923 | 42 | return -1 |
066ce621 MM |
43 | } |
44 | ||
45 | if [prepare_for_testing record_goto.exp $testfile $srcfile $opts] { | |
46 | return -1 | |
47 | } | |
48 | if ![runto_main] { | |
49 | return -1 | |
50 | } | |
51 | ||
52 | # we want a small context sizes to simplify the test | |
53 | gdb_test_no_output "set record instruction-history-size 3" | |
54 | gdb_test_no_output "set record function-call-history-size 3" | |
55 | ||
56 | # trace the call to the test function | |
57 | gdb_test_no_output "record btrace" | |
58 | gdb_test "next" | |
59 | ||
60 | # start by listing all functions | |
3c724c8c | 61 | gdb_test "record function-call-history /ci 1, +20" [multi_line \ |
6e07b1d2 MM |
62 | "1\tmain\tinst 1,1" \ |
63 | "2\t fun4\tinst 2,4" \ | |
64 | "3\t fun1\tinst 5,8" \ | |
65 | "4\t fun4\tinst 9,9" \ | |
66 | "5\t fun2\tinst 10,12" \ | |
67 | "6\t fun1\tinst 13,16" \ | |
68 | "7\t fun2\tinst 17,18" \ | |
69 | "8\t fun4\tinst 19,19" \ | |
70 | "9\t fun3\tinst 20,22" \ | |
71 | "10\t fun1\tinst 23,26" \ | |
72 | "11\t fun3\tinst 27,27" \ | |
73 | "12\t fun2\tinst 28,30" \ | |
74 | "13\t fun1\tinst 31,34" \ | |
75 | "14\t fun2\tinst 35,36" \ | |
76 | "15\t fun3\tinst 37,38" \ | |
77 | "16\t fun4\tinst 39,40" \ | |
3c724c8c | 78 | ] |
066ce621 MM |
79 | |
80 | # let's see if we can go back in history | |
6e07b1d2 | 81 | gdb_test "record goto 19" ".*fun4 \\(\\) at record_goto.c:43.*" |
066ce621 MM |
82 | |
83 | # the function call history should start at the new location | |
3c724c8c | 84 | gdb_test "record function-call-history /ci" [multi_line \ |
6e07b1d2 MM |
85 | "8\t fun4\tinst 19,19" \ |
86 | "9\t fun3\tinst 20,22" \ | |
87 | "10\t fun1\tinst 23,26" \ | |
3c724c8c | 88 | ] "function-call-history from 19 forwards" |
066ce621 MM |
89 | |
90 | # the instruction history should start at the new location | |
3c724c8c | 91 | gdb_test "record instruction-history" [multi_line \ |
066ce621 MM |
92 | "19.*" \ |
93 | "20.*" \ | |
6e07b1d2 | 94 | "21.*" \ |
3c724c8c | 95 | ] "instruction-history from 19 forwards" |
066ce621 MM |
96 | |
97 | # let's go to another place in the history | |
6e07b1d2 | 98 | gdb_test "record goto 27" ".*fun3 \\(\\) at record_goto.c:35.*" |
066ce621 | 99 | |
0b722aec | 100 | # check the back trace at that location |
3c724c8c | 101 | gdb_test "backtrace" [multi_line \ |
0b722aec MM |
102 | "#0.*fun3.*at record_goto.c:35.*" \ |
103 | "#1.*fun4.*at record_goto.c:43.*" \ | |
104 | "#2.*main.*at record_goto.c:49.*" \ | |
105 | "Backtrace stopped: not enough registers or memory available to unwind further" \ | |
3c724c8c | 106 | ] |
0b722aec MM |
107 | |
108 | # walk the backtrace | |
109 | gdb_test "up" ".*fun4.*at record_goto.c:43.*" "up to fun4" | |
110 | gdb_test "up" ".*main.*at record_goto.c:49.*" "up to main" | |
111 | ||
066ce621 | 112 | # the function call history should start at the new location |
3c724c8c | 113 | gdb_test "record function-call-history /ci -" [multi_line \ |
6e07b1d2 MM |
114 | "9\t fun3\tinst 20,22" \ |
115 | "10\t fun1\tinst 23,26" \ | |
116 | "11\t fun3\tinst 27,27" \ | |
3c724c8c | 117 | ] "function-call-history from 27 backwards" |
066ce621 MM |
118 | |
119 | # the instruction history should start at the new location | |
3c724c8c | 120 | gdb_test "record instruction-history -" [multi_line \ |
066ce621 | 121 | "25.*" \ |
6e07b1d2 MM |
122 | "26.*" \ |
123 | "27.*" \ | |
3c724c8c | 124 | ] "instruction-history from 27 backwards" |
066ce621 MM |
125 | |
126 | # test that we can go to the begin of the trace | |
6e07b1d2 | 127 | gdb_test "record goto begin" ".*main \\(\\) at record_goto.c:49.*" |
066ce621 MM |
128 | |
129 | # check that we're filling up the context correctly | |
3c724c8c | 130 | gdb_test "record function-call-history /ci -" [multi_line \ |
6e07b1d2 MM |
131 | "1\tmain\tinst 1,1" \ |
132 | "2\t fun4\tinst 2,4" \ | |
133 | "3\t fun1\tinst 5,8" \ | |
3c724c8c | 134 | ] "function-call-history from begin backwards" |
066ce621 MM |
135 | |
136 | # check that we're filling up the context correctly | |
3c724c8c | 137 | gdb_test "record instruction-history -" [multi_line \ |
066ce621 MM |
138 | "1.*" \ |
139 | "2.*" \ | |
140 | "3.*" \ | |
3c724c8c | 141 | ] "instruction-history from begin backwards" |
066ce621 MM |
142 | |
143 | # we should get the exact same history from the first instruction | |
144 | gdb_test "record goto 2" ".*fun4 \\(\\) at record_goto.c:40.*" | |
145 | ||
146 | # check that we're filling up the context correctly | |
3c724c8c | 147 | gdb_test "record function-call-history /ci -" [multi_line \ |
6e07b1d2 MM |
148 | "1\tmain\tinst 1,1" \ |
149 | "2\t fun4\tinst 2,4" \ | |
150 | "3\t fun1\tinst 5,8\r" \ | |
3c724c8c | 151 | ] "function-call-history from 2 backwards" |
066ce621 MM |
152 | |
153 | # check that we're filling up the context correctly | |
3c724c8c | 154 | gdb_test "record instruction-history -" [multi_line \ |
066ce621 MM |
155 | "1.*" \ |
156 | "2.*" \ | |
157 | "3.*" \ | |
3c724c8c | 158 | ] "instruction-history from 2 backwards" |
066ce621 MM |
159 | |
160 | # check that we can go to the end of the trace | |
161 | gdb_test "record goto end" ".*main \\(\\) at record_goto.c:50.*" | |
162 | ||
163 | # check that we're filling up the context correctly | |
3c724c8c | 164 | gdb_test "record function-call-history /ci" [multi_line \ |
6e07b1d2 MM |
165 | "14\t fun2\tinst 35,36" \ |
166 | "15\t fun3\tinst 37,38" \ | |
167 | "16\t fun4\tinst 39,40" \ | |
3c724c8c | 168 | ] "function-call-history from end forwards" |
066ce621 MM |
169 | |
170 | # check that we're filling up the context correctly | |
3c724c8c | 171 | gdb_test "record instruction-history" [multi_line \ |
066ce621 MM |
172 | "38.*" \ |
173 | "39.*" \ | |
6e07b1d2 | 174 | "40.*\r" \ |
3c724c8c | 175 | ] "instruction-history from end forwards" |
066ce621 MM |
176 | |
177 | # we should get the exact same history from the second to last instruction | |
6e07b1d2 | 178 | gdb_test "record goto 39" ".*fun4 \\(\\) at record_goto.c:44.*" |
066ce621 MM |
179 | |
180 | # check that we're filling up the context correctly | |
3c724c8c | 181 | gdb_test "record function-call-history /ci" [multi_line \ |
6e07b1d2 MM |
182 | "14\t fun2\tinst 35,36" \ |
183 | "15\t fun3\tinst 37,38" \ | |
184 | "16\t fun4\tinst 39,40\r" \ | |
3c724c8c | 185 | ] "function-call-history from 39 forwards" |
066ce621 MM |
186 | |
187 | # check that we're filling up the context correctly | |
3c724c8c | 188 | gdb_test "record instruction-history" [multi_line \ |
066ce621 MM |
189 | "38.*" \ |
190 | "39.*" \ | |
6e07b1d2 | 191 | "40.*\r" \ |
3c724c8c | 192 | ] "instruction-history from 39 forwards" |