1ac7ddfbfSEd Maste //===-- SBModule.cpp --------------------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/API/SBModule.h" 11ac7ddfbfSEd Maste #include "lldb/API/SBAddress.h" 12ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h" 13ac7ddfbfSEd Maste #include "lldb/API/SBModuleSpec.h" 14ac7ddfbfSEd Maste #include "lldb/API/SBProcess.h" 15ac7ddfbfSEd Maste #include "lldb/API/SBStream.h" 16ac7ddfbfSEd Maste #include "lldb/API/SBSymbolContextList.h" 17435933ddSDimitry Andric #include "lldb/Core/Module.h" 18ac7ddfbfSEd Maste #include "lldb/Core/Section.h" 19ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectList.h" 20ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectVariable.h" 21ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h" 224bb0738eSEd Maste #include "lldb/Symbol/SymbolFile.h" 23ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolVendor.h" 24ac7ddfbfSEd Maste #include "lldb/Symbol/Symtab.h" 259f2f44ceSEd Maste #include "lldb/Symbol/TypeSystem.h" 26ac7ddfbfSEd Maste #include "lldb/Symbol/VariableList.h" 27ac7ddfbfSEd Maste #include "lldb/Target/Target.h" 28f678e45dSDimitry Andric #include "lldb/Utility/Log.h" 29f678e45dSDimitry Andric #include "lldb/Utility/StreamString.h" 30ac7ddfbfSEd Maste 31ac7ddfbfSEd Maste using namespace lldb; 32ac7ddfbfSEd Maste using namespace lldb_private; 33ac7ddfbfSEd Maste 34435933ddSDimitry Andric SBModule::SBModule() : m_opaque_sp() {} 35ac7ddfbfSEd Maste 36435933ddSDimitry Andric SBModule::SBModule(const lldb::ModuleSP &module_sp) : m_opaque_sp(module_sp) {} 37ac7ddfbfSEd Maste 38435933ddSDimitry Andric SBModule::SBModule(const SBModuleSpec &module_spec) : m_opaque_sp() { 39ac7ddfbfSEd Maste ModuleSP module_sp; 40435933ddSDimitry Andric Error error = ModuleList::GetSharedModule(*module_spec.m_opaque_ap, module_sp, 41435933ddSDimitry Andric NULL, NULL, NULL); 42ac7ddfbfSEd Maste if (module_sp) 43ac7ddfbfSEd Maste SetSP(module_sp); 44ac7ddfbfSEd Maste } 45ac7ddfbfSEd Maste 46435933ddSDimitry Andric SBModule::SBModule(const SBModule &rhs) : m_opaque_sp(rhs.m_opaque_sp) {} 47ac7ddfbfSEd Maste 48435933ddSDimitry Andric SBModule::SBModule(lldb::SBProcess &process, lldb::addr_t header_addr) 49435933ddSDimitry Andric : m_opaque_sp() { 50ac7ddfbfSEd Maste ProcessSP process_sp(process.GetSP()); 51435933ddSDimitry Andric if (process_sp) { 52ac7ddfbfSEd Maste m_opaque_sp = process_sp->ReadModuleFromMemory(FileSpec(), header_addr); 53435933ddSDimitry Andric if (m_opaque_sp) { 54ac7ddfbfSEd Maste Target &target = process_sp->GetTarget(); 55ac7ddfbfSEd Maste bool changed = false; 5612b93ac6SEd Maste m_opaque_sp->SetLoadAddress(target, 0, true, changed); 57ac7ddfbfSEd Maste target.GetImages().Append(m_opaque_sp); 58ac7ddfbfSEd Maste } 59ac7ddfbfSEd Maste } 60ac7ddfbfSEd Maste } 61ac7ddfbfSEd Maste 62435933ddSDimitry Andric const SBModule &SBModule::operator=(const SBModule &rhs) { 63ac7ddfbfSEd Maste if (this != &rhs) 64ac7ddfbfSEd Maste m_opaque_sp = rhs.m_opaque_sp; 65ac7ddfbfSEd Maste return *this; 66ac7ddfbfSEd Maste } 67ac7ddfbfSEd Maste 68435933ddSDimitry Andric SBModule::~SBModule() {} 69ac7ddfbfSEd Maste 70435933ddSDimitry Andric bool SBModule::IsValid() const { return m_opaque_sp.get() != NULL; } 71ac7ddfbfSEd Maste 72435933ddSDimitry Andric void SBModule::Clear() { m_opaque_sp.reset(); } 73ac7ddfbfSEd Maste 74435933ddSDimitry Andric SBFileSpec SBModule::GetFileSpec() const { 75ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 76ac7ddfbfSEd Maste 77ac7ddfbfSEd Maste SBFileSpec file_spec; 78ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 79ac7ddfbfSEd Maste if (module_sp) 80ac7ddfbfSEd Maste file_spec.SetFileSpec(module_sp->GetFileSpec()); 81ac7ddfbfSEd Maste 82ac7ddfbfSEd Maste if (log) 83ac7ddfbfSEd Maste log->Printf("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 840127ef0fSEd Maste static_cast<void *>(module_sp.get()), 850127ef0fSEd Maste static_cast<const void *>(file_spec.get())); 86ac7ddfbfSEd Maste 87ac7ddfbfSEd Maste return file_spec; 88ac7ddfbfSEd Maste } 89ac7ddfbfSEd Maste 90435933ddSDimitry Andric lldb::SBFileSpec SBModule::GetPlatformFileSpec() const { 91ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 92ac7ddfbfSEd Maste 93ac7ddfbfSEd Maste SBFileSpec file_spec; 94ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 95ac7ddfbfSEd Maste if (module_sp) 96ac7ddfbfSEd Maste file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 97ac7ddfbfSEd Maste 98ac7ddfbfSEd Maste if (log) 99ac7ddfbfSEd Maste log->Printf("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 1000127ef0fSEd Maste static_cast<void *>(module_sp.get()), 1010127ef0fSEd Maste static_cast<const void *>(file_spec.get())); 102ac7ddfbfSEd Maste 103ac7ddfbfSEd Maste return file_spec; 104ac7ddfbfSEd Maste } 105ac7ddfbfSEd Maste 106435933ddSDimitry Andric bool SBModule::SetPlatformFileSpec(const lldb::SBFileSpec &platform_file) { 107ac7ddfbfSEd Maste bool result = false; 108ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 109ac7ddfbfSEd Maste 110ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 111435933ddSDimitry Andric if (module_sp) { 112ac7ddfbfSEd Maste module_sp->SetPlatformFileSpec(*platform_file); 113ac7ddfbfSEd Maste result = true; 114ac7ddfbfSEd Maste } 115ac7ddfbfSEd Maste 116ac7ddfbfSEd Maste if (log) 117ac7ddfbfSEd Maste log->Printf("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i", 1180127ef0fSEd Maste static_cast<void *>(module_sp.get()), 1190127ef0fSEd Maste static_cast<const void *>(platform_file.get()), 1200127ef0fSEd Maste platform_file->GetPath().c_str(), result); 121ac7ddfbfSEd Maste return result; 122ac7ddfbfSEd Maste } 123ac7ddfbfSEd Maste 124435933ddSDimitry Andric lldb::SBFileSpec SBModule::GetRemoteInstallFileSpec() { 125b952cd58SEd Maste SBFileSpec sb_file_spec; 126b952cd58SEd Maste ModuleSP module_sp(GetSP()); 127b952cd58SEd Maste if (module_sp) 128b952cd58SEd Maste sb_file_spec.SetFileSpec(module_sp->GetRemoteInstallFileSpec()); 129b952cd58SEd Maste return sb_file_spec; 130b952cd58SEd Maste } 131b952cd58SEd Maste 132435933ddSDimitry Andric bool SBModule::SetRemoteInstallFileSpec(lldb::SBFileSpec &file) { 133b952cd58SEd Maste ModuleSP module_sp(GetSP()); 134435933ddSDimitry Andric if (module_sp) { 135b952cd58SEd Maste module_sp->SetRemoteInstallFileSpec(file.ref()); 136b952cd58SEd Maste return true; 137b952cd58SEd Maste } 138b952cd58SEd Maste return false; 139b952cd58SEd Maste } 140ac7ddfbfSEd Maste 141435933ddSDimitry Andric const uint8_t *SBModule::GetUUIDBytes() const { 142ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 143ac7ddfbfSEd Maste 144ac7ddfbfSEd Maste const uint8_t *uuid_bytes = NULL; 145ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 146ac7ddfbfSEd Maste if (module_sp) 147ac7ddfbfSEd Maste uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 148ac7ddfbfSEd Maste 149435933ddSDimitry Andric if (log) { 150435933ddSDimitry Andric if (uuid_bytes) { 151ac7ddfbfSEd Maste StreamString s; 152ac7ddfbfSEd Maste module_sp->GetUUID().Dump(&s); 1530127ef0fSEd Maste log->Printf("SBModule(%p)::GetUUIDBytes () => %s", 1540127ef0fSEd Maste static_cast<void *>(module_sp.get()), s.GetData()); 155435933ddSDimitry Andric } else 1560127ef0fSEd Maste log->Printf("SBModule(%p)::GetUUIDBytes () => NULL", 1570127ef0fSEd Maste static_cast<void *>(module_sp.get())); 158ac7ddfbfSEd Maste } 159ac7ddfbfSEd Maste return uuid_bytes; 160ac7ddfbfSEd Maste } 161ac7ddfbfSEd Maste 162435933ddSDimitry Andric const char *SBModule::GetUUIDString() const { 163ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 164ac7ddfbfSEd Maste 1651c3bbb01SEd Maste const char *uuid_cstr = NULL; 166ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 167435933ddSDimitry Andric if (module_sp) { 1681c3bbb01SEd Maste // We are going to return a "const char *" value through the public 1691c3bbb01SEd Maste // API, so we need to constify it so it gets added permanently the 1701c3bbb01SEd Maste // string pool and then we don't need to worry about the lifetime of the 1711c3bbb01SEd Maste // string as it will never go away once it has been put into the ConstString 1721c3bbb01SEd Maste // string pool 1731c3bbb01SEd Maste uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString(); 1741c3bbb01SEd Maste } 1751c3bbb01SEd Maste 176435933ddSDimitry Andric if (uuid_cstr && uuid_cstr[0]) { 1771c3bbb01SEd Maste if (log) 178435933ddSDimitry Andric log->Printf("SBModule(%p)::GetUUIDString () => %s", 179435933ddSDimitry Andric static_cast<void *>(module_sp.get()), uuid_cstr); 1801c3bbb01SEd Maste return uuid_cstr; 181ac7ddfbfSEd Maste } 182ac7ddfbfSEd Maste 183ac7ddfbfSEd Maste if (log) 184435933ddSDimitry Andric log->Printf("SBModule(%p)::GetUUIDString () => NULL", 185435933ddSDimitry Andric static_cast<void *>(module_sp.get())); 1861c3bbb01SEd Maste return NULL; 187ac7ddfbfSEd Maste } 188ac7ddfbfSEd Maste 189435933ddSDimitry Andric bool SBModule::operator==(const SBModule &rhs) const { 190ac7ddfbfSEd Maste if (m_opaque_sp) 191ac7ddfbfSEd Maste return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 192ac7ddfbfSEd Maste return false; 193ac7ddfbfSEd Maste } 194ac7ddfbfSEd Maste 195435933ddSDimitry Andric bool SBModule::operator!=(const SBModule &rhs) const { 196ac7ddfbfSEd Maste if (m_opaque_sp) 197ac7ddfbfSEd Maste return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 198ac7ddfbfSEd Maste return false; 199ac7ddfbfSEd Maste } 200ac7ddfbfSEd Maste 201435933ddSDimitry Andric ModuleSP SBModule::GetSP() const { return m_opaque_sp; } 202ac7ddfbfSEd Maste 203435933ddSDimitry Andric void SBModule::SetSP(const ModuleSP &module_sp) { m_opaque_sp = module_sp; } 204ac7ddfbfSEd Maste 205435933ddSDimitry Andric SBAddress SBModule::ResolveFileAddress(lldb::addr_t vm_addr) { 206ac7ddfbfSEd Maste lldb::SBAddress sb_addr; 207ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 208435933ddSDimitry Andric if (module_sp) { 209ac7ddfbfSEd Maste Address addr; 210ac7ddfbfSEd Maste if (module_sp->ResolveFileAddress(vm_addr, addr)) 211ac7ddfbfSEd Maste sb_addr.ref() = addr; 212ac7ddfbfSEd Maste } 213ac7ddfbfSEd Maste return sb_addr; 214ac7ddfbfSEd Maste } 215ac7ddfbfSEd Maste 216ac7ddfbfSEd Maste SBSymbolContext 217435933ddSDimitry Andric SBModule::ResolveSymbolContextForAddress(const SBAddress &addr, 218435933ddSDimitry Andric uint32_t resolve_scope) { 219ac7ddfbfSEd Maste SBSymbolContext sb_sc; 220ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 221ac7ddfbfSEd Maste if (module_sp && addr.IsValid()) 222435933ddSDimitry Andric module_sp->ResolveSymbolContextForAddress(addr.ref(), resolve_scope, 223435933ddSDimitry Andric *sb_sc); 224ac7ddfbfSEd Maste return sb_sc; 225ac7ddfbfSEd Maste } 226ac7ddfbfSEd Maste 227435933ddSDimitry Andric bool SBModule::GetDescription(SBStream &description) { 228ac7ddfbfSEd Maste Stream &strm = description.ref(); 229ac7ddfbfSEd Maste 230ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 231435933ddSDimitry Andric if (module_sp) { 232ac7ddfbfSEd Maste module_sp->GetDescription(&strm); 233435933ddSDimitry Andric } else 234ac7ddfbfSEd Maste strm.PutCString("No value"); 235ac7ddfbfSEd Maste 236ac7ddfbfSEd Maste return true; 237ac7ddfbfSEd Maste } 238ac7ddfbfSEd Maste 239435933ddSDimitry Andric uint32_t SBModule::GetNumCompileUnits() { 240ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 241435933ddSDimitry Andric if (module_sp) { 242ac7ddfbfSEd Maste return module_sp->GetNumCompileUnits(); 243ac7ddfbfSEd Maste } 244ac7ddfbfSEd Maste return 0; 245ac7ddfbfSEd Maste } 246ac7ddfbfSEd Maste 247435933ddSDimitry Andric SBCompileUnit SBModule::GetCompileUnitAtIndex(uint32_t index) { 248ac7ddfbfSEd Maste SBCompileUnit sb_cu; 249ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 250435933ddSDimitry Andric if (module_sp) { 251ac7ddfbfSEd Maste CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(index); 252ac7ddfbfSEd Maste sb_cu.reset(cu_sp.get()); 253ac7ddfbfSEd Maste } 254ac7ddfbfSEd Maste return sb_cu; 255ac7ddfbfSEd Maste } 256ac7ddfbfSEd Maste 257435933ddSDimitry Andric static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) { 258435933ddSDimitry Andric if (module_sp) { 259ac7ddfbfSEd Maste SymbolVendor *symbols = module_sp->GetSymbolVendor(); 260ac7ddfbfSEd Maste if (symbols) 261ac7ddfbfSEd Maste return symbols->GetSymtab(); 262ac7ddfbfSEd Maste } 263ac7ddfbfSEd Maste return NULL; 264ac7ddfbfSEd Maste } 265ac7ddfbfSEd Maste 266435933ddSDimitry Andric size_t SBModule::GetNumSymbols() { 267ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 268435933ddSDimitry Andric if (module_sp) { 269ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp); 270ac7ddfbfSEd Maste if (symtab) 271ac7ddfbfSEd Maste return symtab->GetNumSymbols(); 272ac7ddfbfSEd Maste } 273ac7ddfbfSEd Maste return 0; 274ac7ddfbfSEd Maste } 275ac7ddfbfSEd Maste 276435933ddSDimitry Andric SBSymbol SBModule::GetSymbolAtIndex(size_t idx) { 277ac7ddfbfSEd Maste SBSymbol sb_symbol; 278ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 279ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp); 280ac7ddfbfSEd Maste if (symtab) 281ac7ddfbfSEd Maste sb_symbol.SetSymbol(symtab->SymbolAtIndex(idx)); 282ac7ddfbfSEd Maste return sb_symbol; 283ac7ddfbfSEd Maste } 284ac7ddfbfSEd Maste 285435933ddSDimitry Andric lldb::SBSymbol SBModule::FindSymbol(const char *name, 286435933ddSDimitry Andric lldb::SymbolType symbol_type) { 287ac7ddfbfSEd Maste SBSymbol sb_symbol; 288435933ddSDimitry Andric if (name && name[0]) { 289ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 290ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp); 291ac7ddfbfSEd Maste if (symtab) 292435933ddSDimitry Andric sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType( 293435933ddSDimitry Andric ConstString(name), symbol_type, Symtab::eDebugAny, 294435933ddSDimitry Andric Symtab::eVisibilityAny)); 295ac7ddfbfSEd Maste } 296ac7ddfbfSEd Maste return sb_symbol; 297ac7ddfbfSEd Maste } 298ac7ddfbfSEd Maste 299435933ddSDimitry Andric lldb::SBSymbolContextList SBModule::FindSymbols(const char *name, 300435933ddSDimitry Andric lldb::SymbolType symbol_type) { 301ac7ddfbfSEd Maste SBSymbolContextList sb_sc_list; 302435933ddSDimitry Andric if (name && name[0]) { 303ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 304ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp); 305435933ddSDimitry Andric if (symtab) { 306ac7ddfbfSEd Maste std::vector<uint32_t> matching_symbol_indexes; 307435933ddSDimitry Andric const size_t num_matches = symtab->FindAllSymbolsWithNameAndType( 308435933ddSDimitry Andric ConstString(name), symbol_type, matching_symbol_indexes); 309435933ddSDimitry Andric if (num_matches) { 310ac7ddfbfSEd Maste SymbolContext sc; 311ac7ddfbfSEd Maste sc.module_sp = module_sp; 312ac7ddfbfSEd Maste SymbolContextList &sc_list = *sb_sc_list; 313435933ddSDimitry Andric for (size_t i = 0; i < num_matches; ++i) { 314ac7ddfbfSEd Maste sc.symbol = symtab->SymbolAtIndex(matching_symbol_indexes[i]); 315ac7ddfbfSEd Maste if (sc.symbol) 316ac7ddfbfSEd Maste sc_list.Append(sc); 317ac7ddfbfSEd Maste } 318ac7ddfbfSEd Maste } 319ac7ddfbfSEd Maste } 320ac7ddfbfSEd Maste } 321ac7ddfbfSEd Maste return sb_sc_list; 322ac7ddfbfSEd Maste } 323ac7ddfbfSEd Maste 324435933ddSDimitry Andric size_t SBModule::GetNumSections() { 325ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 326435933ddSDimitry Andric if (module_sp) { 327ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list. 328ac7ddfbfSEd Maste module_sp->GetSymbolVendor(); 329ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList(); 330ac7ddfbfSEd Maste if (section_list) 331ac7ddfbfSEd Maste return section_list->GetSize(); 332ac7ddfbfSEd Maste } 333ac7ddfbfSEd Maste return 0; 334ac7ddfbfSEd Maste } 335ac7ddfbfSEd Maste 336435933ddSDimitry Andric SBSection SBModule::GetSectionAtIndex(size_t idx) { 337ac7ddfbfSEd Maste SBSection sb_section; 338ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 339435933ddSDimitry Andric if (module_sp) { 340ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list. 341ac7ddfbfSEd Maste module_sp->GetSymbolVendor(); 342ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList(); 343ac7ddfbfSEd Maste 344ac7ddfbfSEd Maste if (section_list) 345ac7ddfbfSEd Maste sb_section.SetSP(section_list->GetSectionAtIndex(idx)); 346ac7ddfbfSEd Maste } 347ac7ddfbfSEd Maste return sb_section; 348ac7ddfbfSEd Maste } 349ac7ddfbfSEd Maste 350435933ddSDimitry Andric lldb::SBSymbolContextList SBModule::FindFunctions(const char *name, 351435933ddSDimitry Andric uint32_t name_type_mask) { 352ac7ddfbfSEd Maste lldb::SBSymbolContextList sb_sc_list; 353ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 354435933ddSDimitry Andric if (name && module_sp) { 355ac7ddfbfSEd Maste const bool append = true; 356ac7ddfbfSEd Maste const bool symbols_ok = true; 357ac7ddfbfSEd Maste const bool inlines_ok = true; 358435933ddSDimitry Andric module_sp->FindFunctions(ConstString(name), NULL, name_type_mask, 359435933ddSDimitry Andric symbols_ok, inlines_ok, append, *sb_sc_list); 360ac7ddfbfSEd Maste } 361ac7ddfbfSEd Maste return sb_sc_list; 362ac7ddfbfSEd Maste } 363ac7ddfbfSEd Maste 364435933ddSDimitry Andric SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name, 365435933ddSDimitry Andric uint32_t max_matches) { 366ac7ddfbfSEd Maste SBValueList sb_value_list; 367ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 368435933ddSDimitry Andric if (name && module_sp) { 369ac7ddfbfSEd Maste VariableList variable_list; 370435933ddSDimitry Andric const uint32_t match_count = module_sp->FindGlobalVariables( 371435933ddSDimitry Andric ConstString(name), NULL, false, max_matches, variable_list); 372ac7ddfbfSEd Maste 373435933ddSDimitry Andric if (match_count > 0) { 374435933ddSDimitry Andric for (uint32_t i = 0; i < match_count; ++i) { 375ac7ddfbfSEd Maste lldb::ValueObjectSP valobj_sp; 376ac7ddfbfSEd Maste TargetSP target_sp(target.GetSP()); 377435933ddSDimitry Andric valobj_sp = ValueObjectVariable::Create( 378435933ddSDimitry Andric target_sp.get(), variable_list.GetVariableAtIndex(i)); 379ac7ddfbfSEd Maste if (valobj_sp) 380ac7ddfbfSEd Maste sb_value_list.Append(SBValue(valobj_sp)); 381ac7ddfbfSEd Maste } 382ac7ddfbfSEd Maste } 383ac7ddfbfSEd Maste } 384ac7ddfbfSEd Maste 385ac7ddfbfSEd Maste return sb_value_list; 386ac7ddfbfSEd Maste } 387ac7ddfbfSEd Maste 388435933ddSDimitry Andric lldb::SBValue SBModule::FindFirstGlobalVariable(lldb::SBTarget &target, 389435933ddSDimitry Andric const char *name) { 390ac7ddfbfSEd Maste SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 391ac7ddfbfSEd Maste if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 392ac7ddfbfSEd Maste return sb_value_list.GetValueAtIndex(0); 393ac7ddfbfSEd Maste return SBValue(); 394ac7ddfbfSEd Maste } 395ac7ddfbfSEd Maste 396435933ddSDimitry Andric lldb::SBType SBModule::FindFirstType(const char *name_cstr) { 397ac7ddfbfSEd Maste SBType sb_type; 398ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 399435933ddSDimitry Andric if (name_cstr && module_sp) { 400ac7ddfbfSEd Maste SymbolContext sc; 401ac7ddfbfSEd Maste const bool exact_match = false; 402ac7ddfbfSEd Maste ConstString name(name_cstr); 403ac7ddfbfSEd Maste 404ac7ddfbfSEd Maste sb_type = SBType(module_sp->FindFirstType(sc, name, exact_match)); 405ac7ddfbfSEd Maste 406435933ddSDimitry Andric if (!sb_type.IsValid()) { 407435933ddSDimitry Andric TypeSystem *type_system = 408435933ddSDimitry Andric module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 4099f2f44ceSEd Maste if (type_system) 4109f2f44ceSEd Maste sb_type = SBType(type_system->GetBuiltinTypeByName(name)); 4119f2f44ceSEd Maste } 412ac7ddfbfSEd Maste } 413ac7ddfbfSEd Maste return sb_type; 414ac7ddfbfSEd Maste } 415ac7ddfbfSEd Maste 416435933ddSDimitry Andric lldb::SBType SBModule::GetBasicType(lldb::BasicType type) { 417ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 418435933ddSDimitry Andric if (module_sp) { 419435933ddSDimitry Andric TypeSystem *type_system = 420435933ddSDimitry Andric module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 4219f2f44ceSEd Maste if (type_system) 4229f2f44ceSEd Maste return SBType(type_system->GetBasicTypeFromAST(type)); 4239f2f44ceSEd Maste } 424ac7ddfbfSEd Maste return SBType(); 425ac7ddfbfSEd Maste } 426ac7ddfbfSEd Maste 427435933ddSDimitry Andric lldb::SBTypeList SBModule::FindTypes(const char *type) { 428ac7ddfbfSEd Maste SBTypeList retval; 429ac7ddfbfSEd Maste 430ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 431435933ddSDimitry Andric if (type && module_sp) { 432ac7ddfbfSEd Maste SymbolContext sc; 433ac7ddfbfSEd Maste TypeList type_list; 434ac7ddfbfSEd Maste const bool exact_match = false; 435ac7ddfbfSEd Maste ConstString name(type); 4364bb0738eSEd Maste llvm::DenseSet<SymbolFile *> searched_symbol_files; 437435933ddSDimitry Andric const uint32_t num_matches = module_sp->FindTypes( 438435933ddSDimitry Andric sc, name, exact_match, UINT32_MAX, searched_symbol_files, type_list); 439ac7ddfbfSEd Maste 440435933ddSDimitry Andric if (num_matches > 0) { 441435933ddSDimitry Andric for (size_t idx = 0; idx < num_matches; idx++) { 442ac7ddfbfSEd Maste TypeSP type_sp(type_list.GetTypeAtIndex(idx)); 443ac7ddfbfSEd Maste if (type_sp) 444ac7ddfbfSEd Maste retval.Append(SBType(type_sp)); 445ac7ddfbfSEd Maste } 446435933ddSDimitry Andric } else { 447435933ddSDimitry Andric TypeSystem *type_system = 448435933ddSDimitry Andric module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 449435933ddSDimitry Andric if (type_system) { 4509f2f44ceSEd Maste CompilerType compiler_type = type_system->GetBuiltinTypeByName(name); 4519f2f44ceSEd Maste if (compiler_type) 4529f2f44ceSEd Maste retval.Append(SBType(compiler_type)); 4539f2f44ceSEd Maste } 454ac7ddfbfSEd Maste } 455ac7ddfbfSEd Maste } 456ac7ddfbfSEd Maste 457ac7ddfbfSEd Maste return retval; 458ac7ddfbfSEd Maste } 459ac7ddfbfSEd Maste 460435933ddSDimitry Andric lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) { 46112b93ac6SEd Maste ModuleSP module_sp(GetSP()); 462435933ddSDimitry Andric if (module_sp) { 46312b93ac6SEd Maste SymbolVendor *vendor = module_sp->GetSymbolVendor(); 464435933ddSDimitry Andric if (vendor) { 46512b93ac6SEd Maste Type *type_ptr = vendor->ResolveTypeUID(uid); 46612b93ac6SEd Maste if (type_ptr) 46712b93ac6SEd Maste return SBType(type_ptr->shared_from_this()); 46812b93ac6SEd Maste } 46912b93ac6SEd Maste } 47012b93ac6SEd Maste return SBType(); 47112b93ac6SEd Maste } 47212b93ac6SEd Maste 473435933ddSDimitry Andric lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) { 474ac7ddfbfSEd Maste SBTypeList sb_type_list; 475ac7ddfbfSEd Maste 476ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 477435933ddSDimitry Andric if (module_sp) { 478ac7ddfbfSEd Maste SymbolVendor *vendor = module_sp->GetSymbolVendor(); 479435933ddSDimitry Andric if (vendor) { 480ac7ddfbfSEd Maste TypeList type_list; 481ac7ddfbfSEd Maste vendor->GetTypes(NULL, type_mask, type_list); 482ac7ddfbfSEd Maste sb_type_list.m_opaque_ap->Append(type_list); 483ac7ddfbfSEd Maste } 484ac7ddfbfSEd Maste } 485ac7ddfbfSEd Maste return sb_type_list; 486ac7ddfbfSEd Maste } 487ac7ddfbfSEd Maste 488435933ddSDimitry Andric SBSection SBModule::FindSection(const char *sect_name) { 489ac7ddfbfSEd Maste SBSection sb_section; 490ac7ddfbfSEd Maste 491ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 492435933ddSDimitry Andric if (sect_name && module_sp) { 493ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list. 494ac7ddfbfSEd Maste module_sp->GetSymbolVendor(); 495ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList(); 496435933ddSDimitry Andric if (section_list) { 497ac7ddfbfSEd Maste ConstString const_sect_name(sect_name); 498ac7ddfbfSEd Maste SectionSP section_sp(section_list->FindSectionByName(const_sect_name)); 499435933ddSDimitry Andric if (section_sp) { 500ac7ddfbfSEd Maste sb_section.SetSP(section_sp); 501ac7ddfbfSEd Maste } 502ac7ddfbfSEd Maste } 503ac7ddfbfSEd Maste } 504ac7ddfbfSEd Maste return sb_section; 505ac7ddfbfSEd Maste } 506ac7ddfbfSEd Maste 507435933ddSDimitry Andric lldb::ByteOrder SBModule::GetByteOrder() { 508ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 509ac7ddfbfSEd Maste if (module_sp) 510ac7ddfbfSEd Maste return module_sp->GetArchitecture().GetByteOrder(); 511ac7ddfbfSEd Maste return eByteOrderInvalid; 512ac7ddfbfSEd Maste } 513ac7ddfbfSEd Maste 514435933ddSDimitry Andric const char *SBModule::GetTriple() { 515ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 516435933ddSDimitry Andric if (module_sp) { 517ac7ddfbfSEd Maste std::string triple(module_sp->GetArchitecture().GetTriple().str()); 518ac7ddfbfSEd Maste // Unique the string so we don't run into ownership issues since 519ac7ddfbfSEd Maste // the const strings put the string into the string pool once and 520ac7ddfbfSEd Maste // the strings never comes out 521ac7ddfbfSEd Maste ConstString const_triple(triple.c_str()); 522ac7ddfbfSEd Maste return const_triple.GetCString(); 523ac7ddfbfSEd Maste } 524ac7ddfbfSEd Maste return NULL; 525ac7ddfbfSEd Maste } 526ac7ddfbfSEd Maste 527435933ddSDimitry Andric uint32_t SBModule::GetAddressByteSize() { 528ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 529ac7ddfbfSEd Maste if (module_sp) 530ac7ddfbfSEd Maste return module_sp->GetArchitecture().GetAddressByteSize(); 531ac7ddfbfSEd Maste return sizeof(void *); 532ac7ddfbfSEd Maste } 533ac7ddfbfSEd Maste 534435933ddSDimitry Andric uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) { 535ac7ddfbfSEd Maste ModuleSP module_sp(GetSP()); 536ac7ddfbfSEd Maste if (module_sp) 537ac7ddfbfSEd Maste return module_sp->GetVersion(versions, num_versions); 538435933ddSDimitry Andric else { 539435933ddSDimitry Andric if (versions && num_versions) { 540ac7ddfbfSEd Maste for (uint32_t i = 0; i < num_versions; ++i) 541ac7ddfbfSEd Maste versions[i] = UINT32_MAX; 542ac7ddfbfSEd Maste } 543ac7ddfbfSEd Maste return 0; 544ac7ddfbfSEd Maste } 545ac7ddfbfSEd Maste } 546ac7ddfbfSEd Maste 547435933ddSDimitry Andric lldb::SBFileSpec SBModule::GetSymbolFileSpec() const { 5481c3bbb01SEd Maste lldb::SBFileSpec sb_file_spec; 5491c3bbb01SEd Maste ModuleSP module_sp(GetSP()); 550435933ddSDimitry Andric if (module_sp) { 5511c3bbb01SEd Maste SymbolVendor *symbol_vendor_ptr = module_sp->GetSymbolVendor(); 5521c3bbb01SEd Maste if (symbol_vendor_ptr) 5531c3bbb01SEd Maste sb_file_spec.SetFileSpec(symbol_vendor_ptr->GetMainFileSpec()); 5541c3bbb01SEd Maste } 5551c3bbb01SEd Maste return sb_file_spec; 5561c3bbb01SEd Maste } 5571c3bbb01SEd Maste 558435933ddSDimitry Andric lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const { 5591c3bbb01SEd Maste lldb::SBAddress sb_addr; 5601c3bbb01SEd Maste ModuleSP module_sp(GetSP()); 561435933ddSDimitry Andric if (module_sp) { 5621c3bbb01SEd Maste ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 5631c3bbb01SEd Maste if (objfile_ptr) 5641c3bbb01SEd Maste sb_addr.ref() = objfile_ptr->GetHeaderAddress(); 5651c3bbb01SEd Maste } 5661c3bbb01SEd Maste return sb_addr; 5671c3bbb01SEd Maste } 568