Skip to content

[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

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lldb/test/API/lang/cpp/gmodules/pch-chain/Makefile
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member Author

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

Copy link
Collaborator

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.

73 changes: 73 additions & 0 deletions lldb/test/API/lang/cpp/gmodules/pch-chain/TestPchChain.py
Original file line number Diff line number Diff line change
@@ -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
)
Copy link
Member Author

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


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"),
],
)
9 changes: 9 additions & 0 deletions lldb/test/API/lang/cpp/gmodules/pch-chain/base-pch.h
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lldb/test/API/lang/cpp/gmodules/pch-chain/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 16 additions & 0 deletions lldb/test/API/lang/cpp/gmodules/pch-chain/pch.h
Original file line number Diff line number Diff line change
@@ -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