forked from OSchip/llvm-project
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
This commit is contained in:
parent
01d98ba0b2
commit
4940f87bcc
Binary file not shown.
|
@ -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
|
|
@ -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> getCUIdentifiers(StringRef Abbrev,
|
|||
(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:
|
||||
|
|
Loading…
Reference in New Issue