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" 13c9660546SGreg Clayton #include "lldb/API/SBProcess.h" 14dde9cff3SCaroline Tice #include "lldb/API/SBStream.h" 15fe356d35SGreg Clayton #include "lldb/API/SBSymbolContextList.h" 1630fdc8d8SChris Lattner #include "lldb/Core/Module.h" 17ceb6b139SCaroline Tice #include "lldb/Core/Log.h" 181f746071SGreg Clayton #include "lldb/Core/Section.h" 1938adbbb8SGreg Clayton #include "lldb/Core/StreamString.h" 20dea8cb4fSGreg Clayton #include "lldb/Core/ValueObjectList.h" 21dea8cb4fSGreg Clayton #include "lldb/Core/ValueObjectVariable.h" 221f746071SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 236f3533fbSEnrico Granata #include "lldb/Symbol/SymbolVendor.h" 241f746071SGreg Clayton #include "lldb/Symbol/Symtab.h" 25dea8cb4fSGreg Clayton #include "lldb/Symbol/VariableList.h" 26dea8cb4fSGreg Clayton #include "lldb/Target/Target.h" 2730fdc8d8SChris Lattner 2830fdc8d8SChris Lattner using namespace lldb; 29ceb6b139SCaroline Tice using namespace lldb_private; 3030fdc8d8SChris Lattner 3130fdc8d8SChris Lattner 3230fdc8d8SChris Lattner SBModule::SBModule () : 336611103cSGreg Clayton m_opaque_sp () 3430fdc8d8SChris Lattner { 3530fdc8d8SChris Lattner } 3630fdc8d8SChris Lattner 3730fdc8d8SChris Lattner SBModule::SBModule (const lldb::ModuleSP& module_sp) : 386611103cSGreg Clayton m_opaque_sp (module_sp) 3930fdc8d8SChris Lattner { 4030fdc8d8SChris Lattner } 4130fdc8d8SChris Lattner 42efabb123SGreg Clayton SBModule::SBModule(const SBModule &rhs) : 43efabb123SGreg Clayton m_opaque_sp (rhs.m_opaque_sp) 44efabb123SGreg Clayton { 45efabb123SGreg Clayton } 46efabb123SGreg Clayton 47c9660546SGreg Clayton SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : 48c9660546SGreg Clayton m_opaque_sp () 49c9660546SGreg Clayton { 50c9660546SGreg Clayton ProcessSP process_sp (process.GetSP()); 51c9660546SGreg Clayton if (process_sp) 52c859e2d5SGreg Clayton { 53c859e2d5SGreg Clayton const bool add_image_to_target = true; 54c859e2d5SGreg Clayton const bool load_image_sections_in_target = true; 55c859e2d5SGreg Clayton m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), 56c859e2d5SGreg Clayton header_addr, 57c859e2d5SGreg Clayton add_image_to_target, 58c859e2d5SGreg Clayton load_image_sections_in_target); 59c859e2d5SGreg Clayton } 60c9660546SGreg Clayton } 61c9660546SGreg Clayton 62efabb123SGreg Clayton const SBModule & 63efabb123SGreg Clayton SBModule::operator = (const SBModule &rhs) 64efabb123SGreg Clayton { 65efabb123SGreg Clayton if (this != &rhs) 66efabb123SGreg Clayton m_opaque_sp = rhs.m_opaque_sp; 67efabb123SGreg Clayton return *this; 68efabb123SGreg Clayton } 69efabb123SGreg Clayton 7030fdc8d8SChris Lattner SBModule::~SBModule () 7130fdc8d8SChris Lattner { 7230fdc8d8SChris Lattner } 7330fdc8d8SChris Lattner 7430fdc8d8SChris Lattner bool 7530fdc8d8SChris Lattner SBModule::IsValid () const 7630fdc8d8SChris Lattner { 776611103cSGreg Clayton return m_opaque_sp.get() != NULL; 7830fdc8d8SChris Lattner } 7930fdc8d8SChris Lattner 805d3bca4eSJim Ingham void 815d3bca4eSJim Ingham SBModule::Clear() 825d3bca4eSJim Ingham { 835d3bca4eSJim Ingham m_opaque_sp.reset(); 845d3bca4eSJim Ingham } 855d3bca4eSJim Ingham 8630fdc8d8SChris Lattner SBFileSpec 8730fdc8d8SChris Lattner SBModule::GetFileSpec () const 8830fdc8d8SChris Lattner { 892d4edfbcSGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 90ceb6b139SCaroline Tice 9130fdc8d8SChris Lattner SBFileSpec file_spec; 92c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 93c2ff9318SGreg Clayton if (module_sp) 94c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetFileSpec()); 95ceb6b139SCaroline Tice 96ceb6b139SCaroline Tice if (log) 97ceb6b139SCaroline Tice { 98cfd1acedSGreg Clayton log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 99c2ff9318SGreg Clayton module_sp.get(), file_spec.get()); 100ceb6b139SCaroline Tice } 101ceb6b139SCaroline Tice 10230fdc8d8SChris Lattner return file_spec; 10330fdc8d8SChris Lattner } 10430fdc8d8SChris Lattner 1052289fa48SGreg Clayton lldb::SBFileSpec 1062289fa48SGreg Clayton SBModule::GetPlatformFileSpec () const 1072289fa48SGreg Clayton { 1082289fa48SGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1092289fa48SGreg Clayton 1102289fa48SGreg Clayton SBFileSpec file_spec; 111c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 112c2ff9318SGreg Clayton if (module_sp) 113c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 1142289fa48SGreg Clayton 1152289fa48SGreg Clayton if (log) 1162289fa48SGreg Clayton { 1172289fa48SGreg Clayton log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 118c2ff9318SGreg Clayton module_sp.get(), file_spec.get()); 1192289fa48SGreg Clayton } 1202289fa48SGreg Clayton 1212289fa48SGreg Clayton return file_spec; 1222289fa48SGreg Clayton 1232289fa48SGreg Clayton } 1242289fa48SGreg Clayton 1252289fa48SGreg Clayton bool 1262289fa48SGreg Clayton SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 1272289fa48SGreg Clayton { 1282289fa48SGreg Clayton bool result = false; 1292289fa48SGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1302289fa48SGreg Clayton 131c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 132c2ff9318SGreg Clayton if (module_sp) 1332289fa48SGreg Clayton { 134c2ff9318SGreg Clayton module_sp->SetPlatformFileSpec(*platform_file); 1352289fa48SGreg Clayton result = true; 1362289fa48SGreg Clayton } 1372289fa48SGreg Clayton 1382289fa48SGreg Clayton if (log) 1392289fa48SGreg Clayton { 1402289fa48SGreg Clayton log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i", 141c2ff9318SGreg Clayton module_sp.get(), 1422289fa48SGreg Clayton platform_file.get(), 1432289fa48SGreg Clayton platform_file->GetDirectory().GetCString(), 1442289fa48SGreg Clayton platform_file->GetDirectory() ? "/" : "", 1452289fa48SGreg Clayton platform_file->GetFilename().GetCString(), 1462289fa48SGreg Clayton result); 1472289fa48SGreg Clayton } 1482289fa48SGreg Clayton return result; 1492289fa48SGreg Clayton } 1502289fa48SGreg Clayton 1512289fa48SGreg Clayton 1522289fa48SGreg Clayton 15330fdc8d8SChris Lattner const uint8_t * 15430fdc8d8SChris Lattner SBModule::GetUUIDBytes () const 15530fdc8d8SChris Lattner { 1562d4edfbcSGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 157ceb6b139SCaroline Tice 1584838131bSGreg Clayton const uint8_t *uuid_bytes = NULL; 159c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 160c2ff9318SGreg Clayton if (module_sp) 161c2ff9318SGreg Clayton uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 162ceb6b139SCaroline Tice 163ceb6b139SCaroline Tice if (log) 1644838131bSGreg Clayton { 1654838131bSGreg Clayton if (uuid_bytes) 1664838131bSGreg Clayton { 1674838131bSGreg Clayton StreamString s; 168c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 169c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData()); 1704838131bSGreg Clayton } 1714838131bSGreg Clayton else 172c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get()); 1734838131bSGreg Clayton } 1744838131bSGreg Clayton return uuid_bytes; 17530fdc8d8SChris Lattner } 17630fdc8d8SChris Lattner 17730fdc8d8SChris Lattner 178df2963edSJohnny Chen const char * 179df2963edSJohnny Chen SBModule::GetUUIDString () const 180df2963edSJohnny Chen { 181df2963edSJohnny Chen LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 182df2963edSJohnny Chen 183df2963edSJohnny Chen static char uuid_string[80]; 184df2963edSJohnny Chen const char * uuid_c_string = NULL; 185c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 186c2ff9318SGreg Clayton if (module_sp) 187c2ff9318SGreg Clayton uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string)); 188df2963edSJohnny Chen 189df2963edSJohnny Chen if (log) 190df2963edSJohnny Chen { 191df2963edSJohnny Chen if (uuid_c_string) 192df2963edSJohnny Chen { 193df2963edSJohnny Chen StreamString s; 194c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 195c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData()); 196df2963edSJohnny Chen } 197df2963edSJohnny Chen else 198c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get()); 199df2963edSJohnny Chen } 200df2963edSJohnny Chen return uuid_c_string; 201df2963edSJohnny Chen } 202df2963edSJohnny Chen 203df2963edSJohnny Chen 20430fdc8d8SChris Lattner bool 20530fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 20630fdc8d8SChris Lattner { 2076611103cSGreg Clayton if (m_opaque_sp) 2086611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 20930fdc8d8SChris Lattner return false; 21030fdc8d8SChris Lattner } 21130fdc8d8SChris Lattner 21230fdc8d8SChris Lattner bool 21330fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 21430fdc8d8SChris Lattner { 2156611103cSGreg Clayton if (m_opaque_sp) 2166611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 21730fdc8d8SChris Lattner return false; 21830fdc8d8SChris Lattner } 21930fdc8d8SChris Lattner 220acdbe816SGreg Clayton ModuleSP 221acdbe816SGreg Clayton SBModule::GetSP () const 222cac9c5f9SGreg Clayton { 223cac9c5f9SGreg Clayton return m_opaque_sp; 224cac9c5f9SGreg Clayton } 22530fdc8d8SChris Lattner 22630fdc8d8SChris Lattner void 227acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 22830fdc8d8SChris Lattner { 2296611103cSGreg Clayton m_opaque_sp = module_sp; 23030fdc8d8SChris Lattner } 23130fdc8d8SChris Lattner 232cac9c5f9SGreg Clayton SBAddress 233cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 23409960031SGreg Clayton { 235cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 236c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 237c2ff9318SGreg Clayton if (module_sp) 238cac9c5f9SGreg Clayton { 239cac9c5f9SGreg Clayton Address addr; 240c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 241cac9c5f9SGreg Clayton sb_addr.ref() = addr; 242cac9c5f9SGreg Clayton } 243cac9c5f9SGreg Clayton return sb_addr; 24409960031SGreg Clayton } 24509960031SGreg Clayton 24609960031SGreg Clayton SBSymbolContext 24709960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 24809960031SGreg Clayton { 24909960031SGreg Clayton SBSymbolContext sb_sc; 250c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 251c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 252c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 25309960031SGreg Clayton return sb_sc; 25409960031SGreg Clayton } 25509960031SGreg Clayton 256dde9cff3SCaroline Tice bool 257dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 258dde9cff3SCaroline Tice { 259da7bc7d0SGreg Clayton Stream &strm = description.ref(); 260da7bc7d0SGreg Clayton 261c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 262c2ff9318SGreg Clayton if (module_sp) 263dde9cff3SCaroline Tice { 264c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 265dde9cff3SCaroline Tice } 266dde9cff3SCaroline Tice else 267da7bc7d0SGreg Clayton strm.PutCString ("No value"); 268dde9cff3SCaroline Tice 269dde9cff3SCaroline Tice return true; 270dde9cff3SCaroline Tice } 271bbdabce2SGreg Clayton 272873a7a4bSJohnny Chen uint32_t 273873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 274873a7a4bSJohnny Chen { 275873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 276873a7a4bSJohnny Chen if (module_sp) 277873a7a4bSJohnny Chen { 278873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 279873a7a4bSJohnny Chen } 280873a7a4bSJohnny Chen return 0; 281873a7a4bSJohnny Chen } 282873a7a4bSJohnny Chen 283873a7a4bSJohnny Chen SBCompileUnit 284873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 285873a7a4bSJohnny Chen { 286873a7a4bSJohnny Chen SBCompileUnit sb_cu; 287873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 288873a7a4bSJohnny Chen if (module_sp) 289873a7a4bSJohnny Chen { 290873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 291873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 292873a7a4bSJohnny Chen } 293873a7a4bSJohnny Chen return sb_cu; 294873a7a4bSJohnny Chen } 295873a7a4bSJohnny Chen 296bbdabce2SGreg Clayton size_t 297bbdabce2SGreg Clayton SBModule::GetNumSymbols () 298bbdabce2SGreg Clayton { 299c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 300c2ff9318SGreg Clayton if (module_sp) 301bbdabce2SGreg Clayton { 302c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 303bbdabce2SGreg Clayton if (obj_file) 304bbdabce2SGreg Clayton { 305bbdabce2SGreg Clayton Symtab *symtab = obj_file->GetSymtab(); 306bbdabce2SGreg Clayton if (symtab) 307bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 308bbdabce2SGreg Clayton } 309bbdabce2SGreg Clayton } 310bbdabce2SGreg Clayton return 0; 311bbdabce2SGreg Clayton } 312bbdabce2SGreg Clayton 313bbdabce2SGreg Clayton SBSymbol 314bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 315bbdabce2SGreg Clayton { 316bbdabce2SGreg Clayton SBSymbol sb_symbol; 317c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 318c2ff9318SGreg Clayton if (module_sp) 319bbdabce2SGreg Clayton { 320c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 321bbdabce2SGreg Clayton if (obj_file) 322bbdabce2SGreg Clayton { 323bbdabce2SGreg Clayton Symtab *symtab = obj_file->GetSymtab(); 324bbdabce2SGreg Clayton if (symtab) 325bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 326bbdabce2SGreg Clayton } 327bbdabce2SGreg Clayton } 328bbdabce2SGreg Clayton return sb_symbol; 329bbdabce2SGreg Clayton } 330fe356d35SGreg Clayton 331cac9c5f9SGreg Clayton size_t 332cac9c5f9SGreg Clayton SBModule::GetNumSections () 333cac9c5f9SGreg Clayton { 334c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 335c2ff9318SGreg Clayton if (module_sp) 336cac9c5f9SGreg Clayton { 337c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 338cac9c5f9SGreg Clayton if (obj_file) 339cac9c5f9SGreg Clayton { 340cac9c5f9SGreg Clayton SectionList *section_list = obj_file->GetSectionList (); 341cac9c5f9SGreg Clayton if (section_list) 342cac9c5f9SGreg Clayton return section_list->GetSize(); 343cac9c5f9SGreg Clayton } 344cac9c5f9SGreg Clayton } 345cac9c5f9SGreg Clayton return 0; 346cac9c5f9SGreg Clayton } 347cac9c5f9SGreg Clayton 348cac9c5f9SGreg Clayton SBSection 349cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 350cac9c5f9SGreg Clayton { 351cac9c5f9SGreg Clayton SBSection sb_section; 352c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 353c2ff9318SGreg Clayton if (module_sp) 354cac9c5f9SGreg Clayton { 355c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 356cac9c5f9SGreg Clayton if (obj_file) 357cac9c5f9SGreg Clayton { 358cac9c5f9SGreg Clayton SectionList *section_list = obj_file->GetSectionList (); 359cac9c5f9SGreg Clayton 360cac9c5f9SGreg Clayton if (section_list) 361e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 362cac9c5f9SGreg Clayton } 363cac9c5f9SGreg Clayton } 364cac9c5f9SGreg Clayton return sb_section; 365cac9c5f9SGreg Clayton } 366cac9c5f9SGreg Clayton 3675569e64eSGreg Clayton lldb::SBSymbolContextList 368fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 3695569e64eSGreg Clayton uint32_t name_type_mask) 370fe356d35SGreg Clayton { 3715569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 372c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 373c2ff9318SGreg Clayton if (name && module_sp) 374fe356d35SGreg Clayton { 3755569e64eSGreg Clayton const bool append = true; 376fe356d35SGreg Clayton const bool symbols_ok = true; 3779df05fbbSSean Callanan const bool inlines_ok = true; 378c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 379b6d70ebcSSean Callanan NULL, 380fe356d35SGreg Clayton name_type_mask, 381fe356d35SGreg Clayton symbols_ok, 3829df05fbbSSean Callanan inlines_ok, 383fe356d35SGreg Clayton append, 3845569e64eSGreg Clayton *sb_sc_list); 385fe356d35SGreg Clayton } 3865569e64eSGreg Clayton return sb_sc_list; 387fe356d35SGreg Clayton } 388fe356d35SGreg Clayton 389dea8cb4fSGreg Clayton 390dea8cb4fSGreg Clayton SBValueList 391dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 392dea8cb4fSGreg Clayton { 393dea8cb4fSGreg Clayton SBValueList sb_value_list; 394c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 395c2ff9318SGreg Clayton if (name && module_sp) 396dea8cb4fSGreg Clayton { 397dea8cb4fSGreg Clayton VariableList variable_list; 398c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 399b6d70ebcSSean Callanan NULL, 400dea8cb4fSGreg Clayton false, 401dea8cb4fSGreg Clayton max_matches, 402dea8cb4fSGreg Clayton variable_list); 403dea8cb4fSGreg Clayton 404dea8cb4fSGreg Clayton if (match_count > 0) 405dea8cb4fSGreg Clayton { 406dea8cb4fSGreg Clayton ValueObjectList &value_object_list = sb_value_list.ref(); 407dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 408dea8cb4fSGreg Clayton { 409dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 410b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 411b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 412dea8cb4fSGreg Clayton if (valobj_sp) 413dea8cb4fSGreg Clayton value_object_list.Append(valobj_sp); 414dea8cb4fSGreg Clayton } 415dea8cb4fSGreg Clayton } 416dea8cb4fSGreg Clayton } 417dea8cb4fSGreg Clayton 418dea8cb4fSGreg Clayton return sb_value_list; 419dea8cb4fSGreg Clayton } 4206f3533fbSEnrico Granata 4216f3533fbSEnrico Granata lldb::SBType 4226f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 4236f3533fbSEnrico Granata { 424fe42ac4dSGreg Clayton SBType sb_type; 425c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 426c2ff9318SGreg Clayton if (name_cstr && module_sp) 427fe42ac4dSGreg Clayton { 4286f3533fbSEnrico Granata SymbolContext sc; 4296f3533fbSEnrico Granata TypeList type_list; 4306f3533fbSEnrico Granata uint32_t num_matches = 0; 43184db9105SGreg Clayton const bool exact_match = false; 4326f3533fbSEnrico Granata ConstString name(name_cstr); 4336f3533fbSEnrico Granata 434c2ff9318SGreg Clayton num_matches = module_sp->FindTypes (sc, 4356f3533fbSEnrico Granata name, 43684db9105SGreg Clayton exact_match, 4376f3533fbSEnrico Granata 1, 4386f3533fbSEnrico Granata type_list); 4396f3533fbSEnrico Granata 4406f3533fbSEnrico Granata if (num_matches) 441fe42ac4dSGreg Clayton sb_type = lldb::SBType(type_list.GetTypeAtIndex(0)); 4426f3533fbSEnrico Granata } 443fe42ac4dSGreg Clayton return sb_type; 4446f3533fbSEnrico Granata } 4456f3533fbSEnrico Granata 4466f3533fbSEnrico Granata lldb::SBTypeList 4476f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 4486f3533fbSEnrico Granata { 4496f3533fbSEnrico Granata 4506f3533fbSEnrico Granata SBTypeList retval; 4516f3533fbSEnrico Granata 452c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 453c2ff9318SGreg Clayton if (type && module_sp) 454fe42ac4dSGreg Clayton { 4556f3533fbSEnrico Granata SymbolContext sc; 4566f3533fbSEnrico Granata TypeList type_list; 45784db9105SGreg Clayton const bool exact_match = false; 4586f3533fbSEnrico Granata uint32_t num_matches = 0; 4596f3533fbSEnrico Granata ConstString name(type); 4606f3533fbSEnrico Granata 461c2ff9318SGreg Clayton num_matches = module_sp->FindTypes (sc, 4626f3533fbSEnrico Granata name, 46384db9105SGreg Clayton exact_match, 4646f3533fbSEnrico Granata UINT32_MAX, 4656f3533fbSEnrico Granata type_list); 4666f3533fbSEnrico Granata 4676f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 4686f3533fbSEnrico Granata { 469fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 470fe42ac4dSGreg Clayton if (type_sp) 471fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 472fe42ac4dSGreg Clayton } 4736f3533fbSEnrico Granata } 4746f3533fbSEnrico Granata 4756f3533fbSEnrico Granata return retval; 4766f3533fbSEnrico Granata } 477cac9c5f9SGreg Clayton 478cac9c5f9SGreg Clayton 479cac9c5f9SGreg Clayton SBSection 480cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 481cac9c5f9SGreg Clayton { 482cac9c5f9SGreg Clayton SBSection sb_section; 483cac9c5f9SGreg Clayton 484c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 485c2ff9318SGreg Clayton if (sect_name && module_sp) 486cac9c5f9SGreg Clayton { 487c2ff9318SGreg Clayton ObjectFile *objfile = module_sp->GetObjectFile(); 488cac9c5f9SGreg Clayton if (objfile) 489cac9c5f9SGreg Clayton { 490cac9c5f9SGreg Clayton SectionList *section_list = objfile->GetSectionList(); 491cac9c5f9SGreg Clayton if (section_list) 492cac9c5f9SGreg Clayton { 493cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 494cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 495cac9c5f9SGreg Clayton if (section_sp) 496cac9c5f9SGreg Clayton { 497e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 498cac9c5f9SGreg Clayton } 499cac9c5f9SGreg Clayton } 500cac9c5f9SGreg Clayton } 501cac9c5f9SGreg Clayton } 502cac9c5f9SGreg Clayton return sb_section; 503cac9c5f9SGreg Clayton } 504cac9c5f9SGreg Clayton 50513d1950aSGreg Clayton lldb::ByteOrder 50613d1950aSGreg Clayton SBModule::GetByteOrder () 50713d1950aSGreg Clayton { 508c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 509c2ff9318SGreg Clayton if (module_sp) 510c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 51113d1950aSGreg Clayton return eByteOrderInvalid; 51213d1950aSGreg Clayton } 51313d1950aSGreg Clayton 51413d1950aSGreg Clayton const char * 51513d1950aSGreg Clayton SBModule::GetTriple () 51613d1950aSGreg Clayton { 517c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 518c2ff9318SGreg Clayton if (module_sp) 51913d1950aSGreg Clayton { 520c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 52113d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 52213d1950aSGreg Clayton // the const strings put the string into the string pool once and 52313d1950aSGreg Clayton // the strings never comes out 52413d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 52513d1950aSGreg Clayton return const_triple.GetCString(); 52613d1950aSGreg Clayton } 52713d1950aSGreg Clayton return NULL; 52813d1950aSGreg Clayton } 52913d1950aSGreg Clayton 53013d1950aSGreg Clayton uint32_t 53113d1950aSGreg Clayton SBModule::GetAddressByteSize() 53213d1950aSGreg Clayton { 533c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 534c2ff9318SGreg Clayton if (module_sp) 535c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 53613d1950aSGreg Clayton return sizeof(void*); 53713d1950aSGreg Clayton } 53813d1950aSGreg Clayton 539c2ff9318SGreg Clayton 540c2ff9318SGreg Clayton uint32_t 541c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 542c2ff9318SGreg Clayton { 543c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 544c2ff9318SGreg Clayton if (module_sp) 545*3467d80bSEnrico Granata return module_sp->GetVersion(versions, num_versions); 546*3467d80bSEnrico Granata else 547c2ff9318SGreg Clayton { 548c2ff9318SGreg Clayton if (versions && num_versions) 549c2ff9318SGreg Clayton { 550c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 551c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 552c2ff9318SGreg Clayton } 553c2ff9318SGreg Clayton return 0; 554c2ff9318SGreg Clayton } 555*3467d80bSEnrico Granata } 556c2ff9318SGreg Clayton 557