[PATCH] D81915: [ObjectYAML][DWARF] Let writeVariableSizedInteger() return Error.

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 05:31:42 PDT 2020


Higuoxing added inline comments.


================
Comment at: llvm/lib/ObjectYAML/DWARFEmitter.cpp:39
 
+static Error errorWithContext(Error Err, StringRef SecName, StringRef Field) {
+  assert(Err);
----------------
jhenderson wrote:
> 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)));
> ```
Thanks a lot! TIL, `toString(Err)` marks the error checked!


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