-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][test] Add test for chained PCH debugging #83582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds a test-case for debugging a program with a pch chain, that is, the main executable depends on a pch that itself included another pch. Currently clang doesn't emit the sekeleton CUs required for LLDB to track all types on the pch chain. Thus this test is XFAILed for now.
$(BUILDDIR)/main.o: main.cpp | ||
$(CC) -cc1 -emit-pch -x c++-header -fmodule-format=obj -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone $(SRCDIR)/base-pch.h -o base-pch.h.gch | ||
$(CC) -cc1 -emit-pch -x c++-header -fmodule-format=obj -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone -include-pch base-pch.h.gch $(SRCDIR)/pch.h -o pch.h.gch | ||
$(CC) -cc1 -emit-obj -x c++ -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone -include-pch pch.h.gch $(SRCDIR)/main.cpp -o $(BUILDDIR)/main.o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to find a better way of doing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not too bad as it is.
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesAdds a test-case for debugging a program with a Currently clang doesn't emit the sekeleton CUs Full diff: https://github.com/llvm/llvm-project/pull/83582.diff 5 Files Affected:
diff --git a/lldb/test/API/lang/cpp/gmodules/pch-chain/Makefile b/lldb/test/API/lang/cpp/gmodules/pch-chain/Makefile
new file mode 100644
index 00000000000000..6477c25dedf7e1
--- /dev/null
+++ b/lldb/test/API/lang/cpp/gmodules/pch-chain/Makefile
@@ -0,0 +1,10 @@
+include Makefile.rules
+
+OBJECTS += main.o
+
+$(EXE): $(BUILDDIR)/main.o
+
+$(BUILDDIR)/main.o: main.cpp
+ $(CC) -cc1 -emit-pch -x c++-header -fmodule-format=obj -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone $(SRCDIR)/base-pch.h -o base-pch.h.gch
+ $(CC) -cc1 -emit-pch -x c++-header -fmodule-format=obj -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone -include-pch base-pch.h.gch $(SRCDIR)/pch.h -o pch.h.gch
+ $(CC) -cc1 -emit-obj -x c++ -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone -include-pch pch.h.gch $(SRCDIR)/main.cpp -o $(BUILDDIR)/main.o
diff --git a/lldb/test/API/lang/cpp/gmodules/pch-chain/TestPchChain.py b/lldb/test/API/lang/cpp/gmodules/pch-chain/TestPchChain.py
new file mode 100644
index 00000000000000..b08c6caa713be0
--- /dev/null
+++ b/lldb/test/API/lang/cpp/gmodules/pch-chain/TestPchChain.py
@@ -0,0 +1,73 @@
+"""
+Tests that we correctly track AST layout info
+(specifically alignment) when moving AST nodes
+between several ClangASTImporter instances
+(in this case, from a pch chain to executable
+to expression AST).
+"""
+
+import lldb
+import os
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestPchChain(TestBase):
+ @add_test_categories(["gmodules"])
+ @expectedFailureAll("Chained pch debugging currently not fully supported")
+ def test_expr(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.target = self.dbg.CreateTarget(exe)
+ self.assertTrue(self.target, VALID_TARGET)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", 9, num_expected_locations=1
+ )
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.expect(
+ "frame variable data",
+ substrs=["row = 1", "col = 2", "row = 3", "col = 4", "stride = 5"],
+ )
+
+ @add_test_categories(["gmodules"])
+ @expectedFailureAll("Chained pch debugging currently not fully supported")
+ def test_frame_var(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.target = self.dbg.CreateTarget(exe)
+ self.assertTrue(self.target, VALID_TARGET)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", 9, num_expected_locations=1
+ )
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.expect_expr(
+ "data",
+ result_type="MatrixData",
+ result_children=[
+ ValueCheck(
+ name="section",
+ children=[
+ ValueCheck(
+ name="origin",
+ children=[
+ ValueCheck(name="row", value="1"),
+ ValueCheck(name="col", value="2"),
+ ],
+ ),
+ ValueCheck(
+ name="size",
+ children=[
+ ValueCheck(name="row", value="3"),
+ ValueCheck(name="col", value="4"),
+ ],
+ ),
+ ],
+ ),
+ ValueCheck(name="stride", value="5"),
+ ],
+ )
diff --git a/lldb/test/API/lang/cpp/gmodules/pch-chain/base-pch.h b/lldb/test/API/lang/cpp/gmodules/pch-chain/base-pch.h
new file mode 100644
index 00000000000000..53dacd796f2c91
--- /dev/null
+++ b/lldb/test/API/lang/cpp/gmodules/pch-chain/base-pch.h
@@ -0,0 +1,9 @@
+#ifndef BASE_PCH_H_IN
+#define BASE_PCH_H_IN
+
+struct [[gnu::aligned(128)]] RowCol {
+ unsigned row;
+ unsigned col;
+};
+
+#endif // _H_IN
diff --git a/lldb/test/API/lang/cpp/gmodules/pch-chain/main.cpp b/lldb/test/API/lang/cpp/gmodules/pch-chain/main.cpp
new file mode 100644
index 00000000000000..5481f3fad1ff76
--- /dev/null
+++ b/lldb/test/API/lang/cpp/gmodules/pch-chain/main.cpp
@@ -0,0 +1,10 @@
+int main(int argc, const char *argv[]) {
+ struct MatrixData data = {0};
+ data.section.origin.row = 1;
+ data.section.origin.col = 2;
+ data.section.size.row = 3;
+ data.section.size.col = 4;
+ data.stride = 5;
+
+ return data.section.size.row;
+}
diff --git a/lldb/test/API/lang/cpp/gmodules/pch-chain/pch.h b/lldb/test/API/lang/cpp/gmodules/pch-chain/pch.h
new file mode 100644
index 00000000000000..6c373ddb1f132d
--- /dev/null
+++ b/lldb/test/API/lang/cpp/gmodules/pch-chain/pch.h
@@ -0,0 +1,16 @@
+#ifndef PCH_H_IN
+#define PCH_H_IN
+
+static const int kAlignment = 64;
+
+struct [[gnu::aligned(kAlignment)]] Submatrix {
+ struct RowCol origin;
+ struct RowCol size;
+};
+
+struct [[gnu::aligned(kAlignment)]] MatrixData {
+ struct Submatrix section;
+ unsigned stride;
+};
+
+#endif // _H_IN
|
self.assertTrue(self.target, VALID_TARGET) | ||
lldbutil.run_break_set_by_file_and_line( | ||
self, "main.cpp", 9, num_expected_locations=1 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason regex breakpoint didn't resolve...probably related to the Makefile shenanigans
$(BUILDDIR)/main.o: main.cpp | ||
$(CC) -cc1 -emit-pch -x c++-header -fmodule-format=obj -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone $(SRCDIR)/base-pch.h -o base-pch.h.gch | ||
$(CC) -cc1 -emit-pch -x c++-header -fmodule-format=obj -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone -include-pch base-pch.h.gch $(SRCDIR)/pch.h -o pch.h.gch | ||
$(CC) -cc1 -emit-obj -x c++ -fmodules -O0 -dwarf-ext-refs -debug-info-kind=standalone -include-pch pch.h.gch $(SRCDIR)/main.cpp -o $(BUILDDIR)/main.o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not too bad as it is.
Adds a test-case for debugging a program with a
pch chain, that is, the main executable depends
on a pch that itself included another pch.
Currently clang doesn't emit the sekeleton CUs
required for LLDB to track all types on the pch chain. Thus this test is XFAILed for now.