[DebugInfo] Handle missed DW_FORM_addrx3 and DW_FORM_strx3 cases
authorBenjamin Maxwell <benjamin.maxwell@arm.com>
Tue, 7 Feb 2023 10:36:34 +0000 (10:36 +0000)
committerBenjamin Maxwell <benjamin.maxwell@arm.com>
Fri, 10 Feb 2023 14:44:18 +0000 (14:44 +0000)
This fixes a few places where the addrx3 and strx3 forms were missed.
Previously this meant if one of these forms appeared somewhere various
errors could occur. This now also adds an extra test case for the addrx3
form (which previously failed).

Differential Revision: https://reviews.llvm.org/D143488

llvm/lib/BinaryFormat/Dwarf.cpp
llvm/lib/CodeGen/AsmPrinter/DIE.cpp
llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp

index fdf12a8..12e9c73 100644 (file)
@@ -737,6 +737,7 @@ std::optional<uint8_t> llvm::dwarf::getFixedFormByteSize(dwarf::Form Form,
     return 2;
 
   case DW_FORM_strx3:
+  case DW_FORM_addrx3:
     return 3;
 
   case DW_FORM_data4:
index 308d4b1..583da56 100644 (file)
@@ -385,6 +385,7 @@ void DIEInteger::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
   case dwarf::DW_FORM_strx2:
   case dwarf::DW_FORM_addrx2:
   case dwarf::DW_FORM_strx3:
+  case dwarf::DW_FORM_addrx3:
   case dwarf::DW_FORM_strp:
   case dwarf::DW_FORM_ref4:
   case dwarf::DW_FORM_data4:
index 1c26f13..804b877 100644 (file)
@@ -160,9 +160,11 @@ bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
     case DW_FORM_ref_sup8:
     case DW_FORM_strx1:
     case DW_FORM_strx2:
+    case DW_FORM_strx3:
     case DW_FORM_strx4:
     case DW_FORM_addrx1:
     case DW_FORM_addrx2:
+    case DW_FORM_addrx3:
     case DW_FORM_addrx4:
     case DW_FORM_sec_offset:
     case DW_FORM_strp:
@@ -300,6 +302,7 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
       Value.uval = Data.getU16(OffsetPtr, &Err);
       break;
     case DW_FORM_strx3:
+    case DW_FORM_addrx3:
       Value.uval = Data.getU24(OffsetPtr, &Err);
       break;
     case DW_FORM_data4:
index 1db5f69..1d16a38 100644 (file)
@@ -51,6 +51,7 @@ void TestAllForms() {
   const AddrType AddrxValue = (AddrType)0x4231abcd4231abcdULL;
   const AddrType Addrx1Value = (AddrType)0x0000aaaabbbbccccULL;
   const AddrType Addrx2Value = (AddrType)0xf00123f00456f000ULL;
+  const AddrType Addrx3Value = (AddrType)0xABABA000B111C222ULL;
   const AddrType Addrx4Value = (AddrType)0xa1b2c3d4e5f6e5d4ULL;
 
   const uint8_t BlockData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
@@ -100,14 +101,14 @@ void TestAllForms() {
   const auto Attr_DW_FORM_addrx = static_cast<dwarf::Attribute>(Attr++);
   const auto Attr_DW_FORM_addrx1 = static_cast<dwarf::Attribute>(Attr++);
   const auto Attr_DW_FORM_addrx2 = static_cast<dwarf::Attribute>(Attr++);
-  // TODO: Add Attr_DW_FORM_addrx3 test (this form type is currently
-  // unsupported)
+  const auto Attr_DW_FORM_addrx3 = static_cast<dwarf::Attribute>(Attr++);
   const auto Attr_DW_FORM_addrx4 = static_cast<dwarf::Attribute>(Attr++);
 
   if (Version >= 5) {
     CUDie.addAttribute(Attr_DW_FORM_addrx, DW_FORM_addrx, AddrxValue);
     CUDie.addAttribute(Attr_DW_FORM_addrx1, DW_FORM_addrx1, Addrx1Value);
     CUDie.addAttribute(Attr_DW_FORM_addrx2, DW_FORM_addrx2, Addrx2Value);
+    CUDie.addAttribute(Attr_DW_FORM_addrx3, DW_FORM_addrx3, Addrx3Value);
     CUDie.addAttribute(Attr_DW_FORM_addrx4, DW_FORM_addrx4, Addrx4Value);
   }
 
@@ -275,6 +276,10 @@ void TestAllForms() {
     EXPECT_TRUE(ExtractedAddrx2Value.has_value());
     EXPECT_EQ(Addrx2Value, *ExtractedAddrx2Value);
 
+    auto ExtractedAddrx3Value = toAddress(DieDG.find(Attr_DW_FORM_addrx3));
+    EXPECT_TRUE(ExtractedAddrx3Value.has_value());
+    EXPECT_EQ(Addrx3Value, *ExtractedAddrx3Value);
+
     auto ExtractedAddrx4Value = toAddress(DieDG.find(Attr_DW_FORM_addrx4));
     EXPECT_TRUE(ExtractedAddrx1Value.has_value());
     EXPECT_EQ(Addrx4Value, *ExtractedAddrx4Value);
index 0d8913b..a7f2722 100644 (file)
@@ -232,9 +232,11 @@ INSTANTIATE_TEST_SUITE_P(
         ParamType(DW_FORM_ref_sup8, 0, 0, DWARF32, SampleU32, 8, true),
         ParamType(DW_FORM_strx1, 0, 0, DWARF32, SampleU32, 1, true),
         ParamType(DW_FORM_strx2, 0, 0, DWARF32, SampleU32, 2, true),
+        ParamType(DW_FORM_strx3, 0, 0, DWARF32, SampleU32, 3, true),
         ParamType(DW_FORM_strx4, 0, 0, DWARF32, SampleU32, 4, true),
         ParamType(DW_FORM_addrx1, 0, 0, DWARF32, SampleU32, 1, true),
         ParamType(DW_FORM_addrx2, 0, 0, DWARF32, SampleU32, 2, true),
+        ParamType(DW_FORM_addrx3, 0, 0, DWARF32, SampleU32, 3, true),
         ParamType(DW_FORM_addrx4, 0, 0, DWARF32, SampleU32, 4, true),
         ParamType(DW_FORM_sec_offset, 0, 1, DWARF32, SampleU32, 0, false),
         ParamType(DW_FORM_sec_offset, 1, 0, DWARF32, SampleU32, 0, false),