Skip to content

Commit 252f3c9

Browse files
authored
[lldb][test] Add test for chained PCH debugging (#83582)
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.
1 parent e6dff54 commit 252f3c9

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include Makefile.rules
2+
3+
OBJECTS += main.o
4+
5+
$(EXE): $(BUILDDIR)/main.o
6+
7+
$(BUILDDIR)/main.o: main.cpp
8+
$(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
9+
$(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
10+
$(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
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
Tests that we correctly track AST layout info
3+
(specifically alignment) when moving AST nodes
4+
between several ClangASTImporter instances
5+
(in this case, from a pch chain to executable
6+
to expression AST).
7+
"""
8+
9+
import lldb
10+
import os
11+
from lldbsuite.test.decorators import *
12+
from lldbsuite.test.lldbtest import *
13+
from lldbsuite.test import lldbutil
14+
15+
16+
class TestPchChain(TestBase):
17+
@add_test_categories(["gmodules"])
18+
@expectedFailureAll("Chained pch debugging currently not fully supported")
19+
def test_expr(self):
20+
self.build()
21+
exe = self.getBuildArtifact("a.out")
22+
self.target = self.dbg.CreateTarget(exe)
23+
self.assertTrue(self.target, VALID_TARGET)
24+
lldbutil.run_break_set_by_file_and_line(
25+
self, "main.cpp", 9, num_expected_locations=1
26+
)
27+
28+
self.runCmd("run", RUN_SUCCEEDED)
29+
30+
self.expect(
31+
"frame variable data",
32+
substrs=["row = 1", "col = 2", "row = 3", "col = 4", "stride = 5"],
33+
)
34+
35+
@add_test_categories(["gmodules"])
36+
@expectedFailureAll("Chained pch debugging currently not fully supported")
37+
def test_frame_var(self):
38+
self.build()
39+
exe = self.getBuildArtifact("a.out")
40+
self.target = self.dbg.CreateTarget(exe)
41+
self.assertTrue(self.target, VALID_TARGET)
42+
lldbutil.run_break_set_by_file_and_line(
43+
self, "main.cpp", 9, num_expected_locations=1
44+
)
45+
46+
self.runCmd("run", RUN_SUCCEEDED)
47+
48+
self.expect_expr(
49+
"data",
50+
result_type="MatrixData",
51+
result_children=[
52+
ValueCheck(
53+
name="section",
54+
children=[
55+
ValueCheck(
56+
name="origin",
57+
children=[
58+
ValueCheck(name="row", value="1"),
59+
ValueCheck(name="col", value="2"),
60+
],
61+
),
62+
ValueCheck(
63+
name="size",
64+
children=[
65+
ValueCheck(name="row", value="3"),
66+
ValueCheck(name="col", value="4"),
67+
],
68+
),
69+
],
70+
),
71+
ValueCheck(name="stride", value="5"),
72+
],
73+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef BASE_PCH_H_IN
2+
#define BASE_PCH_H_IN
3+
4+
struct [[gnu::aligned(128)]] RowCol {
5+
unsigned row;
6+
unsigned col;
7+
};
8+
9+
#endif // _H_IN
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int main(int argc, const char *argv[]) {
2+
struct MatrixData data = {0};
3+
data.section.origin.row = 1;
4+
data.section.origin.col = 2;
5+
data.section.size.row = 3;
6+
data.section.size.col = 4;
7+
data.stride = 5;
8+
9+
return data.section.size.row;
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef PCH_H_IN
2+
#define PCH_H_IN
3+
4+
static const int kAlignment = 64;
5+
6+
struct [[gnu::aligned(kAlignment)]] Submatrix {
7+
struct RowCol origin;
8+
struct RowCol size;
9+
};
10+
11+
struct [[gnu::aligned(kAlignment)]] MatrixData {
12+
struct Submatrix section;
13+
unsigned stride;
14+
};
15+
16+
#endif // _H_IN

0 commit comments

Comments
 (0)