summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ObjectYAML
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2017-01-20 19:03:14 +0000
committerChris Bieneman <beanz@apple.com>2017-01-20 19:03:14 +0000
commit2e752db47a727f7c115f8283e136daf485fcc886 (patch)
tree2ecb943858e98932b02762c00565208caff35626 /llvm/lib/ObjectYAML
parent201b191b82858d2055e92ca8289082ce44ee8bb0 (diff)
downloadbcm5719-llvm-2e752db47a727f7c115f8283e136daf485fcc886.tar.gz
bcm5719-llvm-2e752db47a727f7c115f8283e136daf485fcc886.zip
[DWARF] [ObjectYAML] Adding APIs for unittesting
Summary: This patch adds some new APIs to enable using the YAML DWARF representation in unit tests. The most basic new API is DWARFYAML::EmitDebugSections which converts a YAML string into a series of owned MemoryBuffer objects stored in a StringMap. The string map can then be used to construct a DWARFContext for parsing in place of an ObjectFile. Reviewers: dblaikie, clayborg Subscribers: mgorny, fhahn, jgosnell, aprantl, llvm-commits Differential Revision: https://reviews.llvm.org/D28828 llvm-svn: 292634
Diffstat (limited to 'llvm/lib/ObjectYAML')
-rw-r--r--llvm/lib/ObjectYAML/DWARFEmitter.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 7282384e8ff..1e2e960b9dc 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -330,3 +330,42 @@ void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
}
}
}
+
+typedef void (*EmitFuncType)(raw_ostream &, const DWARFYAML::Data &);
+
+void EmitDebugSectionImpl(
+ const DWARFYAML::Data &DI, EmitFuncType EmitFunc, StringRef Sec,
+ StringMap<std::unique_ptr<MemoryBuffer>> &OutputBuffers) {
+ std::string Data;
+ raw_string_ostream DebugInfoStream(Data);
+ EmitFunc(DebugInfoStream, DI);
+ DebugInfoStream.flush();
+ if (!Data.empty())
+ OutputBuffers[Sec] = MemoryBuffer::getMemBufferCopy(Data);
+}
+
+Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
+DWARFYAML::EmitDebugSections(StringRef YAMLString,
+ bool IsLittleEndian) {
+ StringMap<std::unique_ptr<MemoryBuffer>> DebugSections;
+
+ yaml::Input YIn(YAMLString);
+
+ DWARFYAML::Data DI;
+ DI.IsLittleEndian = IsLittleEndian;
+ YIn >> DI;
+ if (YIn.error())
+ return errorCodeToError(YIn.error());
+
+ EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugInfo, "debug_info",
+ DebugSections);
+ EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugLine, "debug_line",
+ DebugSections);
+ EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugStr, "debug_str",
+ DebugSections);
+ EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugAbbrev, "debug_abbrev",
+ DebugSections);
+ EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugAranges, "debug_aranges",
+ DebugSections);
+ return std::move(DebugSections);
+}
OpenPOWER on IntegriCloud