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" 231f746071SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 246f3533fbSEnrico Granata #include "lldb/Symbol/SymbolVendor.h" 251f746071SGreg Clayton #include "lldb/Symbol/Symtab.h" 26dea8cb4fSGreg Clayton #include "lldb/Symbol/VariableList.h" 27dea8cb4fSGreg Clayton #include "lldb/Target/Target.h" 2830fdc8d8SChris Lattner 2930fdc8d8SChris Lattner using namespace lldb; 30ceb6b139SCaroline Tice using namespace lldb_private; 3130fdc8d8SChris Lattner 3230fdc8d8SChris Lattner 3330fdc8d8SChris Lattner SBModule::SBModule () : 346611103cSGreg Clayton m_opaque_sp () 3530fdc8d8SChris Lattner { 3630fdc8d8SChris Lattner } 3730fdc8d8SChris Lattner 3830fdc8d8SChris Lattner SBModule::SBModule (const lldb::ModuleSP& module_sp) : 396611103cSGreg Clayton m_opaque_sp (module_sp) 4030fdc8d8SChris Lattner { 4130fdc8d8SChris Lattner } 4230fdc8d8SChris Lattner 43226cce25SGreg Clayton SBModule::SBModule(const SBModuleSpec &module_spec) : 44226cce25SGreg Clayton m_opaque_sp () 45226cce25SGreg Clayton { 46226cce25SGreg Clayton ModuleSP module_sp; 47226cce25SGreg Clayton Error error = ModuleList::GetSharedModule (*module_spec.m_opaque_ap, 48226cce25SGreg Clayton module_sp, 49226cce25SGreg Clayton NULL, 50226cce25SGreg Clayton NULL, 51226cce25SGreg Clayton NULL); 52226cce25SGreg Clayton if (module_sp) 53226cce25SGreg Clayton SetSP(module_sp); 54226cce25SGreg Clayton } 55226cce25SGreg Clayton 56efabb123SGreg Clayton SBModule::SBModule(const SBModule &rhs) : 57efabb123SGreg Clayton m_opaque_sp (rhs.m_opaque_sp) 58efabb123SGreg Clayton { 59efabb123SGreg Clayton } 60efabb123SGreg Clayton 61c9660546SGreg Clayton SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : 62c9660546SGreg Clayton m_opaque_sp () 63c9660546SGreg Clayton { 64c9660546SGreg Clayton ProcessSP process_sp (process.GetSP()); 65c9660546SGreg Clayton if (process_sp) 66c859e2d5SGreg Clayton { 6739f7ee86SGreg Clayton m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr); 6839f7ee86SGreg Clayton if (m_opaque_sp) 6939f7ee86SGreg Clayton { 7039f7ee86SGreg Clayton Target &target = process_sp->GetTarget(); 7139f7ee86SGreg Clayton bool changed = false; 72751caf65SGreg Clayton m_opaque_sp->SetLoadAddress(target, 0, true, changed); 7339f7ee86SGreg Clayton target.GetImages().Append(m_opaque_sp); 7439f7ee86SGreg Clayton } 75c859e2d5SGreg Clayton } 76c9660546SGreg Clayton } 77c9660546SGreg Clayton 78efabb123SGreg Clayton const SBModule & 79efabb123SGreg Clayton SBModule::operator = (const SBModule &rhs) 80efabb123SGreg Clayton { 81efabb123SGreg Clayton if (this != &rhs) 82efabb123SGreg Clayton m_opaque_sp = rhs.m_opaque_sp; 83efabb123SGreg Clayton return *this; 84efabb123SGreg Clayton } 85efabb123SGreg Clayton 8630fdc8d8SChris Lattner SBModule::~SBModule () 8730fdc8d8SChris Lattner { 8830fdc8d8SChris Lattner } 8930fdc8d8SChris Lattner 9030fdc8d8SChris Lattner bool 9130fdc8d8SChris Lattner SBModule::IsValid () const 9230fdc8d8SChris Lattner { 936611103cSGreg Clayton return m_opaque_sp.get() != NULL; 9430fdc8d8SChris Lattner } 9530fdc8d8SChris Lattner 965d3bca4eSJim Ingham void 975d3bca4eSJim Ingham SBModule::Clear() 985d3bca4eSJim Ingham { 995d3bca4eSJim Ingham m_opaque_sp.reset(); 1005d3bca4eSJim Ingham } 1015d3bca4eSJim Ingham 10230fdc8d8SChris Lattner SBFileSpec 10330fdc8d8SChris Lattner SBModule::GetFileSpec () const 10430fdc8d8SChris Lattner { 1055160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 106ceb6b139SCaroline Tice 10730fdc8d8SChris Lattner SBFileSpec file_spec; 108c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 109c2ff9318SGreg Clayton if (module_sp) 110c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetFileSpec()); 111ceb6b139SCaroline Tice 112ceb6b139SCaroline Tice if (log) 113cfd1acedSGreg Clayton log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 114324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 115324a1036SSaleem Abdulrasool static_cast<const void*>(file_spec.get())); 116ceb6b139SCaroline Tice 11730fdc8d8SChris Lattner return file_spec; 11830fdc8d8SChris Lattner } 11930fdc8d8SChris Lattner 1202289fa48SGreg Clayton lldb::SBFileSpec 1212289fa48SGreg Clayton SBModule::GetPlatformFileSpec () const 1222289fa48SGreg Clayton { 1235160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1242289fa48SGreg Clayton 1252289fa48SGreg Clayton SBFileSpec file_spec; 126c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 127c2ff9318SGreg Clayton if (module_sp) 128c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 1292289fa48SGreg Clayton 1302289fa48SGreg Clayton if (log) 1312289fa48SGreg Clayton log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 132324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 133324a1036SSaleem Abdulrasool static_cast<const void*>(file_spec.get())); 1342289fa48SGreg Clayton 1352289fa48SGreg Clayton return file_spec; 1362289fa48SGreg Clayton } 1372289fa48SGreg Clayton 1382289fa48SGreg Clayton bool 1392289fa48SGreg Clayton SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 1402289fa48SGreg Clayton { 1412289fa48SGreg Clayton bool result = false; 1425160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1432289fa48SGreg Clayton 144c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 145c2ff9318SGreg Clayton if (module_sp) 1462289fa48SGreg Clayton { 147c2ff9318SGreg Clayton module_sp->SetPlatformFileSpec(*platform_file); 1482289fa48SGreg Clayton result = true; 1492289fa48SGreg Clayton } 1502289fa48SGreg Clayton 1512289fa48SGreg Clayton if (log) 152b5ad4ec7SGreg Clayton log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i", 153324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 154324a1036SSaleem Abdulrasool static_cast<const void*>(platform_file.get()), 155324a1036SSaleem Abdulrasool platform_file->GetPath().c_str(), result); 1562289fa48SGreg Clayton return result; 1572289fa48SGreg Clayton } 1582289fa48SGreg Clayton 159fbb76349SGreg Clayton lldb::SBFileSpec 160fbb76349SGreg Clayton SBModule::GetRemoteInstallFileSpec () 161fbb76349SGreg Clayton { 162fbb76349SGreg Clayton SBFileSpec sb_file_spec; 163fbb76349SGreg Clayton ModuleSP module_sp (GetSP ()); 164fbb76349SGreg Clayton if (module_sp) 165fbb76349SGreg Clayton sb_file_spec.SetFileSpec (module_sp->GetRemoteInstallFileSpec()); 166fbb76349SGreg Clayton return sb_file_spec; 167fbb76349SGreg Clayton } 168fbb76349SGreg Clayton 169fbb76349SGreg Clayton bool 170fbb76349SGreg Clayton SBModule::SetRemoteInstallFileSpec (lldb::SBFileSpec &file) 171fbb76349SGreg Clayton { 172fbb76349SGreg Clayton ModuleSP module_sp (GetSP ()); 173fbb76349SGreg Clayton if (module_sp) 174fbb76349SGreg Clayton { 175fbb76349SGreg Clayton module_sp->SetRemoteInstallFileSpec(file.ref()); 176fbb76349SGreg Clayton return true; 177fbb76349SGreg Clayton } 178fbb76349SGreg Clayton return false; 179fbb76349SGreg Clayton } 1802289fa48SGreg Clayton 1812289fa48SGreg Clayton 18230fdc8d8SChris Lattner const uint8_t * 18330fdc8d8SChris Lattner SBModule::GetUUIDBytes () const 18430fdc8d8SChris Lattner { 1855160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 186ceb6b139SCaroline Tice 1874838131bSGreg Clayton const uint8_t *uuid_bytes = NULL; 188c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 189c2ff9318SGreg Clayton if (module_sp) 190c2ff9318SGreg Clayton uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 191ceb6b139SCaroline Tice 192ceb6b139SCaroline Tice if (log) 1934838131bSGreg Clayton { 1944838131bSGreg Clayton if (uuid_bytes) 1954838131bSGreg Clayton { 1964838131bSGreg Clayton StreamString s; 197c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 198324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", 199324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), s.GetData()); 2004838131bSGreg Clayton } 2014838131bSGreg Clayton else 202324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", 203324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get())); 2044838131bSGreg Clayton } 2054838131bSGreg Clayton return uuid_bytes; 20630fdc8d8SChris Lattner } 20730fdc8d8SChris Lattner 20830fdc8d8SChris Lattner 209df2963edSJohnny Chen const char * 210df2963edSJohnny Chen SBModule::GetUUIDString () const 211df2963edSJohnny Chen { 2125160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 213df2963edSJohnny Chen 214*f1be855aSGreg Clayton const char *uuid_cstr = NULL; 215c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 216c2ff9318SGreg Clayton if (module_sp) 217c16b4af0SJason Molenda { 218*f1be855aSGreg Clayton // We are going to return a "const char *" value through the public 219*f1be855aSGreg Clayton // API, so we need to constify it so it gets added permanently the the 220*f1be855aSGreg Clayton // string pool and then we don't need to worry about the lifetime of the 221*f1be855aSGreg Clayton // string as it will never go away once it has been put into the ConstString 222*f1be855aSGreg Clayton // string pool 223*f1be855aSGreg Clayton uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString(); 224*f1be855aSGreg Clayton } 225*f1be855aSGreg Clayton 226*f1be855aSGreg Clayton if (uuid_cstr && uuid_cstr[0]) 227*f1be855aSGreg Clayton { 228*f1be855aSGreg Clayton if (log) 229*f1be855aSGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => %s", static_cast<void*>(module_sp.get()), uuid_cstr); 230*f1be855aSGreg Clayton return uuid_cstr; 231c16b4af0SJason Molenda } 232df2963edSJohnny Chen 233df2963edSJohnny Chen if (log) 234*f1be855aSGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => NULL", static_cast<void*>(module_sp.get())); 235*f1be855aSGreg Clayton return NULL; 236df2963edSJohnny Chen } 237df2963edSJohnny Chen 238df2963edSJohnny Chen 23930fdc8d8SChris Lattner bool 24030fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 24130fdc8d8SChris Lattner { 2426611103cSGreg Clayton if (m_opaque_sp) 2436611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 24430fdc8d8SChris Lattner return false; 24530fdc8d8SChris Lattner } 24630fdc8d8SChris Lattner 24730fdc8d8SChris Lattner bool 24830fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 24930fdc8d8SChris Lattner { 2506611103cSGreg Clayton if (m_opaque_sp) 2516611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 25230fdc8d8SChris Lattner return false; 25330fdc8d8SChris Lattner } 25430fdc8d8SChris Lattner 255acdbe816SGreg Clayton ModuleSP 256acdbe816SGreg Clayton SBModule::GetSP () const 257cac9c5f9SGreg Clayton { 258cac9c5f9SGreg Clayton return m_opaque_sp; 259cac9c5f9SGreg Clayton } 26030fdc8d8SChris Lattner 26130fdc8d8SChris Lattner void 262acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 26330fdc8d8SChris Lattner { 2646611103cSGreg Clayton m_opaque_sp = module_sp; 26530fdc8d8SChris Lattner } 26630fdc8d8SChris Lattner 267cac9c5f9SGreg Clayton SBAddress 268cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 26909960031SGreg Clayton { 270cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 271c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 272c2ff9318SGreg Clayton if (module_sp) 273cac9c5f9SGreg Clayton { 274cac9c5f9SGreg Clayton Address addr; 275c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 276cac9c5f9SGreg Clayton sb_addr.ref() = addr; 277cac9c5f9SGreg Clayton } 278cac9c5f9SGreg Clayton return sb_addr; 27909960031SGreg Clayton } 28009960031SGreg Clayton 28109960031SGreg Clayton SBSymbolContext 28209960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 28309960031SGreg Clayton { 28409960031SGreg Clayton SBSymbolContext sb_sc; 285c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 286c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 287c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 28809960031SGreg Clayton return sb_sc; 28909960031SGreg Clayton } 29009960031SGreg Clayton 291dde9cff3SCaroline Tice bool 292dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 293dde9cff3SCaroline Tice { 294da7bc7d0SGreg Clayton Stream &strm = description.ref(); 295da7bc7d0SGreg Clayton 296c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 297c2ff9318SGreg Clayton if (module_sp) 298dde9cff3SCaroline Tice { 299c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 300dde9cff3SCaroline Tice } 301dde9cff3SCaroline Tice else 302da7bc7d0SGreg Clayton strm.PutCString ("No value"); 303dde9cff3SCaroline Tice 304dde9cff3SCaroline Tice return true; 305dde9cff3SCaroline Tice } 306bbdabce2SGreg Clayton 307873a7a4bSJohnny Chen uint32_t 308873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 309873a7a4bSJohnny Chen { 310873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 311873a7a4bSJohnny Chen if (module_sp) 312873a7a4bSJohnny Chen { 313873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 314873a7a4bSJohnny Chen } 315873a7a4bSJohnny Chen return 0; 316873a7a4bSJohnny Chen } 317873a7a4bSJohnny Chen 318873a7a4bSJohnny Chen SBCompileUnit 319873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 320873a7a4bSJohnny Chen { 321873a7a4bSJohnny Chen SBCompileUnit sb_cu; 322873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 323873a7a4bSJohnny Chen if (module_sp) 324873a7a4bSJohnny Chen { 325873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 326873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 327873a7a4bSJohnny Chen } 328873a7a4bSJohnny Chen return sb_cu; 329873a7a4bSJohnny Chen } 330873a7a4bSJohnny Chen 331a7499c98SMichael Sartain static Symtab * 332a7499c98SMichael Sartain GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp) 333a7499c98SMichael Sartain { 334a7499c98SMichael Sartain if (module_sp) 335a7499c98SMichael Sartain { 336a7499c98SMichael Sartain SymbolVendor *symbols = module_sp->GetSymbolVendor(); 337a7499c98SMichael Sartain if (symbols) 338a7499c98SMichael Sartain return symbols->GetSymtab(); 339a7499c98SMichael Sartain } 340a7499c98SMichael Sartain return NULL; 341a7499c98SMichael Sartain } 342a7499c98SMichael Sartain 343bbdabce2SGreg Clayton size_t 344bbdabce2SGreg Clayton SBModule::GetNumSymbols () 345bbdabce2SGreg Clayton { 346c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 347c2ff9318SGreg Clayton if (module_sp) 348bbdabce2SGreg Clayton { 349a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 350bbdabce2SGreg Clayton if (symtab) 351bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 352bbdabce2SGreg Clayton } 353bbdabce2SGreg Clayton return 0; 354bbdabce2SGreg Clayton } 355bbdabce2SGreg Clayton 356bbdabce2SGreg Clayton SBSymbol 357bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 358bbdabce2SGreg Clayton { 359bbdabce2SGreg Clayton SBSymbol sb_symbol; 360c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 361a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 362bbdabce2SGreg Clayton if (symtab) 363bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 364bbdabce2SGreg Clayton return sb_symbol; 365bbdabce2SGreg Clayton } 366fe356d35SGreg Clayton 367e14e1925SGreg Clayton lldb::SBSymbol 368e14e1925SGreg Clayton SBModule::FindSymbol (const char *name, 369e14e1925SGreg Clayton lldb::SymbolType symbol_type) 370e14e1925SGreg Clayton { 371e14e1925SGreg Clayton SBSymbol sb_symbol; 372e14e1925SGreg Clayton if (name && name[0]) 373e14e1925SGreg Clayton { 374e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 375a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 376e14e1925SGreg Clayton if (symtab) 377e14e1925SGreg Clayton sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); 378e14e1925SGreg Clayton } 379e14e1925SGreg Clayton return sb_symbol; 380e14e1925SGreg Clayton } 381e14e1925SGreg Clayton 382e14e1925SGreg Clayton 383e14e1925SGreg Clayton lldb::SBSymbolContextList 384e14e1925SGreg Clayton SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type) 385e14e1925SGreg Clayton { 386e14e1925SGreg Clayton SBSymbolContextList sb_sc_list; 387e14e1925SGreg Clayton if (name && name[0]) 388e14e1925SGreg Clayton { 389e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 390a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 391e14e1925SGreg Clayton if (symtab) 392e14e1925SGreg Clayton { 393e14e1925SGreg Clayton std::vector<uint32_t> matching_symbol_indexes; 394e14e1925SGreg Clayton const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); 395e14e1925SGreg Clayton if (num_matches) 396e14e1925SGreg Clayton { 397e14e1925SGreg Clayton SymbolContext sc; 398e14e1925SGreg Clayton sc.module_sp = module_sp; 399e14e1925SGreg Clayton SymbolContextList &sc_list = *sb_sc_list; 400e14e1925SGreg Clayton for (size_t i=0; i<num_matches; ++i) 401e14e1925SGreg Clayton { 402e14e1925SGreg Clayton sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]); 403e14e1925SGreg Clayton if (sc.symbol) 404e14e1925SGreg Clayton sc_list.Append(sc); 405e14e1925SGreg Clayton } 406e14e1925SGreg Clayton } 407e14e1925SGreg Clayton } 408e14e1925SGreg Clayton } 409e14e1925SGreg Clayton return sb_sc_list; 410e14e1925SGreg Clayton 411e14e1925SGreg Clayton } 412e14e1925SGreg Clayton 413e14e1925SGreg Clayton 414e14e1925SGreg Clayton 415cac9c5f9SGreg Clayton size_t 416cac9c5f9SGreg Clayton SBModule::GetNumSections () 417cac9c5f9SGreg Clayton { 418c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 419c2ff9318SGreg Clayton if (module_sp) 420cac9c5f9SGreg Clayton { 421a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 422a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4233046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 424cac9c5f9SGreg Clayton if (section_list) 425cac9c5f9SGreg Clayton return section_list->GetSize(); 426cac9c5f9SGreg Clayton } 427cac9c5f9SGreg Clayton return 0; 428cac9c5f9SGreg Clayton } 429cac9c5f9SGreg Clayton 430cac9c5f9SGreg Clayton SBSection 431cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 432cac9c5f9SGreg Clayton { 433cac9c5f9SGreg Clayton SBSection sb_section; 434c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 435c2ff9318SGreg Clayton if (module_sp) 436cac9c5f9SGreg Clayton { 437a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 438a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4393046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList (); 440cac9c5f9SGreg Clayton 441cac9c5f9SGreg Clayton if (section_list) 442e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 443cac9c5f9SGreg Clayton } 444cac9c5f9SGreg Clayton return sb_section; 445cac9c5f9SGreg Clayton } 446cac9c5f9SGreg Clayton 4475569e64eSGreg Clayton lldb::SBSymbolContextList 448fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 4495569e64eSGreg Clayton uint32_t name_type_mask) 450fe356d35SGreg Clayton { 4515569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 452c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 453c2ff9318SGreg Clayton if (name && module_sp) 454fe356d35SGreg Clayton { 4555569e64eSGreg Clayton const bool append = true; 456fe356d35SGreg Clayton const bool symbols_ok = true; 4579df05fbbSSean Callanan const bool inlines_ok = true; 458c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 459b6d70ebcSSean Callanan NULL, 460fe356d35SGreg Clayton name_type_mask, 461fe356d35SGreg Clayton symbols_ok, 4629df05fbbSSean Callanan inlines_ok, 463fe356d35SGreg Clayton append, 4645569e64eSGreg Clayton *sb_sc_list); 465fe356d35SGreg Clayton } 4665569e64eSGreg Clayton return sb_sc_list; 467fe356d35SGreg Clayton } 468fe356d35SGreg Clayton 469dea8cb4fSGreg Clayton 470dea8cb4fSGreg Clayton SBValueList 471dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 472dea8cb4fSGreg Clayton { 473dea8cb4fSGreg Clayton SBValueList sb_value_list; 474c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 475c2ff9318SGreg Clayton if (name && module_sp) 476dea8cb4fSGreg Clayton { 477dea8cb4fSGreg Clayton VariableList variable_list; 478c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 479b6d70ebcSSean Callanan NULL, 480dea8cb4fSGreg Clayton false, 481dea8cb4fSGreg Clayton max_matches, 482dea8cb4fSGreg Clayton variable_list); 483dea8cb4fSGreg Clayton 484dea8cb4fSGreg Clayton if (match_count > 0) 485dea8cb4fSGreg Clayton { 486dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 487dea8cb4fSGreg Clayton { 488dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 489b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 490b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 491dea8cb4fSGreg Clayton if (valobj_sp) 49285425d77SEnrico Granata sb_value_list.Append(SBValue(valobj_sp)); 493dea8cb4fSGreg Clayton } 494dea8cb4fSGreg Clayton } 495dea8cb4fSGreg Clayton } 496dea8cb4fSGreg Clayton 497dea8cb4fSGreg Clayton return sb_value_list; 498dea8cb4fSGreg Clayton } 4996f3533fbSEnrico Granata 500bcd80b47SEnrico Granata lldb::SBValue 501bcd80b47SEnrico Granata SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name) 502bcd80b47SEnrico Granata { 503bcd80b47SEnrico Granata SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 504bcd80b47SEnrico Granata if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 505bcd80b47SEnrico Granata return sb_value_list.GetValueAtIndex(0); 506bcd80b47SEnrico Granata return SBValue(); 507bcd80b47SEnrico Granata } 508bcd80b47SEnrico Granata 5096f3533fbSEnrico Granata lldb::SBType 5106f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 5116f3533fbSEnrico Granata { 512fe42ac4dSGreg Clayton SBType sb_type; 513c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 514c2ff9318SGreg Clayton if (name_cstr && module_sp) 515fe42ac4dSGreg Clayton { 5166f3533fbSEnrico Granata SymbolContext sc; 51784db9105SGreg Clayton const bool exact_match = false; 5186f3533fbSEnrico Granata ConstString name(name_cstr); 5196f3533fbSEnrico Granata 520b43165b7SGreg Clayton sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match)); 5216f3533fbSEnrico Granata 522b43165b7SGreg Clayton if (!sb_type.IsValid()) 52357ee3067SGreg Clayton sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 5246f3533fbSEnrico Granata } 525fe42ac4dSGreg Clayton return sb_type; 5266f3533fbSEnrico Granata } 5276f3533fbSEnrico Granata 528b43165b7SGreg Clayton lldb::SBType 529b43165b7SGreg Clayton SBModule::GetBasicType(lldb::BasicType type) 530b43165b7SGreg Clayton { 531b43165b7SGreg Clayton ModuleSP module_sp (GetSP ()); 532b43165b7SGreg Clayton if (module_sp) 53357ee3067SGreg Clayton return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type)); 534b43165b7SGreg Clayton return SBType(); 535b43165b7SGreg Clayton } 536b43165b7SGreg Clayton 5376f3533fbSEnrico Granata lldb::SBTypeList 5386f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 5396f3533fbSEnrico Granata { 5406f3533fbSEnrico Granata SBTypeList retval; 5416f3533fbSEnrico Granata 542c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 543c2ff9318SGreg Clayton if (type && module_sp) 544fe42ac4dSGreg Clayton { 5456f3533fbSEnrico Granata SymbolContext sc; 5466f3533fbSEnrico Granata TypeList type_list; 54784db9105SGreg Clayton const bool exact_match = false; 5486f3533fbSEnrico Granata ConstString name(type); 549b43165b7SGreg Clayton const uint32_t num_matches = module_sp->FindTypes (sc, 5506f3533fbSEnrico Granata name, 55184db9105SGreg Clayton exact_match, 5526f3533fbSEnrico Granata UINT32_MAX, 5536f3533fbSEnrico Granata type_list); 5546f3533fbSEnrico Granata 555b43165b7SGreg Clayton if (num_matches > 0) 556b43165b7SGreg Clayton { 5576f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 5586f3533fbSEnrico Granata { 559fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 560fe42ac4dSGreg Clayton if (type_sp) 561fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 562fe42ac4dSGreg Clayton } 5636f3533fbSEnrico Granata } 564b43165b7SGreg Clayton else 565b43165b7SGreg Clayton { 56657ee3067SGreg Clayton SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 567b43165b7SGreg Clayton if (sb_type.IsValid()) 568b43165b7SGreg Clayton retval.Append(sb_type); 569b43165b7SGreg Clayton } 570b43165b7SGreg Clayton } 5716f3533fbSEnrico Granata 5726f3533fbSEnrico Granata return retval; 5736f3533fbSEnrico Granata } 574cac9c5f9SGreg Clayton 5751f4db7daSGreg Clayton lldb::SBType 5761f4db7daSGreg Clayton SBModule::GetTypeByID (lldb::user_id_t uid) 5771f4db7daSGreg Clayton { 5781f4db7daSGreg Clayton ModuleSP module_sp (GetSP ()); 5791f4db7daSGreg Clayton if (module_sp) 5801f4db7daSGreg Clayton { 5811f4db7daSGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 5821f4db7daSGreg Clayton if (vendor) 5831f4db7daSGreg Clayton { 5841f4db7daSGreg Clayton Type *type_ptr = vendor->ResolveTypeUID(uid); 5851f4db7daSGreg Clayton if (type_ptr) 5861f4db7daSGreg Clayton return SBType(type_ptr->shared_from_this()); 5871f4db7daSGreg Clayton } 5881f4db7daSGreg Clayton } 5891f4db7daSGreg Clayton return SBType(); 5901f4db7daSGreg Clayton } 5911f4db7daSGreg Clayton 592f02500c7SGreg Clayton lldb::SBTypeList 593f02500c7SGreg Clayton SBModule::GetTypes (uint32_t type_mask) 594f02500c7SGreg Clayton { 595f02500c7SGreg Clayton SBTypeList sb_type_list; 596f02500c7SGreg Clayton 597f02500c7SGreg Clayton ModuleSP module_sp (GetSP ()); 598f02500c7SGreg Clayton if (module_sp) 599f02500c7SGreg Clayton { 600f02500c7SGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 601f02500c7SGreg Clayton if (vendor) 602f02500c7SGreg Clayton { 603f02500c7SGreg Clayton TypeList type_list; 604f02500c7SGreg Clayton vendor->GetTypes (NULL, type_mask, type_list); 605f02500c7SGreg Clayton sb_type_list.m_opaque_ap->Append(type_list); 606f02500c7SGreg Clayton } 607f02500c7SGreg Clayton } 608f02500c7SGreg Clayton return sb_type_list; 609f02500c7SGreg Clayton } 610cac9c5f9SGreg Clayton 611cac9c5f9SGreg Clayton SBSection 612cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 613cac9c5f9SGreg Clayton { 614cac9c5f9SGreg Clayton SBSection sb_section; 615cac9c5f9SGreg Clayton 616c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 617c2ff9318SGreg Clayton if (sect_name && module_sp) 618cac9c5f9SGreg Clayton { 619a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 620a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 6213046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 622cac9c5f9SGreg Clayton if (section_list) 623cac9c5f9SGreg Clayton { 624cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 625cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 626cac9c5f9SGreg Clayton if (section_sp) 627cac9c5f9SGreg Clayton { 628e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 629cac9c5f9SGreg Clayton } 630cac9c5f9SGreg Clayton } 631cac9c5f9SGreg Clayton } 632cac9c5f9SGreg Clayton return sb_section; 633cac9c5f9SGreg Clayton } 634cac9c5f9SGreg Clayton 63513d1950aSGreg Clayton lldb::ByteOrder 63613d1950aSGreg Clayton SBModule::GetByteOrder () 63713d1950aSGreg Clayton { 638c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 639c2ff9318SGreg Clayton if (module_sp) 640c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 64113d1950aSGreg Clayton return eByteOrderInvalid; 64213d1950aSGreg Clayton } 64313d1950aSGreg Clayton 64413d1950aSGreg Clayton const char * 64513d1950aSGreg Clayton SBModule::GetTriple () 64613d1950aSGreg Clayton { 647c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 648c2ff9318SGreg Clayton if (module_sp) 64913d1950aSGreg Clayton { 650c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 65113d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 65213d1950aSGreg Clayton // the const strings put the string into the string pool once and 65313d1950aSGreg Clayton // the strings never comes out 65413d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 65513d1950aSGreg Clayton return const_triple.GetCString(); 65613d1950aSGreg Clayton } 65713d1950aSGreg Clayton return NULL; 65813d1950aSGreg Clayton } 65913d1950aSGreg Clayton 66013d1950aSGreg Clayton uint32_t 66113d1950aSGreg Clayton SBModule::GetAddressByteSize() 66213d1950aSGreg Clayton { 663c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 664c2ff9318SGreg Clayton if (module_sp) 665c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 66613d1950aSGreg Clayton return sizeof(void*); 66713d1950aSGreg Clayton } 66813d1950aSGreg Clayton 669c2ff9318SGreg Clayton 670c2ff9318SGreg Clayton uint32_t 671c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 672c2ff9318SGreg Clayton { 673c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 674c2ff9318SGreg Clayton if (module_sp) 6753467d80bSEnrico Granata return module_sp->GetVersion(versions, num_versions); 6763467d80bSEnrico Granata else 677c2ff9318SGreg Clayton { 678c2ff9318SGreg Clayton if (versions && num_versions) 679c2ff9318SGreg Clayton { 680c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 681c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 682c2ff9318SGreg Clayton } 683c2ff9318SGreg Clayton return 0; 684c2ff9318SGreg Clayton } 6853467d80bSEnrico Granata } 686c2ff9318SGreg Clayton 687