[Lldb-commits] [lldb] [lldb] [NFC] Rewrite TestRedefinitionsInInlines.py as an API test (PR #94539)
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Wed Jun 5 15:36:33 PDT 2024
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/94539
>From c02e38e5ef017a966ef80000b94a56e394309462 Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Wed, 5 Jun 2024 15:27:23 -0700
Subject: [PATCH 1/2] [lldb] [NFC] Rewrite TestRedefinitionsInInlines.py as an
API test
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.
---
lldb/test/API/lang/c/inlines/Makefile | 3 +
.../c/inlines/TestRedefinitionsInInlines.py | 73 +++++++++++++++----
lldb/test/API/lang/c/inlines/main.c | 23 +++---
3 files changed, 74 insertions(+), 25 deletions(-)
create mode 100644 lldb/test/API/lang/c/inlines/Makefile
diff --git a/lldb/test/API/lang/c/inlines/Makefile b/lldb/test/API/lang/c/inlines/Makefile
new file mode 100644
index 0000000000000..f9555f92be8cd
--- /dev/null
+++ b/lldb/test/API/lang/c/inlines/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py b/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py
index 024b9dad9b0fb..d48f88ad7d563 100644
--- a/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py
+++ b/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py
@@ -1,14 +1,61 @@
-from lldbsuite.test import lldbinline
-from lldbsuite.test import decorators
-
-lldbinline.MakeInlineTest(
- __file__,
- globals(),
- [
- decorators.expectedFailureAll(
- compiler="clang",
- compiler_version=["<", "3.5"],
- bugnumber="llvm.org/pr27845",
+"""Test that inlined argument variables have their correct location in debuginfo"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestRedefinitionsInInlines(TestBase):
+
+ # https://github.com/llvm/llvm-project/issues/28219
+ @skipIf(compiler="clang", compiler_version=["<", "3.5"])
+ def test(self):
+ self.source = "main.c"
+ self.build()
+ (target, process, thread, bp1) = lldbutil.run_to_source_breakpoint(
+ self, "first breakpoint", lldb.SBFileSpec(self.source, False)
)
- ],
-)
+
+ bp2 = target.BreakpointCreateBySourceRegex(
+ "second breakpoint", lldb.SBFileSpec(self.source, False)
+ )
+ bp3 = target.BreakpointCreateBySourceRegex(
+ "third breakpoint", lldb.SBFileSpec(self.source, False)
+ )
+
+ # When called from main(), test2 is passed in the value of 42 in 'b'
+ self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["42"])
+
+ process.Continue()
+
+ self.assertState(process.GetState(), lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
+ bp_id = thread.GetStopReasonDataAtIndex(0)
+ self.assertEqual(bp_id, bp2.GetID())
+
+ self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["42"])
+ self.expect("expression c", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["84"])
+
+ process.Continue()
+
+ # Now we're in test1(), and the first thing it does is call test2(24). "Step in"
+ # and check that we have the value 24 as the argument.
+ self.assertState(process.GetState(), lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertIsNotNone(thread)
+ bp_id = thread.GetStopReasonDataAtIndex(0)
+ self.assertEqual(bp_id, bp3.GetID())
+
+ frame = thread.GetFrameAtIndex(0)
+ self.assertTrue(frame.IsInlined())
+ self.assertEqual(frame.GetFunctionName(), "test1")
+
+ thread.StepInto()
+
+ frame = thread.GetFrameAtIndex(0)
+ self.assertTrue(frame.IsInlined())
+ self.assertEqual(frame.GetFunctionName(), "test2")
+
+ self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["24"])
diff --git a/lldb/test/API/lang/c/inlines/main.c b/lldb/test/API/lang/c/inlines/main.c
index 8fe49180800bd..6ecc04dd508fc 100644
--- a/lldb/test/API/lang/c/inlines/main.c
+++ b/lldb/test/API/lang/c/inlines/main.c
@@ -3,23 +3,22 @@
inline void test1(int) __attribute__ ((always_inline));
inline void test2(int) __attribute__ ((always_inline));
+// Called once from main with b==42 then called from test1 with b==24.
void test2(int b) {
- printf("test2(%d)\n", b); //% self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["42"])
- {
- int c = b * 2;
- printf("c=%d\n", c); //% self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["42"])
- //% self.expect("expression c", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["84"])
- }
+ printf("test2(%d)\n", b); // first breakpoint
+ {
+ int c = b * 2;
+ printf("c=%d\n", c); // second breakpoint
+ }
}
void test1(int a) {
printf("test1(%d)\n", a);
- test2(a+1);//% self.runCmd("step")
- //% self.expect("expression b", DATA_TYPES_DISPLAYED_CORRECTLY, substrs = ["24"])
+ test2(a + 1); // third breakpoint
}
-int main() {
- test2(42);
- test1(23);
- return 0;
+int main(int argc) {
+ test2(42);
+ test1(23);
+ return 0;
}
>From fef2bd2b437dcdf2cc06f8faafe26cfdd1c962e0 Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmolenda at apple.com>
Date: Wed, 5 Jun 2024 15:36:13 -0700
Subject: [PATCH 2/2] whitespace change
---
lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py b/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py
index d48f88ad7d563..062fd88f7d272 100644
--- a/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py
+++ b/lldb/test/API/lang/c/inlines/TestRedefinitionsInInlines.py
@@ -7,7 +7,6 @@
class TestRedefinitionsInInlines(TestBase):
-
# https://github.com/llvm/llvm-project/issues/28219
@skipIf(compiler="clang", compiler_version=["<", "3.5"])
def test(self):
More information about the lldb-commits
mailing list