1 //===-- PythonDataObjectsTests.cpp ------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "gtest/gtest.h" 10 11 #include "llvm/ADT/STLExtras.h" 12 #include "llvm/DebugInfo/PDB/PDBSymbolData.h" 13 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" 14 #include "llvm/Support/FileSystem.h" 15 #include "llvm/Support/Path.h" 16 17 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" 18 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" 19 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h" 20 #include "TestingSupport/TestUtilities.h" 21 #include "lldb/Core/Address.h" 22 #include "lldb/Core/Module.h" 23 #include "lldb/Core/ModuleSpec.h" 24 #include "lldb/Host/FileSystem.h" 25 #include "lldb/Host/HostInfo.h" 26 #include "lldb/Symbol/ClangASTContext.h" 27 #include "lldb/Symbol/CompileUnit.h" 28 #include "lldb/Symbol/LineTable.h" 29 #include "lldb/Symbol/SymbolVendor.h" 30 #include "lldb/Utility/ArchSpec.h" 31 #include "lldb/Utility/FileSpec.h" 32 33 using namespace lldb_private; 34 35 class SymbolFileDWARFTests : public testing::Test { 36 public: 37 void SetUp() override { 38 // Initialize and TearDown the plugin every time, so we get a brand new 39 // AST every time so that modifications to the AST from each test don't 40 // leak into the next test. 41 FileSystem::Initialize(); 42 HostInfo::Initialize(); 43 ObjectFilePECOFF::Initialize(); 44 SymbolFileDWARF::Initialize(); 45 ClangASTContext::Initialize(); 46 SymbolFilePDB::Initialize(); 47 48 m_dwarf_test_exe = GetInputFilePath("test-dwarf.exe"); 49 } 50 51 void TearDown() override { 52 SymbolFilePDB::Terminate(); 53 ClangASTContext::Initialize(); 54 SymbolFileDWARF::Terminate(); 55 ObjectFilePECOFF::Terminate(); 56 HostInfo::Terminate(); 57 FileSystem::Terminate(); 58 } 59 60 protected: 61 std::string m_dwarf_test_exe; 62 }; 63 64 TEST_F(SymbolFileDWARFTests, TestAbilitiesForDWARF) { 65 // Test that when we have Dwarf debug info, SymbolFileDWARF is used. 66 FileSpec fspec(m_dwarf_test_exe); 67 ArchSpec aspec("i686-pc-windows"); 68 lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec); 69 70 SymbolVendor *plugin = module->GetSymbolVendor(); 71 EXPECT_NE(nullptr, plugin); 72 SymbolFile *symfile = plugin->GetSymbolFile(); 73 EXPECT_NE(nullptr, symfile); 74 EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic()); 75 76 uint32_t expected_abilities = SymbolFile::kAllAbilities; 77 EXPECT_EQ(expected_abilities, symfile->CalculateAbilities()); 78 } 79