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 const bool symbols_ok = true; 401 const bool inlines_ok = true; 402 FunctionNameType type = static_cast<FunctionNameType>(name_type_mask); 403 module_sp->FindFunctions(ConstString(name), CompilerDeclContext(), type, 404 symbols_ok, inlines_ok, *sb_sc_list); 405 } 406 return LLDB_RECORD_RESULT(sb_sc_list); 407 } 408 409 SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name, 410 uint32_t max_matches) { 411 LLDB_RECORD_METHOD(lldb::SBValueList, SBModule, FindGlobalVariables, 412 (lldb::SBTarget &, const char *, uint32_t), target, name, 413 max_matches); 414 415 SBValueList sb_value_list; 416 ModuleSP module_sp(GetSP()); 417 if (name && module_sp) { 418 VariableList variable_list; 419 module_sp->FindGlobalVariables(ConstString(name), CompilerDeclContext(), 420 max_matches, variable_list); 421 for (const VariableSP &var_sp : variable_list) { 422 lldb::ValueObjectSP valobj_sp; 423 TargetSP target_sp(target.GetSP()); 424 valobj_sp = ValueObjectVariable::Create(target_sp.get(), var_sp); 425 if (valobj_sp) 426 sb_value_list.Append(SBValue(valobj_sp)); 427 } 428 } 429 430 return LLDB_RECORD_RESULT(sb_value_list); 431 } 432 433 lldb::SBValue SBModule::FindFirstGlobalVariable(lldb::SBTarget &target, 434 const char *name) { 435 LLDB_RECORD_METHOD(lldb::SBValue, SBModule, FindFirstGlobalVariable, 436 (lldb::SBTarget &, const char *), target, name); 437 438 SBValueList sb_value_list(FindGlobalVariables(target, name, 1)); 439 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 440 return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0)); 441 return LLDB_RECORD_RESULT(SBValue()); 442 } 443 444 lldb::SBType SBModule::FindFirstType(const char *name_cstr) { 445 LLDB_RECORD_METHOD(lldb::SBType, SBModule, FindFirstType, (const char *), 446 name_cstr); 447 448 SBType sb_type; 449 ModuleSP module_sp(GetSP()); 450 if (name_cstr && module_sp) { 451 SymbolContext sc; 452 const bool exact_match = false; 453 ConstString name(name_cstr); 454 455 sb_type = SBType(module_sp->FindFirstType(sc, name, exact_match)); 456 457 if (!sb_type.IsValid()) { 458 auto type_system_or_err = 459 module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 460 if (auto err = type_system_or_err.takeError()) { 461 llvm::consumeError(std::move(err)); 462 return LLDB_RECORD_RESULT(SBType()); 463 } 464 sb_type = SBType(type_system_or_err->GetBuiltinTypeByName(name)); 465 } 466 } 467 return LLDB_RECORD_RESULT(sb_type); 468 } 469 470 lldb::SBType SBModule::GetBasicType(lldb::BasicType type) { 471 LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetBasicType, (lldb::BasicType), 472 type); 473 474 ModuleSP module_sp(GetSP()); 475 if (module_sp) { 476 auto type_system_or_err = 477 module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 478 if (auto err = type_system_or_err.takeError()) { 479 llvm::consumeError(std::move(err)); 480 } else { 481 return LLDB_RECORD_RESULT( 482 SBType(type_system_or_err->GetBasicTypeFromAST(type))); 483 } 484 } 485 return LLDB_RECORD_RESULT(SBType()); 486 } 487 488 lldb::SBTypeList SBModule::FindTypes(const char *type) { 489 LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, FindTypes, (const char *), 490 type); 491 492 SBTypeList retval; 493 494 ModuleSP module_sp(GetSP()); 495 if (type && module_sp) { 496 TypeList type_list; 497 const bool exact_match = false; 498 ConstString name(type); 499 llvm::DenseSet<SymbolFile *> searched_symbol_files; 500 module_sp->FindTypes(name, exact_match, UINT32_MAX, searched_symbol_files, 501 type_list); 502 503 if (type_list.Empty()) { 504 auto type_system_or_err = 505 module_sp->GetTypeSystemForLanguage(eLanguageTypeC); 506 if (auto err = type_system_or_err.takeError()) { 507 llvm::consumeError(std::move(err)); 508 } else { 509 CompilerType compiler_type = 510 type_system_or_err->GetBuiltinTypeByName(name); 511 if (compiler_type) 512 retval.Append(SBType(compiler_type)); 513 } 514 } else { 515 for (size_t idx = 0; idx < type_list.GetSize(); idx++) { 516 TypeSP type_sp(type_list.GetTypeAtIndex(idx)); 517 if (type_sp) 518 retval.Append(SBType(type_sp)); 519 } 520 } 521 } 522 return LLDB_RECORD_RESULT(retval); 523 } 524 525 lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) { 526 LLDB_RECORD_METHOD(lldb::SBType, SBModule, GetTypeByID, (lldb::user_id_t), 527 uid); 528 529 ModuleSP module_sp(GetSP()); 530 if (module_sp) { 531 if (SymbolFile *symfile = module_sp->GetSymbolFile()) { 532 Type *type_ptr = symfile->ResolveTypeUID(uid); 533 if (type_ptr) 534 return LLDB_RECORD_RESULT(SBType(type_ptr->shared_from_this())); 535 } 536 } 537 return LLDB_RECORD_RESULT(SBType()); 538 } 539 540 lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) { 541 LLDB_RECORD_METHOD(lldb::SBTypeList, SBModule, GetTypes, (uint32_t), 542 type_mask); 543 544 SBTypeList sb_type_list; 545 546 ModuleSP module_sp(GetSP()); 547 if (!module_sp) 548 return LLDB_RECORD_RESULT(sb_type_list); 549 SymbolFile *symfile = module_sp->GetSymbolFile(); 550 if (!symfile) 551 return LLDB_RECORD_RESULT(sb_type_list); 552 553 TypeClass type_class = static_cast<TypeClass>(type_mask); 554 TypeList type_list; 555 symfile->GetTypes(nullptr, type_class, type_list); 556 sb_type_list.m_opaque_up->Append(type_list); 557 return LLDB_RECORD_RESULT(sb_type_list); 558 } 559 560 SBSection SBModule::FindSection(const char *sect_name) { 561 LLDB_RECORD_METHOD(lldb::SBSection, SBModule, FindSection, (const char *), 562 sect_name); 563 564 SBSection sb_section; 565 566 ModuleSP module_sp(GetSP()); 567 if (sect_name && module_sp) { 568 // Give the symbol vendor a chance to add to the unified section list. 569 module_sp->GetSymbolFile(); 570 SectionList *section_list = module_sp->GetSectionList(); 571 if (section_list) { 572 ConstString const_sect_name(sect_name); 573 SectionSP section_sp(section_list->FindSectionByName(const_sect_name)); 574 if (section_sp) { 575 sb_section.SetSP(section_sp); 576 } 577 } 578 } 579 return LLDB_RECORD_RESULT(sb_section); 580 } 581 582 lldb::ByteOrder SBModule::GetByteOrder() { 583 LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBModule, GetByteOrder); 584 585 ModuleSP module_sp(GetSP()); 586 if (module_sp) 587 return module_sp->GetArchitecture().GetByteOrder(); 588 return eByteOrderInvalid; 589 } 590 591 const char *SBModule::GetTriple() { 592 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModule, GetTriple); 593 594 ModuleSP module_sp(GetSP()); 595 if (module_sp) { 596 std::string triple(module_sp->GetArchitecture().GetTriple().str()); 597 // Unique the string so we don't run into ownership issues since the const 598 // strings put the string into the string pool once and the strings never 599 // comes out 600 ConstString const_triple(triple.c_str()); 601 return const_triple.GetCString(); 602 } 603 return nullptr; 604 } 605 606 uint32_t SBModule::GetAddressByteSize() { 607 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBModule, GetAddressByteSize); 608 609 ModuleSP module_sp(GetSP()); 610 if (module_sp) 611 return module_sp->GetArchitecture().GetAddressByteSize(); 612 return sizeof(void *); 613 } 614 615 uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) { 616 LLDB_RECORD_METHOD(uint32_t, SBModule, GetVersion, (uint32_t *, uint32_t), 617 versions, num_versions); 618 619 llvm::VersionTuple version; 620 if (ModuleSP module_sp = GetSP()) 621 version = module_sp->GetVersion(); 622 uint32_t result = 0; 623 if (!version.empty()) 624 ++result; 625 if (version.getMinor()) 626 ++result; 627 if (version.getSubminor()) 628 ++result; 629 630 if (!versions) 631 return result; 632 633 if (num_versions > 0) 634 versions[0] = version.empty() ? UINT32_MAX : version.getMajor(); 635 if (num_versions > 1) 636 versions[1] = version.getMinor().getValueOr(UINT32_MAX); 637 if (num_versions > 2) 638 versions[2] = version.getSubminor().getValueOr(UINT32_MAX); 639 for (uint32_t i = 3; i < num_versions; ++i) 640 versions[i] = UINT32_MAX; 641 return result; 642 } 643 644 lldb::SBFileSpec SBModule::GetSymbolFileSpec() const { 645 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBModule, 646 GetSymbolFileSpec); 647 648 lldb::SBFileSpec sb_file_spec; 649 ModuleSP module_sp(GetSP()); 650 if (module_sp) { 651 if (SymbolFile *symfile = module_sp->GetSymbolFile()) 652 sb_file_spec.SetFileSpec(symfile->GetObjectFile()->GetFileSpec()); 653 } 654 return LLDB_RECORD_RESULT(sb_file_spec); 655 } 656 657 lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const { 658 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule, 659 GetObjectFileHeaderAddress); 660 661 lldb::SBAddress sb_addr; 662 ModuleSP module_sp(GetSP()); 663 if (module_sp) { 664 ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 665 if (objfile_ptr) 666 sb_addr.ref() = objfile_ptr->GetBaseAddress(); 667 } 668 return LLDB_RECORD_RESULT(sb_addr); 669 } 670 671 lldb::SBAddress SBModule::GetObjectFileEntryPointAddress() const { 672 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBModule, 673 GetObjectFileEntryPointAddress); 674 675 lldb::SBAddress sb_addr; 676 ModuleSP module_sp(GetSP()); 677 if (module_sp) { 678 ObjectFile *objfile_ptr = module_sp->GetObjectFile(); 679 if (objfile_ptr) 680 sb_addr.ref() = objfile_ptr->GetEntryPointAddress(); 681 } 682 return LLDB_RECORD_RESULT(sb_addr); 683 } 684 685 uint32_t SBModule::GetNumberAllocatedModules() { 686 LLDB_RECORD_STATIC_METHOD_NO_ARGS(uint32_t, SBModule, 687 GetNumberAllocatedModules); 688 689 return Module::GetNumberAllocatedModules(); 690 } 691 692 void SBModule::GarbageCollectAllocatedModules() { 693 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBModule, 694 GarbageCollectAllocatedModules); 695 696 const bool mandatory = false; 697 ModuleList::RemoveOrphanSharedModules(mandatory); 698 } 699 700 namespace lldb_private { 701 namespace repro { 702 703 template <> void RegisterMethods<SBModule>(Registry &R) { 704 LLDB_REGISTER_CONSTRUCTOR(SBModule, ()); 705 LLDB_REGISTER_CONSTRUCTOR(SBModule, (const lldb::SBModuleSpec &)); 706 LLDB_REGISTER_CONSTRUCTOR(SBModule, (const lldb::SBModule &)); 707 LLDB_REGISTER_CONSTRUCTOR(SBModule, (lldb::SBProcess &, lldb::addr_t)); 708 LLDB_REGISTER_METHOD(const lldb::SBModule &, SBModule, operator=, 709 (const lldb::SBModule &)); 710 LLDB_REGISTER_METHOD_CONST(bool, SBModule, IsValid, ()); 711 LLDB_REGISTER_METHOD_CONST(bool, SBModule, operator bool, ()); 712 LLDB_REGISTER_METHOD(void, SBModule, Clear, ()); 713 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBModule, GetFileSpec, ()); 714 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBModule, GetPlatformFileSpec, 715 ()); 716 LLDB_REGISTER_METHOD(bool, SBModule, SetPlatformFileSpec, 717 (const lldb::SBFileSpec &)); 718 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModule, GetRemoteInstallFileSpec, 719 ()); 720 LLDB_REGISTER_METHOD(bool, SBModule, SetRemoteInstallFileSpec, 721 (lldb::SBFileSpec &)); 722 LLDB_REGISTER_METHOD_CONST(const char *, SBModule, GetUUIDString, ()); 723 LLDB_REGISTER_METHOD_CONST(bool, SBModule, operator==, 724 (const lldb::SBModule &)); 725 LLDB_REGISTER_METHOD_CONST(bool, SBModule, operator!=, 726 (const lldb::SBModule &)); 727 LLDB_REGISTER_METHOD(lldb::SBAddress, SBModule, ResolveFileAddress, 728 (lldb::addr_t)); 729 LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBModule, 730 ResolveSymbolContextForAddress, 731 (const lldb::SBAddress &, uint32_t)); 732 LLDB_REGISTER_METHOD(bool, SBModule, GetDescription, (lldb::SBStream &)); 733 LLDB_REGISTER_METHOD(uint32_t, SBModule, GetNumCompileUnits, ()); 734 LLDB_REGISTER_METHOD(lldb::SBCompileUnit, SBModule, GetCompileUnitAtIndex, 735 (uint32_t)); 736 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBModule, FindCompileUnits, 737 (const lldb::SBFileSpec &)); 738 LLDB_REGISTER_METHOD(size_t, SBModule, GetNumSymbols, ()); 739 LLDB_REGISTER_METHOD(lldb::SBSymbol, SBModule, GetSymbolAtIndex, (size_t)); 740 LLDB_REGISTER_METHOD(lldb::SBSymbol, SBModule, FindSymbol, 741 (const char *, lldb::SymbolType)); 742 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBModule, FindSymbols, 743 (const char *, lldb::SymbolType)); 744 LLDB_REGISTER_METHOD(size_t, SBModule, GetNumSections, ()); 745 LLDB_REGISTER_METHOD(lldb::SBSection, SBModule, GetSectionAtIndex, (size_t)); 746 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBModule, FindFunctions, 747 (const char *, uint32_t)); 748 LLDB_REGISTER_METHOD(lldb::SBValueList, SBModule, FindGlobalVariables, 749 (lldb::SBTarget &, const char *, uint32_t)); 750 LLDB_REGISTER_METHOD(lldb::SBValue, SBModule, FindFirstGlobalVariable, 751 (lldb::SBTarget &, const char *)); 752 LLDB_REGISTER_METHOD(lldb::SBType, SBModule, FindFirstType, (const char *)); 753 LLDB_REGISTER_METHOD(lldb::SBType, SBModule, GetBasicType, (lldb::BasicType)); 754 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBModule, FindTypes, (const char *)); 755 LLDB_REGISTER_METHOD(lldb::SBType, SBModule, GetTypeByID, (lldb::user_id_t)); 756 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBModule, GetTypes, (uint32_t)); 757 LLDB_REGISTER_METHOD(lldb::SBSection, SBModule, FindSection, (const char *)); 758 LLDB_REGISTER_METHOD(lldb::ByteOrder, SBModule, GetByteOrder, ()); 759 LLDB_REGISTER_METHOD(const char *, SBModule, GetTriple, ()); 760 LLDB_REGISTER_METHOD(uint32_t, SBModule, GetAddressByteSize, ()); 761 LLDB_REGISTER_METHOD(uint32_t, SBModule, GetVersion, (uint32_t *, uint32_t)); 762 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBModule, GetSymbolFileSpec, ()); 763 LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBModule, 764 GetObjectFileHeaderAddress, ()); 765 LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBModule, 766 GetObjectFileEntryPointAddress, ()); 767 LLDB_REGISTER_STATIC_METHOD(uint32_t, SBModule, GetNumberAllocatedModules, 768 ()); 769 LLDB_REGISTER_STATIC_METHOD(void, SBModule, GarbageCollectAllocatedModules, 770 ()); 771 } 772 773 } // namespace repro 774 } // namespace lldb_private 775