Ejemplo n.º 1
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestTypedefs)) {
    FileSpec fspec(m_types_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFilePDB *symfile =
        static_cast<SymbolFilePDB *>(plugin->GetSymbolFile());
    const llvm::pdb::IPDBSession &session = symfile->GetPDBSession();
    SymbolContext sc;
    llvm::DenseSet<SymbolFile *> searched_files;
    TypeMap results;

    const char *TypedefsToCheck[] = {"ClassTypedef", "NSClassTypedef"};
    for (auto Typedef : TypedefsToCheck) {
        TypeMap results;
        EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString(Typedef), nullptr, false,
                                         0, searched_files, results));
        EXPECT_EQ(1u, results.GetSize());
        lldb::TypeSP typedef_type = results.GetTypeAtIndex(0);
        EXPECT_EQ(ConstString(Typedef), typedef_type->GetName());
        CompilerType compiler_type = typedef_type->GetFullCompilerType();
        ClangASTContext *clang_type_system =
            llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem());
        EXPECT_TRUE(
            clang_type_system->IsTypedefType(compiler_type.GetOpaqueQualType()));

        std::string sizeof_var = "sizeof_";
        sizeof_var.append(Typedef);
        EXPECT_EQ(GetGlobalConstantInteger(session, sizeof_var.c_str()),
                  typedef_type->GetByteSize());
    }
}
Ejemplo n.º 2
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestMaxMatches)) {
    FileSpec fspec(m_types_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFilePDB *symfile =
        static_cast<SymbolFilePDB *>(plugin->GetSymbolFile());
    SymbolContext sc;
    llvm::DenseSet<SymbolFile *> searched_files;
    TypeMap results;
    uint32_t num_results = symfile->FindTypes(sc, ConstString(".*"), nullptr,
                           false, 0, searched_files, results);
    // Try to limit ourselves from 1 to 10 results, otherwise we could be doing
    // this thousands of times.
    // The idea is just to make sure that for a variety of values, the number of
    // limited results always
    // comes out to the number we are expecting.
    uint32_t iterations = std::min(num_results, 10u);
    for (uint32_t i = 1; i <= iterations; ++i) {
        uint32_t num_limited_results = symfile->FindTypes(
                                           sc, ConstString(".*"), nullptr, false, i, searched_files, results);
        EXPECT_EQ(i, num_limited_results);
        EXPECT_EQ(num_limited_results, results.GetSize());
    }
}
Ejemplo n.º 3
0
void
Module::Dump(Stream *s)
{
    Mutex::Locker locker (m_mutex);
    //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
    s->Indent();
    s->Printf("Module %s/%s%s%s%s\n",
              m_file.GetDirectory().AsCString(),
              m_file.GetFilename().AsCString(),
              m_object_name ? "(" : "",
              m_object_name ? m_object_name.GetCString() : "",
              m_object_name ? ")" : "");

    s->IndentMore();
    ObjectFile *objfile = GetObjectFile ();

    if (objfile)
        objfile->Dump(s);

    SymbolVendor *symbols = GetSymbolVendor ();

    if (symbols)
        symbols->Dump(s);

    s->IndentLess();
}
Ejemplo n.º 4
0
TEST_F(SymbolFilePDBTests,
       REQUIRES_DIA_SDK(TestLookupOfHeaderFileWithNoInlines)) {
    // Test that when looking up a header file via ResolveSymbolContext (i.e. a
    // file that was not by itself
    // compiled, but only contributes to the combined code of other source files),
    // that if check_inlines
    // is false, no SymbolContexts are returned.
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    EXPECT_NE(nullptr, plugin);
    SymbolFile *symfile = plugin->GetSymbolFile();

    FileSpec header_specs[] = {FileSpec("test-pdb.h", false),
                               FileSpec("test-pdb-nested.h", false)
                              };
    for (const auto &hspec : header_specs) {
        SymbolContextList sc_list;
        uint32_t result_count = symfile->ResolveSymbolContext(
                                    hspec, 0, false, lldb::eSymbolContextCompUnit, sc_list);
        EXPECT_EQ(0u, result_count);
    }
}
Ejemplo n.º 5
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestEnumTypes)) {
    FileSpec fspec(m_types_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFilePDB *symfile =
        static_cast<SymbolFilePDB *>(plugin->GetSymbolFile());
    const llvm::pdb::IPDBSession &session = symfile->GetPDBSession();
    SymbolContext sc;
    llvm::DenseSet<SymbolFile *> searched_files;
    const char *EnumsToCheck[] = {"Enum", "ShortEnum"};
    for (auto Enum : EnumsToCheck) {
        TypeMap results;
        EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString(Enum), nullptr, false, 0,
                                         searched_files, results));
        EXPECT_EQ(1u, results.GetSize());
        lldb::TypeSP enum_type = results.GetTypeAtIndex(0);
        EXPECT_EQ(ConstString(Enum), enum_type->GetName());
        CompilerType compiler_type = enum_type->GetFullCompilerType();
        EXPECT_TRUE(ClangASTContext::IsEnumType(compiler_type.GetOpaqueQualType()));
        clang::EnumDecl *enum_decl = ClangASTContext::GetAsEnumDecl(compiler_type);
        EXPECT_NE(nullptr, enum_decl);
        EXPECT_EQ(2, std::distance(enum_decl->enumerator_begin(),
                                   enum_decl->enumerator_end()));

        std::string sizeof_var = "sizeof_";
        sizeof_var.append(Enum);
        EXPECT_EQ(GetGlobalConstantInteger(session, sizeof_var.c_str()),
                  enum_type->GetByteSize());
    }
}
Ejemplo n.º 6
0
static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) {
  if (module_sp) {
    SymbolVendor *symbols = module_sp->GetSymbolVendor();
    if (symbols)
      return symbols->GetSymtab();
  }
  return NULL;
}
Ejemplo n.º 7
0
TypeList*
Module::GetTypeList ()
{
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        return &symbols->GetTypeList();
    return NULL;
}
Ejemplo n.º 8
0
uint32_t
Module::FindGlobalVariables(const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
{
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        return symbols->FindGlobalVariables(name, append, max_matches, variables);
    return 0;
}
Ejemplo n.º 9
0
uint32_t
Module::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
{
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        return symbols->FindFunctions(regex, append, sc_list);
    return 0;
}
Ejemplo n.º 10
0
uint32_t
Module::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
{
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        return symbols->FindGlobalVariables(regex, append, max_matches, variables);
    return 0;
}
Ejemplo n.º 11
0
uint32_t
Module::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list)
{
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        return symbols->FindFunctions(name, name_type_mask, append, sc_list);
    return 0;
}
Ejemplo n.º 12
0
uint32_t
Module::GetNumCompileUnits()
{
    Mutex::Locker locker (m_mutex);
    Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", this);
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        return symbols->GetNumCompileUnits();
    return 0;
}
Ejemplo n.º 13
0
uint32_t
Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
{
    Mutex::Locker locker (m_mutex);
    uint32_t resolved_flags = 0;

    // Clear the result symbol context in case we don't find anything
    sc.Clear();

    // Get the section from the section/offset address.
    const Section *section = so_addr.GetSection();

    // Make sure the section matches this module before we try and match anything
    if (section && section->GetModule() == this)
    {
        // If the section offset based address resolved itself, then this
        // is the right module.
        sc.module_sp = GetSP();
        resolved_flags |= eSymbolContextModule;

        // Resolve the compile unit, function, block, line table or line
        // entry if requested.
        if (resolve_scope & eSymbolContextCompUnit    ||
            resolve_scope & eSymbolContextFunction    ||
            resolve_scope & eSymbolContextBlock       ||
            resolve_scope & eSymbolContextLineEntry   )
        {
            SymbolVendor *symbols = GetSymbolVendor ();
            if (symbols)
                resolved_flags |= symbols->ResolveSymbolContext (so_addr, resolve_scope, sc);
        }

        // Resolve the symbol if requested, but don't re-look it up if we've already found it.
        if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
        {
            ObjectFile* ofile = GetObjectFile();
            if (ofile)
            {
                Symtab *symtab = ofile->GetSymtab();
                if (symtab)
                {
                    if (so_addr.IsSectionOffset())
                    {
                        sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
                        if (sc.symbol)
                            resolved_flags |= eSymbolContextSymbol;
                    }
                }
            }
        }
    }
    return resolved_flags;
}
Ejemplo n.º 14
0
lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) {
  ModuleSP module_sp(GetSP());
  if (module_sp) {
    SymbolVendor *vendor = module_sp->GetSymbolVendor();
    if (vendor) {
      Type *type_ptr = vendor->ResolveTypeUID(uid);
      if (type_ptr)
        return SBType(type_ptr->shared_from_this());
    }
  }
  return SBType();
}
Ejemplo n.º 15
0
uint32_t
Module::FindTypes (const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
{
    Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
    if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
    {
        SymbolVendor *symbols = GetSymbolVendor ();
        if (symbols)
            return symbols->FindTypes(sc, name, append, max_matches, types);
    }
    return 0;
}
Ejemplo n.º 16
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestLineTablesMatchSpecific)) {
    // Test that when calling ResolveSymbolContext with a specific line number,
    // only line entries
    // which match the requested line are returned.
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFile *symfile = plugin->GetSymbolFile();

    FileSpec source_file("test-pdb.cpp", false);
    FileSpec header1("test-pdb.h", false);
    FileSpec header2("test-pdb-nested.h", false);
    uint32_t cus = symfile->GetNumCompileUnits();
    EXPECT_EQ(2u, cus);

    SymbolContextList sc_list;
    uint32_t scope = lldb::eSymbolContextCompUnit | lldb::eSymbolContextLineEntry;

    // First test with line 7, and verify that only line 7 entries are added.
    uint32_t count =
        symfile->ResolveSymbolContext(source_file, 7, true, scope, sc_list);
    EXPECT_EQ(1u, count);
    SymbolContext sc;
    EXPECT_TRUE(sc_list.GetContextAtIndex(0, sc));

    LineTable *lt = sc.comp_unit->GetLineTable();
    EXPECT_NE(nullptr, lt);
    count = lt->GetSize();
    // We expect one extra entry for termination
    EXPECT_EQ(3u, count);

    VerifyLineEntry(module, sc, source_file, *lt, 7, 0x401040);
    VerifyLineEntry(module, sc, header2, *lt, 7, 0x401089);

    sc_list.Clear();
    // Then test with line 9, and verify that only line 9 entries are added.
    count = symfile->ResolveSymbolContext(source_file, 9, true, scope, sc_list);
    EXPECT_EQ(1u, count);
    EXPECT_TRUE(sc_list.GetContextAtIndex(0, sc));

    lt = sc.comp_unit->GetLineTable();
    EXPECT_NE(nullptr, lt);
    count = lt->GetSize();
    // We expect one extra entry for termination
    EXPECT_EQ(3u, count);

    VerifyLineEntry(module, sc, source_file, *lt, 9, 0x401045);
    VerifyLineEntry(module, sc, header1, *lt, 9, 0x401090);
}
Ejemplo n.º 17
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestResolveSymbolContextFullPath)) {
    // Test that attempting to call ResolveSymbolContext with a full path only
    // finds the one source
    // file that matches the full path.
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    EXPECT_NE(nullptr, plugin);
    SymbolFile *symfile = plugin->GetSymbolFile();

    FileSpec header_spec(
        R"spec(D:\src\llvm\tools\lldb\unittests\SymbolFile\PDB\Inputs\test-pdb.cpp)spec",
        false);
    SymbolContextList sc_list;
    uint32_t result_count = symfile->ResolveSymbolContext(
                                header_spec, 0, false, lldb::eSymbolContextCompUnit, sc_list);
    EXPECT_GE(1u, result_count);
    EXPECT_TRUE(ContainsCompileUnit(sc_list, header_spec));
}

TEST_F(SymbolFilePDBTests,
       REQUIRES_DIA_SDK(TestLookupOfHeaderFileWithInlines)) {
    // Test that when looking up a header file via ResolveSymbolContext (i.e. a
    // file that was not by itself
    // compiled, but only contributes to the combined code of other source files),
    // a SymbolContext is returned
    // for each compiland which has line contributions from the requested header.
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    EXPECT_NE(nullptr, plugin);
    SymbolFile *symfile = plugin->GetSymbolFile();

    FileSpec header_specs[] = {FileSpec("test-pdb.h", false),
                               FileSpec("test-pdb-nested.h", false)
                              };
    FileSpec main_cpp_spec("test-pdb.cpp", false);
    FileSpec alt_cpp_spec("test-pdb-alt.cpp", false);
    for (const auto &hspec : header_specs) {
        SymbolContextList sc_list;
        uint32_t result_count = symfile->ResolveSymbolContext(
                                    hspec, 0, true, lldb::eSymbolContextCompUnit, sc_list);
        EXPECT_EQ(2u, result_count);
        EXPECT_TRUE(ContainsCompileUnit(sc_list, main_cpp_spec));
        EXPECT_TRUE(ContainsCompileUnit(sc_list, alt_cpp_spec));
    }
}
Ejemplo n.º 18
0
lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) {
  SBTypeList sb_type_list;

  ModuleSP module_sp(GetSP());
  if (module_sp) {
    SymbolVendor *vendor = module_sp->GetSymbolVendor();
    if (vendor) {
      TypeList type_list;
      vendor->GetTypes(NULL, type_mask, type_list);
      sb_type_list.m_opaque_ap->Append(type_list);
    }
  }
  return sb_type_list;
}
Ejemplo n.º 19
0
TEST_F(SymbolFilePDBTests, TestAbilitiesForDWARF) {
    // Test that when we have Dwarf debug info, SymbolFileDWARF is used.
    FileSpec fspec(m_dwarf_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    EXPECT_NE(nullptr, plugin);
    SymbolFile *symfile = plugin->GetSymbolFile();
    EXPECT_NE(nullptr, symfile);
    EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());

    uint32_t expected_abilities = SymbolFile::kAllAbilities;
    EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
}
Ejemplo n.º 20
0
CompUnitSP
Module::GetCompileUnitAtIndex (uint32_t index)
{
    Mutex::Locker locker (m_mutex);
    uint32_t num_comp_units = GetNumCompileUnits ();
    CompUnitSP cu_sp;

    if (index < num_comp_units)
    {
        SymbolVendor *symbols = GetSymbolVendor ();
        if (symbols)
            cu_sp = symbols->GetCompileUnitAtIndex(index);
    }
    return cu_sp;
}
Ejemplo n.º 21
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestLineTablesMatchAll)) {
    // Test that when calling ResolveSymbolContext with a line number of 0, all
    // line entries from
    // the specified files are returned.
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFile *symfile = plugin->GetSymbolFile();

    FileSpec source_file("test-pdb.cpp", false);
    FileSpec header1("test-pdb.h", false);
    FileSpec header2("test-pdb-nested.h", false);
    uint32_t cus = symfile->GetNumCompileUnits();
    EXPECT_EQ(2u, cus);

    SymbolContextList sc_list;
    uint32_t scope = lldb::eSymbolContextCompUnit | lldb::eSymbolContextLineEntry;

    uint32_t count =
        symfile->ResolveSymbolContext(source_file, 0, true, scope, sc_list);
    EXPECT_EQ(1u, count);
    SymbolContext sc;
    EXPECT_TRUE(sc_list.GetContextAtIndex(0, sc));

    LineTable *lt = sc.comp_unit->GetLineTable();
    EXPECT_NE(nullptr, lt);
    count = lt->GetSize();
    // We expect one extra entry for termination (per function)
    EXPECT_EQ(16u, count);

    VerifyLineEntry(module, sc, source_file, *lt, 7, 0x401040);
    VerifyLineEntry(module, sc, source_file, *lt, 8, 0x401043);
    VerifyLineEntry(module, sc, source_file, *lt, 9, 0x401045);

    VerifyLineEntry(module, sc, source_file, *lt, 13, 0x401050);
    VerifyLineEntry(module, sc, source_file, *lt, 14, 0x401054);
    VerifyLineEntry(module, sc, source_file, *lt, 15, 0x401070);

    VerifyLineEntry(module, sc, header1, *lt, 9, 0x401090);
    VerifyLineEntry(module, sc, header1, *lt, 10, 0x401093);
    VerifyLineEntry(module, sc, header1, *lt, 11, 0x4010a2);

    VerifyLineEntry(module, sc, header2, *lt, 5, 0x401080);
    VerifyLineEntry(module, sc, header2, *lt, 6, 0x401083);
    VerifyLineEntry(module, sc, header2, *lt, 7, 0x401089);
}
Ejemplo n.º 22
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestNullName)) {
    FileSpec fspec(m_types_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFilePDB *symfile =
        static_cast<SymbolFilePDB *>(plugin->GetSymbolFile());
    SymbolContext sc;
    llvm::DenseSet<SymbolFile *> searched_files;
    TypeMap results;
    uint32_t num_results = symfile->FindTypes(sc, ConstString(), nullptr, false,
                           0, searched_files, results);
    EXPECT_EQ(0u, num_results);
    EXPECT_EQ(0u, results.GetSize());
}
Ejemplo n.º 23
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestAbilitiesForPDB)) {
    // Test that when we have PDB debug info, SymbolFilePDB is used.
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    EXPECT_NE(nullptr, plugin);
    SymbolFile *symfile = plugin->GetSymbolFile();
    EXPECT_NE(nullptr, symfile);
    EXPECT_EQ(symfile->GetPluginName(), SymbolFilePDB::GetPluginNameStatic());

    uint32_t expected_abilities =
        SymbolFile::CompileUnits | SymbolFile::LineTables;
    EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
}
Ejemplo n.º 24
0
lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
  SBTypeList sb_type_list;

  if (m_opaque_ptr) {
    ModuleSP module_sp(m_opaque_ptr->GetModule());
    if (module_sp) {
      SymbolVendor *vendor = module_sp->GetSymbolVendor();
      if (vendor) {
        TypeList type_list;
        vendor->GetTypes(m_opaque_ptr, type_mask, type_list);
        sb_type_list.m_opaque_ap->Append(type_list);
      }
    }
  }
  return sb_type_list;
}
Ejemplo n.º 25
0
uint32_t
Module::FindFunctions (const ConstString &name,
                       const ClangNamespaceDecl *namespace_decl,
                       uint32_t name_type_mask, 
                       bool include_symbols,
                       bool include_inlines,
                       bool append, 
                       SymbolContextList& sc_list)
{
    if (!append)
        sc_list.Clear();

    const uint32_t start_size = sc_list.GetSize();

    // Find all the functions (not symbols, but debug information functions...
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);

    // Now check our symbol table for symbols that are code symbols if requested
    if (include_symbols)
    {
        ObjectFile *objfile = GetObjectFile();
        if (objfile)
        {
            Symtab *symtab = objfile->GetSymtab();
            if (symtab)
            {
                std::vector<uint32_t> symbol_indexes;
                symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
                const uint32_t num_matches = symbol_indexes.size();
                if (num_matches)
                {
                    const bool merge_symbol_into_function = true;
                    SymbolContext sc(this);
                    for (uint32_t i=0; i<num_matches; i++)
                    {
                        sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
                        sc_list.AppendIfUnique (sc, merge_symbol_into_function);
                    }
                }
            }
        }
    }
    return sc_list.GetSize() - start_size;
}
Ejemplo n.º 26
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestResolveSymbolContextBasename)) {
    // Test that attempting to call ResolveSymbolContext with only a basename
    // finds all full paths
    // with the same basename
    FileSpec fspec(m_pdb_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    EXPECT_NE(nullptr, plugin);
    SymbolFile *symfile = plugin->GetSymbolFile();

    FileSpec header_spec("test-pdb.cpp", false);
    SymbolContextList sc_list;
    uint32_t result_count = symfile->ResolveSymbolContext(
                                header_spec, 0, false, lldb::eSymbolContextCompUnit, sc_list);
    EXPECT_EQ(1u, result_count);
    EXPECT_TRUE(ContainsCompileUnit(sc_list, header_spec));
}
Ejemplo n.º 27
0
uint32_t
Module::FindFunctions (const RegularExpression& regex, 
                       bool include_symbols,
                       bool include_inlines,
                       bool append, 
                       SymbolContextList& sc_list)
{
    if (!append)
        sc_list.Clear();
    
    const uint32_t start_size = sc_list.GetSize();
    
    SymbolVendor *symbols = GetSymbolVendor ();
    if (symbols)
        symbols->FindFunctions(regex, include_inlines, append, sc_list);
    // Now check our symbol table for symbols that are code symbols if requested
    if (include_symbols)
    {
        ObjectFile *objfile = GetObjectFile();
        if (objfile)
        {
            Symtab *symtab = objfile->GetSymtab();
            if (symtab)
            {
                std::vector<uint32_t> symbol_indexes;
                symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
                const uint32_t num_matches = symbol_indexes.size();
                if (num_matches)
                {
                    const bool merge_symbol_into_function = true;
                    SymbolContext sc(this);
                    for (uint32_t i=0; i<num_matches; i++)
                    {
                        sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
                        sc_list.AppendIfUnique (sc, merge_symbol_into_function);
                    }
                }
            }
        }
    }
    return sc_list.GetSize() - start_size;
}
Ejemplo n.º 28
0
uint32_t
Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
{
    Mutex::Locker locker (m_mutex);
    Timer scoped_timer(__PRETTY_FUNCTION__,
                       "Module::ResolveSymbolContextForFilePath (%s%s%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
                       file_spec.GetDirectory().AsCString(""),
                       file_spec.GetDirectory() ? "/" : "",
                       file_spec.GetFilename().AsCString(""),
                       line,
                       check_inlines ? "yes" : "no",
                       resolve_scope);

    const uint32_t initial_count = sc_list.GetSize();

    SymbolVendor *symbols = GetSymbolVendor  ();
    if (symbols)
        symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);

    return sc_list.GetSize() - initial_count;
}
Ejemplo n.º 29
0
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestClassInNamespace)) {
    FileSpec fspec(m_types_test_exe.c_str(), false);
    ArchSpec aspec("i686-pc-windows");
    lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

    SymbolVendor *plugin = module->GetSymbolVendor();
    SymbolFilePDB *symfile =
        static_cast<SymbolFilePDB *>(plugin->GetSymbolFile());
    const llvm::pdb::IPDBSession &session = symfile->GetPDBSession();
    SymbolContext sc;
    llvm::DenseSet<SymbolFile *> searched_files;
    TypeMap results;
    EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString("NS::NSClass"), nullptr,
                                     false, 0, searched_files, results));
    EXPECT_EQ(1u, results.GetSize());
    lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
    EXPECT_EQ(ConstString("NS::NSClass"), udt_type->GetName());
    CompilerType compiler_type = udt_type->GetForwardCompilerType();
    EXPECT_TRUE(ClangASTContext::IsClassType(compiler_type.GetOpaqueQualType()));
    EXPECT_EQ(GetGlobalConstantInteger(session, "sizeof_NSClass"),
              udt_type->GetByteSize());
}
Ejemplo n.º 30
0
void
Module::ParseAllDebugSymbols()
{
    Mutex::Locker locker (m_mutex);
    uint32_t num_comp_units = GetNumCompileUnits();
    if (num_comp_units == 0)
        return;

    TargetSP null_target;
    SymbolContext sc(null_target, GetSP());
    uint32_t cu_idx;
    SymbolVendor *symbols = GetSymbolVendor ();

    for (cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
    {
        sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
        if (sc.comp_unit)
        {
            sc.function = NULL;
            symbols->ParseVariablesForContext(sc);

            symbols->ParseCompileUnitFunctions(sc);

            uint32_t func_idx;
            for (func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx)
            {
                symbols->ParseFunctionBlocks(sc);

                // Parse the variables for this function and all its blocks
                symbols->ParseVariablesForContext(sc);
            }


            // Parse all types for this compile unit
            sc.function = NULL;
            symbols->ParseTypes(sc);
        }
    }
}