Skip to content

Commit 19bce17

Browse files
authored
[lldb] [NFC] Rewrite TestRedefinitionsInInlines.py as an API test (#94539)
Rewrite an inline test as an API test, to be a little easier to debug, and add some additional checks that we're in the inlined test1, then step and we are now in the inlined test2 functions.
1 parent 1d75c59 commit 19bce17

File tree

3 files changed

+73
-25
lines changed

3 files changed

+73
-25
lines changed

lldb/test/API/lang/c/inlines/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,60 @@
1-
from lldbsuite.test import lldbinline
2-
from lldbsuite.test import decorators
3-
4-
lldbinline.MakeInlineTest(
5-
__file__,
6-
globals(),
7-
[
8-
decorators.expectedFailureAll(
9-
compiler="clang",
10-
compiler_version=["<", "3.5"],
11-
bugnumber="llvm.org/pr27845",
1+
"""Test that inlined argument variables have their correct location in debuginfo"""
2+
3+
import lldb
4+
from lldbsuite.test.decorators import *
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test import lldbutil
7+
8+
9+
class TestRedefinitionsInInlines(TestBase):
10+
# https://github.com/llvm/llvm-project/issues/28219
11+
@skipIf(compiler="clang", compiler_version=["<", "3.5"])
12+
def test(self):
13+
self.source = "main.c"
14+
self.build()
15+
(target, process, thread, bp1) = lldbutil.run_to_source_breakpoint(
16+
self, "first breakpoint", lldb.SBFileSpec(self.source, False)
17+
)
18+
19+
bp2 = target.BreakpointCreateBySourceRegex(
20+
"second breakpoint", lldb.SBFileSpec(self.source, False)
21+
)
22+
bp3 = target.BreakpointCreateBySourceRegex(
23+
"third breakpoint", lldb.SBFileSpec(self.source, False)
1224
)
13-
],
14-
)
25+
26+
# When called from main(), test2 is passed in the value of 42 in 'b'
27+
self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["42"])
28+
29+
process.Continue()
30+
31+
self.assertState(process.GetState(), lldb.eStateStopped)
32+
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
33+
self.assertIsNotNone(thread)
34+
bp_id = thread.GetStopReasonDataAtIndex(0)
35+
self.assertEqual(bp_id, bp2.GetID())
36+
37+
self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["42"])
38+
self.expect("expression c", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["84"])
39+
40+
process.Continue()
41+
42+
# Now we're in test1(), and the first thing it does is call test2(24). "Step in"
43+
# and check that we have the value 24 as the argument.
44+
self.assertState(process.GetState(), lldb.eStateStopped)
45+
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
46+
self.assertIsNotNone(thread)
47+
bp_id = thread.GetStopReasonDataAtIndex(0)
48+
self.assertEqual(bp_id, bp3.GetID())
49+
50+
frame = thread.GetFrameAtIndex(0)
51+
self.assertTrue(frame.IsInlined())
52+
self.assertEqual(frame.GetFunctionName(), "test1")
53+
54+
thread.StepInto()
55+
56+
frame = thread.GetFrameAtIndex(0)
57+
self.assertTrue(frame.IsInlined())
58+
self.assertEqual(frame.GetFunctionName(), "test2")
59+
60+
self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["24"])

lldb/test/API/lang/c/inlines/main.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
inline void test1(int) __attribute__ ((always_inline));
44
inline void test2(int) __attribute__ ((always_inline));
55

6+
// Called once from main with b==42 then called from test1 with b==24.
67
void test2(int b) {
7-
printf("test2(%d)\n", b); //% self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["42"])
8-
{
9-
int c = b * 2;
10-
printf("c=%d\n", c); //% self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["42"])
11-
//% self.expect("expression c", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["84"])
12-
}
8+
printf("test2(%d)\n", b); // first breakpoint
9+
{
10+
int c = b * 2;
11+
printf("c=%d\n", c); // second breakpoint
12+
}
1313
}
1414

1515
void test1(int a) {
1616
printf("test1(%d)\n", a);
17-
test2(a+1);//% self.runCmd("step")
18-
//% self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["24"])
17+
test2(a + 1); // third breakpoint
1918
}
2019

21-
int main() {
22-
test2(42);
23-
test1(23);
24-
return 0;
20+
int main(int argc) {
21+
test2(42);
22+
test1(23);
23+
return 0;
2524
}

0 commit comments

Comments
 (0)