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