[PATCH] D41063: [dwarfdump] AccelTable extractor return llvm:Error instead of bool
Jonas Devlieghere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 03:37:06 PST 2017
JDevlieghere created this revision.
JDevlieghere added a project: debug-info.
By returning an `llvm::Error` we can have a more informative error message in the verifier.
Repository:
rL LLVM
https://reviews.llvm.org/D41063
Files:
include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/DebugInfo/DWARF/DWARFVerifier.cpp
test/DebugInfo/dwarfdump-accel.test
Index: test/DebugInfo/dwarfdump-accel.test
===================================================================
--- test/DebugInfo/dwarfdump-accel.test
+++ test/DebugInfo/dwarfdump-accel.test
@@ -69,6 +69,6 @@
VERIFY: Verifying .apple_names...
VERIFY-NEXT: Verifying .apple_types...
VERIFY-NEXT: Verifying .apple_namespaces...
-VERIFY-NEXT: error: Section is smaller than size described in section header.
+VERIFY-NEXT: error: Section too small: cannot read buckets and hashes.
VERIFY-NEXT: Verifying .apple_objc...
VERIFY-NEXT: Errors detected.
Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -686,8 +686,8 @@
}
// Verify that the section is not too short.
- if (!AccelTable.extract()) {
- error() << "Section is smaller than size described in section header.\n";
+ if (Error E = AccelTable.extract()) {
+ error() << toString(std::move(E)) << '\n';
return 1;
}
Index: lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFContext.cpp
+++ lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -672,7 +672,8 @@
DWARFDataExtractor AccelSection(Obj, Section, IsLittleEndian, 0);
DataExtractor StrData(StringSection, IsLittleEndian, 0);
Cache.reset(new DWARFAcceleratorTable(AccelSection, StrData));
- Cache->extract();
+ if (Error E = Cache->extract())
+ llvm::consumeError(std::move(E));
return *Cache;
}
Index: lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -22,12 +22,13 @@
using namespace llvm;
-bool DWARFAcceleratorTable::extract() {
+llvm::Error DWARFAcceleratorTable::extract() {
uint32_t Offset = 0;
// Check that we can at least read the header.
if (!AccelSection.isValidOffset(offsetof(Header, HeaderDataLength)+4))
- return false;
+ return make_error<StringError>("Section too small: cannot read header.",
+ inconvertibleErrorCode());
Hdr.Magic = AccelSection.getU32(&Offset);
Hdr.Version = AccelSection.getU16(&Offset);
@@ -40,7 +41,9 @@
// section (see SourceLevelDebugging.rst for the structure of the index).
if (!AccelSection.isValidOffset(sizeof(Hdr) + Hdr.HeaderDataLength +
Hdr.NumBuckets*4 + Hdr.NumHashes*8))
- return false;
+ return make_error<StringError>(
+ "Section too small: cannot read buckets and hashes.",
+ inconvertibleErrorCode());
HdrData.DIEOffsetBase = AccelSection.getU32(&Offset);
uint32_t NumAtoms = AccelSection.getU32(&Offset);
@@ -52,7 +55,7 @@
}
IsValid = true;
- return true;
+ return Error::success();
}
uint32_t DWARFAcceleratorTable::getNumBuckets() { return Hdr.NumBuckets; }
Index: include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
===================================================================
--- include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
+++ include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
@@ -90,7 +90,7 @@
DataExtractor StringSection)
: AccelSection(AccelSection), StringSection(StringSection) {}
- bool extract();
+ llvm::Error extract();
uint32_t getNumBuckets();
uint32_t getNumHashes();
uint32_t getSizeHdr();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41063.126333.patch
Type: text/x-patch
Size: 3520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171211/c5fb7fb7/attachment.bin>
More information about the llvm-commits
mailing list