Layout information for a record gets stored in the `ClangASTImporter` associated with the `DWARFASTParserClang` that originally parsed the record. LLDB sometimes moves clang types from one AST to another (in the reproducer the origin AST was a precompiled-header and the destination was the AST backing the executable). When clang then asks LLDB to `layoutRecordType`, it will do so with the help of the `ClangASTImporter` the type is associated with. If the type's origin is actually in a different LLDB module (and thus a different `DWARFASTParserClang` was used to set its layout info), we won't find the layout info in our local `ClangASTImporter`. In the reproducer this meant we would drop the alignment info of the origin type and misread a variable's contents with `frame var` and `expr`. There is logic in `ClangASTSource::layoutRecordType` to import an origin's layout info. This patch re-uses that infrastructure to import an origin's layout from one `ClangASTImporter` instance to another. rdar://123274144
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""
|
|
Tests that we correctly track AST layout info
|
|
(specifically alignment) when moving AST nodes
|
|
between ClangASTImporter instances (in this case,
|
|
from pch 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 TestPchAlignment(TestBase):
|
|
@add_test_categories(["gmodules"])
|
|
def test_expr(self):
|
|
self.build()
|
|
lldbutil.run_to_source_breakpoint(
|
|
self, "return data", lldb.SBFileSpec("main.cpp")
|
|
)
|
|
|
|
self.expect(
|
|
"frame variable data",
|
|
substrs=["row = 1", "col = 2", "row = 3", "col = 4", "stride = 5"],
|
|
)
|
|
|
|
@add_test_categories(["gmodules"])
|
|
def test_frame_var(self):
|
|
self.build()
|
|
lldbutil.run_to_source_breakpoint(
|
|
self, "return data", lldb.SBFileSpec("main.cpp")
|
|
)
|
|
|
|
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"),
|
|
],
|
|
)
|