Skip to content

Commit f006f03

Browse files
committed
[DWARF] Fix DWARTTypePrinter unable to print qualified name for DW_TAG_typedef DIE
1 parent b0ca543 commit f006f03

File tree

3 files changed

+139
-3
lines changed

3 files changed

+139
-3
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ template <typename DieType> struct DWARFTypePrinter {
6969
case dwarf::DW_TAG_union_type:
7070
case dwarf::DW_TAG_namespace:
7171
case dwarf::DW_TAG_enumeration_type:
72+
case dwarf::DW_TAG_typedef:
7273
return true;
7374
default:
7475
break;

llvm/test/tools/dsymutil/X86/DWARFLinkerParallel/odr-string.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ CHECK: 0x[[STRING:[0-9a-f]*]]: DW_TAG_typedef{{.*[[:space:]].*}}DW_AT_type{{.*}}
132132

133133
CHECK:DW_TAG_reference_type
134134

135-
CHECK: 0x[[CONST_STR_REF:[0-9a-f]*]]: DW_TAG_reference_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x[[CONST_STRING:[0-9a-f]*]] "const string"
135+
CHECK: 0x[[CONST_STR_REF:[0-9a-f]*]]: DW_TAG_reference_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x[[CONST_STRING:[0-9a-f]*]] "const std::__1::string"
136136

137137
CHECK:DW_TAG_const_type
138138

139-
CHECK: 0x[[CONST_STRING]]: DW_TAG_const_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x[[STRING]] "string"
139+
CHECK: 0x[[CONST_STRING]]: DW_TAG_const_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x[[STRING]] "std::__1::string"
140140

141141

142142
CHECK: Compile Unit:
@@ -148,7 +148,7 @@ CHECK: DW_AT_high_pc
148148
CHECK: DW_AT_name{{.*}}"PrintSize"
149149
CHECK: DW_TAG_formal_parameter
150150
CHECK: DW_AT_name{{.*}}"String"
151-
CHECK: DW_AT_type{{.*}}0x00000000[[CONST_STR_REF]] "const string &"
151+
CHECK: DW_AT_type{{.*}}0x00000000[[CONST_STR_REF]] "const std::__1::string &"
152152

153153
CHECK: Compile Unit:
154154
CHECK: DW_TAG_compile_unit

llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/BinaryFormat/Dwarf.h"
1010
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
1111
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
12+
#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
1213
#include "llvm/ObjectYAML/DWARFEmitter.h"
1314
#include "llvm/Testing/Support/Error.h"
1415
#include "gtest/gtest.h"
@@ -704,4 +705,138 @@ TEST(DWARFDie, getNameFromTypeUnit) {
704705
ASSERT_STREQ(Die.getName(DINameKind::ShortName), "STRUCT");
705706
}
706707

708+
void testAppendAndTerminateTemplateParameters(const DWARFDie &DIE,
709+
const std::string &Expected) {
710+
std::string TemplateName;
711+
llvm::raw_string_ostream TemplateNameOS(TemplateName);
712+
llvm::DWARFTypePrinter<DWARFDie> TemplateNamePrinter(TemplateNameOS);
713+
TemplateNamePrinter.appendAndTerminateTemplateParameters(DIE);
714+
EXPECT_THAT(TemplateName, Expected);
715+
}
716+
717+
void testAppendQualifiedName(const DWARFDie &DIE, const std::string &Expected) {
718+
std::string QualifiedName;
719+
llvm::raw_string_ostream TemplateNameOS(QualifiedName);
720+
llvm::DWARFTypePrinter<DWARFDie> TemplateNamePrinter(TemplateNameOS);
721+
TemplateNamePrinter.appendQualifiedName(DIE);
722+
EXPECT_THAT(QualifiedName, Expected);
723+
}
724+
725+
TEST(DWARFDie, DWARFTypePrinterTest) {
726+
// Make sure we can get template parameters and qualified names correctly with
727+
// DWARFTypePrinter when using -gsimple-template-names.
728+
729+
// 0x0000000b: DW_TAG_compile_unit
730+
// 0x0000000c: DW_TAG_base_type
731+
// DW_AT_name ("int")
732+
// 0x00000011: DW_TAG_structure_type
733+
// DW_AT_name ("t1")
734+
// 0x00000015: DW_TAG_template_type_parameter
735+
// DW_AT_type (0x0000001f "t3<int>")
736+
// 0x0000001a: DW_TAG_structure_type
737+
// DW_AT_name ("t2")
738+
// 0x0000001e: NULL
739+
// 0x0000001f: DW_TAG_structure_type
740+
// DW_AT_name ("t3")
741+
// 0x00000023: DW_TAG_template_type_parameter
742+
// DW_AT_type (0x0000000c "int")
743+
// 0x00000028: NULL
744+
// 0x00000029: NULL
745+
const char *yamldata = R"(
746+
debug_abbrev:
747+
- ID: 0
748+
Table:
749+
- Code: 0x1
750+
Tag: DW_TAG_compile_unit
751+
Children: DW_CHILDREN_yes
752+
- Code: 0x2
753+
Tag: DW_TAG_base_type
754+
Children: DW_CHILDREN_no
755+
Attributes:
756+
- Attribute: DW_AT_name
757+
Form: DW_FORM_string
758+
- Code: 0x3
759+
Tag: DW_TAG_structure_type
760+
Children: DW_CHILDREN_yes
761+
Attributes:
762+
- Attribute: DW_AT_name
763+
Form: DW_FORM_string
764+
- Code: 0x4
765+
Tag: DW_TAG_template_type_parameter
766+
Children: DW_CHILDREN_no
767+
Attributes:
768+
- Attribute: DW_AT_type
769+
Form: DW_FORM_ref4
770+
- Code: 0x5
771+
Tag: DW_TAG_structure_type
772+
Children: DW_CHILDREN_no
773+
Attributes:
774+
- Attribute: DW_AT_name
775+
Form: DW_FORM_string
776+
- Code: 0x6
777+
Tag: DW_TAG_structure_type
778+
Children: DW_CHILDREN_yes
779+
Attributes:
780+
- Attribute: DW_AT_name
781+
Form: DW_FORM_string
782+
- Code: 0x7
783+
Tag: DW_TAG_template_type_parameter
784+
Children: DW_CHILDREN_no
785+
Attributes:
786+
- Attribute: DW_AT_type
787+
Form: DW_FORM_ref4
788+
- Code: 0x8
789+
Tag: DW_TAG_typedef
790+
Children: DW_CHILDREN_no
791+
Attributes:
792+
- Attribute: DW_AT_type
793+
Form: DW_FORM_ref4
794+
- Attribute: DW_AT_name
795+
Form: DW_FORM_string
796+
debug_info:
797+
- Version: 4
798+
AddrSize: 8
799+
Entries:
800+
- AbbrCode: 0x1
801+
- AbbrCode: 0x2
802+
Values:
803+
- Value: 0xDEADBEEFDEADBEEF
804+
CStr: int
805+
- AbbrCode: 0x3
806+
Values:
807+
- Value: 0xDEADBEEFDEADBEEF
808+
CStr: t1
809+
- AbbrCode: 0x4
810+
Values:
811+
- Value: 0x0000001f # update
812+
- AbbrCode: 0x5
813+
Values:
814+
- Value: 0xDEADBEEFDEADBEEF
815+
CStr: t2
816+
- AbbrCode: 0x0
817+
- AbbrCode: 0x6
818+
Values:
819+
- Value: 0xDEADBEEFDEADBEEF
820+
CStr: t3
821+
- AbbrCode: 0x7
822+
Values:
823+
- Value: 0x0000000c # update
824+
- AbbrCode: 0x8
825+
Values:
826+
- Value: 0x0000000c
827+
- CStr: my_int
828+
- AbbrCode: 0x0
829+
- AbbrCode: 0x0)";
830+
Expected<StringMap<std::unique_ptr<MemoryBuffer>>> Sections =
831+
DWARFYAML::emitDebugSections(StringRef(yamldata),
832+
/*IsLittleEndian=*/true,
833+
/*Is64BitAddrSize=*/true);
834+
ASSERT_THAT_EXPECTED(Sections, Succeeded());
835+
std::unique_ptr<DWARFContext> Ctx =
836+
DWARFContext::create(*Sections, 4, /*isLittleEndian=*/true);
837+
testAppendAndTerminateTemplateParameters(Ctx->getDIEForOffset(0x11),
838+
"<t3<int> >");
839+
testAppendQualifiedName(Ctx->getDIEForOffset(0x1a), "t1<t3<int> >::t2");
840+
testAppendQualifiedName(Ctx->getDIEForOffset(0x28), "t3<int>::my_int");
841+
}
707842
} // end anonymous namespace

0 commit comments

Comments
 (0)