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