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 1652289fa48SGreg Clayton 1662289fa48SGreg Clayton 16730fdc8d8SChris Lattner const uint8_t * 16830fdc8d8SChris Lattner SBModule::GetUUIDBytes () const 16930fdc8d8SChris Lattner { 1705160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 171ceb6b139SCaroline Tice 1724838131bSGreg Clayton const uint8_t *uuid_bytes = NULL; 173c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 174c2ff9318SGreg Clayton if (module_sp) 175c2ff9318SGreg Clayton uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 176ceb6b139SCaroline Tice 177ceb6b139SCaroline Tice if (log) 1784838131bSGreg Clayton { 1794838131bSGreg Clayton if (uuid_bytes) 1804838131bSGreg Clayton { 1814838131bSGreg Clayton StreamString s; 182c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 183c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData()); 1844838131bSGreg Clayton } 1854838131bSGreg Clayton else 186c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get()); 1874838131bSGreg Clayton } 1884838131bSGreg Clayton return uuid_bytes; 18930fdc8d8SChris Lattner } 19030fdc8d8SChris Lattner 19130fdc8d8SChris Lattner 192df2963edSJohnny Chen const char * 193df2963edSJohnny Chen SBModule::GetUUIDString () const 194df2963edSJohnny Chen { 1955160ce5cSGreg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 196df2963edSJohnny Chen 197c16b4af0SJason Molenda static char uuid_string_buffer[80]; 198df2963edSJohnny Chen const char *uuid_c_string = NULL; 199c16b4af0SJason Molenda std::string uuid_string; 200c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 201c2ff9318SGreg Clayton if (module_sp) 202c16b4af0SJason Molenda uuid_string = module_sp->GetUUID().GetAsString(); 203c16b4af0SJason Molenda 204c16b4af0SJason Molenda if (!uuid_string.empty()) 205c16b4af0SJason Molenda { 206c16b4af0SJason Molenda strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer)); 207c16b4af0SJason Molenda uuid_c_string = uuid_string_buffer; 208c16b4af0SJason Molenda } 209df2963edSJohnny Chen 210df2963edSJohnny Chen if (log) 211df2963edSJohnny Chen { 212c16b4af0SJason Molenda if (!uuid_string.empty()) 213df2963edSJohnny Chen { 214df2963edSJohnny Chen StreamString s; 215c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 216c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData()); 217df2963edSJohnny Chen } 218df2963edSJohnny Chen else 219c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get()); 220df2963edSJohnny Chen } 221df2963edSJohnny Chen return uuid_c_string; 222df2963edSJohnny Chen } 223df2963edSJohnny Chen 224df2963edSJohnny Chen 22530fdc8d8SChris Lattner bool 22630fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 22730fdc8d8SChris Lattner { 2286611103cSGreg Clayton if (m_opaque_sp) 2296611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 23030fdc8d8SChris Lattner return false; 23130fdc8d8SChris Lattner } 23230fdc8d8SChris Lattner 23330fdc8d8SChris Lattner bool 23430fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 23530fdc8d8SChris Lattner { 2366611103cSGreg Clayton if (m_opaque_sp) 2376611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 23830fdc8d8SChris Lattner return false; 23930fdc8d8SChris Lattner } 24030fdc8d8SChris Lattner 241acdbe816SGreg Clayton ModuleSP 242acdbe816SGreg Clayton SBModule::GetSP () const 243cac9c5f9SGreg Clayton { 244cac9c5f9SGreg Clayton return m_opaque_sp; 245cac9c5f9SGreg Clayton } 24630fdc8d8SChris Lattner 24730fdc8d8SChris Lattner void 248acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 24930fdc8d8SChris Lattner { 2506611103cSGreg Clayton m_opaque_sp = module_sp; 25130fdc8d8SChris Lattner } 25230fdc8d8SChris Lattner 253cac9c5f9SGreg Clayton SBAddress 254cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 25509960031SGreg Clayton { 256cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 257c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 258c2ff9318SGreg Clayton if (module_sp) 259cac9c5f9SGreg Clayton { 260cac9c5f9SGreg Clayton Address addr; 261c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 262cac9c5f9SGreg Clayton sb_addr.ref() = addr; 263cac9c5f9SGreg Clayton } 264cac9c5f9SGreg Clayton return sb_addr; 26509960031SGreg Clayton } 26609960031SGreg Clayton 26709960031SGreg Clayton SBSymbolContext 26809960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 26909960031SGreg Clayton { 27009960031SGreg Clayton SBSymbolContext sb_sc; 271c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 272c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 273c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 27409960031SGreg Clayton return sb_sc; 27509960031SGreg Clayton } 27609960031SGreg Clayton 277dde9cff3SCaroline Tice bool 278dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 279dde9cff3SCaroline Tice { 280da7bc7d0SGreg Clayton Stream &strm = description.ref(); 281da7bc7d0SGreg Clayton 282c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 283c2ff9318SGreg Clayton if (module_sp) 284dde9cff3SCaroline Tice { 285c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 286dde9cff3SCaroline Tice } 287dde9cff3SCaroline Tice else 288da7bc7d0SGreg Clayton strm.PutCString ("No value"); 289dde9cff3SCaroline Tice 290dde9cff3SCaroline Tice return true; 291dde9cff3SCaroline Tice } 292bbdabce2SGreg Clayton 293873a7a4bSJohnny Chen uint32_t 294873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 295873a7a4bSJohnny Chen { 296873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 297873a7a4bSJohnny Chen if (module_sp) 298873a7a4bSJohnny Chen { 299873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 300873a7a4bSJohnny Chen } 301873a7a4bSJohnny Chen return 0; 302873a7a4bSJohnny Chen } 303873a7a4bSJohnny Chen 304873a7a4bSJohnny Chen SBCompileUnit 305873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 306873a7a4bSJohnny Chen { 307873a7a4bSJohnny Chen SBCompileUnit sb_cu; 308873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 309873a7a4bSJohnny Chen if (module_sp) 310873a7a4bSJohnny Chen { 311873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 312873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 313873a7a4bSJohnny Chen } 314873a7a4bSJohnny Chen return sb_cu; 315873a7a4bSJohnny Chen } 316873a7a4bSJohnny Chen 317a7499c98SMichael Sartain static Symtab * 318a7499c98SMichael Sartain GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp) 319a7499c98SMichael Sartain { 320a7499c98SMichael Sartain if (module_sp) 321a7499c98SMichael Sartain { 322a7499c98SMichael Sartain SymbolVendor *symbols = module_sp->GetSymbolVendor(); 323a7499c98SMichael Sartain if (symbols) 324a7499c98SMichael Sartain return symbols->GetSymtab(); 325a7499c98SMichael Sartain } 326a7499c98SMichael Sartain return NULL; 327a7499c98SMichael Sartain } 328a7499c98SMichael Sartain 329bbdabce2SGreg Clayton size_t 330bbdabce2SGreg Clayton SBModule::GetNumSymbols () 331bbdabce2SGreg Clayton { 332c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 333c2ff9318SGreg Clayton if (module_sp) 334bbdabce2SGreg Clayton { 335a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 336bbdabce2SGreg Clayton if (symtab) 337bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 338bbdabce2SGreg Clayton } 339bbdabce2SGreg Clayton return 0; 340bbdabce2SGreg Clayton } 341bbdabce2SGreg Clayton 342bbdabce2SGreg Clayton SBSymbol 343bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 344bbdabce2SGreg Clayton { 345bbdabce2SGreg Clayton SBSymbol sb_symbol; 346c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 347a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 348bbdabce2SGreg Clayton if (symtab) 349bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 350bbdabce2SGreg Clayton return sb_symbol; 351bbdabce2SGreg Clayton } 352fe356d35SGreg Clayton 353e14e1925SGreg Clayton lldb::SBSymbol 354e14e1925SGreg Clayton SBModule::FindSymbol (const char *name, 355e14e1925SGreg Clayton lldb::SymbolType symbol_type) 356e14e1925SGreg Clayton { 357e14e1925SGreg Clayton SBSymbol sb_symbol; 358e14e1925SGreg Clayton if (name && name[0]) 359e14e1925SGreg Clayton { 360e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 361a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 362e14e1925SGreg Clayton if (symtab) 363e14e1925SGreg Clayton sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); 364e14e1925SGreg Clayton } 365e14e1925SGreg Clayton return sb_symbol; 366e14e1925SGreg Clayton } 367e14e1925SGreg Clayton 368e14e1925SGreg Clayton 369e14e1925SGreg Clayton lldb::SBSymbolContextList 370e14e1925SGreg Clayton SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type) 371e14e1925SGreg Clayton { 372e14e1925SGreg Clayton SBSymbolContextList sb_sc_list; 373e14e1925SGreg Clayton if (name && name[0]) 374e14e1925SGreg Clayton { 375e14e1925SGreg Clayton ModuleSP module_sp (GetSP ()); 376a7499c98SMichael Sartain Symtab *symtab = GetUnifiedSymbolTable (module_sp); 377e14e1925SGreg Clayton if (symtab) 378e14e1925SGreg Clayton { 379e14e1925SGreg Clayton std::vector<uint32_t> matching_symbol_indexes; 380e14e1925SGreg Clayton const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); 381e14e1925SGreg Clayton if (num_matches) 382e14e1925SGreg Clayton { 383e14e1925SGreg Clayton SymbolContext sc; 384e14e1925SGreg Clayton sc.module_sp = module_sp; 385e14e1925SGreg Clayton SymbolContextList &sc_list = *sb_sc_list; 386e14e1925SGreg Clayton for (size_t i=0; i<num_matches; ++i) 387e14e1925SGreg Clayton { 388e14e1925SGreg Clayton sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]); 389e14e1925SGreg Clayton if (sc.symbol) 390e14e1925SGreg Clayton sc_list.Append(sc); 391e14e1925SGreg Clayton } 392e14e1925SGreg Clayton } 393e14e1925SGreg Clayton } 394e14e1925SGreg Clayton } 395e14e1925SGreg Clayton return sb_sc_list; 396e14e1925SGreg Clayton 397e14e1925SGreg Clayton } 398e14e1925SGreg Clayton 399e14e1925SGreg Clayton 400e14e1925SGreg Clayton 401cac9c5f9SGreg Clayton size_t 402cac9c5f9SGreg Clayton SBModule::GetNumSections () 403cac9c5f9SGreg Clayton { 404c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 405c2ff9318SGreg Clayton if (module_sp) 406cac9c5f9SGreg Clayton { 407a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 408a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4093046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 410cac9c5f9SGreg Clayton if (section_list) 411cac9c5f9SGreg Clayton return section_list->GetSize(); 412cac9c5f9SGreg Clayton } 413cac9c5f9SGreg Clayton return 0; 414cac9c5f9SGreg Clayton } 415cac9c5f9SGreg Clayton 416cac9c5f9SGreg Clayton SBSection 417cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 418cac9c5f9SGreg Clayton { 419cac9c5f9SGreg Clayton SBSection sb_section; 420c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 421c2ff9318SGreg Clayton if (module_sp) 422cac9c5f9SGreg Clayton { 423a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 424a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 4253046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList (); 426cac9c5f9SGreg Clayton 427cac9c5f9SGreg Clayton if (section_list) 428e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 429cac9c5f9SGreg Clayton } 430cac9c5f9SGreg Clayton return sb_section; 431cac9c5f9SGreg Clayton } 432cac9c5f9SGreg Clayton 4335569e64eSGreg Clayton lldb::SBSymbolContextList 434fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 4355569e64eSGreg Clayton uint32_t name_type_mask) 436fe356d35SGreg Clayton { 4375569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 438c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 439c2ff9318SGreg Clayton if (name && module_sp) 440fe356d35SGreg Clayton { 4415569e64eSGreg Clayton const bool append = true; 442fe356d35SGreg Clayton const bool symbols_ok = true; 4439df05fbbSSean Callanan const bool inlines_ok = true; 444c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 445b6d70ebcSSean Callanan NULL, 446fe356d35SGreg Clayton name_type_mask, 447fe356d35SGreg Clayton symbols_ok, 4489df05fbbSSean Callanan inlines_ok, 449fe356d35SGreg Clayton append, 4505569e64eSGreg Clayton *sb_sc_list); 451fe356d35SGreg Clayton } 4525569e64eSGreg Clayton return sb_sc_list; 453fe356d35SGreg Clayton } 454fe356d35SGreg Clayton 455dea8cb4fSGreg Clayton 456dea8cb4fSGreg Clayton SBValueList 457dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 458dea8cb4fSGreg Clayton { 459dea8cb4fSGreg Clayton SBValueList sb_value_list; 460c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 461c2ff9318SGreg Clayton if (name && module_sp) 462dea8cb4fSGreg Clayton { 463dea8cb4fSGreg Clayton VariableList variable_list; 464c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 465b6d70ebcSSean Callanan NULL, 466dea8cb4fSGreg Clayton false, 467dea8cb4fSGreg Clayton max_matches, 468dea8cb4fSGreg Clayton variable_list); 469dea8cb4fSGreg Clayton 470dea8cb4fSGreg Clayton if (match_count > 0) 471dea8cb4fSGreg Clayton { 472dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 473dea8cb4fSGreg Clayton { 474dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 475b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 476b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 477dea8cb4fSGreg Clayton if (valobj_sp) 47885425d77SEnrico Granata sb_value_list.Append(SBValue(valobj_sp)); 479dea8cb4fSGreg Clayton } 480dea8cb4fSGreg Clayton } 481dea8cb4fSGreg Clayton } 482dea8cb4fSGreg Clayton 483dea8cb4fSGreg Clayton return sb_value_list; 484dea8cb4fSGreg Clayton } 4856f3533fbSEnrico Granata 486bcd80b47SEnrico Granata lldb::SBValue 487bcd80b47SEnrico Granata SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name) 488bcd80b47SEnrico Granata { 489bcd80b47SEnrico Granata SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 490bcd80b47SEnrico Granata if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 491bcd80b47SEnrico Granata return sb_value_list.GetValueAtIndex(0); 492bcd80b47SEnrico Granata return SBValue(); 493bcd80b47SEnrico Granata } 494bcd80b47SEnrico Granata 4956f3533fbSEnrico Granata lldb::SBType 4966f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 4976f3533fbSEnrico Granata { 498fe42ac4dSGreg Clayton SBType sb_type; 499c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 500c2ff9318SGreg Clayton if (name_cstr && module_sp) 501fe42ac4dSGreg Clayton { 5026f3533fbSEnrico Granata SymbolContext sc; 50384db9105SGreg Clayton const bool exact_match = false; 5046f3533fbSEnrico Granata ConstString name(name_cstr); 5056f3533fbSEnrico Granata 506b43165b7SGreg Clayton sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match)); 5076f3533fbSEnrico Granata 508b43165b7SGreg Clayton if (!sb_type.IsValid()) 509*57ee3067SGreg Clayton sb_type = SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 5106f3533fbSEnrico Granata } 511fe42ac4dSGreg Clayton return sb_type; 5126f3533fbSEnrico Granata } 5136f3533fbSEnrico Granata 514b43165b7SGreg Clayton lldb::SBType 515b43165b7SGreg Clayton SBModule::GetBasicType(lldb::BasicType type) 516b43165b7SGreg Clayton { 517b43165b7SGreg Clayton ModuleSP module_sp (GetSP ()); 518b43165b7SGreg Clayton if (module_sp) 519*57ee3067SGreg Clayton return SBType (ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), type)); 520b43165b7SGreg Clayton return SBType(); 521b43165b7SGreg Clayton } 522b43165b7SGreg Clayton 5236f3533fbSEnrico Granata lldb::SBTypeList 5246f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 5256f3533fbSEnrico Granata { 5266f3533fbSEnrico Granata SBTypeList retval; 5276f3533fbSEnrico Granata 528c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 529c2ff9318SGreg Clayton if (type && module_sp) 530fe42ac4dSGreg Clayton { 5316f3533fbSEnrico Granata SymbolContext sc; 5326f3533fbSEnrico Granata TypeList type_list; 53384db9105SGreg Clayton const bool exact_match = false; 5346f3533fbSEnrico Granata ConstString name(type); 535b43165b7SGreg Clayton const uint32_t num_matches = module_sp->FindTypes (sc, 5366f3533fbSEnrico Granata name, 53784db9105SGreg Clayton exact_match, 5386f3533fbSEnrico Granata UINT32_MAX, 5396f3533fbSEnrico Granata type_list); 5406f3533fbSEnrico Granata 541b43165b7SGreg Clayton if (num_matches > 0) 542b43165b7SGreg Clayton { 5436f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 5446f3533fbSEnrico Granata { 545fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 546fe42ac4dSGreg Clayton if (type_sp) 547fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 548fe42ac4dSGreg Clayton } 5496f3533fbSEnrico Granata } 550b43165b7SGreg Clayton else 551b43165b7SGreg Clayton { 552*57ee3067SGreg Clayton SBType sb_type(ClangASTContext::GetBasicType (module_sp->GetClangASTContext().getASTContext(), name)); 553b43165b7SGreg Clayton if (sb_type.IsValid()) 554b43165b7SGreg Clayton retval.Append(sb_type); 555b43165b7SGreg Clayton } 556b43165b7SGreg Clayton } 5576f3533fbSEnrico Granata 5586f3533fbSEnrico Granata return retval; 5596f3533fbSEnrico Granata } 560cac9c5f9SGreg Clayton 561f02500c7SGreg Clayton lldb::SBTypeList 562f02500c7SGreg Clayton SBModule::GetTypes (uint32_t type_mask) 563f02500c7SGreg Clayton { 564f02500c7SGreg Clayton SBTypeList sb_type_list; 565f02500c7SGreg Clayton 566f02500c7SGreg Clayton ModuleSP module_sp (GetSP ()); 567f02500c7SGreg Clayton if (module_sp) 568f02500c7SGreg Clayton { 569f02500c7SGreg Clayton SymbolVendor* vendor = module_sp->GetSymbolVendor(); 570f02500c7SGreg Clayton if (vendor) 571f02500c7SGreg Clayton { 572f02500c7SGreg Clayton TypeList type_list; 573f02500c7SGreg Clayton vendor->GetTypes (NULL, type_mask, type_list); 574f02500c7SGreg Clayton sb_type_list.m_opaque_ap->Append(type_list); 575f02500c7SGreg Clayton } 576f02500c7SGreg Clayton } 577f02500c7SGreg Clayton return sb_type_list; 578f02500c7SGreg Clayton } 579cac9c5f9SGreg Clayton 580cac9c5f9SGreg Clayton SBSection 581cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 582cac9c5f9SGreg Clayton { 583cac9c5f9SGreg Clayton SBSection sb_section; 584cac9c5f9SGreg Clayton 585c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 586c2ff9318SGreg Clayton if (sect_name && module_sp) 587cac9c5f9SGreg Clayton { 588a7499c98SMichael Sartain // Give the symbol vendor a chance to add to the unified section list. 589a7499c98SMichael Sartain module_sp->GetSymbolVendor(); 5903046e668SGreg Clayton SectionList *section_list = module_sp->GetSectionList(); 591cac9c5f9SGreg Clayton if (section_list) 592cac9c5f9SGreg Clayton { 593cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 594cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 595cac9c5f9SGreg Clayton if (section_sp) 596cac9c5f9SGreg Clayton { 597e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 598cac9c5f9SGreg Clayton } 599cac9c5f9SGreg Clayton } 600cac9c5f9SGreg Clayton } 601cac9c5f9SGreg Clayton return sb_section; 602cac9c5f9SGreg Clayton } 603cac9c5f9SGreg Clayton 60413d1950aSGreg Clayton lldb::ByteOrder 60513d1950aSGreg Clayton SBModule::GetByteOrder () 60613d1950aSGreg Clayton { 607c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 608c2ff9318SGreg Clayton if (module_sp) 609c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 61013d1950aSGreg Clayton return eByteOrderInvalid; 61113d1950aSGreg Clayton } 61213d1950aSGreg Clayton 61313d1950aSGreg Clayton const char * 61413d1950aSGreg Clayton SBModule::GetTriple () 61513d1950aSGreg Clayton { 616c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 617c2ff9318SGreg Clayton if (module_sp) 61813d1950aSGreg Clayton { 619c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 62013d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 62113d1950aSGreg Clayton // the const strings put the string into the string pool once and 62213d1950aSGreg Clayton // the strings never comes out 62313d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 62413d1950aSGreg Clayton return const_triple.GetCString(); 62513d1950aSGreg Clayton } 62613d1950aSGreg Clayton return NULL; 62713d1950aSGreg Clayton } 62813d1950aSGreg Clayton 62913d1950aSGreg Clayton uint32_t 63013d1950aSGreg Clayton SBModule::GetAddressByteSize() 63113d1950aSGreg Clayton { 632c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 633c2ff9318SGreg Clayton if (module_sp) 634c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 63513d1950aSGreg Clayton return sizeof(void*); 63613d1950aSGreg Clayton } 63713d1950aSGreg Clayton 638c2ff9318SGreg Clayton 639c2ff9318SGreg Clayton uint32_t 640c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 641c2ff9318SGreg Clayton { 642c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 643c2ff9318SGreg Clayton if (module_sp) 6443467d80bSEnrico Granata return module_sp->GetVersion(versions, num_versions); 6453467d80bSEnrico Granata else 646c2ff9318SGreg Clayton { 647c2ff9318SGreg Clayton if (versions && num_versions) 648c2ff9318SGreg Clayton { 649c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 650c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 651c2ff9318SGreg Clayton } 652c2ff9318SGreg Clayton return 0; 653c2ff9318SGreg Clayton } 6543467d80bSEnrico Granata } 655c2ff9318SGreg Clayton 656