[llvm] r269727 - llvm-dwp: Provide error handling for invalid string field forms
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 17:07:11 PDT 2016
Author: dblaikie
Date: Mon May 16 19:07:10 2016
New Revision: 269727
URL: http://llvm.org/viewvc/llvm-project?rev=269727&view=rev
Log:
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.
Added:
llvm/trunk/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo
llvm/trunk/test/tools/llvm-dwp/X86/invalid_string_form.test
Modified:
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
Added: llvm/trunk/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo?rev=269727&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/invalid_string_form.dwo Mon May 16 19:07:10 2016 differ
Added: llvm/trunk/test/tools/llvm-dwp/X86/invalid_string_form.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/invalid_string_form.test?rev=269727&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/invalid_string_form.test (added)
+++ llvm/trunk/test/tools/llvm-dwp/X86/invalid_string_form.test Mon May 16 19:07:10 2016
@@ -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
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=269727&r1=269726&r2=269727&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Mon May 16 19:07:10 2016
@@ -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<const char *>
+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<DWPError>(
+ "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<CompileUnitIdentifiers>
(Name != 0 || Form != 0)) {
switch (Name) {
case dwarf::DW_AT_name: {
- ID.Name = getIndexedString(Form, InfoData, Offset, StrOffsets, Str);
+ Expected<const char *> 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<const char *> EName =
+ getIndexedString(Form, InfoData, Offset, StrOffsets, Str);
+ if (!EName)
+ return EName.takeError();
+ ID.DWOName = *EName;
break;
}
case dwarf::DW_AT_GNU_dwo_id:
More information about the llvm-commits
mailing list