diff options
| author | Chris Bieneman <beanz@apple.com> | 2017-01-20 19:03:14 +0000 |
|---|---|---|
| committer | Chris Bieneman <beanz@apple.com> | 2017-01-20 19:03:14 +0000 |
| commit | 2e752db47a727f7c115f8283e136daf485fcc886 (patch) | |
| tree | 2ecb943858e98932b02762c00565208caff35626 /llvm/unittests/DebugInfo/DWARF | |
| parent | 201b191b82858d2055e92ca8289082ce44ee8bb0 (diff) | |
| download | bcm5719-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/unittests/DebugInfo/DWARF')
| -rw-r--r-- | llvm/unittests/DebugInfo/DWARF/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 56 |
2 files changed, 27 insertions, 30 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt b/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt index eafca4a2fc0..ed512a92ef1 100644 --- a/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt +++ b/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS DebugInfoDWARF MC Object + ObjectYAML Support ) diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index 8cf4e56b0a3..b1454bc67a7 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -13,6 +13,8 @@ #include "llvm/DebugInfo/DWARF/DWARFDie.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" +#include "llvm/ObjectYAML/DWARFYAML.h" +#include "llvm/ObjectYAML/DWARFEmitter.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Host.h" #include "llvm/Support/TargetSelect.h" @@ -1157,41 +1159,35 @@ TEST(DWARFDebugInfo, TestChildIteratorsOnInvalidDie) { EXPECT_EQ(begin, end); } - TEST(DWARFDebugInfo, TestEmptyChildren) { - // Test a DIE that says it has children in the abbreviation, but actually - // doesn't have any attributes, will not return anything during iteration. - // We do this by making sure the begin and end iterators are equal. - uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); - auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; - dwarfgen::Generator *DG = ExpectedDG.get().get(); - dwarfgen::CompileUnit &CU = DG->addCompileUnit(); - - // Scope to allow us to re-use the same DIE names - { - // Create a compile unit DIE that has an abbreviation that says it has - // children, but doesn't have any actual attributes. This helps us test - // a DIE that has only one child: a NULL DIE. - auto CUDie = CU.getUnitDIE(); - CUDie.setForceChildren(); - } - - MemoryBufferRef FileBuffer(DG->generate(), "dwarf"); - auto Obj = object::ObjectFile::createObjectFile(FileBuffer); - EXPECT_TRUE((bool)Obj); - DWARFContextInMemory DwarfContext(*Obj.get()); - + const char *yamldata = "debug_abbrev:\n" + " - Code: 0x00000001\n" + " Tag: DW_TAG_compile_unit\n" + " Children: DW_CHILDREN_yes\n" + " Attributes:\n" + "debug_info:\n" + " - Length: 9\n" + " Version: 4\n" + " AbbrOffset: 0\n" + " AddrSize: 8\n" + " Entries:\n" + " - AbbrCode: 0x00000001\n" + " Values:\n" + " - AbbrCode: 0x00000000\n" + " Values:\n"; + + auto ErrOrSections = DWARFYAML::EmitDebugSections(StringRef(yamldata)); + EXPECT_TRUE((bool)ErrOrSections); + + auto &DebugSections = *ErrOrSections; + + DWARFContextInMemory DwarfContext(DebugSections, 8); + // Verify the number of compile units is correct. uint32_t NumCUs = DwarfContext.getNumCompileUnits(); EXPECT_EQ(NumCUs, 1u); DWARFCompileUnit *U = DwarfContext.getCompileUnitAtIndex(0); - + // Get the compile unit DIE is valid. auto CUDie = U->getUnitDIE(false); EXPECT_TRUE(CUDie.isValid()); |

