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