Skip to content

Commit dae5104

Browse files
authored
[lldb][DWARFASTParserClang] Make GetCXXObjectParameter public and call it from unit-tests (#144879)
My goal is to remove the `object_pointer` member on `ParsedDWARFTypeAttributes` since it's duplicating information that we retrieve with `GetCXXObjectParameter` anyway. To continue having coverage for the `DW_AT_object_pointer` code-paths, instead of checking the `attrs.object_pointer` I'm now calling `GetCXXObjectParameter` directly. We could find some very roundabout way to go via the Clang AST to check that the object parameter was parsed correctly, but that quickly became quite painful. Depends on #144876
1 parent 5148e08 commit dae5104

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ static bool TagIsRecordType(dw_tag_t tag) {
163163
/// a default DWARFDIE. If \c containing_decl_ctx is not a valid
164164
/// C++ declaration context for class methods, assume no object
165165
/// parameter exists for the given \c subprogram.
166-
static DWARFDIE GetCXXObjectParameter(const DWARFDIE &subprogram,
167-
const DWARFDIE &decl_ctx_die) {
166+
DWARFDIE
167+
DWARFASTParserClang::GetCXXObjectParameter(const DWARFDIE &subprogram,
168+
const DWARFDIE &decl_ctx_die) {
168169
assert(subprogram);
169170
assert(subprogram.Tag() == DW_TAG_subprogram ||
170171
subprogram.Tag() == DW_TAG_inlined_subroutine ||

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
112112
void MapDeclDIEToDefDIE(const lldb_private::plugin::dwarf::DWARFDIE &decl_die,
113113
const lldb_private::plugin::dwarf::DWARFDIE &def_die);
114114

115+
lldb_private::plugin::dwarf::DWARFDIE GetCXXObjectParameter(
116+
const lldb_private::plugin::dwarf::DWARFDIE &subprogram,
117+
const lldb_private::plugin::dwarf::DWARFDIE &decl_ctx_die);
118+
115119
protected:
116120
/// Protected typedefs and members.
117121
/// @{

lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -889,18 +889,32 @@ TEST_F(DWARFASTParserClangTests, TestParseDWARFAttributes_ObjectPointer) {
889889
ASSERT_TRUE(context_die.IsValid());
890890
ASSERT_EQ(context_die.Tag(), DW_TAG_structure_type);
891891

892-
auto subprogram_definition = context_die.GetSibling();
893-
ASSERT_TRUE(subprogram_definition.IsValid());
894-
ASSERT_EQ(subprogram_definition.Tag(), DW_TAG_subprogram);
895-
ASSERT_FALSE(subprogram_definition.GetAttributeValueAsOptionalUnsigned(
896-
DW_AT_external));
897-
898-
auto param_die = subprogram_definition.GetFirstChild();
899-
ASSERT_TRUE(param_die.IsValid());
900-
901-
ParsedDWARFTypeAttributes attrs(subprogram_definition);
902-
EXPECT_TRUE(attrs.object_pointer.IsValid());
903-
EXPECT_EQ(attrs.object_pointer, param_die);
892+
{
893+
auto decl_die = context_die.GetFirstChild();
894+
ASSERT_TRUE(decl_die.IsValid());
895+
ASSERT_EQ(decl_die.Tag(), DW_TAG_subprogram);
896+
ASSERT_TRUE(decl_die.GetAttributeValueAsOptionalUnsigned(DW_AT_external));
897+
898+
auto param_die = decl_die.GetFirstChild();
899+
ASSERT_TRUE(param_die.IsValid());
900+
901+
EXPECT_EQ(param_die,
902+
ast_parser.GetCXXObjectParameter(decl_die, context_die));
903+
}
904+
905+
{
906+
auto subprogram_definition = context_die.GetSibling();
907+
ASSERT_TRUE(subprogram_definition.IsValid());
908+
ASSERT_EQ(subprogram_definition.Tag(), DW_TAG_subprogram);
909+
ASSERT_FALSE(subprogram_definition.GetAttributeValueAsOptionalUnsigned(
910+
DW_AT_external));
911+
912+
auto param_die = subprogram_definition.GetFirstChild();
913+
ASSERT_TRUE(param_die.IsValid());
914+
915+
EXPECT_EQ(param_die, ast_parser.GetCXXObjectParameter(subprogram_definition,
916+
context_die));
917+
}
904918
}
905919

906920
TEST_F(DWARFASTParserClangTests, TestParseSubroutine_ExplicitObjectParameter) {

0 commit comments

Comments
 (0)