From 4940f87bcc1aa3aa048b3c38c7013d7a385cac4f Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 17 May 2016 00:07:10 +0000 Subject: [PATCH] llvm-dwp: Provide error handling for invalid string field forms This diagnostic could be improved by adding the name of the input file containing the invalid data and/or some information about how to identify the specific offending attribute/tag in the input. But that's not an immediate priority as these corner cases of invalid input shouldn't come up too often. llvm-svn: 269727 --- .../llvm-dwp/Inputs/invalid_string_form.dwo | Bin 0 -> 1153 bytes .../llvm-dwp/X86/invalid_string_form.test | 3 +++ llvm/tools/llvm-dwp/llvm-dwp.cpp | 24 ++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 llvm/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo create mode 100644 llvm/test/tools/llvm-dwp/X86/invalid_string_form.test diff --git a/llvm/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo b/llvm/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo new file mode 100644 index 0000000000000000000000000000000000000000..663c70fd7f7f7dfb73aee65c1a8a07bca4d24fe3 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|$p4v9kYR&UlZ|SVoiHnNlifxqcAzR=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~`4O1KdQGZ-$ literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-dwp/X86/invalid_string_form.test b/llvm/test/tools/llvm-dwp/X86/invalid_string_form.test new file mode 100644 index 000000000000..e78a145dcb59 --- /dev/null +++ b/llvm/test/tools/llvm-dwp/X86/invalid_string_form.test @@ -0,0 +1,3 @@ +RUN: not llvm-dwp %p/../Inputs/invalid_string_form.dwo -o %t 2>&1 | FileCheck %s + +CHECK: error: string field encoded without DW_FORM_string or DW_FORM_GNU_str_index diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 31b2f63eb0a8..a05736ebe218 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -125,14 +125,14 @@ struct CompileUnitIdentifiers { const char *DWOName = ""; }; -static const char *getIndexedString(uint32_t Form, DataExtractor InfoData, - uint32_t &InfoOffset, StringRef StrOffsets, - StringRef Str) { +static Expected +getIndexedString(uint32_t Form, DataExtractor InfoData, uint32_t &InfoOffset, + StringRef StrOffsets, StringRef Str) { if (Form == dwarf::DW_FORM_string) return InfoData.getCStr(&InfoOffset); - assert(Form == dwarf::DW_FORM_GNU_str_index && "Only string and str_index " - "forms are supported for DWP " - "string attributes"); + if (Form != dwarf::DW_FORM_GNU_str_index) + return make_error( + "string field encoded without DW_FORM_string or DW_FORM_GNU_str_index"); auto StrIndex = InfoData.getULEB128(&InfoOffset); DataExtractor StrOffsetsData(StrOffsets, true, 0); uint32_t StrOffsetsOffset = 4 * StrIndex; @@ -169,11 +169,19 @@ static Expected getCUIdentifiers(StringRef Abbrev, (Name != 0 || Form != 0)) { switch (Name) { case dwarf::DW_AT_name: { - ID.Name = getIndexedString(Form, InfoData, Offset, StrOffsets, Str); + Expected EName = + getIndexedString(Form, InfoData, Offset, StrOffsets, Str); + if (!EName) + return EName.takeError(); + ID.Name = *EName; break; } case dwarf::DW_AT_GNU_dwo_name: { - ID.DWOName = getIndexedString(Form, InfoData, Offset, StrOffsets, Str); + Expected EName = + getIndexedString(Form, InfoData, Offset, StrOffsets, Str); + if (!EName) + return EName.takeError(); + ID.DWOName = *EName; break; } case dwarf::DW_AT_GNU_dwo_id: