[PATCH] D84952: [DWARFYAML] Refactor emitDebugSections(). NFC.
Xing GUO via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 09:39:36 PDT 2020
Higuoxing added a comment.
The motivation of this change is that some DWARF sections are optional in the DWARF structure.
struct Data {
...
Optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
Optional<std::vector<ARange>> DebugAranges;
...
}
When we call the `emitDebugXXX()` function, we have to make sure that `DebugAranges` is not empty.
Error emitDebugAranges() {
assert(DebugAranges && "unexpected emitDebugAranges() call")
...
}
One possible solution is to iterate over the non-empty sections via `getNonEmptySectionNames()`.
The benefit of this approach is that when there's an unexpected `emitDebugXXX()` call, there will be a assertion failure and the failure will be noticed.
Another possible solution is to check the section inside the `emitDebugXXX()` function.
Error emitDebugAranges() {
if (!DebugAranges)
return Error::success();
...
}
The benefit of this approach is that we are able to use the `StringSwitch` class (https://llvm.org/doxygen/classllvm_1_1StringSwitch.html) here and in ELFEmitter.cpp (See Adrian's comments https://reviews.llvm.org/D82296#inline-760267).
Error Err = StringSwitch<Error>(SecName)
.Case("debug_aranges", DWARFYAML::emitDebugAranges())
.Case("debug_xxx", DWARFYAML::emitDebugXXX())
...
.Default(createStringError(errc::not_supported, SecName + " is not supported"));
Any thoughts? Thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84952/new/
https://reviews.llvm.org/D84952
More information about the llvm-commits
mailing list