[llvm] r269723 - llvm-dwp: Add error handling for invalid (non-CU) top level tag in debug_info.dwo

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 16:26:29 PDT 2016


Author: dblaikie
Date: Mon May 16 18:26:29 2016
New Revision: 269723

URL: http://llvm.org/viewvc/llvm-project?rev=269723&view=rev
Log:
llvm-dwp: Add error handling for invalid (non-CU) top level tag in debug_info.dwo

The diagnostic could be improved a bit to include information about
which input file had the mistake (& which unit (counted, since the name
of the unit won't be accessible) within the input).

Added:
    llvm/trunk/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo
    llvm/trunk/test/tools/llvm-dwp/X86/non_cu_top_level.test
Modified:
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Added: llvm/trunk/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo?rev=269723&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo Mon May 16 18:26:29 2016 differ

Added: llvm/trunk/test/tools/llvm-dwp/X86/non_cu_top_level.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/non_cu_top_level.test?rev=269723&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/non_cu_top_level.test (added)
+++ llvm/trunk/test/tools/llvm-dwp/X86/non_cu_top_level.test Mon May 16 18:26:29 2016
@@ -0,0 +1,3 @@
+RUN: not llvm-dwp %p/../Inputs/non_cu_top_level.dwo -o %t 2>&1 | FileCheck %s
+
+CHECK: error: top level DIE is not a compile unit

Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=269723&r1=269722&r2=269723&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Mon May 16 18:26:29 2016
@@ -141,9 +141,10 @@ static const char *getIndexedString(uint
   return StrData.getCStr(&StrOffset);
 }
 
-static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info,
-                                               StringRef StrOffsets,
-                                               StringRef Str) {
+static Expected<CompileUnitIdentifiers> getCUIdentifiers(StringRef Abbrev,
+                                                         StringRef Info,
+                                                         StringRef StrOffsets,
+                                                         StringRef Str) {
   uint32_t Offset = 0;
   DataExtractor InfoData(Info, true, 0);
   InfoData.getU32(&Offset); // Length
@@ -156,9 +157,8 @@ static CompileUnitIdentifiers getCUIdent
   DataExtractor AbbrevData(Abbrev, true, 0);
   uint32_t AbbrevOffset = getCUAbbrev(Abbrev, AbbrCode);
   uint64_t Tag = AbbrevData.getULEB128(&AbbrevOffset);
-  (void)Tag;
-  // FIXME: Real error handling
-  assert(Tag == dwarf::DW_TAG_compile_unit);
+  if (Tag != dwarf::DW_TAG_compile_unit)
+    return make_error<DWPError>("top level DIE is not a compile unit");
   // DW_CHILDREN
   AbbrevData.getU8(&AbbrevOffset);
   uint32_t Name;
@@ -506,11 +506,14 @@ static Error write(MCStreamer &Out, Arra
           continue;
         auto P =
             IndexEntries.insert(std::make_pair(E.getSignature(), CurEntry));
-        CompileUnitIdentifiers ID = getCUIdentifiers(
+        Expected<CompileUnitIdentifiers> EID = getCUIdentifiers(
             getSubsection(AbbrevSection, E, DW_SECT_ABBREV),
             getSubsection(InfoSection, E, DW_SECT_INFO),
             getSubsection(CurStrOffsetSection, E, DW_SECT_STR_OFFSETS),
             CurStrSection);
+        if (!EID)
+          return EID.takeError();
+        const auto &ID = *EID;
         if (!P.second)
           return make_error<DWPError>(buildDuplicateError(*P.first, ID, Input));
         auto &NewEntry = P.first->second;
@@ -537,8 +540,11 @@ static Error write(MCStreamer &Out, Arra
                            ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
       }
     } else {
-      CompileUnitIdentifiers ID = getCUIdentifiers(
+      Expected<CompileUnitIdentifiers> EID = getCUIdentifiers(
           AbbrevSection, InfoSection, CurStrOffsetSection, CurStrSection);
+      if (!EID)
+        return EID.takeError();
+      const auto &ID = *EID;
       auto P = IndexEntries.insert(std::make_pair(ID.Signature, CurEntry));
       if (!P.second)
         return make_error<DWPError>(buildDuplicateError(*P.first, ID, ""));




More information about the llvm-commits mailing list