[PATCH] D81915: [ObjectYAML][DWARF] Let writeVariableSizedInteger() return Error.
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 16 04:58:25 PDT 2020
jhenderson added inline comments.
================
Comment at: llvm/lib/ObjectYAML/DWARFEmitter.cpp:39
+static Error errorWithContext(Error Err, StringRef SecName, StringRef Field) {
+ assert(Err);
----------------
This isn't too far off what I had in mind, but is probably more than what you actually need.
Take a look at ELFDumper.cpp in llvm-readobj. You'll see several instances where the function `toString` is used to convert an error into a string and then this string is used as part of a new error message. For example, in `printRelocation` you have the following:
```
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
this->dumper()->getRelocationTarget(SymTab, R);
if (!Target)
this->reportUniqueWarning(createError(
"unable to print relocation " + Twine(RelIndex) + " in section " +
Twine(SecIndex) + ": " + toString(Target.takeError())));
```
When the `Target` contains an error, the `toString` method is used, combined with other context information into a new error message. Consequently, you'd explicitly build up your message with the lower-level error message and higher level things. For example:
```
if (Error Err = writeVariableSizedInteger(
Descriptor.Address, Range.AddrSize, OS, DI.IsLittleEndian))
return createStringError(errc::not_supported, "unable to write debug_aranges address: " + toString(std::move(Err)));
```
================
Comment at: llvm/lib/ObjectYAML/DWARFEmitter.cpp:65
else
- assert(false && "Invalid integer write size.");
+ return createStringError(errc::not_supported, "invalid integer write size");
+
----------------
I'd slightly modify this error to include the size that has been requested.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81915/new/
https://reviews.llvm.org/D81915
More information about the llvm-commits
mailing list