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; 7239f7ee86SGreg Clayton m_opaque_sp->SetLoadAddress(target, 0, 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) 113ceb6b139SCaroline Tice { 114cfd1acedSGreg Clayton log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 115c2ff9318SGreg Clayton module_sp.get(), file_spec.get()); 116ceb6b139SCaroline Tice } 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 { 1332289fa48SGreg Clayton log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 134c2ff9318SGreg Clayton module_sp.get(), file_spec.get()); 1352289fa48SGreg Clayton } 1362289fa48SGreg Clayton 1372289fa48SGreg Clayton return file_spec; 1382289fa48SGreg Clayton 1392289fa48SGreg Clayton } 1402289fa48SGreg Clayton 1412289fa48SGreg Clayton bool 1422289fa48SGreg Clayton SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 1432289fa48SGreg Clayton { 1442289fa48SGreg Clayton bool result = false; 1455160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1462289fa48SGreg Clayton 147c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 148c2ff9318SGreg Clayton if (module_sp) 1492289fa48SGreg Clayton { 150c2ff9318SGreg Clayton module_sp->SetPlatformFileSpec(*platform_file); 1512289fa48SGreg Clayton result = true; 1522289fa48SGreg Clayton } 1532289fa48SGreg Clayton 1542289fa48SGreg Clayton if (log) 1552289fa48SGreg Clayton { 156b5ad4ec7SGreg Clayton log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i", 157c2ff9318SGreg Clayton module_sp.get(), 1582289fa48SGreg Clayton platform_file.get(), 159b5ad4ec7SGreg Clayton platform_file->GetPath().c_str(), 1602289fa48SGreg Clayton result); 1612289fa48SGreg Clayton } 1622289fa48SGreg Clayton return result; 1632289fa48SGreg Clayton } 1642289fa48SGreg Clayton 165*fbb76349SGreg Clayton lldb::SBFileSpec 166*fbb76349SGreg Clayton SBModule::GetRemoteInstallFileSpec () 167*fbb76349SGreg Clayton { 168*fbb76349SGreg Clayton SBFileSpec sb_file_spec; 169*fbb76349SGreg Clayton ModuleSP module_sp (GetSP ()); 170*fbb76349SGreg Clayton if (module_sp) 171*fbb76349SGreg Clayton sb_file_spec.SetFileSpec (module_sp->GetRemoteInstallFileSpec()); 172*fbb76349SGreg Clayton return sb_file_spec; 173*fbb76349SGreg Clayton } 174*fbb76349SGreg Clayton 175*fbb76349SGreg Clayton bool 176*fbb76349SGreg Clayton SBModule::SetRemoteInstallFileSpec (lldb::SBFileSpec &file) 177*fbb76349SGreg Clayton { 178*fbb76349SGreg Clayton ModuleSP module_sp (GetSP ()); 179*fbb76349SGreg Clayton if (module_sp) 180*fbb76349SGreg Clayton { 181*fbb76349SGreg Clayton module_sp->SetRemoteInstallFileSpec(file.ref()); 182*fbb76349SGreg Clayton return true; 183*fbb76349SGreg Clayton } 184*fbb76349SGreg Clayton return false; 185*fbb76349SGreg Clayton } 1862289fa48SGreg Clayton 1872289fa48SGreg Clayton 18830fdc8d8SChris Lattner const uint8_t * 18930fdc8d8SChris Lattner SBModule::GetUUIDBytes () const 19030fdc8d8SChris Lattner { 1915160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 192ceb6b139SCaroline Tice 1934838131bSGreg Clayton const uint8_t *uuid_bytes = NULL; 194c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 195c2ff9318SGreg Clayton if (module_sp) 196c2ff9318SGreg Clayton uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 197ceb6b139SCaroline Tice 198ceb6b139SCaroline Tice if (log) 1994838131bSGreg Clayton { 2004838131bSGreg Clayton if (uuid_bytes) 2014838131bSGreg Clayton { 2024838131bSGreg Clayton StreamString s; 203c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 204c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData()); 2054838131bSGreg Clayton } 2064838131bSGreg Clayton else 207c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get()); 2084838131bSGreg Clayton } 2094838131bSGreg Clayton return uuid_bytes; 21030fdc8d8SChris Lattner } 21130fdc8d8SChris Lattner 21230fdc8d8SChris Lattner 213df2963edSJohnny Chen const char * 214df2963edSJohnny Chen SBModule::GetUUIDString () const 215df2963edSJohnny Chen { 2165160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 217df2963edSJohnny Chen 218c16b4af0SJason Molenda static char uuid_string_buffer[80]; 219df2963edSJohnny Chen const char *uuid_c_string = NULL; 220c16b4af0SJason Molenda std::string uuid_string; 221c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 222c2ff9318SGreg Clayton if (module_sp) 223c16b4af0SJason Molenda uuid_string = module_sp->GetUUID().GetAsString(); 224c16b4af0SJason Molenda 225c16b4af0SJason Molenda if (!uuid_string.empty()) 226c16b4af0SJason Molenda { 227c16b4af0SJason Molenda strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer)); 228c16b4af0SJason Molenda uuid_c_string = uuid_string_buffer; 229c16b4af0SJason Molenda } 230df2963edSJohnny Chen 231df2963edSJohnny Chen if (log) 232df2963edSJohnny Chen { 233c16b4af0SJason Molenda if (!uuid_string.empty()) 234df2963edSJohnny Chen { 235df2963edSJohnny Chen StreamString s; 236c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 237c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData()); 238df2963edSJohnny Chen } 239df2963edSJohnny Chen else 240c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get()); 241df2963edSJohnny Chen } 242df2963edSJohnny Chen return uuid_c_string; 243df2963edSJohnny Chen } 244df2963edSJohnny Chen 245df2963edSJohnny Chen 24630fdc8d8SChris Lattner bool 24730fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 24830fdc8d8SChris Lattner { 2496611103cSGreg Clayton if (m_opaque_sp) 2506611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 25130fdc8d8SChris Lattner return false; 25230fdc8d8SChris Lattner } 25330fdc8d8SChris Lattner 25430fdc8d8SChris Lattner bool 25530fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 25630fdc8d8SChris Lattner { 2576611103cSGreg Clayton if (m_opaque_sp) 2586611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 25930fdc8d8SChris Lattner return false; 26030fdc8d8SChris Lattner } 26130fdc8d8SChris Lattner 262acdbe816SGreg Clayton ModuleSP 263acdbe816SGreg Clayton SBModule::GetSP () const 264cac9c5f9SGreg Clayton { 265cac9c5f9SGreg Clayton return m_opaque_sp; 266cac9c5f9SGreg Clayton } 26730fdc8d8SChris Lattner 26830fdc8d8SChris Lattner void 269acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 27030fdc8d8SChris Lattner { 2716611103cSGreg Clayton m_opaque_sp = module_sp; 27230fdc8d8SChris Lattner } 27330fdc8d8SChris Lattner 274cac9c5f9SGreg Clayton SBAddress 275cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 27609960031SGreg Clayton { 277cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 278c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 279c2ff9318SGreg Clayton if (module_sp) 280cac9c5f9SGreg Clayton { 281cac9c5f9SGreg Clayton Address addr; 282c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 283cac9c5f9SGreg Clayton sb_addr.ref() = addr; 284cac9c5f9SGreg Clayton } 285cac9c5f9SGreg Clayton return sb_addr; 28609960031SGreg Clayton } 28709960031SGreg Clayton 28809960031SGreg Clayton SBSymbolContext 28909960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 29009960031SGreg Clayton { 29109960031SGreg Clayton SBSymbolContext sb_sc; 292c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 293c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 294c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 29509960031SGreg Clayton return sb_sc; 29609960031SGreg Clayton } 29709960031SGreg Clayton 298dde9cff3SCaroline Tice bool 299dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 300dde9cff3SCaroline Tice { 301da7bc7d0SGreg Clayton Stream &strm = description.ref(); 302da7bc7d0SGreg Clayton 303c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 304c2ff9318SGreg Clayton if (module_sp) 305dde9cff3SCaroline Tice { 306c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 307dde9cff3SCaroline Tice } 308dde9cff3SCaroline Tice else 309da7bc7d0SGreg Clayton strm.PutCString ("No value"); 310dde9cff3SCaroline Tice 311dde9cff3SCaroline Tice return true; 312dde9cff3SCaroline Tice } 313bbdabce2SGreg Clayton 314873a7a4bSJohnny Chen uint32_t 315873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 316873a7a4bSJohnny Chen { 317873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 318873a7a4bSJohnny Chen if (module_sp) 319873a7a4bSJohnny Chen { 320873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 321873a7a4bSJohnny Chen } 322873a7a4bSJohnny Chen return 0; 323873a7a4bSJohnny Chen } 324873a7a4bSJohnny Chen 325873a7a4bSJohnny Chen SBCompileUnit 326873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 327873a7a4bSJohnny Chen { 328873a7a4bSJohnny Chen SBCompileUnit sb_cu; 329873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 330873a7a4bSJohnny Chen if (module_sp) 331873a7a4bSJohnny Chen { 332873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 333873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 334873a7a4bSJohnny Chen } 335873a7a4bSJohnny Chen return sb_cu; 336873a7a4bSJohnny Chen } 337873a7a4bSJohnny Chen 338a7499c98SMichael Sartain static Symtab * 339a7499c98SMichael Sartain GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp) 340a7499c98SMichael Sartain { 341a7499c98SMichael Sartain if (module_sp) 342a7499c98SMichael Sartain { 343a7499c98SMichael Sartain SymbolVendor *symbols = module_sp->GetSymbolVendor(); 344a7499c98SMichael Sartain if (symbols) 345a7499c98SMichael Sartain return symbols->GetSymtab(); 346a7499c98SMichael Sartain } 347a7499c98SMichael Sartain return NULL; 348a7499c98SMichael Sartain } 349a7499c98SMichael Sartain 350bbdabce2SGreg Clayton size_t 351bbdabce2SGreg Clayton SBModule::GetNumSymbols () 352bbdabce2SGreg Clayton { 353c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 354c2ff9318SGreg Clayton if (module_sp) 355bbdabce2SGreg Clayton { 356a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 357bbdabce2SGreg Clayton if (symtab) 358bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 359bbdabce2SGreg Clayton } 360bbdabce2SGreg Clayton return 0; 361bbdabce2SGreg Clayton } 362bbdabce2SGreg Clayton 363bbdabce2SGreg Clayton SBSymbol 364bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 365bbdabce2SGreg Clayton { 366bbdabce2SGreg Clayton SBSymbol sb_symbol; 367c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 368a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 369bbdabce2SGreg Clayton if (symtab) 370bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 371bbdabce2SGreg Clayton return sb_symbol; 372bbdabce2SGreg Clayton } 373fe356d35SGreg Clayton 374e14e1925SGreg Clayton lldb::SBSymbol 375e14e1925SGreg Clayton SBModule::FindSymbol (const char *name, 376e14e1925SGreg Clayton lldb::SymbolType symbol_type) 377e14e1925SGreg Clayton { 378e14e1925SGreg Clayton SBSymbol sb_symbol; 379e14e1925SGreg Clayton if (name && name[0]) 380e14e1925SGreg Clayton { 381e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 382a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 383e14e1925SGreg Clayton if (symtab) 384e14e1925SGreg Clayton sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); 385e14e1925SGreg Clayton } 386e14e1925SGreg Clayton return sb_symbol; 387e14e1925SGreg Clayton } 388e14e1925SGreg Clayton 389e14e1925SGreg Clayton 390e14e1925SGreg Clayton lldb::SBSymbolContextList 391e14e1925SGreg Clayton SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type) 392e14e1925SGreg Clayton { 393e14e1925SGreg Clayton SBSymbolContextList sb_sc_list; 394e14e1925SGreg Clayton if (name && name[0]) 395e14e1925SGreg Clayton { 396e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 397a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 398e14e1925SGreg Clayton if (symtab) 399e14e1925SGreg Clayton { 400e14e1925SGreg Clayton std::vector<uint32_t> matching_symbol_indexes; 401e14e1925SGreg Clayton const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); 402e14e1925SGreg Clayton if (num_matches) 403e14e1925SGreg Clayton { 404e14e1925SGreg Clayton SymbolContext sc; 405e14e1925SGreg Clayton sc.module_sp = module_sp; 406e14e1925SGreg Clayton SymbolContextList &sc_list = *sb_sc_list; 407e14e1925SGreg Clayton for (size_t i=0; i<num_matches; ++i) 408e14e1925SGreg Clayton { 409e14e1925SGreg Clayton sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]); 410e14e1925SGreg Clayton if (sc.symbol) 411e14e1925SGreg Clayton sc_list.Append(sc); 412e14e1925SGreg Clayton } 413e14e1925SGreg Clayton } 414e14e1925SGreg Clayton } 415e14e1925SGreg Clayton } 416e14e1925SGreg Clayton return sb_sc_list; 417e14e1925SGreg Clayton 418e14e1925SGreg Clayton } 419e14e1925SGreg Clayton 420e14e1925SGreg Clayton 421e14e1925SGreg Clayton 422cac9c5f9SGreg Clayton size_t 423cac9c5f9SGreg Clayton SBModule::GetNumSections () 424cac9c5f9SGreg Clayton { 425c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 426c2ff9318SGreg Clayton if (module_sp) 427cac9c5f9SGreg Clayton { 428a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 429a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4303046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 431cac9c5f9SGreg Clayton if (section_list) 432cac9c5f9SGreg Clayton return section_list->GetSize(); 433cac9c5f9SGreg Clayton } 434cac9c5f9SGreg Clayton return 0; 435cac9c5f9SGreg Clayton } 436cac9c5f9SGreg Clayton 437cac9c5f9SGreg Clayton SBSection 438cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 439cac9c5f9SGreg Clayton { 440cac9c5f9SGreg Clayton SBSection sb_section; 441c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 442c2ff9318SGreg Clayton if (module_sp) 443cac9c5f9SGreg Clayton { 444a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 445a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4463046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList (); 447cac9c5f9SGreg Clayton 448cac9c5f9SGreg Clayton if (section_list) 449e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 450cac9c5f9SGreg Clayton } 451cac9c5f9SGreg Clayton return sb_section; 452cac9c5f9SGreg Clayton } 453cac9c5f9SGreg Clayton 4545569e64eSGreg Clayton lldb::SBSymbolContextList 455fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 4565569e64eSGreg Clayton uint32_t name_type_mask) 457fe356d35SGreg Clayton { 4585569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 459c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 460c2ff9318SGreg Clayton if (name && module_sp) 461fe356d35SGreg Clayton { 4625569e64eSGreg Clayton const bool append = true; 463fe356d35SGreg Clayton const bool symbols_ok = true; 4649df05fbbSSean Callanan const bool inlines_ok = true; 465c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 466b6d70ebcSSean Callanan NULL, 467fe356d35SGreg Clayton name_type_mask, 468fe356d35SGreg Clayton symbols_ok, 4699df05fbbSSean Callanan inlines_ok, 470fe356d35SGreg Clayton append, 4715569e64eSGreg Clayton *sb_sc_list); 472fe356d35SGreg Clayton } 4735569e64eSGreg Clayton return sb_sc_list; 474fe356d35SGreg Clayton } 475fe356d35SGreg Clayton 476dea8cb4fSGreg Clayton 477dea8cb4fSGreg Clayton SBValueList 478dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 479dea8cb4fSGreg Clayton { 480dea8cb4fSGreg Clayton SBValueList sb_value_list; 481c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 482c2ff9318SGreg Clayton if (name && module_sp) 483dea8cb4fSGreg Clayton { 484dea8cb4fSGreg Clayton VariableList variable_list; 485c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 486b6d70ebcSSean Callanan NULL, 487dea8cb4fSGreg Clayton false, 488dea8cb4fSGreg Clayton max_matches, 489dea8cb4fSGreg Clayton variable_list); 490dea8cb4fSGreg Clayton 491dea8cb4fSGreg Clayton if (match_count > 0) 492dea8cb4fSGreg Clayton { 493dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 494dea8cb4fSGreg Clayton { 495dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 496b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 497b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 498dea8cb4fSGreg Clayton if (valobj_sp) 49985425d77SEnrico Granata sb_value_list.Append(SBValue(valobj_sp)); 500dea8cb4fSGreg Clayton } 501dea8cb4fSGreg Clayton } 502dea8cb4fSGreg Clayton } 503dea8cb4fSGreg Clayton 504dea8cb4fSGreg Clayton return sb_value_list; 505dea8cb4fSGreg Clayton } 5066f3533fbSEnrico Granata 507bcd80b47SEnrico Granata lldb::SBValue 508bcd80b47SEnrico Granata SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name) 509bcd80b47SEnrico Granata { 510bcd80b47SEnrico Granata SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 511bcd80b47SEnrico Granata if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 512bcd80b47SEnrico Granata return sb_value_list.GetValueAtIndex(0); 513bcd80b47SEnrico Granata return SBValue(); 514bcd80b47SEnrico Granata } 515bcd80b47SEnrico Granata 5166f3533fbSEnrico Granata lldb::SBType 5176f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 5186f3533fbSEnrico Granata { 519fe42ac4dSGreg Clayton SBType sb_type; 520c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 521c2ff9318SGreg Clayton if (name_cstr && module_sp) 522fe42ac4dSGreg Clayton { 5236f3533fbSEnrico Granata SymbolContext sc; 52484db9105SGreg Clayton const bool exact_match = false; 5256f3533fbSEnrico Granata ConstString name(name_cstr); 5266f3533fbSEnrico Granata 527b43165b7SGreg Clayton sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match)); 5286f3533fbSEnrico Granata 529b43165b7SGreg Clayton if (!sb_type.IsValid()) 53057ee3067SGreg Clayton sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 5316f3533fbSEnrico Granata } 532fe42ac4dSGreg Clayton return sb_type; 5336f3533fbSEnrico Granata } 5346f3533fbSEnrico Granata 535b43165b7SGreg Clayton lldb::SBType 536b43165b7SGreg Clayton SBModule::GetBasicType(lldb::BasicType type) 537b43165b7SGreg Clayton { 538b43165b7SGreg Clayton ModuleSP module_sp (GetSP ()); 539b43165b7SGreg Clayton if (module_sp) 54057ee3067SGreg Clayton return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type)); 541b43165b7SGreg Clayton return SBType(); 542b43165b7SGreg Clayton } 543b43165b7SGreg Clayton 5446f3533fbSEnrico Granata lldb::SBTypeList 5456f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 5466f3533fbSEnrico Granata { 5476f3533fbSEnrico Granata SBTypeList retval; 5486f3533fbSEnrico Granata 549c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 550c2ff9318SGreg Clayton if (type && module_sp) 551fe42ac4dSGreg Clayton { 5526f3533fbSEnrico Granata SymbolContext sc; 5536f3533fbSEnrico Granata TypeList type_list; 55484db9105SGreg Clayton const bool exact_match = false; 5556f3533fbSEnrico Granata ConstString name(type); 556b43165b7SGreg Clayton const uint32_t num_matches = module_sp->FindTypes (sc, 5576f3533fbSEnrico Granata name, 55884db9105SGreg Clayton exact_match, 5596f3533fbSEnrico Granata UINT32_MAX, 5606f3533fbSEnrico Granata type_list); 5616f3533fbSEnrico Granata 562b43165b7SGreg Clayton if (num_matches > 0) 563b43165b7SGreg Clayton { 5646f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 5656f3533fbSEnrico Granata { 566fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 567fe42ac4dSGreg Clayton if (type_sp) 568fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 569fe42ac4dSGreg Clayton } 5706f3533fbSEnrico Granata } 571b43165b7SGreg Clayton else 572b43165b7SGreg Clayton { 57357ee3067SGreg Clayton SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 574b43165b7SGreg Clayton if (sb_type.IsValid()) 575b43165b7SGreg Clayton retval.Append(sb_type); 576b43165b7SGreg Clayton } 577b43165b7SGreg Clayton } 5786f3533fbSEnrico Granata 5796f3533fbSEnrico Granata return retval; 5806f3533fbSEnrico Granata } 581cac9c5f9SGreg Clayton 582f02500c7SGreg Clayton lldb::SBTypeList 583f02500c7SGreg Clayton SBModule::GetTypes (uint32_t type_mask) 584f02500c7SGreg Clayton { 585f02500c7SGreg Clayton SBTypeList sb_type_list; 586f02500c7SGreg Clayton 587f02500c7SGreg Clayton ModuleSP module_sp (GetSP ()); 588f02500c7SGreg Clayton if (module_sp) 589f02500c7SGreg Clayton { 590f02500c7SGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 591f02500c7SGreg Clayton if (vendor) 592f02500c7SGreg Clayton { 593f02500c7SGreg Clayton TypeList type_list; 594f02500c7SGreg Clayton vendor->GetTypes (NULL, type_mask, type_list); 595f02500c7SGreg Clayton sb_type_list.m_opaque_ap->Append(type_list); 596f02500c7SGreg Clayton } 597f02500c7SGreg Clayton } 598f02500c7SGreg Clayton return sb_type_list; 599f02500c7SGreg Clayton } 600cac9c5f9SGreg Clayton 601cac9c5f9SGreg Clayton SBSection 602cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 603cac9c5f9SGreg Clayton { 604cac9c5f9SGreg Clayton SBSection sb_section; 605cac9c5f9SGreg Clayton 606c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 607c2ff9318SGreg Clayton if (sect_name && module_sp) 608cac9c5f9SGreg Clayton { 609a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 610a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 6113046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 612cac9c5f9SGreg Clayton if (section_list) 613cac9c5f9SGreg Clayton { 614cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 615cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 616cac9c5f9SGreg Clayton if (section_sp) 617cac9c5f9SGreg Clayton { 618e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 619cac9c5f9SGreg Clayton } 620cac9c5f9SGreg Clayton } 621cac9c5f9SGreg Clayton } 622cac9c5f9SGreg Clayton return sb_section; 623cac9c5f9SGreg Clayton } 624cac9c5f9SGreg Clayton 62513d1950aSGreg Clayton lldb::ByteOrder 62613d1950aSGreg Clayton SBModule::GetByteOrder () 62713d1950aSGreg Clayton { 628c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 629c2ff9318SGreg Clayton if (module_sp) 630c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 63113d1950aSGreg Clayton return eByteOrderInvalid; 63213d1950aSGreg Clayton } 63313d1950aSGreg Clayton 63413d1950aSGreg Clayton const char * 63513d1950aSGreg Clayton SBModule::GetTriple () 63613d1950aSGreg Clayton { 637c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 638c2ff9318SGreg Clayton if (module_sp) 63913d1950aSGreg Clayton { 640c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 64113d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 64213d1950aSGreg Clayton // the const strings put the string into the string pool once and 64313d1950aSGreg Clayton // the strings never comes out 64413d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 64513d1950aSGreg Clayton return const_triple.GetCString(); 64613d1950aSGreg Clayton } 64713d1950aSGreg Clayton return NULL; 64813d1950aSGreg Clayton } 64913d1950aSGreg Clayton 65013d1950aSGreg Clayton uint32_t 65113d1950aSGreg Clayton SBModule::GetAddressByteSize() 65213d1950aSGreg Clayton { 653c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 654c2ff9318SGreg Clayton if (module_sp) 655c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 65613d1950aSGreg Clayton return sizeof(void*); 65713d1950aSGreg Clayton } 65813d1950aSGreg Clayton 659c2ff9318SGreg Clayton 660c2ff9318SGreg Clayton uint32_t 661c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 662c2ff9318SGreg Clayton { 663c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 664c2ff9318SGreg Clayton if (module_sp) 6653467d80bSEnrico Granata return module_sp->GetVersion(versions, num_versions); 6663467d80bSEnrico Granata else 667c2ff9318SGreg Clayton { 668c2ff9318SGreg Clayton if (versions && num_versions) 669c2ff9318SGreg Clayton { 670c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 671c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 672c2ff9318SGreg Clayton } 673c2ff9318SGreg Clayton return 0; 674c2ff9318SGreg Clayton } 6753467d80bSEnrico Granata } 676c2ff9318SGreg Clayton 677