1ac7ddfbfSEd Maste //===-- SBModule.cpp --------------------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/API/SBModule.h" 11ac7ddfbfSEd Maste #include "lldb/API/SBAddress.h" 12ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h" 13ac7ddfbfSEd Maste #include "lldb/API/SBModuleSpec.h" 14ac7ddfbfSEd Maste #include "lldb/API/SBProcess.h" 15ac7ddfbfSEd Maste #include "lldb/API/SBStream.h" 16ac7ddfbfSEd Maste #include "lldb/API/SBSymbolContextList.h" 17ac7ddfbfSEd Maste #include "lldb/Core/Module.h" 18ac7ddfbfSEd Maste #include "lldb/Core/Log.h" 19ac7ddfbfSEd Maste #include "lldb/Core/Section.h" 20ac7ddfbfSEd Maste #include "lldb/Core/StreamString.h" 21ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectList.h" 22ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectVariable.h" 23ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h" 24ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolVendor.h" 25ac7ddfbfSEd Maste #include "lldb/Symbol/Symtab.h" 269f2f44ceSEd Maste #include "lldb/Symbol/TypeSystem.h" 27ac7ddfbfSEd Maste #include "lldb/Symbol/VariableList.h" 28ac7ddfbfSEd Maste #include "lldb/Target/Target.h" 29ac7ddfbfSEd Maste 30ac7ddfbfSEd Maste using namespace lldb; 31ac7ddfbfSEd Maste using namespace lldb_private; 32ac7ddfbfSEd Maste 33ac7ddfbfSEd Maste 34ac7ddfbfSEd Maste SBModule::SBModule () : 35ac7ddfbfSEd Maste m_opaque_sp () 36ac7ddfbfSEd Maste { 37ac7ddfbfSEd Maste } 38ac7ddfbfSEd Maste 39ac7ddfbfSEd Maste SBModule::SBModule (const lldb::ModuleSP& module_sp) : 40ac7ddfbfSEd Maste m_opaque_sp (module_sp) 41ac7ddfbfSEd Maste { 42ac7ddfbfSEd Maste } 43ac7ddfbfSEd Maste 44ac7ddfbfSEd Maste SBModule::SBModule(const SBModuleSpec &module_spec) : 45ac7ddfbfSEd Maste m_opaque_sp () 46ac7ddfbfSEd Maste { 47ac7ddfbfSEd Maste ModuleSP module_sp; 48ac7ddfbfSEd Maste Error error = ModuleList::GetSharedModule (*module_spec.m_opaque_ap, 49ac7ddfbfSEd Maste module_sp, 50ac7ddfbfSEd Maste NULL, 51ac7ddfbfSEd Maste NULL, 52ac7ddfbfSEd Maste NULL); 53ac7ddfbfSEd Maste if (module_sp) 54ac7ddfbfSEd Maste SetSP(module_sp); 55ac7ddfbfSEd Maste } 56ac7ddfbfSEd Maste 57ac7ddfbfSEd Maste SBModule::SBModule(const SBModule &rhs) : 58ac7ddfbfSEd Maste m_opaque_sp (rhs.m_opaque_sp) 59ac7ddfbfSEd Maste { 60ac7ddfbfSEd Maste } 61ac7ddfbfSEd Maste 62ac7ddfbfSEd Maste SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : 63ac7ddfbfSEd Maste m_opaque_sp () 64ac7ddfbfSEd Maste { 65ac7ddfbfSEd Maste ProcessSP process_sp (process.GetSP()); 66ac7ddfbfSEd Maste if (process_sp) 67ac7ddfbfSEd Maste { 68ac7ddfbfSEd Maste m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr); 69ac7ddfbfSEd Maste if (m_opaque_sp) 70ac7ddfbfSEd Maste { 71ac7ddfbfSEd Maste Target &target = process_sp->GetTarget(); 72ac7ddfbfSEd Maste bool changed = false; 7312b93ac6SEd Maste m_opaque_sp->SetLoadAddress(target, 0, true, changed); 74ac7ddfbfSEd Maste target.GetImages().Append(m_opaque_sp); 75ac7ddfbfSEd Maste } 76ac7ddfbfSEd Maste } 77ac7ddfbfSEd Maste } 78ac7ddfbfSEd Maste 79ac7ddfbfSEd Maste const SBModule & 80ac7ddfbfSEd Maste SBModule::operator = (const SBModule &rhs) 81ac7ddfbfSEd Maste { 82ac7ddfbfSEd Maste if (this != &rhs) 83ac7ddfbfSEd Maste m_opaque_sp = rhs.m_opaque_sp; 84ac7ddfbfSEd Maste return *this; 85ac7ddfbfSEd Maste } 86ac7ddfbfSEd Maste 87ac7ddfbfSEd Maste SBModule::~SBModule () 88ac7ddfbfSEd Maste { 89ac7ddfbfSEd Maste } 90ac7ddfbfSEd Maste 91ac7ddfbfSEd Maste bool 92ac7ddfbfSEd Maste SBModule::IsValid () const 93ac7ddfbfSEd Maste { 94ac7ddfbfSEd Maste return m_opaque_sp.get() != NULL; 95ac7ddfbfSEd Maste } 96ac7ddfbfSEd Maste 97ac7ddfbfSEd Maste void 98ac7ddfbfSEd Maste SBModule::Clear() 99ac7ddfbfSEd Maste { 100ac7ddfbfSEd Maste m_opaque_sp.reset(); 101ac7ddfbfSEd Maste } 102ac7ddfbfSEd Maste 103ac7ddfbfSEd Maste SBFileSpec 104ac7ddfbfSEd Maste SBModule::GetFileSpec () const 105ac7ddfbfSEd Maste { 106ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 107ac7ddfbfSEd Maste 108ac7ddfbfSEd Maste SBFileSpec file_spec; 109ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 110ac7ddfbfSEd Maste if (module_sp) 111ac7ddfbfSEd Maste file_spec.SetFileSpec(module_sp->GetFileSpec()); 112ac7ddfbfSEd Maste 113ac7ddfbfSEd Maste if (log) 114ac7ddfbfSEd Maste log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 1150127ef0fSEd Maste static_cast<void*>(module_sp.get()), 1160127ef0fSEd Maste static_cast<const void*>(file_spec.get())); 117ac7ddfbfSEd Maste 118ac7ddfbfSEd Maste return file_spec; 119ac7ddfbfSEd Maste } 120ac7ddfbfSEd Maste 121ac7ddfbfSEd Maste lldb::SBFileSpec 122ac7ddfbfSEd Maste SBModule::GetPlatformFileSpec () const 123ac7ddfbfSEd Maste { 124ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 125ac7ddfbfSEd Maste 126ac7ddfbfSEd Maste SBFileSpec file_spec; 127ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 128ac7ddfbfSEd Maste if (module_sp) 129ac7ddfbfSEd Maste file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 130ac7ddfbfSEd Maste 131ac7ddfbfSEd Maste if (log) 132ac7ddfbfSEd Maste log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 1330127ef0fSEd Maste static_cast<void*>(module_sp.get()), 1340127ef0fSEd Maste static_cast<const void*>(file_spec.get())); 135ac7ddfbfSEd Maste 136ac7ddfbfSEd Maste return file_spec; 137ac7ddfbfSEd Maste } 138ac7ddfbfSEd Maste 139ac7ddfbfSEd Maste bool 140ac7ddfbfSEd Maste SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 141ac7ddfbfSEd Maste { 142ac7ddfbfSEd Maste bool result = false; 143ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 144ac7ddfbfSEd Maste 145ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 146ac7ddfbfSEd Maste if (module_sp) 147ac7ddfbfSEd Maste { 148ac7ddfbfSEd Maste module_sp->SetPlatformFileSpec(*platform_file); 149ac7ddfbfSEd Maste result = true; 150ac7ddfbfSEd Maste } 151ac7ddfbfSEd Maste 152ac7ddfbfSEd Maste if (log) 153ac7ddfbfSEd Maste log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i", 1540127ef0fSEd Maste static_cast<void*>(module_sp.get()), 1550127ef0fSEd Maste static_cast<const void*>(platform_file.get()), 1560127ef0fSEd Maste platform_file->GetPath().c_str(), result); 157ac7ddfbfSEd Maste return result; 158ac7ddfbfSEd Maste } 159ac7ddfbfSEd Maste 160b952cd58SEd Maste lldb::SBFileSpec 161b952cd58SEd Maste SBModule::GetRemoteInstallFileSpec () 162b952cd58SEd Maste { 163b952cd58SEd Maste SBFileSpec sb_file_spec; 164b952cd58SEd Maste ModuleSP module_sp (GetSP ()); 165b952cd58SEd Maste if (module_sp) 166b952cd58SEd Maste sb_file_spec.SetFileSpec (module_sp->GetRemoteInstallFileSpec()); 167b952cd58SEd Maste return sb_file_spec; 168b952cd58SEd Maste } 169b952cd58SEd Maste 170b952cd58SEd Maste bool 171b952cd58SEd Maste SBModule::SetRemoteInstallFileSpec (lldb::SBFileSpec &file) 172b952cd58SEd Maste { 173b952cd58SEd Maste ModuleSP module_sp (GetSP ()); 174b952cd58SEd Maste if (module_sp) 175b952cd58SEd Maste { 176b952cd58SEd Maste module_sp->SetRemoteInstallFileSpec(file.ref()); 177b952cd58SEd Maste return true; 178b952cd58SEd Maste } 179b952cd58SEd Maste return false; 180b952cd58SEd Maste } 181ac7ddfbfSEd Maste 182ac7ddfbfSEd Maste 183ac7ddfbfSEd Maste const uint8_t * 184ac7ddfbfSEd Maste SBModule::GetUUIDBytes () const 185ac7ddfbfSEd Maste { 186ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 187ac7ddfbfSEd Maste 188ac7ddfbfSEd Maste const uint8_t *uuid_bytes = NULL; 189ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 190ac7ddfbfSEd Maste if (module_sp) 191ac7ddfbfSEd Maste uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 192ac7ddfbfSEd Maste 193ac7ddfbfSEd Maste if (log) 194ac7ddfbfSEd Maste { 195ac7ddfbfSEd Maste if (uuid_bytes) 196ac7ddfbfSEd Maste { 197ac7ddfbfSEd Maste StreamString s; 198ac7ddfbfSEd Maste module_sp->GetUUID().Dump (&s); 1990127ef0fSEd Maste log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", 2000127ef0fSEd Maste static_cast<void*>(module_sp.get()), s.GetData()); 201ac7ddfbfSEd Maste } 202ac7ddfbfSEd Maste else 2030127ef0fSEd Maste log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", 2040127ef0fSEd Maste static_cast<void*>(module_sp.get())); 205ac7ddfbfSEd Maste } 206ac7ddfbfSEd Maste return uuid_bytes; 207ac7ddfbfSEd Maste } 208ac7ddfbfSEd Maste 209ac7ddfbfSEd Maste 210ac7ddfbfSEd Maste const char * 211ac7ddfbfSEd Maste SBModule::GetUUIDString () const 212ac7ddfbfSEd Maste { 213ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 214ac7ddfbfSEd Maste 2151c3bbb01SEd Maste const char *uuid_cstr = NULL; 216ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 217ac7ddfbfSEd Maste if (module_sp) 218ac7ddfbfSEd Maste { 2191c3bbb01SEd Maste // We are going to return a "const char *" value through the public 2201c3bbb01SEd Maste // API, so we need to constify it so it gets added permanently the 2211c3bbb01SEd Maste // string pool and then we don't need to worry about the lifetime of the 2221c3bbb01SEd Maste // string as it will never go away once it has been put into the ConstString 2231c3bbb01SEd Maste // string pool 2241c3bbb01SEd Maste uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString(); 2251c3bbb01SEd Maste } 2261c3bbb01SEd Maste 2271c3bbb01SEd Maste if (uuid_cstr && uuid_cstr[0]) 2281c3bbb01SEd Maste { 2291c3bbb01SEd Maste if (log) 2301c3bbb01SEd Maste log->Printf ("SBModule(%p)::GetUUIDString () => %s", static_cast<void*>(module_sp.get()), uuid_cstr); 2311c3bbb01SEd Maste return uuid_cstr; 232ac7ddfbfSEd Maste } 233ac7ddfbfSEd Maste 234ac7ddfbfSEd Maste if (log) 2351c3bbb01SEd Maste log->Printf ("SBModule(%p)::GetUUIDString () => NULL", static_cast<void*>(module_sp.get())); 2361c3bbb01SEd Maste return NULL; 237ac7ddfbfSEd Maste } 238ac7ddfbfSEd Maste 239ac7ddfbfSEd Maste 240ac7ddfbfSEd Maste bool 241ac7ddfbfSEd Maste SBModule::operator == (const SBModule &rhs) const 242ac7ddfbfSEd Maste { 243ac7ddfbfSEd Maste if (m_opaque_sp) 244ac7ddfbfSEd Maste return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 245ac7ddfbfSEd Maste return false; 246ac7ddfbfSEd Maste } 247ac7ddfbfSEd Maste 248ac7ddfbfSEd Maste bool 249ac7ddfbfSEd Maste SBModule::operator != (const SBModule &rhs) const 250ac7ddfbfSEd Maste { 251ac7ddfbfSEd Maste if (m_opaque_sp) 252ac7ddfbfSEd Maste return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 253ac7ddfbfSEd Maste return false; 254ac7ddfbfSEd Maste } 255ac7ddfbfSEd Maste 256ac7ddfbfSEd Maste ModuleSP 257ac7ddfbfSEd Maste SBModule::GetSP () const 258ac7ddfbfSEd Maste { 259ac7ddfbfSEd Maste return m_opaque_sp; 260ac7ddfbfSEd Maste } 261ac7ddfbfSEd Maste 262ac7ddfbfSEd Maste void 263ac7ddfbfSEd Maste SBModule::SetSP (const ModuleSP &module_sp) 264ac7ddfbfSEd Maste { 265ac7ddfbfSEd Maste m_opaque_sp = module_sp; 266ac7ddfbfSEd Maste } 267ac7ddfbfSEd Maste 268ac7ddfbfSEd Maste SBAddress 269ac7ddfbfSEd Maste SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 270ac7ddfbfSEd Maste { 271ac7ddfbfSEd Maste lldb::SBAddress sb_addr; 272ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 273ac7ddfbfSEd Maste if (module_sp) 274ac7ddfbfSEd Maste { 275ac7ddfbfSEd Maste Address addr; 276ac7ddfbfSEd Maste if (module_sp->ResolveFileAddress (vm_addr, addr)) 277ac7ddfbfSEd Maste sb_addr.ref() = addr; 278ac7ddfbfSEd Maste } 279ac7ddfbfSEd Maste return sb_addr; 280ac7ddfbfSEd Maste } 281ac7ddfbfSEd Maste 282ac7ddfbfSEd Maste SBSymbolContext 283ac7ddfbfSEd Maste SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 284ac7ddfbfSEd Maste { 285ac7ddfbfSEd Maste SBSymbolContext sb_sc; 286ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 287ac7ddfbfSEd Maste if (module_sp && addr.IsValid()) 288ac7ddfbfSEd Maste module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 289ac7ddfbfSEd Maste return sb_sc; 290ac7ddfbfSEd Maste } 291ac7ddfbfSEd Maste 292ac7ddfbfSEd Maste bool 293ac7ddfbfSEd Maste SBModule::GetDescription (SBStream &description) 294ac7ddfbfSEd Maste { 295ac7ddfbfSEd Maste Stream &strm = description.ref(); 296ac7ddfbfSEd Maste 297ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 298ac7ddfbfSEd Maste if (module_sp) 299ac7ddfbfSEd Maste { 300ac7ddfbfSEd Maste module_sp->GetDescription (&strm); 301ac7ddfbfSEd Maste } 302ac7ddfbfSEd Maste else 303ac7ddfbfSEd Maste strm.PutCString ("No value"); 304ac7ddfbfSEd Maste 305ac7ddfbfSEd Maste return true; 306ac7ddfbfSEd Maste } 307ac7ddfbfSEd Maste 308ac7ddfbfSEd Maste uint32_t 309ac7ddfbfSEd Maste SBModule::GetNumCompileUnits() 310ac7ddfbfSEd Maste { 311ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 312ac7ddfbfSEd Maste if (module_sp) 313ac7ddfbfSEd Maste { 314ac7ddfbfSEd Maste return module_sp->GetNumCompileUnits (); 315ac7ddfbfSEd Maste } 316ac7ddfbfSEd Maste return 0; 317ac7ddfbfSEd Maste } 318ac7ddfbfSEd Maste 319ac7ddfbfSEd Maste SBCompileUnit 320ac7ddfbfSEd Maste SBModule::GetCompileUnitAtIndex (uint32_t index) 321ac7ddfbfSEd Maste { 322ac7ddfbfSEd Maste SBCompileUnit sb_cu; 323ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 324ac7ddfbfSEd Maste if (module_sp) 325ac7ddfbfSEd Maste { 326ac7ddfbfSEd Maste CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 327ac7ddfbfSEd Maste sb_cu.reset(cu_sp.get()); 328ac7ddfbfSEd Maste } 329ac7ddfbfSEd Maste return sb_cu; 330ac7ddfbfSEd Maste } 331ac7ddfbfSEd Maste 332ac7ddfbfSEd Maste static Symtab * 333ac7ddfbfSEd Maste GetUnifiedSymbolTable (const lldb::ModuleSP& module_sp) 334ac7ddfbfSEd Maste { 335ac7ddfbfSEd Maste if (module_sp) 336ac7ddfbfSEd Maste { 337ac7ddfbfSEd Maste SymbolVendor *symbols = module_sp->GetSymbolVendor(); 338ac7ddfbfSEd Maste if (symbols) 339ac7ddfbfSEd Maste return symbols->GetSymtab(); 340ac7ddfbfSEd Maste } 341ac7ddfbfSEd Maste return NULL; 342ac7ddfbfSEd Maste } 343ac7ddfbfSEd Maste 344ac7ddfbfSEd Maste size_t 345ac7ddfbfSEd Maste SBModule::GetNumSymbols () 346ac7ddfbfSEd Maste { 347ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 348ac7ddfbfSEd Maste if (module_sp) 349ac7ddfbfSEd Maste { 350ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable (module_sp); 351ac7ddfbfSEd Maste if (symtab) 352ac7ddfbfSEd Maste return symtab->GetNumSymbols(); 353ac7ddfbfSEd Maste } 354ac7ddfbfSEd Maste return 0; 355ac7ddfbfSEd Maste } 356ac7ddfbfSEd Maste 357ac7ddfbfSEd Maste SBSymbol 358ac7ddfbfSEd Maste SBModule::GetSymbolAtIndex (size_t idx) 359ac7ddfbfSEd Maste { 360ac7ddfbfSEd Maste SBSymbol sb_symbol; 361ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 362ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable (module_sp); 363ac7ddfbfSEd Maste if (symtab) 364ac7ddfbfSEd Maste sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 365ac7ddfbfSEd Maste return sb_symbol; 366ac7ddfbfSEd Maste } 367ac7ddfbfSEd Maste 368ac7ddfbfSEd Maste lldb::SBSymbol 369ac7ddfbfSEd Maste SBModule::FindSymbol (const char *name, 370ac7ddfbfSEd Maste lldb::SymbolType symbol_type) 371ac7ddfbfSEd Maste { 372ac7ddfbfSEd Maste SBSymbol sb_symbol; 373ac7ddfbfSEd Maste if (name && name[0]) 374ac7ddfbfSEd Maste { 375ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 376ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable (module_sp); 377ac7ddfbfSEd Maste if (symtab) 378ac7ddfbfSEd Maste sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny)); 379ac7ddfbfSEd Maste } 380ac7ddfbfSEd Maste return sb_symbol; 381ac7ddfbfSEd Maste } 382ac7ddfbfSEd Maste 383ac7ddfbfSEd Maste 384ac7ddfbfSEd Maste lldb::SBSymbolContextList 385ac7ddfbfSEd Maste SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type) 386ac7ddfbfSEd Maste { 387ac7ddfbfSEd Maste SBSymbolContextList sb_sc_list; 388ac7ddfbfSEd Maste if (name && name[0]) 389ac7ddfbfSEd Maste { 390ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 391ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable (module_sp); 392ac7ddfbfSEd Maste if (symtab) 393ac7ddfbfSEd Maste { 394ac7ddfbfSEd Maste std::vector<uint32_t> matching_symbol_indexes; 395ac7ddfbfSEd Maste const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes); 396ac7ddfbfSEd Maste if (num_matches) 397ac7ddfbfSEd Maste { 398ac7ddfbfSEd Maste SymbolContext sc; 399ac7ddfbfSEd Maste sc.module_sp = module_sp; 400ac7ddfbfSEd Maste SymbolContextList &sc_list = *sb_sc_list; 401ac7ddfbfSEd Maste for (size_t i=0; i<num_matches; ++i) 402ac7ddfbfSEd Maste { 403ac7ddfbfSEd Maste sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]); 404ac7ddfbfSEd Maste if (sc.symbol) 405ac7ddfbfSEd Maste sc_list.Append(sc); 406ac7ddfbfSEd Maste } 407ac7ddfbfSEd Maste } 408ac7ddfbfSEd Maste } 409ac7ddfbfSEd Maste } 410ac7ddfbfSEd Maste return sb_sc_list; 411ac7ddfbfSEd Maste 412ac7ddfbfSEd Maste } 413ac7ddfbfSEd Maste 414ac7ddfbfSEd Maste 415ac7ddfbfSEd Maste 416ac7ddfbfSEd Maste size_t 417ac7ddfbfSEd Maste SBModule::GetNumSections () 418ac7ddfbfSEd Maste { 419ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 420ac7ddfbfSEd Maste if (module_sp) 421ac7ddfbfSEd Maste { 422ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list. 423ac7ddfbfSEd Maste module_sp->GetSymbolVendor(); 424ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList(); 425ac7ddfbfSEd Maste if (section_list) 426ac7ddfbfSEd Maste return section_list->GetSize(); 427ac7ddfbfSEd Maste } 428ac7ddfbfSEd Maste return 0; 429ac7ddfbfSEd Maste } 430ac7ddfbfSEd Maste 431ac7ddfbfSEd Maste SBSection 432ac7ddfbfSEd Maste SBModule::GetSectionAtIndex (size_t idx) 433ac7ddfbfSEd Maste { 434ac7ddfbfSEd Maste SBSection sb_section; 435ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 436ac7ddfbfSEd Maste if (module_sp) 437ac7ddfbfSEd Maste { 438ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list. 439ac7ddfbfSEd Maste module_sp->GetSymbolVendor(); 440ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList (); 441ac7ddfbfSEd Maste 442ac7ddfbfSEd Maste if (section_list) 443ac7ddfbfSEd Maste sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 444ac7ddfbfSEd Maste } 445ac7ddfbfSEd Maste return sb_section; 446ac7ddfbfSEd Maste } 447ac7ddfbfSEd Maste 448ac7ddfbfSEd Maste lldb::SBSymbolContextList 449ac7ddfbfSEd Maste SBModule::FindFunctions (const char *name, 450ac7ddfbfSEd Maste uint32_t name_type_mask) 451ac7ddfbfSEd Maste { 452ac7ddfbfSEd Maste lldb::SBSymbolContextList sb_sc_list; 453ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 454ac7ddfbfSEd Maste if (name && module_sp) 455ac7ddfbfSEd Maste { 456ac7ddfbfSEd Maste const bool append = true; 457ac7ddfbfSEd Maste const bool symbols_ok = true; 458ac7ddfbfSEd Maste const bool inlines_ok = true; 459ac7ddfbfSEd Maste module_sp->FindFunctions (ConstString(name), 460ac7ddfbfSEd Maste NULL, 461ac7ddfbfSEd Maste name_type_mask, 462ac7ddfbfSEd Maste symbols_ok, 463ac7ddfbfSEd Maste inlines_ok, 464ac7ddfbfSEd Maste append, 465ac7ddfbfSEd Maste *sb_sc_list); 466ac7ddfbfSEd Maste } 467ac7ddfbfSEd Maste return sb_sc_list; 468ac7ddfbfSEd Maste } 469ac7ddfbfSEd Maste 470ac7ddfbfSEd Maste 471ac7ddfbfSEd Maste SBValueList 472ac7ddfbfSEd Maste SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 473ac7ddfbfSEd Maste { 474ac7ddfbfSEd Maste SBValueList sb_value_list; 475ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 476ac7ddfbfSEd Maste if (name && module_sp) 477ac7ddfbfSEd Maste { 478ac7ddfbfSEd Maste VariableList variable_list; 479ac7ddfbfSEd Maste const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 480ac7ddfbfSEd Maste NULL, 481ac7ddfbfSEd Maste false, 482ac7ddfbfSEd Maste max_matches, 483ac7ddfbfSEd Maste variable_list); 484ac7ddfbfSEd Maste 485ac7ddfbfSEd Maste if (match_count > 0) 486ac7ddfbfSEd Maste { 487ac7ddfbfSEd Maste for (uint32_t i=0; i<match_count; ++i) 488ac7ddfbfSEd Maste { 489ac7ddfbfSEd Maste lldb::ValueObjectSP valobj_sp; 490ac7ddfbfSEd Maste TargetSP target_sp (target.GetSP()); 491ac7ddfbfSEd Maste valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 492ac7ddfbfSEd Maste if (valobj_sp) 493ac7ddfbfSEd Maste sb_value_list.Append(SBValue(valobj_sp)); 494ac7ddfbfSEd Maste } 495ac7ddfbfSEd Maste } 496ac7ddfbfSEd Maste } 497ac7ddfbfSEd Maste 498ac7ddfbfSEd Maste return sb_value_list; 499ac7ddfbfSEd Maste } 500ac7ddfbfSEd Maste 501ac7ddfbfSEd Maste lldb::SBValue 502ac7ddfbfSEd Maste SBModule::FindFirstGlobalVariable (lldb::SBTarget &target, const char *name) 503ac7ddfbfSEd Maste { 504ac7ddfbfSEd Maste SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 505ac7ddfbfSEd Maste if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 506ac7ddfbfSEd Maste return sb_value_list.GetValueAtIndex(0); 507ac7ddfbfSEd Maste return SBValue(); 508ac7ddfbfSEd Maste } 509ac7ddfbfSEd Maste 510ac7ddfbfSEd Maste lldb::SBType 511ac7ddfbfSEd Maste SBModule::FindFirstType (const char *name_cstr) 512ac7ddfbfSEd Maste { 513ac7ddfbfSEd Maste SBType sb_type; 514ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 515ac7ddfbfSEd Maste if (name_cstr && module_sp) 516ac7ddfbfSEd Maste { 517ac7ddfbfSEd Maste SymbolContext sc; 518ac7ddfbfSEd Maste const bool exact_match = false; 519ac7ddfbfSEd Maste ConstString name(name_cstr); 520ac7ddfbfSEd Maste 521ac7ddfbfSEd Maste sb_type = SBType (module_sp->FindFirstType(sc, name, exact_match)); 522ac7ddfbfSEd Maste 523ac7ddfbfSEd Maste if (!sb_type.IsValid()) 5249f2f44ceSEd Maste { 5259f2f44ceSEd Maste TypeSystem *type_system = module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 5269f2f44ceSEd Maste if (type_system) 5279f2f44ceSEd Maste sb_type = SBType (type_system->GetBuiltinTypeByName(name)); 5289f2f44ceSEd Maste } 529ac7ddfbfSEd Maste } 530ac7ddfbfSEd Maste return sb_type; 531ac7ddfbfSEd Maste } 532ac7ddfbfSEd Maste 533ac7ddfbfSEd Maste lldb::SBType 534ac7ddfbfSEd Maste SBModule::GetBasicType(lldb::BasicType type) 535ac7ddfbfSEd Maste { 536ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 537ac7ddfbfSEd Maste if (module_sp) 5389f2f44ceSEd Maste { 5399f2f44ceSEd Maste TypeSystem *type_system = module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 5409f2f44ceSEd Maste if (type_system) 5419f2f44ceSEd Maste return SBType (type_system->GetBasicTypeFromAST(type)); 5429f2f44ceSEd Maste } 543ac7ddfbfSEd Maste return SBType(); 544ac7ddfbfSEd Maste } 545ac7ddfbfSEd Maste 546ac7ddfbfSEd Maste lldb::SBTypeList 547ac7ddfbfSEd Maste SBModule::FindTypes (const char *type) 548ac7ddfbfSEd Maste { 549ac7ddfbfSEd Maste SBTypeList retval; 550ac7ddfbfSEd Maste 551ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 552ac7ddfbfSEd Maste if (type && module_sp) 553ac7ddfbfSEd Maste { 554ac7ddfbfSEd Maste SymbolContext sc; 555ac7ddfbfSEd Maste TypeList type_list; 556ac7ddfbfSEd Maste const bool exact_match = false; 557ac7ddfbfSEd Maste ConstString name(type); 558ac7ddfbfSEd Maste const uint32_t num_matches = module_sp->FindTypes (sc, 559ac7ddfbfSEd Maste name, 560ac7ddfbfSEd Maste exact_match, 561ac7ddfbfSEd Maste UINT32_MAX, 562ac7ddfbfSEd Maste type_list); 563ac7ddfbfSEd Maste 564ac7ddfbfSEd Maste if (num_matches > 0) 565ac7ddfbfSEd Maste { 566ac7ddfbfSEd Maste for (size_t idx = 0; idx < num_matches; idx++) 567ac7ddfbfSEd Maste { 568ac7ddfbfSEd Maste TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 569ac7ddfbfSEd Maste if (type_sp) 570ac7ddfbfSEd Maste retval.Append(SBType(type_sp)); 571ac7ddfbfSEd Maste } 572ac7ddfbfSEd Maste } 573ac7ddfbfSEd Maste else 574ac7ddfbfSEd Maste { 5759f2f44ceSEd Maste TypeSystem *type_system = module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 5769f2f44ceSEd Maste if (type_system) 5779f2f44ceSEd Maste { 5789f2f44ceSEd Maste CompilerType compiler_type = type_system->GetBuiltinTypeByName(name); 5799f2f44ceSEd Maste if (compiler_type) 5809f2f44ceSEd Maste retval.Append(SBType(compiler_type)); 5819f2f44ceSEd Maste } 582ac7ddfbfSEd Maste } 583ac7ddfbfSEd Maste } 584ac7ddfbfSEd Maste 585ac7ddfbfSEd Maste return retval; 586ac7ddfbfSEd Maste } 587ac7ddfbfSEd Maste 58812b93ac6SEd Maste lldb::SBType 58912b93ac6SEd Maste SBModule::GetTypeByID (lldb::user_id_t uid) 59012b93ac6SEd Maste { 59112b93ac6SEd Maste ModuleSP module_sp (GetSP ()); 59212b93ac6SEd Maste if (module_sp) 59312b93ac6SEd Maste { 59412b93ac6SEd Maste SymbolVendor* vendor = module_sp->GetSymbolVendor(); 59512b93ac6SEd Maste if (vendor) 59612b93ac6SEd Maste { 59712b93ac6SEd Maste Type *type_ptr = vendor->ResolveTypeUID(uid); 59812b93ac6SEd Maste if (type_ptr) 59912b93ac6SEd Maste return SBType(type_ptr->shared_from_this()); 60012b93ac6SEd Maste } 60112b93ac6SEd Maste } 60212b93ac6SEd Maste return SBType(); 60312b93ac6SEd Maste } 60412b93ac6SEd Maste 605ac7ddfbfSEd Maste lldb::SBTypeList 606ac7ddfbfSEd Maste SBModule::GetTypes (uint32_t type_mask) 607ac7ddfbfSEd Maste { 608ac7ddfbfSEd Maste SBTypeList sb_type_list; 609ac7ddfbfSEd Maste 610ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 611ac7ddfbfSEd Maste if (module_sp) 612ac7ddfbfSEd Maste { 613ac7ddfbfSEd Maste SymbolVendor* vendor = module_sp->GetSymbolVendor(); 614ac7ddfbfSEd Maste if (vendor) 615ac7ddfbfSEd Maste { 616ac7ddfbfSEd Maste TypeList type_list; 617ac7ddfbfSEd Maste vendor->GetTypes (NULL, type_mask, type_list); 618ac7ddfbfSEd Maste sb_type_list.m_opaque_ap->Append(type_list); 619ac7ddfbfSEd Maste } 620ac7ddfbfSEd Maste } 621ac7ddfbfSEd Maste return sb_type_list; 622ac7ddfbfSEd Maste } 623ac7ddfbfSEd Maste 624ac7ddfbfSEd Maste SBSection 625ac7ddfbfSEd Maste SBModule::FindSection (const char *sect_name) 626ac7ddfbfSEd Maste { 627ac7ddfbfSEd Maste SBSection sb_section; 628ac7ddfbfSEd Maste 629ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 630ac7ddfbfSEd Maste if (sect_name && module_sp) 631ac7ddfbfSEd Maste { 632ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list. 633ac7ddfbfSEd Maste module_sp->GetSymbolVendor(); 634ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList(); 635ac7ddfbfSEd Maste if (section_list) 636ac7ddfbfSEd Maste { 637ac7ddfbfSEd Maste ConstString const_sect_name(sect_name); 638ac7ddfbfSEd Maste SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 639ac7ddfbfSEd Maste if (section_sp) 640ac7ddfbfSEd Maste { 641ac7ddfbfSEd Maste sb_section.SetSP (section_sp); 642ac7ddfbfSEd Maste } 643ac7ddfbfSEd Maste } 644ac7ddfbfSEd Maste } 645ac7ddfbfSEd Maste return sb_section; 646ac7ddfbfSEd Maste } 647ac7ddfbfSEd Maste 648ac7ddfbfSEd Maste lldb::ByteOrder 649ac7ddfbfSEd Maste SBModule::GetByteOrder () 650ac7ddfbfSEd Maste { 651ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 652ac7ddfbfSEd Maste if (module_sp) 653ac7ddfbfSEd Maste return module_sp->GetArchitecture().GetByteOrder(); 654ac7ddfbfSEd Maste return eByteOrderInvalid; 655ac7ddfbfSEd Maste } 656ac7ddfbfSEd Maste 657ac7ddfbfSEd Maste const char * 658ac7ddfbfSEd Maste SBModule::GetTriple () 659ac7ddfbfSEd Maste { 660ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 661ac7ddfbfSEd Maste if (module_sp) 662ac7ddfbfSEd Maste { 663ac7ddfbfSEd Maste std::string triple (module_sp->GetArchitecture().GetTriple().str()); 664ac7ddfbfSEd Maste // Unique the string so we don't run into ownership issues since 665ac7ddfbfSEd Maste // the const strings put the string into the string pool once and 666ac7ddfbfSEd Maste // the strings never comes out 667ac7ddfbfSEd Maste ConstString const_triple (triple.c_str()); 668ac7ddfbfSEd Maste return const_triple.GetCString(); 669ac7ddfbfSEd Maste } 670ac7ddfbfSEd Maste return NULL; 671ac7ddfbfSEd Maste } 672ac7ddfbfSEd Maste 673ac7ddfbfSEd Maste uint32_t 674ac7ddfbfSEd Maste SBModule::GetAddressByteSize() 675ac7ddfbfSEd Maste { 676ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 677ac7ddfbfSEd Maste if (module_sp) 678ac7ddfbfSEd Maste return module_sp->GetArchitecture().GetAddressByteSize(); 679ac7ddfbfSEd Maste return sizeof(void*); 680ac7ddfbfSEd Maste } 681ac7ddfbfSEd Maste 682ac7ddfbfSEd Maste 683ac7ddfbfSEd Maste uint32_t 684ac7ddfbfSEd Maste SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 685ac7ddfbfSEd Maste { 686ac7ddfbfSEd Maste ModuleSP module_sp (GetSP ()); 687ac7ddfbfSEd Maste if (module_sp) 688ac7ddfbfSEd Maste return module_sp->GetVersion(versions, num_versions); 689ac7ddfbfSEd Maste else 690ac7ddfbfSEd Maste { 691ac7ddfbfSEd Maste if (versions && num_versions) 692ac7ddfbfSEd Maste { 693ac7ddfbfSEd Maste for (uint32_t i=0; i<num_versions; ++i) 694ac7ddfbfSEd Maste versions[i] = UINT32_MAX; 695ac7ddfbfSEd Maste } 696ac7ddfbfSEd Maste return 0; 697ac7ddfbfSEd Maste } 698ac7ddfbfSEd Maste } 699ac7ddfbfSEd Maste 7001c3bbb01SEd Maste lldb::SBFileSpec 7011c3bbb01SEd Maste SBModule::GetSymbolFileSpec() const 7021c3bbb01SEd Maste { 7031c3bbb01SEd Maste lldb::SBFileSpec sb_file_spec; 7041c3bbb01SEd Maste ModuleSP module_sp(GetSP()); 7051c3bbb01SEd Maste if (module_sp) 7061c3bbb01SEd Maste { 7071c3bbb01SEd Maste SymbolVendor *symbol_vendor_ptr = module_sp->GetSymbolVendor(); 7081c3bbb01SEd Maste if (symbol_vendor_ptr) 7091c3bbb01SEd Maste sb_file_spec.SetFileSpec(symbol_vendor_ptr->GetMainFileSpec()); 7101c3bbb01SEd Maste } 7111c3bbb01SEd Maste return sb_file_spec; 7121c3bbb01SEd Maste } 7131c3bbb01SEd Maste 7141c3bbb01SEd Maste lldb::SBAddress 7151c3bbb01SEd Maste SBModule::GetObjectFileHeaderAddress() const 7161c3bbb01SEd Maste { 7171c3bbb01SEd Maste lldb::SBAddress sb_addr; 7181c3bbb01SEd Maste ModuleSP module_sp (GetSP ()); 7191c3bbb01SEd Maste if (module_sp) 7201c3bbb01SEd Maste { 7211c3bbb01SEd Maste ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 7221c3bbb01SEd Maste if (objfile_ptr) 7231c3bbb01SEd Maste sb_addr.ref() = objfile_ptr->GetHeaderAddress(); 7241c3bbb01SEd Maste } 7251c3bbb01SEd Maste return sb_addr; 7261c3bbb01SEd Maste } 727