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)", 114*324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 115*324a1036SSaleem 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)", 132*324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 133*324a1036SSaleem 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", 153*324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), 154*324a1036SSaleem Abdulrasool static_cast<const void*>(platform_file.get()), 155*324a1036SSaleem 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); 198*324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", 199*324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), s.GetData()); 2004838131bSGreg Clayton } 2014838131bSGreg Clayton else 202*324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", 203*324a1036SSaleem 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 214c16b4af0SJason Molenda static char uuid_string_buffer[80]; 215df2963edSJohnny Chen const char *uuid_c_string = NULL; 216c16b4af0SJason Molenda std::string uuid_string; 217c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 218c2ff9318SGreg Clayton if (module_sp) 219c16b4af0SJason Molenda uuid_string = module_sp->GetUUID().GetAsString(); 220c16b4af0SJason Molenda 221c16b4af0SJason Molenda if (!uuid_string.empty()) 222c16b4af0SJason Molenda { 223c16b4af0SJason Molenda strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer)); 224c16b4af0SJason Molenda uuid_c_string = uuid_string_buffer; 225c16b4af0SJason Molenda } 226df2963edSJohnny Chen 227df2963edSJohnny Chen if (log) 228df2963edSJohnny Chen { 229c16b4af0SJason Molenda if (!uuid_string.empty()) 230df2963edSJohnny Chen { 231df2963edSJohnny Chen StreamString s; 232c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 233*324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDString () => %s", 234*324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get()), s.GetData()); 235df2963edSJohnny Chen } 236df2963edSJohnny Chen else 237*324a1036SSaleem Abdulrasool log->Printf ("SBModule(%p)::GetUUIDString () => NULL", 238*324a1036SSaleem Abdulrasool static_cast<void*>(module_sp.get())); 239df2963edSJohnny Chen } 240df2963edSJohnny Chen return uuid_c_string; 241df2963edSJohnny Chen } 242df2963edSJohnny Chen 243df2963edSJohnny Chen 24430fdc8d8SChris Lattner bool 24530fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 24630fdc8d8SChris Lattner { 2476611103cSGreg Clayton if (m_opaque_sp) 2486611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 24930fdc8d8SChris Lattner return false; 25030fdc8d8SChris Lattner } 25130fdc8d8SChris Lattner 25230fdc8d8SChris Lattner bool 25330fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 25430fdc8d8SChris Lattner { 2556611103cSGreg Clayton if (m_opaque_sp) 2566611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 25730fdc8d8SChris Lattner return false; 25830fdc8d8SChris Lattner } 25930fdc8d8SChris Lattner 260acdbe816SGreg Clayton ModuleSP 261acdbe816SGreg Clayton SBModule::GetSP () const 262cac9c5f9SGreg Clayton { 263cac9c5f9SGreg Clayton return m_opaque_sp; 264cac9c5f9SGreg Clayton } 26530fdc8d8SChris Lattner 26630fdc8d8SChris Lattner void 267acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 26830fdc8d8SChris Lattner { 2696611103cSGreg Clayton m_opaque_sp = module_sp; 27030fdc8d8SChris Lattner } 27130fdc8d8SChris Lattner 272cac9c5f9SGreg Clayton SBAddress 273cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 27409960031SGreg Clayton { 275cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 276c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 277c2ff9318SGreg Clayton if (module_sp) 278cac9c5f9SGreg Clayton { 279cac9c5f9SGreg Clayton Address addr; 280c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 281cac9c5f9SGreg Clayton sb_addr.ref() = addr; 282cac9c5f9SGreg Clayton } 283cac9c5f9SGreg Clayton return sb_addr; 28409960031SGreg Clayton } 28509960031SGreg Clayton 28609960031SGreg Clayton SBSymbolContext 28709960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 28809960031SGreg Clayton { 28909960031SGreg Clayton SBSymbolContext sb_sc; 290c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 291c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 292c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 29309960031SGreg Clayton return sb_sc; 29409960031SGreg Clayton } 29509960031SGreg Clayton 296dde9cff3SCaroline Tice bool 297dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 298dde9cff3SCaroline Tice { 299da7bc7d0SGreg Clayton Stream &strm = description.ref(); 300da7bc7d0SGreg Clayton 301c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 302c2ff9318SGreg Clayton if (module_sp) 303dde9cff3SCaroline Tice { 304c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 305dde9cff3SCaroline Tice } 306dde9cff3SCaroline Tice else 307da7bc7d0SGreg Clayton strm.PutCString ("No value"); 308dde9cff3SCaroline Tice 309dde9cff3SCaroline Tice return true; 310dde9cff3SCaroline Tice } 311bbdabce2SGreg Clayton 312873a7a4bSJohnny Chen uint32_t 313873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 314873a7a4bSJohnny Chen { 315873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 316873a7a4bSJohnny Chen if (module_sp) 317873a7a4bSJohnny Chen { 318873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 319873a7a4bSJohnny Chen } 320873a7a4bSJohnny Chen return 0; 321873a7a4bSJohnny Chen } 322873a7a4bSJohnny Chen 323873a7a4bSJohnny Chen SBCompileUnit 324873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 325873a7a4bSJohnny Chen { 326873a7a4bSJohnny Chen SBCompileUnit sb_cu; 327873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 328873a7a4bSJohnny Chen if (module_sp) 329873a7a4bSJohnny Chen { 330873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 331873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 332873a7a4bSJohnny Chen } 333873a7a4bSJohnny Chen return sb_cu; 334873a7a4bSJohnny Chen } 335873a7a4bSJohnny Chen 336a7499c98SMichael Sartain static Symtab * 337a7499c98SMichael Sartain GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp) 338a7499c98SMichael Sartain { 339a7499c98SMichael Sartain if (module_sp) 340a7499c98SMichael Sartain { 341a7499c98SMichael Sartain SymbolVendor *symbols = module_sp->GetSymbolVendor(); 342a7499c98SMichael Sartain if (symbols) 343a7499c98SMichael Sartain return symbols->GetSymtab(); 344a7499c98SMichael Sartain } 345a7499c98SMichael Sartain return NULL; 346a7499c98SMichael Sartain } 347a7499c98SMichael Sartain 348bbdabce2SGreg Clayton size_t 349bbdabce2SGreg Clayton SBModule::GetNumSymbols () 350bbdabce2SGreg Clayton { 351c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 352c2ff9318SGreg Clayton if (module_sp) 353bbdabce2SGreg Clayton { 354a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 355bbdabce2SGreg Clayton if (symtab) 356bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 357bbdabce2SGreg Clayton } 358bbdabce2SGreg Clayton return 0; 359bbdabce2SGreg Clayton } 360bbdabce2SGreg Clayton 361bbdabce2SGreg Clayton SBSymbol 362bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 363bbdabce2SGreg Clayton { 364bbdabce2SGreg Clayton SBSymbol sb_symbol; 365c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 366a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 367bbdabce2SGreg Clayton if (symtab) 368bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 369bbdabce2SGreg Clayton return sb_symbol; 370bbdabce2SGreg Clayton } 371fe356d35SGreg Clayton 372e14e1925SGreg Clayton lldb::SBSymbol 373e14e1925SGreg Clayton SBModule::FindSymbol (const char *name, 374e14e1925SGreg Clayton lldb::SymbolType symbol_type) 375e14e1925SGreg Clayton { 376e14e1925SGreg Clayton SBSymbol sb_symbol; 377e14e1925SGreg Clayton if (name && name[0]) 378e14e1925SGreg Clayton { 379e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 380a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 381e14e1925SGreg Clayton if (symtab) 382e14e1925SGreg Clayton sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); 383e14e1925SGreg Clayton } 384e14e1925SGreg Clayton return sb_symbol; 385e14e1925SGreg Clayton } 386e14e1925SGreg Clayton 387e14e1925SGreg Clayton 388e14e1925SGreg Clayton lldb::SBSymbolContextList 389e14e1925SGreg Clayton SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type) 390e14e1925SGreg Clayton { 391e14e1925SGreg Clayton SBSymbolContextList sb_sc_list; 392e14e1925SGreg Clayton if (name && name[0]) 393e14e1925SGreg Clayton { 394e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 395a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 396e14e1925SGreg Clayton if (symtab) 397e14e1925SGreg Clayton { 398e14e1925SGreg Clayton std::vector<uint32_t> matching_symbol_indexes; 399e14e1925SGreg Clayton const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); 400e14e1925SGreg Clayton if (num_matches) 401e14e1925SGreg Clayton { 402e14e1925SGreg Clayton SymbolContext sc; 403e14e1925SGreg Clayton sc.module_sp = module_sp; 404e14e1925SGreg Clayton SymbolContextList &sc_list = *sb_sc_list; 405e14e1925SGreg Clayton for (size_t i=0; i<num_matches; ++i) 406e14e1925SGreg Clayton { 407e14e1925SGreg Clayton sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]); 408e14e1925SGreg Clayton if (sc.symbol) 409e14e1925SGreg Clayton sc_list.Append(sc); 410e14e1925SGreg Clayton } 411e14e1925SGreg Clayton } 412e14e1925SGreg Clayton } 413e14e1925SGreg Clayton } 414e14e1925SGreg Clayton return sb_sc_list; 415e14e1925SGreg Clayton 416e14e1925SGreg Clayton } 417e14e1925SGreg Clayton 418e14e1925SGreg Clayton 419e14e1925SGreg Clayton 420cac9c5f9SGreg Clayton size_t 421cac9c5f9SGreg Clayton SBModule::GetNumSections () 422cac9c5f9SGreg Clayton { 423c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 424c2ff9318SGreg Clayton if (module_sp) 425cac9c5f9SGreg Clayton { 426a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 427a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4283046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 429cac9c5f9SGreg Clayton if (section_list) 430cac9c5f9SGreg Clayton return section_list->GetSize(); 431cac9c5f9SGreg Clayton } 432cac9c5f9SGreg Clayton return 0; 433cac9c5f9SGreg Clayton } 434cac9c5f9SGreg Clayton 435cac9c5f9SGreg Clayton SBSection 436cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 437cac9c5f9SGreg Clayton { 438cac9c5f9SGreg Clayton SBSection sb_section; 439c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 440c2ff9318SGreg Clayton if (module_sp) 441cac9c5f9SGreg Clayton { 442a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 443a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4443046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList (); 445cac9c5f9SGreg Clayton 446cac9c5f9SGreg Clayton if (section_list) 447e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 448cac9c5f9SGreg Clayton } 449cac9c5f9SGreg Clayton return sb_section; 450cac9c5f9SGreg Clayton } 451cac9c5f9SGreg Clayton 4525569e64eSGreg Clayton lldb::SBSymbolContextList 453fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 4545569e64eSGreg Clayton uint32_t name_type_mask) 455fe356d35SGreg Clayton { 4565569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 457c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 458c2ff9318SGreg Clayton if (name && module_sp) 459fe356d35SGreg Clayton { 4605569e64eSGreg Clayton const bool append = true; 461fe356d35SGreg Clayton const bool symbols_ok = true; 4629df05fbbSSean Callanan const bool inlines_ok = true; 463c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 464b6d70ebcSSean Callanan NULL, 465fe356d35SGreg Clayton name_type_mask, 466fe356d35SGreg Clayton symbols_ok, 4679df05fbbSSean Callanan inlines_ok, 468fe356d35SGreg Clayton append, 4695569e64eSGreg Clayton *sb_sc_list); 470fe356d35SGreg Clayton } 4715569e64eSGreg Clayton return sb_sc_list; 472fe356d35SGreg Clayton } 473fe356d35SGreg Clayton 474dea8cb4fSGreg Clayton 475dea8cb4fSGreg Clayton SBValueList 476dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 477dea8cb4fSGreg Clayton { 478dea8cb4fSGreg Clayton SBValueList sb_value_list; 479c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 480c2ff9318SGreg Clayton if (name && module_sp) 481dea8cb4fSGreg Clayton { 482dea8cb4fSGreg Clayton VariableList variable_list; 483c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 484b6d70ebcSSean Callanan NULL, 485dea8cb4fSGreg Clayton false, 486dea8cb4fSGreg Clayton max_matches, 487dea8cb4fSGreg Clayton variable_list); 488dea8cb4fSGreg Clayton 489dea8cb4fSGreg Clayton if (match_count > 0) 490dea8cb4fSGreg Clayton { 491dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 492dea8cb4fSGreg Clayton { 493dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 494b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 495b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 496dea8cb4fSGreg Clayton if (valobj_sp) 49785425d77SEnrico Granata sb_value_list.Append(SBValue(valobj_sp)); 498dea8cb4fSGreg Clayton } 499dea8cb4fSGreg Clayton } 500dea8cb4fSGreg Clayton } 501dea8cb4fSGreg Clayton 502dea8cb4fSGreg Clayton return sb_value_list; 503dea8cb4fSGreg Clayton } 5046f3533fbSEnrico Granata 505bcd80b47SEnrico Granata lldb::SBValue 506bcd80b47SEnrico Granata SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name) 507bcd80b47SEnrico Granata { 508bcd80b47SEnrico Granata SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 509bcd80b47SEnrico Granata if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 510bcd80b47SEnrico Granata return sb_value_list.GetValueAtIndex(0); 511bcd80b47SEnrico Granata return SBValue(); 512bcd80b47SEnrico Granata } 513bcd80b47SEnrico Granata 5146f3533fbSEnrico Granata lldb::SBType 5156f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 5166f3533fbSEnrico Granata { 517fe42ac4dSGreg Clayton SBType sb_type; 518c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 519c2ff9318SGreg Clayton if (name_cstr && module_sp) 520fe42ac4dSGreg Clayton { 5216f3533fbSEnrico Granata SymbolContext sc; 52284db9105SGreg Clayton const bool exact_match = false; 5236f3533fbSEnrico Granata ConstString name(name_cstr); 5246f3533fbSEnrico Granata 525b43165b7SGreg Clayton sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match)); 5266f3533fbSEnrico Granata 527b43165b7SGreg Clayton if (!sb_type.IsValid()) 52857ee3067SGreg Clayton sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 5296f3533fbSEnrico Granata } 530fe42ac4dSGreg Clayton return sb_type; 5316f3533fbSEnrico Granata } 5326f3533fbSEnrico Granata 533b43165b7SGreg Clayton lldb::SBType 534b43165b7SGreg Clayton SBModule::GetBasicType(lldb::BasicType type) 535b43165b7SGreg Clayton { 536b43165b7SGreg Clayton ModuleSP module_sp (GetSP ()); 537b43165b7SGreg Clayton if (module_sp) 53857ee3067SGreg Clayton return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type)); 539b43165b7SGreg Clayton return SBType(); 540b43165b7SGreg Clayton } 541b43165b7SGreg Clayton 5426f3533fbSEnrico Granata lldb::SBTypeList 5436f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 5446f3533fbSEnrico Granata { 5456f3533fbSEnrico Granata SBTypeList retval; 5466f3533fbSEnrico Granata 547c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 548c2ff9318SGreg Clayton if (type && module_sp) 549fe42ac4dSGreg Clayton { 5506f3533fbSEnrico Granata SymbolContext sc; 5516f3533fbSEnrico Granata TypeList type_list; 55284db9105SGreg Clayton const bool exact_match = false; 5536f3533fbSEnrico Granata ConstString name(type); 554b43165b7SGreg Clayton const uint32_t num_matches = module_sp->FindTypes (sc, 5556f3533fbSEnrico Granata name, 55684db9105SGreg Clayton exact_match, 5576f3533fbSEnrico Granata UINT32_MAX, 5586f3533fbSEnrico Granata type_list); 5596f3533fbSEnrico Granata 560b43165b7SGreg Clayton if (num_matches > 0) 561b43165b7SGreg Clayton { 5626f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 5636f3533fbSEnrico Granata { 564fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 565fe42ac4dSGreg Clayton if (type_sp) 566fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 567fe42ac4dSGreg Clayton } 5686f3533fbSEnrico Granata } 569b43165b7SGreg Clayton else 570b43165b7SGreg Clayton { 57157ee3067SGreg Clayton SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 572b43165b7SGreg Clayton if (sb_type.IsValid()) 573b43165b7SGreg Clayton retval.Append(sb_type); 574b43165b7SGreg Clayton } 575b43165b7SGreg Clayton } 5766f3533fbSEnrico Granata 5776f3533fbSEnrico Granata return retval; 5786f3533fbSEnrico Granata } 579cac9c5f9SGreg Clayton 5801f4db7daSGreg Clayton lldb::SBType 5811f4db7daSGreg Clayton SBModule::GetTypeByID (lldb::user_id_t uid) 5821f4db7daSGreg Clayton { 5831f4db7daSGreg Clayton ModuleSP module_sp (GetSP ()); 5841f4db7daSGreg Clayton if (module_sp) 5851f4db7daSGreg Clayton { 5861f4db7daSGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 5871f4db7daSGreg Clayton if (vendor) 5881f4db7daSGreg Clayton { 5891f4db7daSGreg Clayton Type *type_ptr = vendor->ResolveTypeUID(uid); 5901f4db7daSGreg Clayton if (type_ptr) 5911f4db7daSGreg Clayton return SBType(type_ptr->shared_from_this()); 5921f4db7daSGreg Clayton } 5931f4db7daSGreg Clayton } 5941f4db7daSGreg Clayton return SBType(); 5951f4db7daSGreg Clayton } 5961f4db7daSGreg Clayton 597f02500c7SGreg Clayton lldb::SBTypeList 598f02500c7SGreg Clayton SBModule::GetTypes (uint32_t type_mask) 599f02500c7SGreg Clayton { 600f02500c7SGreg Clayton SBTypeList sb_type_list; 601f02500c7SGreg Clayton 602f02500c7SGreg Clayton ModuleSP module_sp (GetSP ()); 603f02500c7SGreg Clayton if (module_sp) 604f02500c7SGreg Clayton { 605f02500c7SGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 606f02500c7SGreg Clayton if (vendor) 607f02500c7SGreg Clayton { 608f02500c7SGreg Clayton TypeList type_list; 609f02500c7SGreg Clayton vendor->GetTypes (NULL, type_mask, type_list); 610f02500c7SGreg Clayton sb_type_list.m_opaque_ap->Append(type_list); 611f02500c7SGreg Clayton } 612f02500c7SGreg Clayton } 613f02500c7SGreg Clayton return sb_type_list; 614f02500c7SGreg Clayton } 615cac9c5f9SGreg Clayton 616cac9c5f9SGreg Clayton SBSection 617cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 618cac9c5f9SGreg Clayton { 619cac9c5f9SGreg Clayton SBSection sb_section; 620cac9c5f9SGreg Clayton 621c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 622c2ff9318SGreg Clayton if (sect_name && module_sp) 623cac9c5f9SGreg Clayton { 624a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 625a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 6263046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 627cac9c5f9SGreg Clayton if (section_list) 628cac9c5f9SGreg Clayton { 629cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 630cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 631cac9c5f9SGreg Clayton if (section_sp) 632cac9c5f9SGreg Clayton { 633e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 634cac9c5f9SGreg Clayton } 635cac9c5f9SGreg Clayton } 636cac9c5f9SGreg Clayton } 637cac9c5f9SGreg Clayton return sb_section; 638cac9c5f9SGreg Clayton } 639cac9c5f9SGreg Clayton 64013d1950aSGreg Clayton lldb::ByteOrder 64113d1950aSGreg Clayton SBModule::GetByteOrder () 64213d1950aSGreg Clayton { 643c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 644c2ff9318SGreg Clayton if (module_sp) 645c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 64613d1950aSGreg Clayton return eByteOrderInvalid; 64713d1950aSGreg Clayton } 64813d1950aSGreg Clayton 64913d1950aSGreg Clayton const char * 65013d1950aSGreg Clayton SBModule::GetTriple () 65113d1950aSGreg Clayton { 652c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 653c2ff9318SGreg Clayton if (module_sp) 65413d1950aSGreg Clayton { 655c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 65613d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 65713d1950aSGreg Clayton // the const strings put the string into the string pool once and 65813d1950aSGreg Clayton // the strings never comes out 65913d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 66013d1950aSGreg Clayton return const_triple.GetCString(); 66113d1950aSGreg Clayton } 66213d1950aSGreg Clayton return NULL; 66313d1950aSGreg Clayton } 66413d1950aSGreg Clayton 66513d1950aSGreg Clayton uint32_t 66613d1950aSGreg Clayton SBModule::GetAddressByteSize() 66713d1950aSGreg Clayton { 668c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 669c2ff9318SGreg Clayton if (module_sp) 670c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 67113d1950aSGreg Clayton return sizeof(void*); 67213d1950aSGreg Clayton } 67313d1950aSGreg Clayton 674c2ff9318SGreg Clayton 675c2ff9318SGreg Clayton uint32_t 676c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 677c2ff9318SGreg Clayton { 678c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 679c2ff9318SGreg Clayton if (module_sp) 6803467d80bSEnrico Granata return module_sp->GetVersion(versions, num_versions); 6813467d80bSEnrico Granata else 682c2ff9318SGreg Clayton { 683c2ff9318SGreg Clayton if (versions && num_versions) 684c2ff9318SGreg Clayton { 685c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 686c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 687c2ff9318SGreg Clayton } 688c2ff9318SGreg Clayton return 0; 689c2ff9318SGreg Clayton } 6903467d80bSEnrico Granata } 691c2ff9318SGreg Clayton 692