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" 1838adbbb8SGreg Clayton #include "lldb/Core/StreamString.h" 19dea8cb4fSGreg Clayton #include "lldb/Core/ValueObjectList.h" 20dea8cb4fSGreg Clayton #include "lldb/Core/ValueObjectVariable.h" 216f3533fbSEnrico Granata #include "lldb/Symbol/SymbolVendor.h" 22dea8cb4fSGreg Clayton #include "lldb/Symbol/VariableList.h" 23dea8cb4fSGreg Clayton #include "lldb/Target/Target.h" 2430fdc8d8SChris Lattner 2530fdc8d8SChris Lattner using namespace lldb; 26ceb6b139SCaroline Tice using namespace lldb_private; 2730fdc8d8SChris Lattner 2830fdc8d8SChris Lattner 2930fdc8d8SChris Lattner SBModule::SBModule () : 306611103cSGreg Clayton m_opaque_sp () 3130fdc8d8SChris Lattner { 3230fdc8d8SChris Lattner } 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner SBModule::SBModule (const lldb::ModuleSP& module_sp) : 356611103cSGreg Clayton m_opaque_sp (module_sp) 3630fdc8d8SChris Lattner { 3730fdc8d8SChris Lattner } 3830fdc8d8SChris Lattner 39efabb123SGreg Clayton SBModule::SBModule(const SBModule &rhs) : 40efabb123SGreg Clayton m_opaque_sp (rhs.m_opaque_sp) 41efabb123SGreg Clayton { 42efabb123SGreg Clayton } 43efabb123SGreg Clayton 44c9660546SGreg Clayton SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : 45c9660546SGreg Clayton m_opaque_sp () 46c9660546SGreg Clayton { 47c9660546SGreg Clayton ProcessSP process_sp (process.GetSP()); 48c9660546SGreg Clayton if (process_sp) 49c859e2d5SGreg Clayton { 50c859e2d5SGreg Clayton const bool add_image_to_target = true; 51c859e2d5SGreg Clayton const bool load_image_sections_in_target = true; 52c859e2d5SGreg Clayton m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), 53c859e2d5SGreg Clayton header_addr, 54c859e2d5SGreg Clayton add_image_to_target, 55c859e2d5SGreg Clayton load_image_sections_in_target); 56c859e2d5SGreg Clayton } 57c9660546SGreg Clayton } 58c9660546SGreg Clayton 59efabb123SGreg Clayton const SBModule & 60efabb123SGreg Clayton SBModule::operator = (const SBModule &rhs) 61efabb123SGreg Clayton { 62efabb123SGreg Clayton if (this != &rhs) 63efabb123SGreg Clayton m_opaque_sp = rhs.m_opaque_sp; 64efabb123SGreg Clayton return *this; 65efabb123SGreg Clayton } 66efabb123SGreg Clayton 6730fdc8d8SChris Lattner SBModule::~SBModule () 6830fdc8d8SChris Lattner { 6930fdc8d8SChris Lattner } 7030fdc8d8SChris Lattner 7130fdc8d8SChris Lattner bool 7230fdc8d8SChris Lattner SBModule::IsValid () const 7330fdc8d8SChris Lattner { 746611103cSGreg Clayton return m_opaque_sp.get() != NULL; 7530fdc8d8SChris Lattner } 7630fdc8d8SChris Lattner 775d3bca4eSJim Ingham void 785d3bca4eSJim Ingham SBModule::Clear() 795d3bca4eSJim Ingham { 805d3bca4eSJim Ingham m_opaque_sp.reset(); 815d3bca4eSJim Ingham } 825d3bca4eSJim Ingham 8330fdc8d8SChris Lattner SBFileSpec 8430fdc8d8SChris Lattner SBModule::GetFileSpec () const 8530fdc8d8SChris Lattner { 862d4edfbcSGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 87ceb6b139SCaroline Tice 8830fdc8d8SChris Lattner SBFileSpec file_spec; 89c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 90c2ff9318SGreg Clayton if (module_sp) 91c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetFileSpec()); 92ceb6b139SCaroline Tice 93ceb6b139SCaroline Tice if (log) 94ceb6b139SCaroline Tice { 95cfd1acedSGreg Clayton log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)", 96c2ff9318SGreg Clayton module_sp.get(), file_spec.get()); 97ceb6b139SCaroline Tice } 98ceb6b139SCaroline Tice 9930fdc8d8SChris Lattner return file_spec; 10030fdc8d8SChris Lattner } 10130fdc8d8SChris Lattner 1022289fa48SGreg Clayton lldb::SBFileSpec 1032289fa48SGreg Clayton SBModule::GetPlatformFileSpec () const 1042289fa48SGreg Clayton { 1052289fa48SGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1062289fa48SGreg Clayton 1072289fa48SGreg Clayton SBFileSpec file_spec; 108c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 109c2ff9318SGreg Clayton if (module_sp) 110c2ff9318SGreg Clayton file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 1112289fa48SGreg Clayton 1122289fa48SGreg Clayton if (log) 1132289fa48SGreg Clayton { 1142289fa48SGreg Clayton log->Printf ("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)", 115c2ff9318SGreg Clayton module_sp.get(), file_spec.get()); 1162289fa48SGreg Clayton } 1172289fa48SGreg Clayton 1182289fa48SGreg Clayton return file_spec; 1192289fa48SGreg Clayton 1202289fa48SGreg Clayton } 1212289fa48SGreg Clayton 1222289fa48SGreg Clayton bool 1232289fa48SGreg Clayton SBModule::SetPlatformFileSpec (const lldb::SBFileSpec &platform_file) 1242289fa48SGreg Clayton { 1252289fa48SGreg Clayton bool result = false; 1262289fa48SGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1272289fa48SGreg Clayton 128c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 129c2ff9318SGreg Clayton if (module_sp) 1302289fa48SGreg Clayton { 131c2ff9318SGreg Clayton module_sp->SetPlatformFileSpec(*platform_file); 1322289fa48SGreg Clayton result = true; 1332289fa48SGreg Clayton } 1342289fa48SGreg Clayton 1352289fa48SGreg Clayton if (log) 1362289fa48SGreg Clayton { 1372289fa48SGreg Clayton log->Printf ("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s%s%s)) => %i", 138c2ff9318SGreg Clayton module_sp.get(), 1392289fa48SGreg Clayton platform_file.get(), 1402289fa48SGreg Clayton platform_file->GetDirectory().GetCString(), 1412289fa48SGreg Clayton platform_file->GetDirectory() ? "/" : "", 1422289fa48SGreg Clayton platform_file->GetFilename().GetCString(), 1432289fa48SGreg Clayton result); 1442289fa48SGreg Clayton } 1452289fa48SGreg Clayton return result; 1462289fa48SGreg Clayton } 1472289fa48SGreg Clayton 1482289fa48SGreg Clayton 1492289fa48SGreg Clayton 15030fdc8d8SChris Lattner const uint8_t * 15130fdc8d8SChris Lattner SBModule::GetUUIDBytes () const 15230fdc8d8SChris Lattner { 1532d4edfbcSGreg Clayton LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 154ceb6b139SCaroline Tice 1554838131bSGreg Clayton const uint8_t *uuid_bytes = NULL; 156c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 157c2ff9318SGreg Clayton if (module_sp) 158c2ff9318SGreg Clayton uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes(); 159ceb6b139SCaroline Tice 160ceb6b139SCaroline Tice if (log) 1614838131bSGreg Clayton { 1624838131bSGreg Clayton if (uuid_bytes) 1634838131bSGreg Clayton { 1644838131bSGreg Clayton StreamString s; 165c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 166c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", module_sp.get(), s.GetData()); 1674838131bSGreg Clayton } 1684838131bSGreg Clayton else 169c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", module_sp.get()); 1704838131bSGreg Clayton } 1714838131bSGreg Clayton return uuid_bytes; 17230fdc8d8SChris Lattner } 17330fdc8d8SChris Lattner 17430fdc8d8SChris Lattner 175df2963edSJohnny Chen const char * 176df2963edSJohnny Chen SBModule::GetUUIDString () const 177df2963edSJohnny Chen { 178df2963edSJohnny Chen LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 179df2963edSJohnny Chen 180df2963edSJohnny Chen static char uuid_string[80]; 181df2963edSJohnny Chen const char * uuid_c_string = NULL; 182c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 183c2ff9318SGreg Clayton if (module_sp) 184c2ff9318SGreg Clayton uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string)); 185df2963edSJohnny Chen 186df2963edSJohnny Chen if (log) 187df2963edSJohnny Chen { 188df2963edSJohnny Chen if (uuid_c_string) 189df2963edSJohnny Chen { 190df2963edSJohnny Chen StreamString s; 191c2ff9318SGreg Clayton module_sp->GetUUID().Dump (&s); 192c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => %s", module_sp.get(), s.GetData()); 193df2963edSJohnny Chen } 194df2963edSJohnny Chen else 195c2ff9318SGreg Clayton log->Printf ("SBModule(%p)::GetUUIDString () => NULL", module_sp.get()); 196df2963edSJohnny Chen } 197df2963edSJohnny Chen return uuid_c_string; 198df2963edSJohnny Chen } 199df2963edSJohnny Chen 200df2963edSJohnny Chen 20130fdc8d8SChris Lattner bool 20230fdc8d8SChris Lattner SBModule::operator == (const SBModule &rhs) const 20330fdc8d8SChris Lattner { 2046611103cSGreg Clayton if (m_opaque_sp) 2056611103cSGreg Clayton return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 20630fdc8d8SChris Lattner return false; 20730fdc8d8SChris Lattner } 20830fdc8d8SChris Lattner 20930fdc8d8SChris Lattner bool 21030fdc8d8SChris Lattner SBModule::operator != (const SBModule &rhs) const 21130fdc8d8SChris Lattner { 2126611103cSGreg Clayton if (m_opaque_sp) 2136611103cSGreg Clayton return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 21430fdc8d8SChris Lattner return false; 21530fdc8d8SChris Lattner } 21630fdc8d8SChris Lattner 217acdbe816SGreg Clayton ModuleSP 218acdbe816SGreg Clayton SBModule::GetSP () const 219cac9c5f9SGreg Clayton { 220cac9c5f9SGreg Clayton return m_opaque_sp; 221cac9c5f9SGreg Clayton } 22230fdc8d8SChris Lattner 22330fdc8d8SChris Lattner void 224acdbe816SGreg Clayton SBModule::SetSP (const ModuleSP &module_sp) 22530fdc8d8SChris Lattner { 2266611103cSGreg Clayton m_opaque_sp = module_sp; 22730fdc8d8SChris Lattner } 22830fdc8d8SChris Lattner 229cac9c5f9SGreg Clayton SBAddress 230cac9c5f9SGreg Clayton SBModule::ResolveFileAddress (lldb::addr_t vm_addr) 23109960031SGreg Clayton { 232cac9c5f9SGreg Clayton lldb::SBAddress sb_addr; 233c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 234c2ff9318SGreg Clayton if (module_sp) 235cac9c5f9SGreg Clayton { 236cac9c5f9SGreg Clayton Address addr; 237c2ff9318SGreg Clayton if (module_sp->ResolveFileAddress (vm_addr, addr)) 238cac9c5f9SGreg Clayton sb_addr.ref() = addr; 239cac9c5f9SGreg Clayton } 240cac9c5f9SGreg Clayton return sb_addr; 24109960031SGreg Clayton } 24209960031SGreg Clayton 24309960031SGreg Clayton SBSymbolContext 24409960031SGreg Clayton SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) 24509960031SGreg Clayton { 24609960031SGreg Clayton SBSymbolContext sb_sc; 247c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 248c2ff9318SGreg Clayton if (module_sp && addr.IsValid()) 249c2ff9318SGreg Clayton module_sp->ResolveSymbolContextForAddress (addr.ref(), resolve_scope, *sb_sc); 25009960031SGreg Clayton return sb_sc; 25109960031SGreg Clayton } 25209960031SGreg Clayton 253dde9cff3SCaroline Tice bool 254dde9cff3SCaroline Tice SBModule::GetDescription (SBStream &description) 255dde9cff3SCaroline Tice { 256da7bc7d0SGreg Clayton Stream &strm = description.ref(); 257da7bc7d0SGreg Clayton 258c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 259c2ff9318SGreg Clayton if (module_sp) 260dde9cff3SCaroline Tice { 261c2ff9318SGreg Clayton module_sp->GetDescription (&strm); 262dde9cff3SCaroline Tice } 263dde9cff3SCaroline Tice else 264da7bc7d0SGreg Clayton strm.PutCString ("No value"); 265dde9cff3SCaroline Tice 266dde9cff3SCaroline Tice return true; 267dde9cff3SCaroline Tice } 268bbdabce2SGreg Clayton 269bbdabce2SGreg Clayton size_t 270bbdabce2SGreg Clayton SBModule::GetNumSymbols () 271bbdabce2SGreg Clayton { 272c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 273c2ff9318SGreg Clayton if (module_sp) 274bbdabce2SGreg Clayton { 275c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 276bbdabce2SGreg Clayton if (obj_file) 277bbdabce2SGreg Clayton { 278bbdabce2SGreg Clayton Symtab *symtab = obj_file->GetSymtab(); 279bbdabce2SGreg Clayton if (symtab) 280bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 281bbdabce2SGreg Clayton } 282bbdabce2SGreg Clayton } 283bbdabce2SGreg Clayton return 0; 284bbdabce2SGreg Clayton } 285bbdabce2SGreg Clayton 286bbdabce2SGreg Clayton SBSymbol 287bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 288bbdabce2SGreg Clayton { 289bbdabce2SGreg Clayton SBSymbol sb_symbol; 290c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 291c2ff9318SGreg Clayton if (module_sp) 292bbdabce2SGreg Clayton { 293c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 294bbdabce2SGreg Clayton if (obj_file) 295bbdabce2SGreg Clayton { 296bbdabce2SGreg Clayton Symtab *symtab = obj_file->GetSymtab(); 297bbdabce2SGreg Clayton if (symtab) 298bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 299bbdabce2SGreg Clayton } 300bbdabce2SGreg Clayton } 301bbdabce2SGreg Clayton return sb_symbol; 302bbdabce2SGreg Clayton } 303fe356d35SGreg Clayton 304cac9c5f9SGreg Clayton size_t 305cac9c5f9SGreg Clayton SBModule::GetNumSections () 306cac9c5f9SGreg Clayton { 307c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 308c2ff9318SGreg Clayton if (module_sp) 309cac9c5f9SGreg Clayton { 310c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 311cac9c5f9SGreg Clayton if (obj_file) 312cac9c5f9SGreg Clayton { 313cac9c5f9SGreg Clayton SectionList *section_list = obj_file->GetSectionList (); 314cac9c5f9SGreg Clayton if (section_list) 315cac9c5f9SGreg Clayton return section_list->GetSize(); 316cac9c5f9SGreg Clayton } 317cac9c5f9SGreg Clayton } 318cac9c5f9SGreg Clayton return 0; 319cac9c5f9SGreg Clayton } 320cac9c5f9SGreg Clayton 321cac9c5f9SGreg Clayton SBSection 322cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 323cac9c5f9SGreg Clayton { 324cac9c5f9SGreg Clayton SBSection sb_section; 325c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 326c2ff9318SGreg Clayton if (module_sp) 327cac9c5f9SGreg Clayton { 328c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 329cac9c5f9SGreg Clayton if (obj_file) 330cac9c5f9SGreg Clayton { 331cac9c5f9SGreg Clayton SectionList *section_list = obj_file->GetSectionList (); 332cac9c5f9SGreg Clayton 333cac9c5f9SGreg Clayton if (section_list) 334*e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 335cac9c5f9SGreg Clayton } 336cac9c5f9SGreg Clayton } 337cac9c5f9SGreg Clayton return sb_section; 338cac9c5f9SGreg Clayton } 339cac9c5f9SGreg Clayton 3405569e64eSGreg Clayton lldb::SBSymbolContextList 341fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 3425569e64eSGreg Clayton uint32_t name_type_mask) 343fe356d35SGreg Clayton { 3445569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 345c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 346c2ff9318SGreg Clayton if (name && module_sp) 347fe356d35SGreg Clayton { 3485569e64eSGreg Clayton const bool append = true; 349fe356d35SGreg Clayton const bool symbols_ok = true; 3509df05fbbSSean Callanan const bool inlines_ok = true; 351c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 352b6d70ebcSSean Callanan NULL, 353fe356d35SGreg Clayton name_type_mask, 354fe356d35SGreg Clayton symbols_ok, 3559df05fbbSSean Callanan inlines_ok, 356fe356d35SGreg Clayton append, 3575569e64eSGreg Clayton *sb_sc_list); 358fe356d35SGreg Clayton } 3595569e64eSGreg Clayton return sb_sc_list; 360fe356d35SGreg Clayton } 361fe356d35SGreg Clayton 362dea8cb4fSGreg Clayton 363dea8cb4fSGreg Clayton SBValueList 364dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 365dea8cb4fSGreg Clayton { 366dea8cb4fSGreg Clayton SBValueList sb_value_list; 367c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 368c2ff9318SGreg Clayton if (name && module_sp) 369dea8cb4fSGreg Clayton { 370dea8cb4fSGreg Clayton VariableList variable_list; 371c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 372b6d70ebcSSean Callanan NULL, 373dea8cb4fSGreg Clayton false, 374dea8cb4fSGreg Clayton max_matches, 375dea8cb4fSGreg Clayton variable_list); 376dea8cb4fSGreg Clayton 377dea8cb4fSGreg Clayton if (match_count > 0) 378dea8cb4fSGreg Clayton { 379dea8cb4fSGreg Clayton ValueObjectList &value_object_list = sb_value_list.ref(); 380dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 381dea8cb4fSGreg Clayton { 382dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 383b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 384b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 385dea8cb4fSGreg Clayton if (valobj_sp) 386dea8cb4fSGreg Clayton value_object_list.Append(valobj_sp); 387dea8cb4fSGreg Clayton } 388dea8cb4fSGreg Clayton } 389dea8cb4fSGreg Clayton } 390dea8cb4fSGreg Clayton 391dea8cb4fSGreg Clayton return sb_value_list; 392dea8cb4fSGreg Clayton } 3936f3533fbSEnrico Granata 3946f3533fbSEnrico Granata lldb::SBType 3956f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 3966f3533fbSEnrico Granata { 397fe42ac4dSGreg Clayton SBType sb_type; 398c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 399c2ff9318SGreg Clayton if (name_cstr && module_sp) 400fe42ac4dSGreg Clayton { 4016f3533fbSEnrico Granata SymbolContext sc; 4026f3533fbSEnrico Granata TypeList type_list; 4036f3533fbSEnrico Granata uint32_t num_matches = 0; 4046f3533fbSEnrico Granata ConstString name(name_cstr); 4056f3533fbSEnrico Granata 406c2ff9318SGreg Clayton num_matches = module_sp->FindTypes (sc, 4076f3533fbSEnrico Granata name, 408b6d70ebcSSean Callanan NULL, 4096f3533fbSEnrico Granata false, 4106f3533fbSEnrico Granata 1, 4116f3533fbSEnrico Granata type_list); 4126f3533fbSEnrico Granata 4136f3533fbSEnrico Granata if (num_matches) 414fe42ac4dSGreg Clayton sb_type = lldb::SBType(type_list.GetTypeAtIndex(0)); 4156f3533fbSEnrico Granata } 416fe42ac4dSGreg Clayton return sb_type; 4176f3533fbSEnrico Granata } 4186f3533fbSEnrico Granata 4196f3533fbSEnrico Granata lldb::SBTypeList 4206f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 4216f3533fbSEnrico Granata { 4226f3533fbSEnrico Granata 4236f3533fbSEnrico Granata SBTypeList retval; 4246f3533fbSEnrico Granata 425c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 426c2ff9318SGreg Clayton if (type && module_sp) 427fe42ac4dSGreg Clayton { 4286f3533fbSEnrico Granata SymbolContext sc; 4296f3533fbSEnrico Granata TypeList type_list; 4306f3533fbSEnrico Granata uint32_t num_matches = 0; 4316f3533fbSEnrico Granata ConstString name(type); 4326f3533fbSEnrico Granata 433c2ff9318SGreg Clayton num_matches = module_sp->FindTypes (sc, 4346f3533fbSEnrico Granata name, 435b6d70ebcSSean Callanan NULL, 4366f3533fbSEnrico Granata false, 4376f3533fbSEnrico Granata UINT32_MAX, 4386f3533fbSEnrico Granata type_list); 4396f3533fbSEnrico Granata 4406f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 4416f3533fbSEnrico Granata { 442fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 443fe42ac4dSGreg Clayton if (type_sp) 444fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 445fe42ac4dSGreg Clayton } 4466f3533fbSEnrico Granata } 4476f3533fbSEnrico Granata 4486f3533fbSEnrico Granata return retval; 4496f3533fbSEnrico Granata } 450cac9c5f9SGreg Clayton 451cac9c5f9SGreg Clayton 452cac9c5f9SGreg Clayton SBSection 453cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 454cac9c5f9SGreg Clayton { 455cac9c5f9SGreg Clayton SBSection sb_section; 456cac9c5f9SGreg Clayton 457c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 458c2ff9318SGreg Clayton if (sect_name && module_sp) 459cac9c5f9SGreg Clayton { 460c2ff9318SGreg Clayton ObjectFile *objfile = module_sp->GetObjectFile(); 461cac9c5f9SGreg Clayton if (objfile) 462cac9c5f9SGreg Clayton { 463cac9c5f9SGreg Clayton SectionList *section_list = objfile->GetSectionList(); 464cac9c5f9SGreg Clayton if (section_list) 465cac9c5f9SGreg Clayton { 466cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 467cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 468cac9c5f9SGreg Clayton if (section_sp) 469cac9c5f9SGreg Clayton { 470*e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 471cac9c5f9SGreg Clayton } 472cac9c5f9SGreg Clayton } 473cac9c5f9SGreg Clayton } 474cac9c5f9SGreg Clayton } 475cac9c5f9SGreg Clayton return sb_section; 476cac9c5f9SGreg Clayton } 477cac9c5f9SGreg Clayton 47813d1950aSGreg Clayton lldb::ByteOrder 47913d1950aSGreg Clayton SBModule::GetByteOrder () 48013d1950aSGreg Clayton { 481c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 482c2ff9318SGreg Clayton if (module_sp) 483c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 48413d1950aSGreg Clayton return eByteOrderInvalid; 48513d1950aSGreg Clayton } 48613d1950aSGreg Clayton 48713d1950aSGreg Clayton const char * 48813d1950aSGreg Clayton SBModule::GetTriple () 48913d1950aSGreg Clayton { 490c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 491c2ff9318SGreg Clayton if (module_sp) 49213d1950aSGreg Clayton { 493c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 49413d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 49513d1950aSGreg Clayton // the const strings put the string into the string pool once and 49613d1950aSGreg Clayton // the strings never comes out 49713d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 49813d1950aSGreg Clayton return const_triple.GetCString(); 49913d1950aSGreg Clayton } 50013d1950aSGreg Clayton return NULL; 50113d1950aSGreg Clayton } 50213d1950aSGreg Clayton 50313d1950aSGreg Clayton uint32_t 50413d1950aSGreg Clayton SBModule::GetAddressByteSize() 50513d1950aSGreg Clayton { 506c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 507c2ff9318SGreg Clayton if (module_sp) 508c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 50913d1950aSGreg Clayton return sizeof(void*); 51013d1950aSGreg Clayton } 51113d1950aSGreg Clayton 512c2ff9318SGreg Clayton 513c2ff9318SGreg Clayton uint32_t 514c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 515c2ff9318SGreg Clayton { 516c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 517c2ff9318SGreg Clayton if (module_sp) 518c2ff9318SGreg Clayton { 519c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 520c2ff9318SGreg Clayton if (obj_file) 521c2ff9318SGreg Clayton return obj_file->GetVersion (versions, num_versions); 522c2ff9318SGreg Clayton } 523c2ff9318SGreg Clayton 524c2ff9318SGreg Clayton if (versions && num_versions) 525c2ff9318SGreg Clayton { 526c2ff9318SGreg Clayton for (uint32_t i=0; i<num_versions; ++i) 527c2ff9318SGreg Clayton versions[i] = UINT32_MAX; 528c2ff9318SGreg Clayton } 529c2ff9318SGreg Clayton return 0; 530c2ff9318SGreg Clayton } 531c2ff9318SGreg Clayton 532