130fdc8d8SChris Lattner //===-- SBModule.cpp --------------------------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner #include "lldb/API/SBModule.h" 1109960031SGreg Clayton #include "lldb/API/SBAddress.h" 1209960031SGreg Clayton #include "lldb/API/SBFileSpec.h" 13226cce25SGreg Clayton #include "lldb/API/SBModuleSpec.h" 14c9660546SGreg Clayton #include "lldb/API/SBProcess.h" 15dde9cff3SCaroline Tice #include "lldb/API/SBStream.h" 16fe356d35SGreg Clayton #include "lldb/API/SBSymbolContextList.h" 1730fdc8d8SChris Lattner #include "lldb/Core/Module.h" 18ceb6b139SCaroline Tice #include "lldb/Core/Log.h" 191f746071SGreg Clayton #include "lldb/Core/Section.h" 2038adbbb8SGreg Clayton #include "lldb/Core/StreamString.h" 21dea8cb4fSGreg Clayton #include "lldb/Core/ValueObjectList.h" 22dea8cb4fSGreg Clayton #include "lldb/Core/ValueObjectVariable.h" 2388c6b62eSZachary Turner #include "lldb/Symbol/ClangASTContext.h" 241f746071SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 256f3533fbSEnrico Granata #include "lldb/Symbol/SymbolVendor.h" 261f746071SGreg Clayton #include "lldb/Symbol/Symtab.h" 27dea8cb4fSGreg Clayton #include "lldb/Symbol/VariableList.h" 28dea8cb4fSGreg Clayton #include "lldb/Target/Target.h" 2930fdc8d8SChris Lattner 3030fdc8d8SChris Lattner using namespace lldb; 31ceb6b139SCaroline Tice using namespace lldb_private; 3230fdc8d8SChris Lattner 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner SBModule::SBModule () : 356611103cSGreg Clayton m_opaque_sp () 3630fdc8d8SChris Lattner { 3730fdc8d8SChris Lattner } 3830fdc8d8SChris Lattner 3930fdc8d8SChris Lattner SBModule::SBModule (const lldb::ModuleSP& module_sp) : 406611103cSGreg Clayton m_opaque_sp (module_sp) 4130fdc8d8SChris Lattner { 4230fdc8d8SChris Lattner } 4330fdc8d8SChris Lattner 44226cce25SGreg Clayton SBModule::SBModule(const SBModuleSpec &module_spec) : 45226cce25SGreg Clayton m_opaque_sp () 46226cce25SGreg Clayton { 47226cce25SGreg Clayton ModuleSP module_sp; 48226cce25SGreg Clayton Error error = ModuleList::GetSharedModule (*module_spec.m_opaque_ap, 49226cce25SGreg Clayton module_sp, 50226cce25SGreg Clayton NULL, 51226cce25SGreg Clayton NULL, 52226cce25SGreg Clayton NULL); 53226cce25SGreg Clayton if (module_sp) 54226cce25SGreg Clayton SetSP(module_sp); 55226cce25SGreg Clayton } 56226cce25SGreg Clayton 57efabb123SGreg Clayton SBModule::SBModule(const SBModule &rhs) : 58efabb123SGreg Clayton m_opaque_sp (rhs.m_opaque_sp) 59efabb123SGreg Clayton { 60efabb123SGreg Clayton } 61efabb123SGreg Clayton 62c9660546SGreg Clayton SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : 63c9660546SGreg Clayton m_opaque_sp () 64c9660546SGreg Clayton { 65c9660546SGreg Clayton ProcessSP process_sp (process.GetSP()); 66c9660546SGreg Clayton if (process_sp) 67c859e2d5SGreg Clayton { 6839f7ee86SGreg Clayton m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr); 6939f7ee86SGreg Clayton if (m_opaque_sp) 7039f7ee86SGreg Clayton { 7139f7ee86SGreg Clayton Target &target = process_sp->GetTarget(); 7239f7ee86SGreg Clayton bool changed = false; 73751caf65SGreg Clayton m_opaque_sp->SetLoadAddress(target, 0, true, changed); 7439f7ee86SGreg Clayton target.GetImages().Append(m_opaque_sp); 7539f7ee86SGreg Clayton } 76c859e2d5SGreg Clayton } 77c9660546SGreg Clayton } 78c9660546SGreg Clayton 79efabb123SGreg Clayton const SBModule & 80efabb123SGreg Clayton SBModule::operator = (const SBModule &rhs) 81efabb123SGreg Clayton { 82efabb123SGreg Clayton if (this != &rhs) 83efabb123SGreg Clayton m_opaque_sp = rhs.m_opaque_sp; 84efabb123SGreg Clayton return *this; 85efabb123SGreg Clayton } 86efabb123SGreg Clayton 8730fdc8d8SChris Lattner SBModule::~SBModule () 8830fdc8d8SChris Lattner { 8930fdc8d8SChris Lattner } 9030fdc8d8SChris Lattner 9130fdc8d8SChris Lattner bool 9230fdc8d8SChris Lattner SBModule::IsValid () const 9330fdc8d8SChris Lattner { 946611103cSGreg Clayton return m_opaque_sp.get() != NULL; 9530fdc8d8SChris Lattner } 9630fdc8d8SChris Lattner 975d3bca4eSJim Ingham void 985d3bca4eSJim Ingham SBModule::Clear() 995d3bca4eSJim Ingham { 1005d3bca4eSJim Ingham m_opaque_sp.reset(); 1015d3bca4eSJim Ingham } 1025d3bca4eSJim Ingham 10330fdc8d8SChris Lattner SBFileSpec 10430fdc8d8SChris Lattner SBModule::GetFileSpec () const 10530fdc8d8SChris Lattner { 1065160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 107ceb6b139SCaroline Tice 10830fdc8d8SChris Lattner SBFileSpec file_spec; 109c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 110c2ff9318SGreg Clayton if (module_sp) 111c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetFileSpec()); 112ceb6b139SCaroline Tice 113ceb6b139SCaroline Tice if (log) 114cfd1acedSGreg Clayton log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 115324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 116324a1036SSaleem Abdulrasool static_cast<const void*>(file_spec.get())); 117ceb6b139SCaroline Tice 11830fdc8d8SChris Lattner return file_spec; 11930fdc8d8SChris Lattner } 12030fdc8d8SChris Lattner 1212289fa48SGreg Clayton lldb::SBFileSpec 1222289fa48SGreg Clayton SBModule::GetPlatformFileSpec () const 1232289fa48SGreg Clayton { 1245160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1252289fa48SGreg Clayton 1262289fa48SGreg Clayton SBFileSpec file_spec; 127c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 128c2ff9318SGreg Clayton if (module_sp) 129c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 1302289fa48SGreg Clayton 1312289fa48SGreg Clayton if (log) 1322289fa48SGreg Clayton log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 133324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 134324a1036SSaleem Abdulrasool static_cast<const void*>(file_spec.get())); 1352289fa48SGreg Clayton 1362289fa48SGreg Clayton return file_spec; 1372289fa48SGreg Clayton } 1382289fa48SGreg Clayton 1392289fa48SGreg Clayton bool 1402289fa48SGreg Clayton SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 1412289fa48SGreg Clayton { 1422289fa48SGreg Clayton bool result = false; 1435160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1442289fa48SGreg Clayton 145c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 146c2ff9318SGreg Clayton if (module_sp) 1472289fa48SGreg Clayton { 148c2ff9318SGreg Clayton module_sp->SetPlatformFileSpec(*platform_file); 1492289fa48SGreg Clayton result = true; 1502289fa48SGreg Clayton } 1512289fa48SGreg Clayton 1522289fa48SGreg Clayton if (log) 153b5ad4ec7SGreg Clayton log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i", 154324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 155324a1036SSaleem Abdulrasool static_cast<const void*>(platform_file.get()), 156324a1036SSaleem Abdulrasool platform_file->GetPath().c_str(), result); 1572289fa48SGreg Clayton return result; 1582289fa48SGreg Clayton } 1592289fa48SGreg Clayton 160fbb76349SGreg Clayton lldb::SBFileSpec 161fbb76349SGreg Clayton SBModule::GetRemoteInstallFileSpec () 162fbb76349SGreg Clayton { 163fbb76349SGreg Clayton SBFileSpec sb_file_spec; 164fbb76349SGreg Clayton ModuleSP module_sp (GetSP ()); 165fbb76349SGreg Clayton if (module_sp) 166fbb76349SGreg Clayton sb_file_spec.SetFileSpec (module_sp->GetRemoteInstallFileSpec()); 167fbb76349SGreg Clayton return sb_file_spec; 168fbb76349SGreg Clayton } 169fbb76349SGreg Clayton 170fbb76349SGreg Clayton bool 171fbb76349SGreg Clayton SBModule::SetRemoteInstallFileSpec (lldb::SBFileSpec &file) 172fbb76349SGreg Clayton { 173fbb76349SGreg Clayton ModuleSP module_sp (GetSP ()); 174fbb76349SGreg Clayton if (module_sp) 175fbb76349SGreg Clayton { 176fbb76349SGreg Clayton module_sp->SetRemoteInstallFileSpec(file.ref()); 177fbb76349SGreg Clayton return true; 178fbb76349SGreg Clayton } 179fbb76349SGreg Clayton return false; 180fbb76349SGreg Clayton } 1812289fa48SGreg Clayton 1822289fa48SGreg Clayton 18330fdc8d8SChris Lattner const uint8_t * 18430fdc8d8SChris Lattner SBModule::GetUUIDBytes () const 18530fdc8d8SChris Lattner { 1865160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 187ceb6b139SCaroline Tice 1884838131bSGreg Clayton const uint8_t *uuid_bytes = NULL; 189c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 190c2ff9318SGreg Clayton if (module_sp) 191c2ff9318SGreg Clayton uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 192ceb6b139SCaroline Tice 193ceb6b139SCaroline Tice if (log) 1944838131bSGreg Clayton { 1954838131bSGreg Clayton if (uuid_bytes) 1964838131bSGreg Clayton { 1974838131bSGreg Clayton StreamString s; 198c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 199324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", 200324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), s.GetData()); 2014838131bSGreg Clayton } 2024838131bSGreg Clayton else 203324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", 204324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get())); 2054838131bSGreg Clayton } 2064838131bSGreg Clayton return uuid_bytes; 20730fdc8d8SChris Lattner } 20830fdc8d8SChris Lattner 20930fdc8d8SChris Lattner 210df2963edSJohnny Chen const char * 211df2963edSJohnny Chen SBModule::GetUUIDString () const 212df2963edSJohnny Chen { 2135160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 214df2963edSJohnny Chen 215f1be855aSGreg Clayton const char *uuid_cstr = NULL; 216c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 217c2ff9318SGreg Clayton if (module_sp) 218c16b4af0SJason Molenda { 219f1be855aSGreg Clayton // We are going to return a "const char *" value through the public 220f1be855aSGreg Clayton // API, so we need to constify it so it gets added permanently the the 221f1be855aSGreg Clayton // string pool and then we don't need to worry about the lifetime of the 222f1be855aSGreg Clayton // string as it will never go away once it has been put into the ConstString 223f1be855aSGreg Clayton // string pool 224f1be855aSGreg Clayton uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString(); 225f1be855aSGreg Clayton } 226f1be855aSGreg Clayton 227f1be855aSGreg Clayton if (uuid_cstr && uuid_cstr[0]) 228f1be855aSGreg Clayton { 229f1be855aSGreg Clayton if (log) 230f1be855aSGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => %s", static_cast<void*>(module_sp.get()), uuid_cstr); 231f1be855aSGreg Clayton return uuid_cstr; 232c16b4af0SJason Molenda } 233df2963edSJohnny Chen 234df2963edSJohnny Chen if (log) 235f1be855aSGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => NULL", static_cast<void*>(module_sp.get())); 236f1be855aSGreg Clayton return NULL; 237df2963edSJohnny Chen } 238df2963edSJohnny Chen 239df2963edSJohnny Chen 24030fdc8d8SChris Lattner bool 24130fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 24230fdc8d8SChris Lattner { 2436611103cSGreg Clayton if (m_opaque_sp) 2446611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 24530fdc8d8SChris Lattner return false; 24630fdc8d8SChris Lattner } 24730fdc8d8SChris Lattner 24830fdc8d8SChris Lattner bool 24930fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 25030fdc8d8SChris Lattner { 2516611103cSGreg Clayton if (m_opaque_sp) 2526611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 25330fdc8d8SChris Lattner return false; 25430fdc8d8SChris Lattner } 25530fdc8d8SChris Lattner 256acdbe816SGreg Clayton ModuleSP 257acdbe816SGreg Clayton SBModule::GetSP () const 258cac9c5f9SGreg Clayton { 259cac9c5f9SGreg Clayton return m_opaque_sp; 260cac9c5f9SGreg Clayton } 26130fdc8d8SChris Lattner 26230fdc8d8SChris Lattner void 263acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 26430fdc8d8SChris Lattner { 2656611103cSGreg Clayton m_opaque_sp = module_sp; 26630fdc8d8SChris Lattner } 26730fdc8d8SChris Lattner 268cac9c5f9SGreg Clayton SBAddress 269cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 27009960031SGreg Clayton { 271cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 272c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 273c2ff9318SGreg Clayton if (module_sp) 274cac9c5f9SGreg Clayton { 275cac9c5f9SGreg Clayton Address addr; 276c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 277cac9c5f9SGreg Clayton sb_addr.ref() = addr; 278cac9c5f9SGreg Clayton } 279cac9c5f9SGreg Clayton return sb_addr; 28009960031SGreg Clayton } 28109960031SGreg Clayton 28209960031SGreg Clayton SBSymbolContext 28309960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 28409960031SGreg Clayton { 28509960031SGreg Clayton SBSymbolContext sb_sc; 286c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 287c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 288c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 28909960031SGreg Clayton return sb_sc; 29009960031SGreg Clayton } 29109960031SGreg Clayton 292dde9cff3SCaroline Tice bool 293dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 294dde9cff3SCaroline Tice { 295da7bc7d0SGreg Clayton Stream &strm = description.ref(); 296da7bc7d0SGreg Clayton 297c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 298c2ff9318SGreg Clayton if (module_sp) 299dde9cff3SCaroline Tice { 300c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 301dde9cff3SCaroline Tice } 302dde9cff3SCaroline Tice else 303da7bc7d0SGreg Clayton strm.PutCString ("No value"); 304dde9cff3SCaroline Tice 305dde9cff3SCaroline Tice return true; 306dde9cff3SCaroline Tice } 307bbdabce2SGreg Clayton 308873a7a4bSJohnny Chen uint32_t 309873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 310873a7a4bSJohnny Chen { 311873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 312873a7a4bSJohnny Chen if (module_sp) 313873a7a4bSJohnny Chen { 314873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 315873a7a4bSJohnny Chen } 316873a7a4bSJohnny Chen return 0; 317873a7a4bSJohnny Chen } 318873a7a4bSJohnny Chen 319873a7a4bSJohnny Chen SBCompileUnit 320873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 321873a7a4bSJohnny Chen { 322873a7a4bSJohnny Chen SBCompileUnit sb_cu; 323873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 324873a7a4bSJohnny Chen if (module_sp) 325873a7a4bSJohnny Chen { 326873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 327873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 328873a7a4bSJohnny Chen } 329873a7a4bSJohnny Chen return sb_cu; 330873a7a4bSJohnny Chen } 331873a7a4bSJohnny Chen 332a7499c98SMichael Sartain static Symtab * 333a7499c98SMichael Sartain GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp) 334a7499c98SMichael Sartain { 335a7499c98SMichael Sartain if (module_sp) 336a7499c98SMichael Sartain { 337a7499c98SMichael Sartain SymbolVendor *symbols = module_sp->GetSymbolVendor(); 338a7499c98SMichael Sartain if (symbols) 339a7499c98SMichael Sartain return symbols->GetSymtab(); 340a7499c98SMichael Sartain } 341a7499c98SMichael Sartain return NULL; 342a7499c98SMichael Sartain } 343a7499c98SMichael Sartain 344bbdabce2SGreg Clayton size_t 345bbdabce2SGreg Clayton SBModule::GetNumSymbols () 346bbdabce2SGreg Clayton { 347c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 348c2ff9318SGreg Clayton if (module_sp) 349bbdabce2SGreg Clayton { 350a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 351bbdabce2SGreg Clayton if (symtab) 352bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 353bbdabce2SGreg Clayton } 354bbdabce2SGreg Clayton return 0; 355bbdabce2SGreg Clayton } 356bbdabce2SGreg Clayton 357bbdabce2SGreg Clayton SBSymbol 358bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 359bbdabce2SGreg Clayton { 360bbdabce2SGreg Clayton SBSymbol sb_symbol; 361c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 362a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 363bbdabce2SGreg Clayton if (symtab) 364bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 365bbdabce2SGreg Clayton return sb_symbol; 366bbdabce2SGreg Clayton } 367fe356d35SGreg Clayton 368e14e1925SGreg Clayton lldb::SBSymbol 369e14e1925SGreg Clayton SBModule::FindSymbol (const char *name, 370e14e1925SGreg Clayton lldb::SymbolType symbol_type) 371e14e1925SGreg Clayton { 372e14e1925SGreg Clayton SBSymbol sb_symbol; 373e14e1925SGreg Clayton if (name && name[0]) 374e14e1925SGreg Clayton { 375e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 376a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 377e14e1925SGreg Clayton if (symtab) 378e14e1925SGreg Clayton sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); 379e14e1925SGreg Clayton } 380e14e1925SGreg Clayton return sb_symbol; 381e14e1925SGreg Clayton } 382e14e1925SGreg Clayton 383e14e1925SGreg Clayton 384e14e1925SGreg Clayton lldb::SBSymbolContextList 385e14e1925SGreg Clayton SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type) 386e14e1925SGreg Clayton { 387e14e1925SGreg Clayton SBSymbolContextList sb_sc_list; 388e14e1925SGreg Clayton if (name && name[0]) 389e14e1925SGreg Clayton { 390e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 391a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 392e14e1925SGreg Clayton if (symtab) 393e14e1925SGreg Clayton { 394e14e1925SGreg Clayton std::vector<uint32_t> matching_symbol_indexes; 395e14e1925SGreg Clayton const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); 396e14e1925SGreg Clayton if (num_matches) 397e14e1925SGreg Clayton { 398e14e1925SGreg Clayton SymbolContext sc; 399e14e1925SGreg Clayton sc.module_sp = module_sp; 400e14e1925SGreg Clayton SymbolContextList &sc_list = *sb_sc_list; 401e14e1925SGreg Clayton for (size_t i=0; i<num_matches; ++i) 402e14e1925SGreg Clayton { 403e14e1925SGreg Clayton sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]); 404e14e1925SGreg Clayton if (sc.symbol) 405e14e1925SGreg Clayton sc_list.Append(sc); 406e14e1925SGreg Clayton } 407e14e1925SGreg Clayton } 408e14e1925SGreg Clayton } 409e14e1925SGreg Clayton } 410e14e1925SGreg Clayton return sb_sc_list; 411e14e1925SGreg Clayton 412e14e1925SGreg Clayton } 413e14e1925SGreg Clayton 414e14e1925SGreg Clayton 415e14e1925SGreg Clayton 416cac9c5f9SGreg Clayton size_t 417cac9c5f9SGreg Clayton SBModule::GetNumSections () 418cac9c5f9SGreg Clayton { 419c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 420c2ff9318SGreg Clayton if (module_sp) 421cac9c5f9SGreg Clayton { 422a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 423a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4243046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 425cac9c5f9SGreg Clayton if (section_list) 426cac9c5f9SGreg Clayton return section_list->GetSize(); 427cac9c5f9SGreg Clayton } 428cac9c5f9SGreg Clayton return 0; 429cac9c5f9SGreg Clayton } 430cac9c5f9SGreg Clayton 431cac9c5f9SGreg Clayton SBSection 432cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 433cac9c5f9SGreg Clayton { 434cac9c5f9SGreg Clayton SBSection sb_section; 435c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 436c2ff9318SGreg Clayton if (module_sp) 437cac9c5f9SGreg Clayton { 438a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 439a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4403046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList (); 441cac9c5f9SGreg Clayton 442cac9c5f9SGreg Clayton if (section_list) 443e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 444cac9c5f9SGreg Clayton } 445cac9c5f9SGreg Clayton return sb_section; 446cac9c5f9SGreg Clayton } 447cac9c5f9SGreg Clayton 4485569e64eSGreg Clayton lldb::SBSymbolContextList 449fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 4505569e64eSGreg Clayton uint32_t name_type_mask) 451fe356d35SGreg Clayton { 4525569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 453c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 454c2ff9318SGreg Clayton if (name && module_sp) 455fe356d35SGreg Clayton { 4565569e64eSGreg Clayton const bool append = true; 457fe356d35SGreg Clayton const bool symbols_ok = true; 4589df05fbbSSean Callanan const bool inlines_ok = true; 459c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 460b6d70ebcSSean Callanan NULL, 461fe356d35SGreg Clayton name_type_mask, 462fe356d35SGreg Clayton symbols_ok, 4639df05fbbSSean Callanan inlines_ok, 464fe356d35SGreg Clayton append, 4655569e64eSGreg Clayton *sb_sc_list); 466fe356d35SGreg Clayton } 4675569e64eSGreg Clayton return sb_sc_list; 468fe356d35SGreg Clayton } 469fe356d35SGreg Clayton 470dea8cb4fSGreg Clayton 471dea8cb4fSGreg Clayton SBValueList 472dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 473dea8cb4fSGreg Clayton { 474dea8cb4fSGreg Clayton SBValueList sb_value_list; 475c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 476c2ff9318SGreg Clayton if (name && module_sp) 477dea8cb4fSGreg Clayton { 478dea8cb4fSGreg Clayton VariableList variable_list; 479c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 480b6d70ebcSSean Callanan NULL, 481dea8cb4fSGreg Clayton false, 482dea8cb4fSGreg Clayton max_matches, 483dea8cb4fSGreg Clayton variable_list); 484dea8cb4fSGreg Clayton 485dea8cb4fSGreg Clayton if (match_count > 0) 486dea8cb4fSGreg Clayton { 487dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 488dea8cb4fSGreg Clayton { 489dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 490b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 491b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 492dea8cb4fSGreg Clayton if (valobj_sp) 49385425d77SEnrico Granata sb_value_list.Append(SBValue(valobj_sp)); 494dea8cb4fSGreg Clayton } 495dea8cb4fSGreg Clayton } 496dea8cb4fSGreg Clayton } 497dea8cb4fSGreg Clayton 498dea8cb4fSGreg Clayton return sb_value_list; 499dea8cb4fSGreg Clayton } 5006f3533fbSEnrico Granata 501bcd80b47SEnrico Granata lldb::SBValue 502bcd80b47SEnrico Granata SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name) 503bcd80b47SEnrico Granata { 504bcd80b47SEnrico Granata SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 505bcd80b47SEnrico Granata if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 506bcd80b47SEnrico Granata return sb_value_list.GetValueAtIndex(0); 507bcd80b47SEnrico Granata return SBValue(); 508bcd80b47SEnrico Granata } 509bcd80b47SEnrico Granata 5106f3533fbSEnrico Granata lldb::SBType 5116f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 5126f3533fbSEnrico Granata { 513fe42ac4dSGreg Clayton SBType sb_type; 514c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 515c2ff9318SGreg Clayton if (name_cstr && module_sp) 516fe42ac4dSGreg Clayton { 5176f3533fbSEnrico Granata SymbolContext sc; 51884db9105SGreg Clayton const bool exact_match = false; 5196f3533fbSEnrico Granata ConstString name(name_cstr); 5206f3533fbSEnrico Granata 521b43165b7SGreg Clayton sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match)); 5226f3533fbSEnrico Granata 523b43165b7SGreg Clayton if (!sb_type.IsValid()) 52457ee3067SGreg Clayton sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 5256f3533fbSEnrico Granata } 526fe42ac4dSGreg Clayton return sb_type; 5276f3533fbSEnrico Granata } 5286f3533fbSEnrico Granata 529b43165b7SGreg Clayton lldb::SBType 530b43165b7SGreg Clayton SBModule::GetBasicType(lldb::BasicType type) 531b43165b7SGreg Clayton { 532b43165b7SGreg Clayton ModuleSP module_sp (GetSP ()); 533b43165b7SGreg Clayton if (module_sp) 53457ee3067SGreg Clayton return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type)); 535b43165b7SGreg Clayton return SBType(); 536b43165b7SGreg Clayton } 537b43165b7SGreg Clayton 5386f3533fbSEnrico Granata lldb::SBTypeList 5396f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 5406f3533fbSEnrico Granata { 5416f3533fbSEnrico Granata SBTypeList retval; 5426f3533fbSEnrico Granata 543c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 544c2ff9318SGreg Clayton if (type && module_sp) 545fe42ac4dSGreg Clayton { 5466f3533fbSEnrico Granata SymbolContext sc; 5476f3533fbSEnrico Granata TypeList type_list; 54884db9105SGreg Clayton const bool exact_match = false; 5496f3533fbSEnrico Granata ConstString name(type); 550b43165b7SGreg Clayton const uint32_t num_matches = module_sp->FindTypes (sc, 5516f3533fbSEnrico Granata name, 55284db9105SGreg Clayton exact_match, 5536f3533fbSEnrico Granata UINT32_MAX, 5546f3533fbSEnrico Granata type_list); 5556f3533fbSEnrico Granata 556b43165b7SGreg Clayton if (num_matches > 0) 557b43165b7SGreg Clayton { 5586f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 5596f3533fbSEnrico Granata { 560fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 561fe42ac4dSGreg Clayton if (type_sp) 562fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 563fe42ac4dSGreg Clayton } 5646f3533fbSEnrico Granata } 565b43165b7SGreg Clayton else 566b43165b7SGreg Clayton { 56757ee3067SGreg Clayton SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 568b43165b7SGreg Clayton if (sb_type.IsValid()) 569b43165b7SGreg Clayton retval.Append(sb_type); 570b43165b7SGreg Clayton } 571b43165b7SGreg Clayton } 5726f3533fbSEnrico Granata 5736f3533fbSEnrico Granata return retval; 5746f3533fbSEnrico Granata } 575cac9c5f9SGreg Clayton 5761f4db7daSGreg Clayton lldb::SBType 5771f4db7daSGreg Clayton SBModule::GetTypeByID (lldb::user_id_t uid) 5781f4db7daSGreg Clayton { 5791f4db7daSGreg Clayton ModuleSP module_sp (GetSP ()); 5801f4db7daSGreg Clayton if (module_sp) 5811f4db7daSGreg Clayton { 5821f4db7daSGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 5831f4db7daSGreg Clayton if (vendor) 5841f4db7daSGreg Clayton { 5851f4db7daSGreg Clayton Type *type_ptr = vendor->ResolveTypeUID(uid); 5861f4db7daSGreg Clayton if (type_ptr) 5871f4db7daSGreg Clayton return SBType(type_ptr->shared_from_this()); 5881f4db7daSGreg Clayton } 5891f4db7daSGreg Clayton } 5901f4db7daSGreg Clayton return SBType(); 5911f4db7daSGreg Clayton } 5921f4db7daSGreg Clayton 593f02500c7SGreg Clayton lldb::SBTypeList 594f02500c7SGreg Clayton SBModule::GetTypes (uint32_t type_mask) 595f02500c7SGreg Clayton { 596f02500c7SGreg Clayton SBTypeList sb_type_list; 597f02500c7SGreg Clayton 598f02500c7SGreg Clayton ModuleSP module_sp (GetSP ()); 599f02500c7SGreg Clayton if (module_sp) 600f02500c7SGreg Clayton { 601f02500c7SGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 602f02500c7SGreg Clayton if (vendor) 603f02500c7SGreg Clayton { 604f02500c7SGreg Clayton TypeList type_list; 605f02500c7SGreg Clayton vendor->GetTypes (NULL, type_mask, type_list); 606f02500c7SGreg Clayton sb_type_list.m_opaque_ap->Append(type_list); 607f02500c7SGreg Clayton } 608f02500c7SGreg Clayton } 609f02500c7SGreg Clayton return sb_type_list; 610f02500c7SGreg Clayton } 611cac9c5f9SGreg Clayton 612cac9c5f9SGreg Clayton SBSection 613cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 614cac9c5f9SGreg Clayton { 615cac9c5f9SGreg Clayton SBSection sb_section; 616cac9c5f9SGreg Clayton 617c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 618c2ff9318SGreg Clayton if (sect_name && module_sp) 619cac9c5f9SGreg Clayton { 620a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 621a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 6223046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 623cac9c5f9SGreg Clayton if (section_list) 624cac9c5f9SGreg Clayton { 625cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 626cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 627cac9c5f9SGreg Clayton if (section_sp) 628cac9c5f9SGreg Clayton { 629e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 630cac9c5f9SGreg Clayton } 631cac9c5f9SGreg Clayton } 632cac9c5f9SGreg Clayton } 633cac9c5f9SGreg Clayton return sb_section; 634cac9c5f9SGreg Clayton } 635cac9c5f9SGreg Clayton 63613d1950aSGreg Clayton lldb::ByteOrder 63713d1950aSGreg Clayton SBModule::GetByteOrder () 63813d1950aSGreg Clayton { 639c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 640c2ff9318SGreg Clayton if (module_sp) 641c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 64213d1950aSGreg Clayton return eByteOrderInvalid; 64313d1950aSGreg Clayton } 64413d1950aSGreg Clayton 64513d1950aSGreg Clayton const char * 64613d1950aSGreg Clayton SBModule::GetTriple () 64713d1950aSGreg Clayton { 648c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 649c2ff9318SGreg Clayton if (module_sp) 65013d1950aSGreg Clayton { 651c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 65213d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 65313d1950aSGreg Clayton // the const strings put the string into the string pool once and 65413d1950aSGreg Clayton // the strings never comes out 65513d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 65613d1950aSGreg Clayton return const_triple.GetCString(); 65713d1950aSGreg Clayton } 65813d1950aSGreg Clayton return NULL; 65913d1950aSGreg Clayton } 66013d1950aSGreg Clayton 66113d1950aSGreg Clayton uint32_t 66213d1950aSGreg Clayton SBModule::GetAddressByteSize() 66313d1950aSGreg Clayton { 664c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 665c2ff9318SGreg Clayton if (module_sp) 666c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 66713d1950aSGreg Clayton return sizeof(void*); 66813d1950aSGreg Clayton } 66913d1950aSGreg Clayton 670c2ff9318SGreg Clayton 671c2ff9318SGreg Clayton uint32_t 672c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 673c2ff9318SGreg Clayton { 674c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 675c2ff9318SGreg Clayton if (module_sp) 6763467d80bSEnrico Granata return module_sp->GetVersion(versions, num_versions); 6773467d80bSEnrico Granata else 678c2ff9318SGreg Clayton { 679c2ff9318SGreg Clayton if (versions && num_versions) 680c2ff9318SGreg Clayton { 681c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 682c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 683c2ff9318SGreg Clayton } 684c2ff9318SGreg Clayton return 0; 685c2ff9318SGreg Clayton } 6863467d80bSEnrico Granata } 687c2ff9318SGreg Clayton 688*eb2c19a5SIlia K lldb::SBFileSpec 689*eb2c19a5SIlia K SBModule::GetSymbolFileSpec() const 690*eb2c19a5SIlia K { 691*eb2c19a5SIlia K lldb::SBFileSpec sb_file_spec; 692*eb2c19a5SIlia K ModuleSP module_sp(GetSP()); 693*eb2c19a5SIlia K if (module_sp) 694*eb2c19a5SIlia K { 695*eb2c19a5SIlia K SymbolVendor *symbol_vendor_ptr = module_sp->GetSymbolVendor(); 696*eb2c19a5SIlia K if (symbol_vendor_ptr) 697*eb2c19a5SIlia K sb_file_spec.SetFileSpec(symbol_vendor_ptr->GetMainFileSpec()); 698*eb2c19a5SIlia K } 699*eb2c19a5SIlia K return sb_file_spec; 700*eb2c19a5SIlia K } 701*eb2c19a5SIlia K 702*eb2c19a5SIlia K lldb::SBAddress 703*eb2c19a5SIlia K SBModule::GetObjectFileHeaderAddress() const 704*eb2c19a5SIlia K { 705*eb2c19a5SIlia K lldb::SBAddress sb_addr; 706*eb2c19a5SIlia K ModuleSP module_sp (GetSP ()); 707*eb2c19a5SIlia K if (module_sp) 708*eb2c19a5SIlia K { 709*eb2c19a5SIlia K ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 710*eb2c19a5SIlia K if (objfile_ptr) 711*eb2c19a5SIlia K sb_addr.ref() = objfile_ptr->GetHeaderAddress(); 712*eb2c19a5SIlia K } 713*eb2c19a5SIlia K return sb_addr; 714*eb2c19a5SIlia K } 715