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 269873a7a4bSJohnny Chen uint32_t 270873a7a4bSJohnny Chen SBModule::GetNumCompileUnits() 271873a7a4bSJohnny Chen { 272873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 273873a7a4bSJohnny Chen if (module_sp) 274873a7a4bSJohnny Chen { 275873a7a4bSJohnny Chen return module_sp->GetNumCompileUnits (); 276873a7a4bSJohnny Chen } 277873a7a4bSJohnny Chen return 0; 278873a7a4bSJohnny Chen } 279873a7a4bSJohnny Chen 280873a7a4bSJohnny Chen SBCompileUnit 281873a7a4bSJohnny Chen SBModule::GetCompileUnitAtIndex (uint32_t index) 282873a7a4bSJohnny Chen { 283873a7a4bSJohnny Chen SBCompileUnit sb_cu; 284873a7a4bSJohnny Chen ModuleSP module_sp (GetSP ()); 285873a7a4bSJohnny Chen if (module_sp) 286873a7a4bSJohnny Chen { 287873a7a4bSJohnny Chen CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex (index); 288873a7a4bSJohnny Chen sb_cu.reset(cu_sp.get()); 289873a7a4bSJohnny Chen } 290873a7a4bSJohnny Chen return sb_cu; 291873a7a4bSJohnny Chen } 292873a7a4bSJohnny Chen 293bbdabce2SGreg Clayton size_t 294bbdabce2SGreg Clayton SBModule::GetNumSymbols () 295bbdabce2SGreg Clayton { 296c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 297c2ff9318SGreg Clayton if (module_sp) 298bbdabce2SGreg Clayton { 299c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 300bbdabce2SGreg Clayton if (obj_file) 301bbdabce2SGreg Clayton { 302bbdabce2SGreg Clayton Symtab *symtab = obj_file->GetSymtab(); 303bbdabce2SGreg Clayton if (symtab) 304bbdabce2SGreg Clayton return symtab->GetNumSymbols(); 305bbdabce2SGreg Clayton } 306bbdabce2SGreg Clayton } 307bbdabce2SGreg Clayton return 0; 308bbdabce2SGreg Clayton } 309bbdabce2SGreg Clayton 310bbdabce2SGreg Clayton SBSymbol 311bbdabce2SGreg Clayton SBModule::GetSymbolAtIndex (size_t idx) 312bbdabce2SGreg Clayton { 313bbdabce2SGreg Clayton SBSymbol sb_symbol; 314c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 315c2ff9318SGreg Clayton if (module_sp) 316bbdabce2SGreg Clayton { 317c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 318bbdabce2SGreg Clayton if (obj_file) 319bbdabce2SGreg Clayton { 320bbdabce2SGreg Clayton Symtab *symtab = obj_file->GetSymtab(); 321bbdabce2SGreg Clayton if (symtab) 322bbdabce2SGreg Clayton sb_symbol.SetSymbol(symtab->SymbolAtIndex (idx)); 323bbdabce2SGreg Clayton } 324bbdabce2SGreg Clayton } 325bbdabce2SGreg Clayton return sb_symbol; 326bbdabce2SGreg Clayton } 327fe356d35SGreg Clayton 328cac9c5f9SGreg Clayton size_t 329cac9c5f9SGreg Clayton SBModule::GetNumSections () 330cac9c5f9SGreg Clayton { 331c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 332c2ff9318SGreg Clayton if (module_sp) 333cac9c5f9SGreg Clayton { 334c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 335cac9c5f9SGreg Clayton if (obj_file) 336cac9c5f9SGreg Clayton { 337cac9c5f9SGreg Clayton SectionList *section_list = obj_file->GetSectionList (); 338cac9c5f9SGreg Clayton if (section_list) 339cac9c5f9SGreg Clayton return section_list->GetSize(); 340cac9c5f9SGreg Clayton } 341cac9c5f9SGreg Clayton } 342cac9c5f9SGreg Clayton return 0; 343cac9c5f9SGreg Clayton } 344cac9c5f9SGreg Clayton 345cac9c5f9SGreg Clayton SBSection 346cac9c5f9SGreg Clayton SBModule::GetSectionAtIndex (size_t idx) 347cac9c5f9SGreg Clayton { 348cac9c5f9SGreg Clayton SBSection sb_section; 349c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 350c2ff9318SGreg Clayton if (module_sp) 351cac9c5f9SGreg Clayton { 352c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 353cac9c5f9SGreg Clayton if (obj_file) 354cac9c5f9SGreg Clayton { 355cac9c5f9SGreg Clayton SectionList *section_list = obj_file->GetSectionList (); 356cac9c5f9SGreg Clayton 357cac9c5f9SGreg Clayton if (section_list) 358e72dfb32SGreg Clayton sb_section.SetSP(section_list->GetSectionAtIndex (idx)); 359cac9c5f9SGreg Clayton } 360cac9c5f9SGreg Clayton } 361cac9c5f9SGreg Clayton return sb_section; 362cac9c5f9SGreg Clayton } 363cac9c5f9SGreg Clayton 3645569e64eSGreg Clayton lldb::SBSymbolContextList 365fe356d35SGreg Clayton SBModule::FindFunctions (const char *name, 3665569e64eSGreg Clayton uint32_t name_type_mask) 367fe356d35SGreg Clayton { 3685569e64eSGreg Clayton lldb::SBSymbolContextList sb_sc_list; 369c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 370c2ff9318SGreg Clayton if (name && module_sp) 371fe356d35SGreg Clayton { 3725569e64eSGreg Clayton const bool append = true; 373fe356d35SGreg Clayton const bool symbols_ok = true; 3749df05fbbSSean Callanan const bool inlines_ok = true; 375c2ff9318SGreg Clayton module_sp->FindFunctions (ConstString(name), 376b6d70ebcSSean Callanan NULL, 377fe356d35SGreg Clayton name_type_mask, 378fe356d35SGreg Clayton symbols_ok, 3799df05fbbSSean Callanan inlines_ok, 380fe356d35SGreg Clayton append, 3815569e64eSGreg Clayton *sb_sc_list); 382fe356d35SGreg Clayton } 3835569e64eSGreg Clayton return sb_sc_list; 384fe356d35SGreg Clayton } 385fe356d35SGreg Clayton 386dea8cb4fSGreg Clayton 387dea8cb4fSGreg Clayton SBValueList 388dea8cb4fSGreg Clayton SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches) 389dea8cb4fSGreg Clayton { 390dea8cb4fSGreg Clayton SBValueList sb_value_list; 391c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 392c2ff9318SGreg Clayton if (name && module_sp) 393dea8cb4fSGreg Clayton { 394dea8cb4fSGreg Clayton VariableList variable_list; 395c2ff9318SGreg Clayton const uint32_t match_count = module_sp->FindGlobalVariables (ConstString (name), 396b6d70ebcSSean Callanan NULL, 397dea8cb4fSGreg Clayton false, 398dea8cb4fSGreg Clayton max_matches, 399dea8cb4fSGreg Clayton variable_list); 400dea8cb4fSGreg Clayton 401dea8cb4fSGreg Clayton if (match_count > 0) 402dea8cb4fSGreg Clayton { 403dea8cb4fSGreg Clayton ValueObjectList &value_object_list = sb_value_list.ref(); 404dea8cb4fSGreg Clayton for (uint32_t i=0; i<match_count; ++i) 405dea8cb4fSGreg Clayton { 406dea8cb4fSGreg Clayton lldb::ValueObjectSP valobj_sp; 407b9556accSGreg Clayton TargetSP target_sp (target.GetSP()); 408b9556accSGreg Clayton valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); 409dea8cb4fSGreg Clayton if (valobj_sp) 410dea8cb4fSGreg Clayton value_object_list.Append(valobj_sp); 411dea8cb4fSGreg Clayton } 412dea8cb4fSGreg Clayton } 413dea8cb4fSGreg Clayton } 414dea8cb4fSGreg Clayton 415dea8cb4fSGreg Clayton return sb_value_list; 416dea8cb4fSGreg Clayton } 4176f3533fbSEnrico Granata 4186f3533fbSEnrico Granata lldb::SBType 4196f3533fbSEnrico Granata SBModule::FindFirstType (const char *name_cstr) 4206f3533fbSEnrico Granata { 421fe42ac4dSGreg Clayton SBType sb_type; 422c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 423c2ff9318SGreg Clayton if (name_cstr && module_sp) 424fe42ac4dSGreg Clayton { 4256f3533fbSEnrico Granata SymbolContext sc; 4266f3533fbSEnrico Granata TypeList type_list; 4276f3533fbSEnrico Granata uint32_t num_matches = 0; 428*84db9105SGreg Clayton const bool exact_match = false; 4296f3533fbSEnrico Granata ConstString name(name_cstr); 4306f3533fbSEnrico Granata 431c2ff9318SGreg Clayton num_matches = module_sp->FindTypes (sc, 4326f3533fbSEnrico Granata name, 433*84db9105SGreg Clayton exact_match, 4346f3533fbSEnrico Granata 1, 4356f3533fbSEnrico Granata type_list); 4366f3533fbSEnrico Granata 4376f3533fbSEnrico Granata if (num_matches) 438fe42ac4dSGreg Clayton sb_type = lldb::SBType(type_list.GetTypeAtIndex(0)); 4396f3533fbSEnrico Granata } 440fe42ac4dSGreg Clayton return sb_type; 4416f3533fbSEnrico Granata } 4426f3533fbSEnrico Granata 4436f3533fbSEnrico Granata lldb::SBTypeList 4446f3533fbSEnrico Granata SBModule::FindTypes (const char *type) 4456f3533fbSEnrico Granata { 4466f3533fbSEnrico Granata 4476f3533fbSEnrico Granata SBTypeList retval; 4486f3533fbSEnrico Granata 449c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 450c2ff9318SGreg Clayton if (type && module_sp) 451fe42ac4dSGreg Clayton { 4526f3533fbSEnrico Granata SymbolContext sc; 4536f3533fbSEnrico Granata TypeList type_list; 454*84db9105SGreg Clayton const bool exact_match = false; 4556f3533fbSEnrico Granata uint32_t num_matches = 0; 4566f3533fbSEnrico Granata ConstString name(type); 4576f3533fbSEnrico Granata 458c2ff9318SGreg Clayton num_matches = module_sp->FindTypes (sc, 4596f3533fbSEnrico Granata name, 460*84db9105SGreg Clayton exact_match, 4616f3533fbSEnrico Granata UINT32_MAX, 4626f3533fbSEnrico Granata type_list); 4636f3533fbSEnrico Granata 4646f3533fbSEnrico Granata for (size_t idx = 0; idx < num_matches; idx++) 4656f3533fbSEnrico Granata { 466fe42ac4dSGreg Clayton TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 467fe42ac4dSGreg Clayton if (type_sp) 468fe42ac4dSGreg Clayton retval.Append(SBType(type_sp)); 469fe42ac4dSGreg Clayton } 4706f3533fbSEnrico Granata } 4716f3533fbSEnrico Granata 4726f3533fbSEnrico Granata return retval; 4736f3533fbSEnrico Granata } 474cac9c5f9SGreg Clayton 475cac9c5f9SGreg Clayton 476cac9c5f9SGreg Clayton SBSection 477cac9c5f9SGreg Clayton SBModule::FindSection (const char *sect_name) 478cac9c5f9SGreg Clayton { 479cac9c5f9SGreg Clayton SBSection sb_section; 480cac9c5f9SGreg Clayton 481c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 482c2ff9318SGreg Clayton if (sect_name && module_sp) 483cac9c5f9SGreg Clayton { 484c2ff9318SGreg Clayton ObjectFile *objfile = module_sp->GetObjectFile(); 485cac9c5f9SGreg Clayton if (objfile) 486cac9c5f9SGreg Clayton { 487cac9c5f9SGreg Clayton SectionList *section_list = objfile->GetSectionList(); 488cac9c5f9SGreg Clayton if (section_list) 489cac9c5f9SGreg Clayton { 490cac9c5f9SGreg Clayton ConstString const_sect_name(sect_name); 491cac9c5f9SGreg Clayton SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); 492cac9c5f9SGreg Clayton if (section_sp) 493cac9c5f9SGreg Clayton { 494e72dfb32SGreg Clayton sb_section.SetSP (section_sp); 495cac9c5f9SGreg Clayton } 496cac9c5f9SGreg Clayton } 497cac9c5f9SGreg Clayton } 498cac9c5f9SGreg Clayton } 499cac9c5f9SGreg Clayton return sb_section; 500cac9c5f9SGreg Clayton } 501cac9c5f9SGreg Clayton 50213d1950aSGreg Clayton lldb::ByteOrder 50313d1950aSGreg Clayton SBModule::GetByteOrder () 50413d1950aSGreg Clayton { 505c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 506c2ff9318SGreg Clayton if (module_sp) 507c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetByteOrder(); 50813d1950aSGreg Clayton return eByteOrderInvalid; 50913d1950aSGreg Clayton } 51013d1950aSGreg Clayton 51113d1950aSGreg Clayton const char * 51213d1950aSGreg Clayton SBModule::GetTriple () 51313d1950aSGreg Clayton { 514c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 515c2ff9318SGreg Clayton if (module_sp) 51613d1950aSGreg Clayton { 517c2ff9318SGreg Clayton std::string triple (module_sp->GetArchitecture().GetTriple().str()); 51813d1950aSGreg Clayton // Unique the string so we don't run into ownership issues since 51913d1950aSGreg Clayton // the const strings put the string into the string pool once and 52013d1950aSGreg Clayton // the strings never comes out 52113d1950aSGreg Clayton ConstString const_triple (triple.c_str()); 52213d1950aSGreg Clayton return const_triple.GetCString(); 52313d1950aSGreg Clayton } 52413d1950aSGreg Clayton return NULL; 52513d1950aSGreg Clayton } 52613d1950aSGreg Clayton 52713d1950aSGreg Clayton uint32_t 52813d1950aSGreg Clayton SBModule::GetAddressByteSize() 52913d1950aSGreg Clayton { 530c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 531c2ff9318SGreg Clayton if (module_sp) 532c2ff9318SGreg Clayton return module_sp->GetArchitecture().GetAddressByteSize(); 53313d1950aSGreg Clayton return sizeof(void*); 53413d1950aSGreg Clayton } 53513d1950aSGreg Clayton 536c2ff9318SGreg Clayton 537c2ff9318SGreg Clayton uint32_t 538c2ff9318SGreg Clayton SBModule::GetVersion (uint32_t *versions, uint32_t num_versions) 539c2ff9318SGreg Clayton { 540c2ff9318SGreg Clayton ModuleSP module_sp (GetSP ()); 541c2ff9318SGreg Clayton if (module_sp) 542c2ff9318SGreg Clayton { 543c2ff9318SGreg Clayton ObjectFile *obj_file = module_sp->GetObjectFile(); 544c2ff9318SGreg Clayton if (obj_file) 545c2ff9318SGreg Clayton return obj_file->GetVersion (versions, num_versions); 546c2ff9318SGreg Clayton } 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 } 555c2ff9318SGreg Clayton 556