1 //===-- PythonDataObjectsTests.cpp ------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "gtest/gtest.h"
11 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
15 #include "llvm/Support/FileSystem.h"
16 #include "llvm/Support/Path.h"
17 
18 #include "lldb/Core/Address.h"
19 #include "lldb/Core/ArchSpec.h"
20 #include "lldb/Core/Module.h"
21 #include "lldb/Core/ModuleSpec.h"
22 #include "lldb/Host/HostInfo.h"
23 #include "lldb/Symbol/ClangASTContext.h"
24 #include "lldb/Symbol/CompileUnit.h"
25 #include "lldb/Symbol/LineTable.h"
26 #include "lldb/Symbol/SymbolVendor.h"
27 #include "lldb/Utility/FileSpec.h"
28 
29 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
30 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
31 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
32 
33 extern const char *TestMainArgv0;
34 
35 using namespace lldb_private;
36 
37 class SymbolFileDWARFTests : public testing::Test {
38 public:
39   void SetUp() override {
40 // Initialize and TearDown the plugin every time, so we get a brand new
41 // AST every time so that modifications to the AST from each test don't
42 // leak into the next test.
43     HostInfo::Initialize();
44     ObjectFilePECOFF::Initialize();
45     SymbolFileDWARF::Initialize();
46     ClangASTContext::Initialize();
47     SymbolFilePDB::Initialize();
48 
49     llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
50     llvm::SmallString<128> inputs_folder = exe_folder;
51     llvm::sys::path::append(inputs_folder, "Inputs");
52 
53     m_dwarf_test_exe = inputs_folder;
54     llvm::sys::path::append(m_dwarf_test_exe, "test-dwarf.exe");
55   }
56 
57   void TearDown() override {
58     SymbolFilePDB::Terminate();
59     ClangASTContext::Initialize();
60     SymbolFileDWARF::Terminate();
61     ObjectFilePECOFF::Terminate();
62     HostInfo::Terminate();
63   }
64 
65 protected:
66   llvm::SmallString<128> m_dwarf_test_exe;
67 };
68 
69 TEST_F(SymbolFileDWARFTests, TestAbilitiesForDWARF) {
70   // Test that when we have Dwarf debug info, SymbolFileDWARF is used.
71   FileSpec fspec(m_dwarf_test_exe.c_str(), false);
72   ArchSpec aspec("i686-pc-windows");
73   lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
74 
75   SymbolVendor *plugin = module->GetSymbolVendor();
76   EXPECT_NE(nullptr, plugin);
77   SymbolFile *symfile = plugin->GetSymbolFile();
78   EXPECT_NE(nullptr, symfile);
79   EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());
80 
81   uint32_t expected_abilities = SymbolFile::kAllAbilities;
82   EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
83 }
84