]> granicus.if.org Git - llvm/commit
Add error handling to the DataExtractor class
authorPavel Labath <pavel@labath.sk>
Tue, 27 Aug 2019 11:24:08 +0000 (11:24 +0000)
committerPavel Labath <pavel@labath.sk>
Tue, 27 Aug 2019 11:24:08 +0000 (11:24 +0000)
commit49276e2904b24cb1a602d0e00f996824d00eb33e
tree58ce009dbb416f25e7409caf2e2debcdfff06973
parent4d6de2d3288b284aa3a080491646a67967243325
Add error handling to the DataExtractor class

Summary:
This is motivated by D63591, where we realized that there isn't a really
good way of telling whether a DataExtractor is reading actual data, or
is it just returning default values because it reached the end of the
buffer.

This patch resolves that by providing a new "Cursor" class. A Cursor
object encapsulates two things:
- the current position/offset in the DataExtractor
- an error object

Storing the error object inside the Cursor enables one to use the same
pattern as the std::{io}stream API, where one can blindly perform a
sequence of reads and only check for errors once at the end of the
operation. Similarly to the stream API, as soon as we encounter one
error, all of the subsequent operations are skipped (return default
values) too, even if the would suceed with clear error state. Unlike the
std::stream API (but in line with other llvm APIs), we force the error
state to be checked through usage of llvm::Error.

Reviewers: probinson, dblaikie, JDevlieghere, aprantl, echristo

Subscribers: kristina, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63713

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370042 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
include/llvm/Support/DataExtractor.h
lib/DebugInfo/DWARF/DWARFDataExtractor.cpp
lib/Support/DataExtractor.cpp
unittests/Support/DataExtractorTest.cpp