|
9 | 9 | #include "llvm/BinaryFormat/Dwarf.h"
|
10 | 10 | #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
|
11 | 11 | #include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
| 12 | +#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h" |
12 | 13 | #include "llvm/ObjectYAML/DWARFEmitter.h"
|
13 | 14 | #include "llvm/Testing/Support/Error.h"
|
14 | 15 | #include "gtest/gtest.h"
|
@@ -704,4 +705,138 @@ TEST(DWARFDie, getNameFromTypeUnit) {
|
704 | 705 | ASSERT_STREQ(Die.getName(DINameKind::ShortName), "STRUCT");
|
705 | 706 | }
|
706 | 707 |
|
| 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 | +} |
707 | 842 | } // end anonymous namespace
|
0 commit comments