[PATCH] D84952: [DWARFYAML] Refactor emitDebugSections(). NFC.
Xing GUO via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 09:23:04 PDT 2020
Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Higuoxing requested review of this revision.
This patch refactors emitDebugSections() to make sure that sections
exist when they are emitted.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84952
Files:
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp
Index: llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp
===================================================================
--- llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp
+++ llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp
@@ -201,3 +201,12 @@
EXPECT_THAT_ERROR(parseDWARFYAML(Yaml, Data),
FailedWithMessage("missing required key 'Descriptor'"));
}
+
+TEST(EmitDebugSections, UnsupportedSection) {
+ StringRef Yaml = R"(
+debug_rnglists: []
+)";
+ auto SectionsOrErr = DWARFYAML::emitDebugSections(Yaml);
+ EXPECT_THAT_ERROR(SectionsOrErr.takeError(),
+ FailedWithMessage("debug_rnglists is not supported"));
+}
Index: llvm/lib/ObjectYAML/DWARFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -775,23 +775,40 @@
return createStringError(YIn.error(), GeneratedDiag.getMessage());
StringMap<std::unique_ptr<MemoryBuffer>> DebugSections;
- Error Err = emitDebugSectionImpl(DI, &DWARFYAML::emitDebugInfo, "debug_info",
- DebugSections);
- Err = joinErrors(std::move(Err),
- emitDebugSectionImpl(DI, &DWARFYAML::emitDebugLine,
- "debug_line", DebugSections));
- Err = joinErrors(std::move(Err),
- emitDebugSectionImpl(DI, &DWARFYAML::emitDebugStr,
- "debug_str", DebugSections));
- Err = joinErrors(std::move(Err),
- emitDebugSectionImpl(DI, &DWARFYAML::emitDebugAbbrev,
- "debug_abbrev", DebugSections));
- Err = joinErrors(std::move(Err),
- emitDebugSectionImpl(DI, &DWARFYAML::emitDebugAranges,
- "debug_aranges", DebugSections));
- Err = joinErrors(std::move(Err),
- emitDebugSectionImpl(DI, &DWARFYAML::emitDebugRanges,
- "debug_ranges", DebugSections));
+
+ Error Err = Error::success();
+ cantFail(std::move(Err));
+
+ for (StringRef SecName : DI.getNonEmptySectionNames()) {
+ if (SecName == "debug_abbrev")
+ Err = joinErrors(std::move(Err),
+ emitDebugSectionImpl(DI, &DWARFYAML::emitDebugAbbrev,
+ SecName, DebugSections));
+ else if (SecName == "debug_aranges")
+ Err = joinErrors(std::move(Err),
+ emitDebugSectionImpl(DI, &DWARFYAML::emitDebugAranges,
+ SecName, DebugSections));
+ else if (SecName == "debug_info")
+ Err = joinErrors(std::move(Err),
+ emitDebugSectionImpl(DI, &DWARFYAML::emitDebugInfo,
+ SecName, DebugSections));
+ else if (SecName == "debug_line")
+ Err = joinErrors(std::move(Err),
+ emitDebugSectionImpl(DI, &DWARFYAML::emitDebugLine,
+ SecName, DebugSections));
+ else if (SecName == "debug_ranges")
+ Err = joinErrors(std::move(Err),
+ emitDebugSectionImpl(DI, &DWARFYAML::emitDebugRanges,
+ SecName, DebugSections));
+ else if (SecName == "debug_str")
+ Err = joinErrors(std::move(Err),
+ emitDebugSectionImpl(DI, &DWARFYAML::emitDebugStr,
+ SecName, DebugSections));
+ else
+ Err = joinErrors(std::move(Err),
+ createStringError(errc::not_supported,
+ SecName + " is not supported"));
+ }
if (Err)
return std::move(Err);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84952.281956.patch
Type: text/x-patch
Size: 3769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/6d005776/attachment.bin>
More information about the llvm-commits
mailing list