From 7bb62ef1e9932d01ab2ba8102882ae3d4b416073 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 16 May 2016 23:26:29 +0000 Subject: [PATCH] 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). llvm-svn: 269723 --- .../llvm-dwp/Inputs/non_cu_top_level.dwo | Bin 0 -> 1153 bytes .../tools/llvm-dwp/X86/non_cu_top_level.test | 3 +++ llvm/tools/llvm-dwp/llvm-dwp.cpp | 22 +++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 llvm/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo create mode 100644 llvm/test/tools/llvm-dwp/X86/non_cu_top_level.test diff --git a/llvm/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo b/llvm/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo new file mode 100644 index 0000000000000000000000000000000000000000..26f276ad05329c1c69b940d72df13e5de72bf572 GIT binary patch literal 1153 zcmb<-^>JfjWMqH=Mg}_u1P><4zz~5X=l~XWVBlh4XGqO0D5=y-DbHs}&PmKmS13y@ zD$dN$Q!v)E)H6`fC@Ct<%T_Qlvoy0X*HqBR$tla#M~InPYC;W2E+_yS$^|4HfmjrX zS->J3j0}t{3`|N-r7xY|$p4v9h+%_MlbvdloiHnNlifxqcAzR=AZ7wOhJk^R@i!mH zrFzAcxh087K)R#|LTA8ODXB@N>G3)F$zWIOLAXFkG;Vx;T3T^xNini;W?ou8GCwgX zsVKD!StKVjFBQxOx`84f4b+Vk_xuG)T+k%53zBDsNg~nLpzJ0jF%T17KZwtSrUt~l0X1|5RE`r!gAy(WlrMoKj?MlC rNUp$YA5<$riWx&UL<=)k7lXn9n@d3AP{*Lz$jrcsCIT~`4O1KdT;*JA literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-dwp/X86/non_cu_top_level.test b/llvm/test/tools/llvm-dwp/X86/non_cu_top_level.test new file mode 100644 index 000000000000..60b8742cdc25 --- /dev/null +++ b/llvm/test/tools/llvm-dwp/X86/non_cu_top_level.test @@ -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 diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 5e83d7c9cacc..31b2f63eb0a8 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -141,9 +141,10 @@ static const char *getIndexedString(uint32_t Form, DataExtractor InfoData, return StrData.getCStr(&StrOffset); } -static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info, - StringRef StrOffsets, - StringRef Str) { +static Expected 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 getCUIdentifiers(StringRef Abbrev, StringRef Info, 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("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, ArrayRef Inputs) { continue; auto P = IndexEntries.insert(std::make_pair(E.getSignature(), CurEntry)); - CompileUnitIdentifiers ID = getCUIdentifiers( + Expected 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(buildDuplicateError(*P.first, ID, Input)); auto &NewEntry = P.first->second; @@ -537,8 +540,11 @@ static Error write(MCStreamer &Out, ArrayRef Inputs) { ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); } } else { - CompileUnitIdentifiers ID = getCUIdentifiers( + Expected 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(buildDuplicateError(*P.first, ID, ""));