1 | volatile int x; |
2 | |
3 | void __attribute__((noinline)) sink() { |
4 | x++; //% self.filecheck("bt", "main.cpp", "-implicit-check-not=artificial") |
5 | // CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4 |
6 | // CHECK-NEXT: frame #1: 0x{{[0-9a-f]+}} a.out`func3() at main.cpp:26:3 |
7 | // CHECK-SAME: [artificial] |
8 | // CHECK-NEXT: frame #2: 0x{{[0-9a-f]+}} a.out`func2() |
9 | // CHECK-NEXT: frame #3: 0x{{[0-9a-f]+}} a.out`func1() at main.cpp:35:3 |
10 | // CHECK-SAME: [artificial] |
11 | // CHECK-NEXT: frame #4: 0x{{[0-9a-f]+}} a.out`main |
12 | // In the GNU style, the artificial frames will point after the tail call |
13 | // instruction. In v5 they should point to the instruction itself. |
14 | //% frame1 = self.thread().GetFrameAtIndex(1) |
15 | //% func3 = frame1.GetFunction() |
16 | //% func3_insns = func3.GetInstructions(self.target()) |
17 | //% self.trace("func3:\n%s"%func3_insns) |
18 | //% last_insn = func3_insns.GetInstructionAtIndex(func3_insns.GetSize()-1) |
19 | //% addr = last_insn.GetAddress() |
20 | //% if "GNU" in self.name: addr.OffsetAddress(last_insn.GetByteSize()) |
21 | //% self.assertEqual(frame1.GetPCAddress(), addr) |
22 | } |
23 | |
24 | void __attribute__((noinline)) func3() { |
25 | x++; |
26 | sink(); /* tail */ |
27 | } |
28 | |
29 | void __attribute__((disable_tail_calls, noinline)) func2() { |
30 | func3(); /* regular */ |
31 | } |
32 | |
33 | void __attribute__((noinline)) func1() { |
34 | x++; |
35 | func2(); /* tail */ |
36 | } |
37 | |
38 | int __attribute__((disable_tail_calls)) main() { |
39 | // DEBUG: self.runCmd("log enable lldb step -f /tmp/lldbstep.log") |
40 | func1(); /* regular */ |
41 | return 0; |
42 | } |
43 | |