summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ObjectYAML
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2018-04-20 12:33:49 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2018-04-20 12:33:49 +0000
commit5c709eda073c78b81d9bbb5d24e5412409031bd5 (patch)
treec65a40bb4effa78661d33d46839ef05ca11c72e1 /llvm/lib/ObjectYAML
parent4dd9a557fc336e96303a1cda975a0e4decab8635 (diff)
downloadbcm5719-llvm-5c709eda073c78b81d9bbb5d24e5412409031bd5.tar.gz
bcm5719-llvm-5c709eda073c78b81d9bbb5d24e5412409031bd5.zip
[ObjectYAML] Add ability for DWARFYAML to calculate DIE lengths
This patch adds the ability for the ObjectYAML DWARFEmitter to calculate the lengths of DIEs. This is accomplished by creating a DIEFixupVisitor class which traverses the DWARF DIEs to calculate and fix up the lengths in the Compile Unit header. The DIEFixupVisitor can be extended in the future to enable more complex fix ups which will enable simplified YAML string representations. This is also very useful when using the YAML format in unit tests because you no longer need to know the length of the compile unit when writing the YAML string. Differential commandeered from Chris Bieneman (beanz) Differential revision: https://reviews.llvm.org/D30666 llvm-svn: 330421
Diffstat (limited to 'llvm/lib/ObjectYAML')
-rw-r--r--llvm/lib/ObjectYAML/DWARFEmitter.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index c49c2249cdf..1135127eddc 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -149,7 +149,6 @@ protected:
writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian);
writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
}
-
}
void onStartDIE(const DWARFYAML::Unit &CU,
@@ -308,11 +307,48 @@ EmitDebugSectionImpl(const DWARFYAML::Data &DI, EmitFuncType EmitFunc,
OutputBuffers[Sec] = MemoryBuffer::getMemBufferCopy(Data);
}
+class DIEFixupVisitor : public DWARFYAML::Visitor {
+ uint64_t Length;
+
+public:
+ DIEFixupVisitor(DWARFYAML::Data &DI) : DWARFYAML::Visitor(DI){};
+
+private:
+ virtual void onStartCompileUnit(DWARFYAML::Unit &CU) { Length = 7; }
+
+ virtual void onEndCompileUnit(DWARFYAML::Unit &CU) {
+ CU.Length.setLength(Length);
+ }
+
+ virtual void onStartDIE(DWARFYAML::Unit &CU, DWARFYAML::Entry &DIE) {
+ Length += getULEB128Size(DIE.AbbrCode);
+ }
+
+ virtual void onValue(const uint8_t U) { Length += 1; }
+ virtual void onValue(const uint16_t U) { Length += 2; }
+ virtual void onValue(const uint32_t U) { Length += 4; }
+ virtual void onValue(const uint64_t U, const bool LEB = false) {
+ if (LEB)
+ Length += getULEB128Size(U);
+ else
+ Length += 8;
+ }
+ virtual void onValue(const int64_t S, const bool LEB = false) {
+ if (LEB)
+ Length += getSLEB128Size(S);
+ else
+ Length += 8;
+ }
+ virtual void onValue(const StringRef String) { Length += String.size() + 1; }
+
+ virtual void onValue(const MemoryBufferRef MBR) {
+ Length += MBR.getBufferSize();
+ }
+};
+
Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
-DWARFYAML::EmitDebugSections(StringRef YAMLString,
+DWARFYAML::EmitDebugSections(StringRef YAMLString, bool ApplyFixups,
bool IsLittleEndian) {
- StringMap<std::unique_ptr<MemoryBuffer>> DebugSections;
-
yaml::Input YIn(YAMLString);
DWARFYAML::Data DI;
@@ -321,6 +357,12 @@ DWARFYAML::EmitDebugSections(StringRef YAMLString,
if (YIn.error())
return errorCodeToError(YIn.error());
+ if (ApplyFixups) {
+ DIEFixupVisitor DIFixer(DI);
+ DIFixer.traverseDebugInfo();
+ }
+
+ StringMap<std::unique_ptr<MemoryBuffer>> DebugSections;
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugInfo, "debug_info",
DebugSections);
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugLine, "debug_line",
OpenPOWER on IntegriCloud