1 //===-- SBModule.cpp ------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBModule.h" 10 #include "lldb/Utility/ReproducerInstrumentation.h" 11 #include "lldb/API/SBAddress.h" 12 #include "lldb/API/SBFileSpec.h" 13 #include "lldb/API/SBModuleSpec.h" 14 #include "lldb/API/SBProcess.h" 15 #include "lldb/API/SBStream.h" 16 #include "lldb/API/SBSymbolContextList.h" 17 #include "lldb/Core/Module.h" 18 #include "lldb/Core/Section.h" 19 #include "lldb/Core/ValueObjectList.h" 20 #include "lldb/Core/ValueObjectVariable.h" 21 #include "lldb/Symbol/ObjectFile.h" 22 #include "lldb/Symbol/SymbolFile.h" 23 #include "lldb/Symbol/Symtab.h" 24 #include "lldb/Symbol/TypeSystem.h" 25 #include "lldb/Symbol/VariableList.h" 26 #include "lldb/Target/Target.h" 27 #include "lldb/Utility/StreamString.h" 28 29 using namespace lldb; 30 using namespace lldb_private; 31 32 SBModule::SBModule() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBModule); } 33 34 SBModule::SBModule(const lldb::ModuleSP &module_sp) : m_opaque_sp(module_sp) {} 35 36 SBModule::SBModule(const SBModuleSpec &module_spec) { 37 LLDB_RECORD_CONSTRUCTOR(SBModule, (const lldb::SBModuleSpec &), module_spec); 38 39 ModuleSP module_sp; 40 Status error = ModuleList::GetSharedModule( 41 *module_spec.m_opaque_up, module_sp, nullptr, nullptr, nullptr); 42 if (module_sp) 43 SetSP(module_sp); 44 } 45 46 SBModule::SBModule(const SBModule &rhs) : m_opaque_sp(rhs.m_opaque_sp) { 47 LLDB_RECORD_CONSTRUCTOR(SBModule, (const lldb::SBModule &), rhs); 48 } 49 50 SBModule::SBModule(lldb::SBProcess &process, lldb::addr_t header_addr) { 51 LLDB_RECORD_CONSTRUCTOR(SBModule, (lldb::SBProcess &, lldb::addr_t), process, 52 header_addr); 53 54 ProcessSP process_sp(process.GetSP()); 55 if (process_sp) { 56 m_opaque_sp = process_sp->ReadModuleFromMemory(FileSpec(), header_addr); 57 if (m_opaque_sp) { 58 Target &target = process_sp->GetTarget(); 59 bool changed = false; 60 m_opaque_sp->SetLoadAddress(target, 0, true, changed); 61 target.GetImages().Append(m_opaque_sp); 62 } 63 } 64 } 65 66 const SBModule &SBModule::operator=(const SBModule &rhs) { 67 LLDB_RECORD_METHOD(const lldb::SBModule &, SBModule, operator=, 68 (const lldb::SBModule &), rhs); 69 70 if (this != &rhs) 71 m_opaque_sp = rhs.m_opaque_sp; 72 return LLDB_RECORD_RESULT(*this); 73 } 74 75 SBModule::~SBModule() = default; 76 77 bool SBModule::IsValid() const { 78 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModule, IsValid); 79 return this->operator bool(); 80 } 81 SBModule::operator bool() const { 82 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModule, operator bool); 83 84 return m_opaque_sp.get() != nullptr; 85 } 86 87 void SBModule::Clear() { 88 LLDB_RECORD_METHOD_NO_ARGS(void, SBModule, Clear); 89 90 m_opaque_sp.reset(); 91 } 92 93 SBFileSpec SBModule::GetFileSpec() const { 94 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule, GetFileSpec); 95 96 SBFileSpec file_spec; 97 ModuleSP module_sp(GetSP()); 98 if (module_sp) 99 file_spec.SetFileSpec(module_sp->GetFileSpec()); 100 101 return LLDB_RECORD_RESULT(file_spec); 102 } 103 104 lldb::SBFileSpec SBModule::GetPlatformFileSpec() const { 105 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule, 106 GetPlatformFileSpec); 107 108 SBFileSpec file_spec; 109 ModuleSP module_sp(GetSP()); 110 if (module_sp) 111 file_spec.SetFileSpec(module_sp->GetPlatformFileSpec()); 112 113 return LLDB_RECORD_RESULT(file_spec); 114 } 115 116 bool SBModule::SetPlatformFileSpec(const lldb::SBFileSpec &platform_file) { 117 LLDB_RECORD_METHOD(bool, SBModule, SetPlatformFileSpec, 118 (const lldb::SBFileSpec &), platform_file); 119 120 bool result = false; 121 122 ModuleSP module_sp(GetSP()); 123 if (module_sp) { 124 module_sp->SetPlatformFileSpec(*platform_file); 125 result = true; 126 } 127 128 return result; 129 } 130 131 lldb::SBFileSpec SBModule::GetRemoteInstallFileSpec() { 132 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModule, 133 GetRemoteInstallFileSpec); 134 135 SBFileSpec sb_file_spec; 136 ModuleSP module_sp(GetSP()); 137 if (module_sp) 138 sb_file_spec.SetFileSpec(module_sp->GetRemoteInstallFileSpec()); 139 return LLDB_RECORD_RESULT(sb_file_spec); 140 } 141 142 bool SBModule::SetRemoteInstallFileSpec(lldb::SBFileSpec &file) { 143 LLDB_RECORD_METHOD(bool, SBModule, SetRemoteInstallFileSpec, 144 (lldb::SBFileSpec &), file); 145 146 ModuleSP module_sp(GetSP()); 147 if (module_sp) { 148 module_sp->SetRemoteInstallFileSpec(file.ref()); 149 return true; 150 } 151 return false; 152 } 153 154 const uint8_t *SBModule::GetUUIDBytes() const { 155 LLDB_RECORD_METHOD_CONST_NO_ARGS(const uint8_t *, SBModule, GetUUIDBytes); 156 157 const uint8_t *uuid_bytes = nullptr; 158 ModuleSP module_sp(GetSP()); 159 if (module_sp) 160 uuid_bytes = module_sp->GetUUID().GetBytes().data(); 161 162 return uuid_bytes; 163 } 164 165 const char *SBModule::GetUUIDString() const { 166 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBModule, GetUUIDString); 167 168 const char *uuid_cstr = nullptr; 169 ModuleSP module_sp(GetSP()); 170 if (module_sp) { 171 // We are going to return a "const char *" value through the public API, so 172 // we need to constify it so it gets added permanently the string pool and 173 // then we don't need to worry about the lifetime of the string as it will 174 // never go away once it has been put into the ConstString string pool 175 uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString(); 176 } 177 178 if (uuid_cstr && uuid_cstr[0]) { 179 return uuid_cstr; 180 } 181 182 return nullptr; 183 } 184 185 bool SBModule::operator==(const SBModule &rhs) const { 186 LLDB_RECORD_METHOD_CONST(bool, SBModule, operator==, (const lldb::SBModule &), 187 rhs); 188 189 if (m_opaque_sp) 190 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 191 return false; 192 } 193 194 bool SBModule::operator!=(const SBModule &rhs) const { 195 LLDB_RECORD_METHOD_CONST(bool, SBModule, operator!=, (const lldb::SBModule &), 196 rhs); 197 198 if (m_opaque_sp) 199 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 200 return false; 201 } 202 203 ModuleSP SBModule::GetSP() const { return m_opaque_sp; } 204 205 void SBModule::SetSP(const ModuleSP &module_sp) { m_opaque_sp = module_sp; } 206 207 SBAddress SBModule::ResolveFileAddress(lldb::addr_t vm_addr) { 208 LLDB_RECORD_METHOD(lldb::SBAddress, SBModule, ResolveFileAddress, 209 (lldb::addr_t), vm_addr); 210 211 lldb::SBAddress sb_addr; 212 ModuleSP module_sp(GetSP()); 213 if (module_sp) { 214 Address addr; 215 if (module_sp->ResolveFileAddress(vm_addr, addr)) 216 sb_addr.ref() = addr; 217 } 218 return LLDB_RECORD_RESULT(sb_addr); 219 } 220 221 SBSymbolContext 222 SBModule::ResolveSymbolContextForAddress(const SBAddress &addr, 223 uint32_t resolve_scope) { 224 LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBModule, 225 ResolveSymbolContextForAddress, 226 (const lldb::SBAddress &, uint32_t), addr, resolve_scope); 227 228 SBSymbolContext sb_sc; 229 ModuleSP module_sp(GetSP()); 230 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope); 231 if (module_sp && addr.IsValid()) 232 module_sp->ResolveSymbolContextForAddress(addr.ref(), scope, *sb_sc); 233 return LLDB_RECORD_RESULT(sb_sc); 234 } 235 236 bool SBModule::GetDescription(SBStream &description) { 237 LLDB_RECORD_METHOD(bool, SBModule, GetDescription, (lldb::SBStream &), 238 description); 239 240 Stream &strm = description.ref(); 241 242 ModuleSP module_sp(GetSP()); 243 if (module_sp) { 244 module_sp->GetDescription(strm.AsRawOstream()); 245 } else 246 strm.PutCString("No value"); 247 248 return true; 249 } 250 251 uint32_t SBModule::GetNumCompileUnits() { 252 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetNumCompileUnits); 253 254 ModuleSP module_sp(GetSP()); 255 if (module_sp) { 256 return module_sp->GetNumCompileUnits(); 257 } 258 return 0; 259 } 260 261 SBCompileUnit SBModule::GetCompileUnitAtIndex(uint32_t index) { 262 LLDB_RECORD_METHOD(lldb::SBCompileUnit, SBModule, GetCompileUnitAtIndex, 263 (uint32_t), index); 264 265 SBCompileUnit sb_cu; 266 ModuleSP module_sp(GetSP()); 267 if (module_sp) { 268 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(index); 269 sb_cu.reset(cu_sp.get()); 270 } 271 return LLDB_RECORD_RESULT(sb_cu); 272 } 273 274 SBSymbolContextList SBModule::FindCompileUnits(const SBFileSpec &sb_file_spec) { 275 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBModule, FindCompileUnits, 276 (const lldb::SBFileSpec &), sb_file_spec); 277 278 SBSymbolContextList sb_sc_list; 279 const ModuleSP module_sp(GetSP()); 280 if (sb_file_spec.IsValid() && module_sp) { 281 module_sp->FindCompileUnits(*sb_file_spec, *sb_sc_list); 282 } 283 return LLDB_RECORD_RESULT(sb_sc_list); 284 } 285 286 static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) { 287 if (module_sp) 288 return module_sp->GetSymtab(); 289 return nullptr; 290 } 291 292 size_t SBModule::GetNumSymbols() { 293 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModule, GetNumSymbols); 294 295 ModuleSP module_sp(GetSP()); 296 if (Symtab *symtab = GetUnifiedSymbolTable(module_sp)) 297 return symtab->GetNumSymbols(); 298 return 0; 299 } 300 301 SBSymbol SBModule::GetSymbolAtIndex(size_t idx) { 302 LLDB_RECORD_METHOD(lldb::SBSymbol, SBModule, GetSymbolAtIndex, (size_t), idx); 303 304 SBSymbol sb_symbol; 305 ModuleSP module_sp(GetSP()); 306 Symtab *symtab = GetUnifiedSymbolTable(module_sp); 307 if (symtab) 308 sb_symbol.SetSymbol(symtab->SymbolAtIndex(idx)); 309 return LLDB_RECORD_RESULT(sb_symbol); 310 } 311 312 lldb::SBSymbol SBModule::FindSymbol(const char *name, 313 lldb::SymbolType symbol_type) { 314 LLDB_RECORD_METHOD(lldb::SBSymbol, SBModule, FindSymbol, 315 (const char *, lldb::SymbolType), name, symbol_type); 316 317 SBSymbol sb_symbol; 318 if (name && name[0]) { 319 ModuleSP module_sp(GetSP()); 320 Symtab *symtab = GetUnifiedSymbolTable(module_sp); 321 if (symtab) 322 sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType( 323 ConstString(name), symbol_type, Symtab::eDebugAny, 324 Symtab::eVisibilityAny)); 325 } 326 return LLDB_RECORD_RESULT(sb_symbol); 327 } 328 329 lldb::SBSymbolContextList SBModule::FindSymbols(const char *name, 330 lldb::SymbolType symbol_type) { 331 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBModule, FindSymbols, 332 (const char *, lldb::SymbolType), name, symbol_type); 333 334 SBSymbolContextList sb_sc_list; 335 if (name && name[0]) { 336 ModuleSP module_sp(GetSP()); 337 Symtab *symtab = GetUnifiedSymbolTable(module_sp); 338 if (symtab) { 339 std::vector<uint32_t> matching_symbol_indexes; 340 symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, 341 matching_symbol_indexes); 342 const size_t num_matches = matching_symbol_indexes.size(); 343 if (num_matches) { 344 SymbolContext sc; 345 sc.module_sp = module_sp; 346 SymbolContextList &sc_list = *sb_sc_list; 347 for (size_t i = 0; i < num_matches; ++i) { 348 sc.symbol = symtab->SymbolAtIndex(matching_symbol_indexes[i]); 349 if (sc.symbol) 350 sc_list.Append(sc); 351 } 352 } 353 } 354 } 355 return LLDB_RECORD_RESULT(sb_sc_list); 356 } 357 358 size_t SBModule::GetNumSections() { 359 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModule, GetNumSections); 360 361 ModuleSP module_sp(GetSP()); 362 if (module_sp) { 363 // Give the symbol vendor a chance to add to the unified section list. 364 module_sp->GetSymbolFile(); 365 SectionList *section_list = module_sp->GetSectionList(); 366 if (section_list) 367 return section_list->GetSize(); 368 } 369 return 0; 370 } 371 372 SBSection SBModule::GetSectionAtIndex(size_t idx) { 373 LLDB_RECORD_METHOD(lldb::SBSection, SBModule, GetSectionAtIndex, (size_t), 374 idx); 375 376 SBSection sb_section; 377 ModuleSP module_sp(GetSP()); 378 if (module_sp) { 379 // Give the symbol vendor a chance to add to the unified section list. 380 module_sp->GetSymbolFile(); 381 SectionList *section_list = module_sp->GetSectionList(); 382 383 if (section_list) 384 sb_section.SetSP(section_list->GetSectionAtIndex(idx)); 385 } 386 return LLDB_RECORD_RESULT(sb_section); 387 } 388 389 lldb::SBSymbolContextList SBModule::FindFunctions(const char *name, 390 uint32_t name_type_mask) { 391 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBModule, FindFunctions, 392 (const char *, uint32_t), name, name_type_mask); 393 394 lldb::SBSymbolContextList sb_sc_list; 395 ModuleSP module_sp(GetSP()); 396 if (name && module_sp) { 397 398 ModuleFunctionSearchOptions function_options; 399 function_options.include_symbols = true; 400 function_options.include_inlines = true; 401 FunctionNameType type = static_cast<FunctionNameType>(name_type_mask); 402 module_sp->FindFunctions(ConstString(name), CompilerDeclContext(), type, 403 function_options, *sb_sc_list); 404 } 405 return LLDB_RECORD_RESULT(sb_sc_list); 406 } 407 408 SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name, 409 uint32_t max_matches) { 410 LLDB_RECORD_METHOD(lldb::SBValueList, SBModule, FindGlobalVariables, 411 (lldb::SBTarget &, const char *, uint32_t), target, name, 412 max_matches); 413 414 SBValueList sb_value_list; 415 ModuleSP module_sp(GetSP()); 416 if (name && module_sp) { 417 VariableList variable_list; 418 module_sp->FindGlobalVariables(ConstString(name), CompilerDeclContext(), 419 max_matches, variable_list); 420 for (const VariableSP &var_sp : variable_list) { 421 lldb::ValueObjectSP valobj_sp; 422 TargetSP target_sp(target.GetSP()); 423 valobj_sp = ValueObjectVariable::Create(target_sp.get(), var_sp); 424 if (valobj_sp) 425 sb_value_list.Append(SBValue(valobj_sp)); 426 } 427 } 428 429 return LLDB_RECORD_RESULT(sb_value_list); 430 } 431 432 lldb::SBValue SBModule::FindFirstGlobalVariable(lldb::SBTarget &target, 433 const char *name) { 434 LLDB_RECORD_METHOD(lldb::SBValue, SBModule, FindFirstGlobalVariable, 435 (lldb::SBTarget &, const char *), target, name); 436 437 SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 438 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 439 return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0)); 440 return LLDB_RECORD_RESULT(SBValue()); 441 } 442 443 lldb::SBType SBModule::FindFirstType(const char *name_cstr) { 444 LLDB_RECORD_METHOD(lldb::SBType, SBModule, FindFirstType, (const char *), 445 name_cstr); 446 447 SBType sb_type; 448 ModuleSP module_sp(GetSP()); 449 if (name_cstr && module_sp) { 450 SymbolContext sc; 451 const bool exact_match = false; 452 ConstString name(name_cstr); 453 454 sb_type = SBType(module_sp->FindFirstType(sc, name, exact_match)); 455 456 if (!sb_type.IsValid()) { 457 auto type_system_or_err = 458 module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 459 if (auto err = type_system_or_err.takeError()) { 460 llvm::consumeError(std::move(err)); 461 return LLDB_RECORD_RESULT(SBType()); 462 } 463 sb_type = SBType(type_system_or_err->GetBuiltinTypeByName(name)); 464 } 465 } 466 return LLDB_RECORD_RESULT(sb_type); 467 } 468 469 lldb::SBType SBModule::GetBasicType(lldb::BasicType type) { 470 LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetBasicType, (lldb::BasicType), 471 type); 472 473 ModuleSP module_sp(GetSP()); 474 if (module_sp) { 475 auto type_system_or_err = 476 module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 477 if (auto err = type_system_or_err.takeError()) { 478 llvm::consumeError(std::move(err)); 479 } else { 480 return LLDB_RECORD_RESULT( 481 SBType(type_system_or_err->GetBasicTypeFromAST(type))); 482 } 483 } 484 return LLDB_RECORD_RESULT(SBType()); 485 } 486 487 lldb::SBTypeList SBModule::FindTypes(const char *type) { 488 LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, FindTypes, (const char *), 489 type); 490 491 SBTypeList retval; 492 493 ModuleSP module_sp(GetSP()); 494 if (type && module_sp) { 495 TypeList type_list; 496 const bool exact_match = false; 497 ConstString name(type); 498 llvm::DenseSet<SymbolFile *> searched_symbol_files; 499 module_sp->FindTypes(name, exact_match, UINT32_MAX, searched_symbol_files, 500 type_list); 501 502 if (type_list.Empty()) { 503 auto type_system_or_err = 504 module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 505 if (auto err = type_system_or_err.takeError()) { 506 llvm::consumeError(std::move(err)); 507 } else { 508 CompilerType compiler_type = 509 type_system_or_err->GetBuiltinTypeByName(name); 510 if (compiler_type) 511 retval.Append(SBType(compiler_type)); 512 } 513 } else { 514 for (size_t idx = 0; idx < type_list.GetSize(); idx++) { 515 TypeSP type_sp(type_list.GetTypeAtIndex(idx)); 516 if (type_sp) 517 retval.Append(SBType(type_sp)); 518 } 519 } 520 } 521 return LLDB_RECORD_RESULT(retval); 522 } 523 524 lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) { 525 LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetTypeByID, (lldb::user_id_t), 526 uid); 527 528 ModuleSP module_sp(GetSP()); 529 if (module_sp) { 530 if (SymbolFile *symfile = module_sp->GetSymbolFile()) { 531 Type *type_ptr = symfile->ResolveTypeUID(uid); 532 if (type_ptr) 533 return LLDB_RECORD_RESULT(SBType(type_ptr->shared_from_this())); 534 } 535 } 536 return LLDB_RECORD_RESULT(SBType()); 537 } 538 539 lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) { 540 LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, GetTypes, (uint32_t), 541 type_mask); 542 543 SBTypeList sb_type_list; 544 545 ModuleSP module_sp(GetSP()); 546 if (!module_sp) 547 return LLDB_RECORD_RESULT(sb_type_list); 548 SymbolFile *symfile = module_sp->GetSymbolFile(); 549 if (!symfile) 550 return LLDB_RECORD_RESULT(sb_type_list); 551 552 TypeClass type_class = static_cast<TypeClass>(type_mask); 553 TypeList type_list; 554 symfile->GetTypes(nullptr, type_class, type_list); 555 sb_type_list.m_opaque_up->Append(type_list); 556 return LLDB_RECORD_RESULT(sb_type_list); 557 } 558 559 SBSection SBModule::FindSection(const char *sect_name) { 560 LLDB_RECORD_METHOD(lldb::SBSection, SBModule, FindSection, (const char *), 561 sect_name); 562 563 SBSection sb_section; 564 565 ModuleSP module_sp(GetSP()); 566 if (sect_name && module_sp) { 567 // Give the symbol vendor a chance to add to the unified section list. 568 module_sp->GetSymbolFile(); 569 SectionList *section_list = module_sp->GetSectionList(); 570 if (section_list) { 571 ConstString const_sect_name(sect_name); 572 SectionSP section_sp(section_list->FindSectionByName(const_sect_name)); 573 if (section_sp) { 574 sb_section.SetSP(section_sp); 575 } 576 } 577 } 578 return LLDB_RECORD_RESULT(sb_section); 579 } 580 581 lldb::ByteOrder SBModule::GetByteOrder() { 582 LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBModule, GetByteOrder); 583 584 ModuleSP module_sp(GetSP()); 585 if (module_sp) 586 return module_sp->GetArchitecture().GetByteOrder(); 587 return eByteOrderInvalid; 588 } 589 590 const char *SBModule::GetTriple() { 591 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModule, GetTriple); 592 593 ModuleSP module_sp(GetSP()); 594 if (module_sp) { 595 std::string triple(module_sp->GetArchitecture().GetTriple().str()); 596 // Unique the string so we don't run into ownership issues since the const 597 // strings put the string into the string pool once and the strings never 598 // comes out 599 ConstString const_triple(triple.c_str()); 600 return const_triple.GetCString(); 601 } 602 return nullptr; 603 } 604 605 uint32_t SBModule::GetAddressByteSize() { 606 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetAddressByteSize); 607 608 ModuleSP module_sp(GetSP()); 609 if (module_sp) 610 return module_sp->GetArchitecture().GetAddressByteSize(); 611 return sizeof(void *); 612 } 613 614 uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) { 615 LLDB_RECORD_METHOD(uint32_t, SBModule, GetVersion, (uint32_t *, uint32_t), 616 versions, num_versions); 617 618 llvm::VersionTuple version; 619 if (ModuleSP module_sp = GetSP()) 620 version = module_sp->GetVersion(); 621 uint32_t result = 0; 622 if (!version.empty()) 623 ++result; 624 if (version.getMinor()) 625 ++result; 626 if (version.getSubminor()) 627 ++result; 628 629 if (!versions) 630 return result; 631 632 if (num_versions > 0) 633 versions[0] = version.empty() ? UINT32_MAX : version.getMajor(); 634 if (num_versions > 1) 635 versions[1] = version.getMinor().getValueOr(UINT32_MAX); 636 if (num_versions > 2) 637 versions[2] = version.getSubminor().getValueOr(UINT32_MAX); 638 for (uint32_t i = 3; i < num_versions; ++i) 639 versions[i] = UINT32_MAX; 640 return result; 641 } 642 643 lldb::SBFileSpec SBModule::GetSymbolFileSpec() const { 644 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule, 645 GetSymbolFileSpec); 646 647 lldb::SBFileSpec sb_file_spec; 648 ModuleSP module_sp(GetSP()); 649 if (module_sp) { 650 if (SymbolFile *symfile = module_sp->GetSymbolFile()) 651 sb_file_spec.SetFileSpec(symfile->GetObjectFile()->GetFileSpec()); 652 } 653 return LLDB_RECORD_RESULT(sb_file_spec); 654 } 655 656 lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const { 657 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule, 658 GetObjectFileHeaderAddress); 659 660 lldb::SBAddress sb_addr; 661 ModuleSP module_sp(GetSP()); 662 if (module_sp) { 663 ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 664 if (objfile_ptr) 665 sb_addr.ref() = objfile_ptr->GetBaseAddress(); 666 } 667 return LLDB_RECORD_RESULT(sb_addr); 668 } 669 670 lldb::SBAddress SBModule::GetObjectFileEntryPointAddress() const { 671 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule, 672 GetObjectFileEntryPointAddress); 673 674 lldb::SBAddress sb_addr; 675 ModuleSP module_sp(GetSP()); 676 if (module_sp) { 677 ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 678 if (objfile_ptr) 679 sb_addr.ref() = objfile_ptr->GetEntryPointAddress(); 680 } 681 return LLDB_RECORD_RESULT(sb_addr); 682 } 683 684 uint32_t SBModule::GetNumberAllocatedModules() { 685 LLDB_RECORD_STATIC_METHOD_NO_ARGS(uint32_t, SBModule, 686 GetNumberAllocatedModules); 687 688 return Module::GetNumberAllocatedModules(); 689 } 690 691 void SBModule::GarbageCollectAllocatedModules() { 692 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBModule, 693 GarbageCollectAllocatedModules); 694 695 const bool mandatory = false; 696 ModuleList::RemoveOrphanSharedModules(mandatory); 697 } 698