1 //===-- SBTarget.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/SBTarget.h" 10 #include "SBReproducerPrivate.h" 11 12 #include "lldb/lldb-public.h" 13 14 #include "lldb/API/SBBreakpoint.h" 15 #include "lldb/API/SBDebugger.h" 16 #include "lldb/API/SBEnvironment.h" 17 #include "lldb/API/SBEvent.h" 18 #include "lldb/API/SBExpressionOptions.h" 19 #include "lldb/API/SBFileSpec.h" 20 #include "lldb/API/SBListener.h" 21 #include "lldb/API/SBModule.h" 22 #include "lldb/API/SBModuleSpec.h" 23 #include "lldb/API/SBProcess.h" 24 #include "lldb/API/SBSourceManager.h" 25 #include "lldb/API/SBStream.h" 26 #include "lldb/API/SBStringList.h" 27 #include "lldb/API/SBStructuredData.h" 28 #include "lldb/API/SBSymbolContextList.h" 29 #include "lldb/API/SBTrace.h" 30 #include "lldb/Breakpoint/BreakpointID.h" 31 #include "lldb/Breakpoint/BreakpointIDList.h" 32 #include "lldb/Breakpoint/BreakpointList.h" 33 #include "lldb/Breakpoint/BreakpointLocation.h" 34 #include "lldb/Core/Address.h" 35 #include "lldb/Core/AddressResolver.h" 36 #include "lldb/Core/Debugger.h" 37 #include "lldb/Core/Disassembler.h" 38 #include "lldb/Core/Module.h" 39 #include "lldb/Core/ModuleSpec.h" 40 #include "lldb/Core/SearchFilter.h" 41 #include "lldb/Core/Section.h" 42 #include "lldb/Core/StructuredDataImpl.h" 43 #include "lldb/Core/ValueObjectConstResult.h" 44 #include "lldb/Core/ValueObjectList.h" 45 #include "lldb/Core/ValueObjectVariable.h" 46 #include "lldb/Host/Host.h" 47 #include "lldb/Symbol/DeclVendor.h" 48 #include "lldb/Symbol/ObjectFile.h" 49 #include "lldb/Symbol/SymbolFile.h" 50 #include "lldb/Symbol/SymbolVendor.h" 51 #include "lldb/Symbol/TypeSystem.h" 52 #include "lldb/Symbol/VariableList.h" 53 #include "lldb/Target/ABI.h" 54 #include "lldb/Target/Language.h" 55 #include "lldb/Target/LanguageRuntime.h" 56 #include "lldb/Target/Process.h" 57 #include "lldb/Target/StackFrame.h" 58 #include "lldb/Target/Target.h" 59 #include "lldb/Target/TargetList.h" 60 #include "lldb/Utility/ArchSpec.h" 61 #include "lldb/Utility/Args.h" 62 #include "lldb/Utility/FileSpec.h" 63 #include "lldb/Utility/ProcessInfo.h" 64 #include "lldb/Utility/RegularExpression.h" 65 66 #include "Commands/CommandObjectBreakpoint.h" 67 #include "lldb/Interpreter/CommandReturnObject.h" 68 #include "llvm/Support/PrettyStackTrace.h" 69 #include "llvm/Support/Regex.h" 70 71 using namespace lldb; 72 using namespace lldb_private; 73 74 #define DEFAULT_DISASM_BYTE_SIZE 32 75 76 static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) { 77 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex()); 78 79 auto process_sp = target.GetProcessSP(); 80 if (process_sp) { 81 const auto state = process_sp->GetState(); 82 if (process_sp->IsAlive() && state == eStateConnected) { 83 // If we are already connected, then we have already specified the 84 // listener, so if a valid listener is supplied, we need to error out to 85 // let the client know. 86 if (attach_info.GetListener()) 87 return Status("process is connected and already has a listener, pass " 88 "empty listener"); 89 } 90 } 91 92 return target.Attach(attach_info, nullptr); 93 } 94 95 // SBTarget constructor 96 SBTarget::SBTarget() : m_opaque_sp() { 97 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTarget); 98 } 99 100 SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) { 101 LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &), rhs); 102 } 103 104 SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) { 105 LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &), target_sp); 106 } 107 108 const SBTarget &SBTarget::operator=(const SBTarget &rhs) { 109 LLDB_RECORD_METHOD(const lldb::SBTarget &, 110 SBTarget, operator=,(const lldb::SBTarget &), rhs); 111 112 if (this != &rhs) 113 m_opaque_sp = rhs.m_opaque_sp; 114 return LLDB_RECORD_RESULT(*this); 115 } 116 117 // Destructor 118 SBTarget::~SBTarget() = default; 119 120 bool SBTarget::EventIsTargetEvent(const SBEvent &event) { 121 LLDB_RECORD_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent, 122 (const lldb::SBEvent &), event); 123 124 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr; 125 } 126 127 SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) { 128 LLDB_RECORD_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent, 129 (const lldb::SBEvent &), event); 130 131 return LLDB_RECORD_RESULT( 132 Target::TargetEventData::GetTargetFromEvent(event.get())); 133 } 134 135 uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) { 136 LLDB_RECORD_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent, 137 (const lldb::SBEvent &), event); 138 139 const ModuleList module_list = 140 Target::TargetEventData::GetModuleListFromEvent(event.get()); 141 return module_list.GetSize(); 142 } 143 144 SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx, 145 const SBEvent &event) { 146 LLDB_RECORD_STATIC_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndexFromEvent, 147 (const uint32_t, const lldb::SBEvent &), idx, 148 event); 149 150 const ModuleList module_list = 151 Target::TargetEventData::GetModuleListFromEvent(event.get()); 152 return LLDB_RECORD_RESULT(SBModule(module_list.GetModuleAtIndex(idx))); 153 } 154 155 const char *SBTarget::GetBroadcasterClassName() { 156 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBTarget, 157 GetBroadcasterClassName); 158 159 return Target::GetStaticBroadcasterClass().AsCString(); 160 } 161 162 bool SBTarget::IsValid() const { 163 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, IsValid); 164 return this->operator bool(); 165 } 166 SBTarget::operator bool() const { 167 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, operator bool); 168 169 return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid(); 170 } 171 172 SBProcess SBTarget::GetProcess() { 173 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBTarget, GetProcess); 174 175 SBProcess sb_process; 176 ProcessSP process_sp; 177 TargetSP target_sp(GetSP()); 178 if (target_sp) { 179 process_sp = target_sp->GetProcessSP(); 180 sb_process.SetSP(process_sp); 181 } 182 183 return LLDB_RECORD_RESULT(sb_process); 184 } 185 186 SBPlatform SBTarget::GetPlatform() { 187 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBTarget, GetPlatform); 188 189 TargetSP target_sp(GetSP()); 190 if (!target_sp) 191 return LLDB_RECORD_RESULT(SBPlatform()); 192 193 SBPlatform platform; 194 platform.m_opaque_sp = target_sp->GetPlatform(); 195 196 return LLDB_RECORD_RESULT(platform); 197 } 198 199 SBDebugger SBTarget::GetDebugger() const { 200 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBDebugger, SBTarget, GetDebugger); 201 202 SBDebugger debugger; 203 TargetSP target_sp(GetSP()); 204 if (target_sp) 205 debugger.reset(target_sp->GetDebugger().shared_from_this()); 206 return LLDB_RECORD_RESULT(debugger); 207 } 208 209 SBStructuredData SBTarget::GetStatistics() { 210 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBTarget, GetStatistics); 211 212 SBStructuredData data; 213 TargetSP target_sp(GetSP()); 214 if (!target_sp) 215 return LLDB_RECORD_RESULT(data); 216 217 auto stats_up = std::make_unique<StructuredData::Dictionary>(); 218 int i = 0; 219 for (auto &Entry : target_sp->GetStatistics()) { 220 std::string Desc = lldb_private::GetStatDescription( 221 static_cast<lldb_private::StatisticKind>(i)); 222 stats_up->AddIntegerItem(Desc, Entry); 223 i += 1; 224 } 225 226 data.m_impl_up->SetObjectSP(std::move(stats_up)); 227 return LLDB_RECORD_RESULT(data); 228 } 229 230 void SBTarget::SetCollectingStats(bool v) { 231 LLDB_RECORD_METHOD(void, SBTarget, SetCollectingStats, (bool), v); 232 233 TargetSP target_sp(GetSP()); 234 if (!target_sp) 235 return; 236 return target_sp->SetCollectingStats(v); 237 } 238 239 bool SBTarget::GetCollectingStats() { 240 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, GetCollectingStats); 241 242 TargetSP target_sp(GetSP()); 243 if (!target_sp) 244 return false; 245 return target_sp->GetCollectingStats(); 246 } 247 248 SBProcess SBTarget::LoadCore(const char *core_file) { 249 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *), 250 core_file); 251 252 lldb::SBError error; // Ignored 253 return LLDB_RECORD_RESULT(LoadCore(core_file, error)); 254 } 255 256 SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) { 257 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore, 258 (const char *, lldb::SBError &), core_file, error); 259 260 SBProcess sb_process; 261 TargetSP target_sp(GetSP()); 262 if (target_sp) { 263 FileSpec filespec(core_file); 264 FileSystem::Instance().Resolve(filespec); 265 ProcessSP process_sp(target_sp->CreateProcess( 266 target_sp->GetDebugger().GetListener(), "", &filespec, false)); 267 if (process_sp) { 268 error.SetError(process_sp->LoadCore()); 269 if (error.Success()) 270 sb_process.SetSP(process_sp); 271 } else { 272 error.SetErrorString("Failed to create the process"); 273 } 274 } else { 275 error.SetErrorString("SBTarget is invalid"); 276 } 277 return LLDB_RECORD_RESULT(sb_process); 278 } 279 280 SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp, 281 const char *working_directory) { 282 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LaunchSimple, 283 (const char **, const char **, const char *), argv, envp, 284 working_directory); 285 286 TargetSP target_sp = GetSP(); 287 if (!target_sp) 288 return LLDB_RECORD_RESULT(SBProcess()); 289 290 SBLaunchInfo launch_info = GetLaunchInfo(); 291 292 if (Module *exe_module = target_sp->GetExecutableModulePointer()) 293 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), 294 /*add_as_first_arg*/ true); 295 if (argv) 296 launch_info.SetArguments(argv, /*append*/ true); 297 if (envp) 298 launch_info.SetEnvironmentEntries(envp, /*append*/ false); 299 if (working_directory) 300 launch_info.SetWorkingDirectory(working_directory); 301 302 SBError error; 303 return LLDB_RECORD_RESULT(Launch(launch_info, error)); 304 } 305 306 SBError SBTarget::Install() { 307 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBTarget, Install); 308 309 SBError sb_error; 310 TargetSP target_sp(GetSP()); 311 if (target_sp) { 312 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 313 sb_error.ref() = target_sp->Install(nullptr); 314 } 315 return LLDB_RECORD_RESULT(sb_error); 316 } 317 318 SBProcess SBTarget::Launch(SBListener &listener, char const **argv, 319 char const **envp, const char *stdin_path, 320 const char *stdout_path, const char *stderr_path, 321 const char *working_directory, 322 uint32_t launch_flags, // See LaunchFlags 323 bool stop_at_entry, lldb::SBError &error) { 324 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch, 325 (lldb::SBListener &, const char **, const char **, 326 const char *, const char *, const char *, const char *, 327 uint32_t, bool, lldb::SBError &), 328 listener, argv, envp, stdin_path, stdout_path, stderr_path, 329 working_directory, launch_flags, stop_at_entry, error); 330 331 SBProcess sb_process; 332 ProcessSP process_sp; 333 TargetSP target_sp(GetSP()); 334 335 if (target_sp) { 336 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 337 338 if (stop_at_entry) 339 launch_flags |= eLaunchFlagStopAtEntry; 340 341 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) 342 launch_flags |= eLaunchFlagDisableASLR; 343 344 StateType state = eStateInvalid; 345 process_sp = target_sp->GetProcessSP(); 346 if (process_sp) { 347 state = process_sp->GetState(); 348 349 if (process_sp->IsAlive() && state != eStateConnected) { 350 if (state == eStateAttaching) 351 error.SetErrorString("process attach is in progress"); 352 else 353 error.SetErrorString("a process is already being debugged"); 354 return LLDB_RECORD_RESULT(sb_process); 355 } 356 } 357 358 if (state == eStateConnected) { 359 // If we are already connected, then we have already specified the 360 // listener, so if a valid listener is supplied, we need to error out to 361 // let the client know. 362 if (listener.IsValid()) { 363 error.SetErrorString("process is connected and already has a listener, " 364 "pass empty listener"); 365 return LLDB_RECORD_RESULT(sb_process); 366 } 367 } 368 369 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) 370 launch_flags |= eLaunchFlagDisableSTDIO; 371 372 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path), 373 FileSpec(stderr_path), 374 FileSpec(working_directory), launch_flags); 375 376 Module *exe_module = target_sp->GetExecutableModulePointer(); 377 if (exe_module) 378 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 379 if (argv) { 380 launch_info.GetArguments().AppendArguments(argv); 381 } else { 382 auto default_launch_info = target_sp->GetProcessLaunchInfo(); 383 launch_info.GetArguments().AppendArguments( 384 default_launch_info.GetArguments()); 385 } 386 if (envp) { 387 launch_info.GetEnvironment() = Environment(envp); 388 } else { 389 auto default_launch_info = target_sp->GetProcessLaunchInfo(); 390 launch_info.GetEnvironment() = default_launch_info.GetEnvironment(); 391 } 392 393 if (listener.IsValid()) 394 launch_info.SetListener(listener.GetSP()); 395 396 error.SetError(target_sp->Launch(launch_info, nullptr)); 397 398 sb_process.SetSP(target_sp->GetProcessSP()); 399 } else { 400 error.SetErrorString("SBTarget is invalid"); 401 } 402 403 return LLDB_RECORD_RESULT(sb_process); 404 } 405 406 SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) { 407 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch, 408 (lldb::SBLaunchInfo &, lldb::SBError &), sb_launch_info, 409 error); 410 411 412 SBProcess sb_process; 413 TargetSP target_sp(GetSP()); 414 415 if (target_sp) { 416 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 417 StateType state = eStateInvalid; 418 { 419 ProcessSP process_sp = target_sp->GetProcessSP(); 420 if (process_sp) { 421 state = process_sp->GetState(); 422 423 if (process_sp->IsAlive() && state != eStateConnected) { 424 if (state == eStateAttaching) 425 error.SetErrorString("process attach is in progress"); 426 else 427 error.SetErrorString("a process is already being debugged"); 428 return LLDB_RECORD_RESULT(sb_process); 429 } 430 } 431 } 432 433 lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref(); 434 435 if (!launch_info.GetExecutableFile()) { 436 Module *exe_module = target_sp->GetExecutableModulePointer(); 437 if (exe_module) 438 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 439 } 440 441 const ArchSpec &arch_spec = target_sp->GetArchitecture(); 442 if (arch_spec.IsValid()) 443 launch_info.GetArchitecture() = arch_spec; 444 445 error.SetError(target_sp->Launch(launch_info, nullptr)); 446 sb_launch_info.set_ref(launch_info); 447 sb_process.SetSP(target_sp->GetProcessSP()); 448 } else { 449 error.SetErrorString("SBTarget is invalid"); 450 } 451 452 return LLDB_RECORD_RESULT(sb_process); 453 } 454 455 lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) { 456 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Attach, 457 (lldb::SBAttachInfo &, lldb::SBError &), sb_attach_info, 458 error); 459 460 SBProcess sb_process; 461 TargetSP target_sp(GetSP()); 462 463 if (target_sp) { 464 ProcessAttachInfo &attach_info = sb_attach_info.ref(); 465 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) { 466 PlatformSP platform_sp = target_sp->GetPlatform(); 467 // See if we can pre-verify if a process exists or not 468 if (platform_sp && platform_sp->IsConnected()) { 469 lldb::pid_t attach_pid = attach_info.GetProcessID(); 470 ProcessInstanceInfo instance_info; 471 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) { 472 attach_info.SetUserID(instance_info.GetEffectiveUserID()); 473 } else { 474 error.ref().SetErrorStringWithFormat( 475 "no process found with process ID %" PRIu64, attach_pid); 476 return LLDB_RECORD_RESULT(sb_process); 477 } 478 } 479 } 480 error.SetError(AttachToProcess(attach_info, *target_sp)); 481 if (error.Success()) 482 sb_process.SetSP(target_sp->GetProcessSP()); 483 } else { 484 error.SetErrorString("SBTarget is invalid"); 485 } 486 487 return LLDB_RECORD_RESULT(sb_process); 488 } 489 490 lldb::SBProcess SBTarget::AttachToProcessWithID( 491 SBListener &listener, 492 lldb::pid_t pid, // The process ID to attach to 493 SBError &error // An error explaining what went wrong if attach fails 494 ) { 495 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID, 496 (lldb::SBListener &, lldb::pid_t, lldb::SBError &), 497 listener, pid, error); 498 499 SBProcess sb_process; 500 TargetSP target_sp(GetSP()); 501 502 if (target_sp) { 503 ProcessAttachInfo attach_info; 504 attach_info.SetProcessID(pid); 505 if (listener.IsValid()) 506 attach_info.SetListener(listener.GetSP()); 507 508 ProcessInstanceInfo instance_info; 509 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info)) 510 attach_info.SetUserID(instance_info.GetEffectiveUserID()); 511 512 error.SetError(AttachToProcess(attach_info, *target_sp)); 513 if (error.Success()) 514 sb_process.SetSP(target_sp->GetProcessSP()); 515 } else 516 error.SetErrorString("SBTarget is invalid"); 517 518 return LLDB_RECORD_RESULT(sb_process); 519 } 520 521 lldb::SBProcess SBTarget::AttachToProcessWithName( 522 SBListener &listener, 523 const char *name, // basename of process to attach to 524 bool wait_for, // if true wait for a new instance of "name" to be launched 525 SBError &error // An error explaining what went wrong if attach fails 526 ) { 527 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithName, 528 (lldb::SBListener &, const char *, bool, lldb::SBError &), 529 listener, name, wait_for, error); 530 531 SBProcess sb_process; 532 TargetSP target_sp(GetSP()); 533 534 if (name && target_sp) { 535 ProcessAttachInfo attach_info; 536 attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native); 537 attach_info.SetWaitForLaunch(wait_for); 538 if (listener.IsValid()) 539 attach_info.SetListener(listener.GetSP()); 540 541 error.SetError(AttachToProcess(attach_info, *target_sp)); 542 if (error.Success()) 543 sb_process.SetSP(target_sp->GetProcessSP()); 544 } else 545 error.SetErrorString("SBTarget is invalid"); 546 547 return LLDB_RECORD_RESULT(sb_process); 548 } 549 550 lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url, 551 const char *plugin_name, 552 SBError &error) { 553 LLDB_RECORD_METHOD( 554 lldb::SBProcess, SBTarget, ConnectRemote, 555 (lldb::SBListener &, const char *, const char *, lldb::SBError &), 556 listener, url, plugin_name, error); 557 558 SBProcess sb_process; 559 ProcessSP process_sp; 560 TargetSP target_sp(GetSP()); 561 562 if (target_sp) { 563 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 564 if (listener.IsValid()) 565 process_sp = 566 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr, 567 true); 568 else 569 process_sp = target_sp->CreateProcess( 570 target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true); 571 572 if (process_sp) { 573 sb_process.SetSP(process_sp); 574 error.SetError(process_sp->ConnectRemote(url)); 575 } else { 576 error.SetErrorString("unable to create lldb_private::Process"); 577 } 578 } else { 579 error.SetErrorString("SBTarget is invalid"); 580 } 581 582 return LLDB_RECORD_RESULT(sb_process); 583 } 584 585 SBFileSpec SBTarget::GetExecutable() { 586 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBTarget, GetExecutable); 587 588 SBFileSpec exe_file_spec; 589 TargetSP target_sp(GetSP()); 590 if (target_sp) { 591 Module *exe_module = target_sp->GetExecutableModulePointer(); 592 if (exe_module) 593 exe_file_spec.SetFileSpec(exe_module->GetFileSpec()); 594 } 595 596 return LLDB_RECORD_RESULT(exe_file_spec); 597 } 598 599 bool SBTarget::operator==(const SBTarget &rhs) const { 600 LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator==,(const lldb::SBTarget &), 601 rhs); 602 603 return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 604 } 605 606 bool SBTarget::operator!=(const SBTarget &rhs) const { 607 LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator!=,(const lldb::SBTarget &), 608 rhs); 609 610 return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 611 } 612 613 lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; } 614 615 void SBTarget::SetSP(const lldb::TargetSP &target_sp) { 616 m_opaque_sp = target_sp; 617 } 618 619 lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) { 620 LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress, 621 (lldb::addr_t), vm_addr); 622 623 lldb::SBAddress sb_addr; 624 Address &addr = sb_addr.ref(); 625 TargetSP target_sp(GetSP()); 626 if (target_sp) { 627 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 628 if (target_sp->ResolveLoadAddress(vm_addr, addr)) 629 return LLDB_RECORD_RESULT(sb_addr); 630 } 631 632 // We have a load address that isn't in a section, just return an address 633 // with the offset filled in (the address) and the section set to NULL 634 addr.SetRawAddress(vm_addr); 635 return LLDB_RECORD_RESULT(sb_addr); 636 } 637 638 lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) { 639 LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress, 640 (lldb::addr_t), file_addr); 641 642 lldb::SBAddress sb_addr; 643 Address &addr = sb_addr.ref(); 644 TargetSP target_sp(GetSP()); 645 if (target_sp) { 646 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 647 if (target_sp->ResolveFileAddress(file_addr, addr)) 648 return LLDB_RECORD_RESULT(sb_addr); 649 } 650 651 addr.SetRawAddress(file_addr); 652 return LLDB_RECORD_RESULT(sb_addr); 653 } 654 655 lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id, 656 lldb::addr_t vm_addr) { 657 LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress, 658 (uint32_t, lldb::addr_t), stop_id, vm_addr); 659 660 lldb::SBAddress sb_addr; 661 Address &addr = sb_addr.ref(); 662 TargetSP target_sp(GetSP()); 663 if (target_sp) { 664 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 665 if (target_sp->ResolveLoadAddress(vm_addr, addr)) 666 return LLDB_RECORD_RESULT(sb_addr); 667 } 668 669 // We have a load address that isn't in a section, just return an address 670 // with the offset filled in (the address) and the section set to NULL 671 addr.SetRawAddress(vm_addr); 672 return LLDB_RECORD_RESULT(sb_addr); 673 } 674 675 SBSymbolContext 676 SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr, 677 uint32_t resolve_scope) { 678 LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBTarget, 679 ResolveSymbolContextForAddress, 680 (const lldb::SBAddress &, uint32_t), addr, resolve_scope); 681 682 SBSymbolContext sc; 683 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope); 684 if (addr.IsValid()) { 685 TargetSP target_sp(GetSP()); 686 if (target_sp) 687 target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope, 688 sc.ref()); 689 } 690 return LLDB_RECORD_RESULT(sc); 691 } 692 693 size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size, 694 lldb::SBError &error) { 695 LLDB_RECORD_METHOD(size_t, SBTarget, ReadMemory, 696 (const lldb::SBAddress, void *, size_t, lldb::SBError &), 697 addr, buf, size, error); 698 699 SBError sb_error; 700 size_t bytes_read = 0; 701 TargetSP target_sp(GetSP()); 702 if (target_sp) { 703 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 704 bytes_read = 705 target_sp->ReadMemory(addr.ref(), buf, size, sb_error.ref(), true); 706 } else { 707 sb_error.SetErrorString("invalid target"); 708 } 709 710 return bytes_read; 711 } 712 713 SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file, 714 uint32_t line) { 715 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 716 (const char *, uint32_t), file, line); 717 718 return LLDB_RECORD_RESULT( 719 SBBreakpoint(BreakpointCreateByLocation(SBFileSpec(file, false), line))); 720 } 721 722 SBBreakpoint 723 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, 724 uint32_t line) { 725 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 726 (const lldb::SBFileSpec &, uint32_t), sb_file_spec, line); 727 728 return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0)); 729 } 730 731 SBBreakpoint 732 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, 733 uint32_t line, lldb::addr_t offset) { 734 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 735 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t), 736 sb_file_spec, line, offset); 737 738 SBFileSpecList empty_list; 739 return LLDB_RECORD_RESULT( 740 BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list)); 741 } 742 743 SBBreakpoint 744 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, 745 uint32_t line, lldb::addr_t offset, 746 SBFileSpecList &sb_module_list) { 747 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 748 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t, 749 lldb::SBFileSpecList &), 750 sb_file_spec, line, offset, sb_module_list); 751 752 return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0, 753 offset, sb_module_list)); 754 } 755 756 SBBreakpoint SBTarget::BreakpointCreateByLocation( 757 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column, 758 lldb::addr_t offset, SBFileSpecList &sb_module_list) { 759 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 760 (const lldb::SBFileSpec &, uint32_t, uint32_t, 761 lldb::addr_t, lldb::SBFileSpecList &), 762 sb_file_spec, line, column, offset, sb_module_list); 763 764 SBBreakpoint sb_bp; 765 TargetSP target_sp(GetSP()); 766 if (target_sp && line != 0) { 767 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 768 769 const LazyBool check_inlines = eLazyBoolCalculate; 770 const LazyBool skip_prologue = eLazyBoolCalculate; 771 const bool internal = false; 772 const bool hardware = false; 773 const LazyBool move_to_nearest_code = eLazyBoolCalculate; 774 const FileSpecList *module_list = nullptr; 775 if (sb_module_list.GetSize() > 0) { 776 module_list = sb_module_list.get(); 777 } 778 sb_bp = target_sp->CreateBreakpoint( 779 module_list, *sb_file_spec, line, column, offset, check_inlines, 780 skip_prologue, internal, hardware, move_to_nearest_code); 781 } 782 783 return LLDB_RECORD_RESULT(sb_bp); 784 } 785 786 SBBreakpoint SBTarget::BreakpointCreateByLocation( 787 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column, 788 lldb::addr_t offset, SBFileSpecList &sb_module_list, 789 bool move_to_nearest_code) { 790 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 791 (const lldb::SBFileSpec &, uint32_t, uint32_t, 792 lldb::addr_t, lldb::SBFileSpecList &, bool), 793 sb_file_spec, line, column, offset, sb_module_list, 794 move_to_nearest_code); 795 796 SBBreakpoint sb_bp; 797 TargetSP target_sp(GetSP()); 798 if (target_sp && line != 0) { 799 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 800 801 const LazyBool check_inlines = eLazyBoolCalculate; 802 const LazyBool skip_prologue = eLazyBoolCalculate; 803 const bool internal = false; 804 const bool hardware = false; 805 const FileSpecList *module_list = nullptr; 806 if (sb_module_list.GetSize() > 0) { 807 module_list = sb_module_list.get(); 808 } 809 sb_bp = target_sp->CreateBreakpoint( 810 module_list, *sb_file_spec, line, column, offset, check_inlines, 811 skip_prologue, internal, hardware, 812 move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo); 813 } 814 815 return LLDB_RECORD_RESULT(sb_bp); 816 } 817 818 SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name, 819 const char *module_name) { 820 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 821 (const char *, const char *), symbol_name, module_name); 822 823 SBBreakpoint sb_bp; 824 TargetSP target_sp(GetSP()); 825 if (target_sp.get()) { 826 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 827 828 const bool internal = false; 829 const bool hardware = false; 830 const LazyBool skip_prologue = eLazyBoolCalculate; 831 const lldb::addr_t offset = 0; 832 if (module_name && module_name[0]) { 833 FileSpecList module_spec_list; 834 module_spec_list.Append(FileSpec(module_name)); 835 sb_bp = target_sp->CreateBreakpoint( 836 &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto, 837 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware); 838 } else { 839 sb_bp = target_sp->CreateBreakpoint( 840 nullptr, nullptr, symbol_name, eFunctionNameTypeAuto, 841 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware); 842 } 843 } 844 845 return LLDB_RECORD_RESULT(sb_bp); 846 } 847 848 lldb::SBBreakpoint 849 SBTarget::BreakpointCreateByName(const char *symbol_name, 850 const SBFileSpecList &module_list, 851 const SBFileSpecList &comp_unit_list) { 852 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 853 (const char *, const lldb::SBFileSpecList &, 854 const lldb::SBFileSpecList &), 855 symbol_name, module_list, comp_unit_list); 856 857 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto; 858 return LLDB_RECORD_RESULT( 859 BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown, 860 module_list, comp_unit_list)); 861 } 862 863 lldb::SBBreakpoint SBTarget::BreakpointCreateByName( 864 const char *symbol_name, uint32_t name_type_mask, 865 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { 866 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 867 (const char *, uint32_t, const lldb::SBFileSpecList &, 868 const lldb::SBFileSpecList &), 869 symbol_name, name_type_mask, module_list, comp_unit_list); 870 871 return LLDB_RECORD_RESULT( 872 BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown, 873 module_list, comp_unit_list)); 874 } 875 876 lldb::SBBreakpoint SBTarget::BreakpointCreateByName( 877 const char *symbol_name, uint32_t name_type_mask, 878 LanguageType symbol_language, const SBFileSpecList &module_list, 879 const SBFileSpecList &comp_unit_list) { 880 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 881 (const char *, uint32_t, lldb::LanguageType, 882 const lldb::SBFileSpecList &, 883 const lldb::SBFileSpecList &), 884 symbol_name, name_type_mask, symbol_language, module_list, 885 comp_unit_list); 886 887 SBBreakpoint sb_bp; 888 TargetSP target_sp(GetSP()); 889 if (target_sp && symbol_name && symbol_name[0]) { 890 const bool internal = false; 891 const bool hardware = false; 892 const LazyBool skip_prologue = eLazyBoolCalculate; 893 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 894 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask); 895 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(), 896 symbol_name, mask, symbol_language, 0, 897 skip_prologue, internal, hardware); 898 } 899 900 return LLDB_RECORD_RESULT(sb_bp); 901 } 902 903 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames( 904 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask, 905 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { 906 LLDB_RECORD_METHOD( 907 lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames, 908 (const char **, uint32_t, uint32_t, const lldb::SBFileSpecList &, 909 const lldb::SBFileSpecList &), 910 symbol_names, num_names, name_type_mask, module_list, comp_unit_list); 911 912 return LLDB_RECORD_RESULT(BreakpointCreateByNames( 913 symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 914 module_list, comp_unit_list)); 915 } 916 917 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames( 918 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask, 919 LanguageType symbol_language, const SBFileSpecList &module_list, 920 const SBFileSpecList &comp_unit_list) { 921 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames, 922 (const char **, uint32_t, uint32_t, lldb::LanguageType, 923 const lldb::SBFileSpecList &, 924 const lldb::SBFileSpecList &), 925 symbol_names, num_names, name_type_mask, symbol_language, 926 module_list, comp_unit_list); 927 928 return LLDB_RECORD_RESULT(BreakpointCreateByNames( 929 symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 0, 930 module_list, comp_unit_list)); 931 } 932 933 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames( 934 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask, 935 LanguageType symbol_language, lldb::addr_t offset, 936 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { 937 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames, 938 (const char **, uint32_t, uint32_t, lldb::LanguageType, 939 lldb::addr_t, const lldb::SBFileSpecList &, 940 const lldb::SBFileSpecList &), 941 symbol_names, num_names, name_type_mask, symbol_language, 942 offset, module_list, comp_unit_list); 943 944 SBBreakpoint sb_bp; 945 TargetSP target_sp(GetSP()); 946 if (target_sp && num_names > 0) { 947 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 948 const bool internal = false; 949 const bool hardware = false; 950 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask); 951 const LazyBool skip_prologue = eLazyBoolCalculate; 952 sb_bp = target_sp->CreateBreakpoint( 953 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask, 954 symbol_language, offset, skip_prologue, internal, hardware); 955 } 956 957 return LLDB_RECORD_RESULT(sb_bp); 958 } 959 960 SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex, 961 const char *module_name) { 962 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex, 963 (const char *, const char *), symbol_name_regex, 964 module_name); 965 966 SBFileSpecList module_spec_list; 967 SBFileSpecList comp_unit_list; 968 if (module_name && module_name[0]) { 969 module_spec_list.Append(FileSpec(module_name)); 970 } 971 return LLDB_RECORD_RESULT( 972 BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown, 973 module_spec_list, comp_unit_list)); 974 } 975 976 lldb::SBBreakpoint 977 SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex, 978 const SBFileSpecList &module_list, 979 const SBFileSpecList &comp_unit_list) { 980 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex, 981 (const char *, const lldb::SBFileSpecList &, 982 const lldb::SBFileSpecList &), 983 symbol_name_regex, module_list, comp_unit_list); 984 985 return LLDB_RECORD_RESULT(BreakpointCreateByRegex( 986 symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list)); 987 } 988 989 lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex( 990 const char *symbol_name_regex, LanguageType symbol_language, 991 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { 992 LLDB_RECORD_METHOD( 993 lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex, 994 (const char *, lldb::LanguageType, const lldb::SBFileSpecList &, 995 const lldb::SBFileSpecList &), 996 symbol_name_regex, symbol_language, module_list, comp_unit_list); 997 998 999 SBBreakpoint sb_bp; 1000 TargetSP target_sp(GetSP()); 1001 if (target_sp && symbol_name_regex && symbol_name_regex[0]) { 1002 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1003 RegularExpression regexp((llvm::StringRef(symbol_name_regex))); 1004 const bool internal = false; 1005 const bool hardware = false; 1006 const LazyBool skip_prologue = eLazyBoolCalculate; 1007 1008 sb_bp = target_sp->CreateFuncRegexBreakpoint( 1009 module_list.get(), comp_unit_list.get(), std::move(regexp), 1010 symbol_language, skip_prologue, internal, hardware); 1011 } 1012 1013 return LLDB_RECORD_RESULT(sb_bp); 1014 } 1015 1016 SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) { 1017 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByAddress, 1018 (lldb::addr_t), address); 1019 1020 SBBreakpoint sb_bp; 1021 TargetSP target_sp(GetSP()); 1022 if (target_sp) { 1023 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1024 const bool hardware = false; 1025 sb_bp = target_sp->CreateBreakpoint(address, false, hardware); 1026 } 1027 1028 return LLDB_RECORD_RESULT(sb_bp); 1029 } 1030 1031 SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) { 1032 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateBySBAddress, 1033 (lldb::SBAddress &), sb_address); 1034 1035 SBBreakpoint sb_bp; 1036 TargetSP target_sp(GetSP()); 1037 if (!sb_address.IsValid()) { 1038 return LLDB_RECORD_RESULT(sb_bp); 1039 } 1040 1041 if (target_sp) { 1042 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1043 const bool hardware = false; 1044 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware); 1045 } 1046 1047 return LLDB_RECORD_RESULT(sb_bp); 1048 } 1049 1050 lldb::SBBreakpoint 1051 SBTarget::BreakpointCreateBySourceRegex(const char *source_regex, 1052 const lldb::SBFileSpec &source_file, 1053 const char *module_name) { 1054 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, 1055 BreakpointCreateBySourceRegex, 1056 (const char *, const lldb::SBFileSpec &, const char *), 1057 source_regex, source_file, module_name); 1058 1059 SBFileSpecList module_spec_list; 1060 1061 if (module_name && module_name[0]) { 1062 module_spec_list.Append(FileSpec(module_name)); 1063 } 1064 1065 SBFileSpecList source_file_list; 1066 if (source_file.IsValid()) { 1067 source_file_list.Append(source_file); 1068 } 1069 1070 return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex( 1071 source_regex, module_spec_list, source_file_list)); 1072 } 1073 1074 lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex( 1075 const char *source_regex, const SBFileSpecList &module_list, 1076 const lldb::SBFileSpecList &source_file_list) { 1077 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, 1078 BreakpointCreateBySourceRegex, 1079 (const char *, const lldb::SBFileSpecList &, 1080 const lldb::SBFileSpecList &), 1081 source_regex, module_list, source_file_list); 1082 1083 return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex( 1084 source_regex, module_list, source_file_list, SBStringList())); 1085 } 1086 1087 lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex( 1088 const char *source_regex, const SBFileSpecList &module_list, 1089 const lldb::SBFileSpecList &source_file_list, 1090 const SBStringList &func_names) { 1091 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, 1092 BreakpointCreateBySourceRegex, 1093 (const char *, const lldb::SBFileSpecList &, 1094 const lldb::SBFileSpecList &, const lldb::SBStringList &), 1095 source_regex, module_list, source_file_list, func_names); 1096 1097 SBBreakpoint sb_bp; 1098 TargetSP target_sp(GetSP()); 1099 if (target_sp && source_regex && source_regex[0]) { 1100 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1101 const bool hardware = false; 1102 const LazyBool move_to_nearest_code = eLazyBoolCalculate; 1103 RegularExpression regexp((llvm::StringRef(source_regex))); 1104 std::unordered_set<std::string> func_names_set; 1105 for (size_t i = 0; i < func_names.GetSize(); i++) { 1106 func_names_set.insert(func_names.GetStringAtIndex(i)); 1107 } 1108 1109 sb_bp = target_sp->CreateSourceRegexBreakpoint( 1110 module_list.get(), source_file_list.get(), func_names_set, 1111 std::move(regexp), false, hardware, move_to_nearest_code); 1112 } 1113 1114 return LLDB_RECORD_RESULT(sb_bp); 1115 } 1116 1117 lldb::SBBreakpoint 1118 SBTarget::BreakpointCreateForException(lldb::LanguageType language, 1119 bool catch_bp, bool throw_bp) { 1120 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateForException, 1121 (lldb::LanguageType, bool, bool), language, catch_bp, 1122 throw_bp); 1123 1124 SBBreakpoint sb_bp; 1125 TargetSP target_sp(GetSP()); 1126 if (target_sp) { 1127 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1128 const bool hardware = false; 1129 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp, 1130 hardware); 1131 } 1132 1133 return LLDB_RECORD_RESULT(sb_bp); 1134 } 1135 1136 lldb::SBBreakpoint SBTarget::BreakpointCreateFromScript( 1137 const char *class_name, SBStructuredData &extra_args, 1138 const SBFileSpecList &module_list, const SBFileSpecList &file_list, 1139 bool request_hardware) { 1140 LLDB_RECORD_METHOD( 1141 lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript, 1142 (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &, 1143 const lldb::SBFileSpecList &, bool), 1144 class_name, extra_args, module_list, file_list, request_hardware); 1145 1146 SBBreakpoint sb_bp; 1147 TargetSP target_sp(GetSP()); 1148 if (target_sp) { 1149 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1150 Status error; 1151 1152 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP(); 1153 sb_bp = 1154 target_sp->CreateScriptedBreakpoint(class_name, 1155 module_list.get(), 1156 file_list.get(), 1157 false, /* internal */ 1158 request_hardware, 1159 obj_sp, 1160 &error); 1161 } 1162 1163 return LLDB_RECORD_RESULT(sb_bp); 1164 } 1165 1166 uint32_t SBTarget::GetNumBreakpoints() const { 1167 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumBreakpoints); 1168 1169 TargetSP target_sp(GetSP()); 1170 if (target_sp) { 1171 // The breakpoint list is thread safe, no need to lock 1172 return target_sp->GetBreakpointList().GetSize(); 1173 } 1174 return 0; 1175 } 1176 1177 SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const { 1178 LLDB_RECORD_METHOD_CONST(lldb::SBBreakpoint, SBTarget, GetBreakpointAtIndex, 1179 (uint32_t), idx); 1180 1181 SBBreakpoint sb_breakpoint; 1182 TargetSP target_sp(GetSP()); 1183 if (target_sp) { 1184 // The breakpoint list is thread safe, no need to lock 1185 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); 1186 } 1187 return LLDB_RECORD_RESULT(sb_breakpoint); 1188 } 1189 1190 bool SBTarget::BreakpointDelete(break_id_t bp_id) { 1191 LLDB_RECORD_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t), 1192 bp_id); 1193 1194 bool result = false; 1195 TargetSP target_sp(GetSP()); 1196 if (target_sp) { 1197 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1198 result = target_sp->RemoveBreakpointByID(bp_id); 1199 } 1200 1201 return result; 1202 } 1203 1204 SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) { 1205 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID, 1206 (lldb::break_id_t), bp_id); 1207 1208 SBBreakpoint sb_breakpoint; 1209 TargetSP target_sp(GetSP()); 1210 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) { 1211 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1212 sb_breakpoint = target_sp->GetBreakpointByID(bp_id); 1213 } 1214 1215 return LLDB_RECORD_RESULT(sb_breakpoint); 1216 } 1217 1218 bool SBTarget::FindBreakpointsByName(const char *name, 1219 SBBreakpointList &bkpts) { 1220 LLDB_RECORD_METHOD(bool, SBTarget, FindBreakpointsByName, 1221 (const char *, lldb::SBBreakpointList &), name, bkpts); 1222 1223 TargetSP target_sp(GetSP()); 1224 if (target_sp) { 1225 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1226 llvm::Expected<std::vector<BreakpointSP>> expected_vector = 1227 target_sp->GetBreakpointList().FindBreakpointsByName(name); 1228 if (!expected_vector) { 1229 LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS), 1230 "invalid breakpoint name: {}", 1231 llvm::toString(expected_vector.takeError())); 1232 return false; 1233 } 1234 for (BreakpointSP bkpt_sp : *expected_vector) { 1235 bkpts.AppendByID(bkpt_sp->GetID()); 1236 } 1237 } 1238 return true; 1239 } 1240 1241 void SBTarget::GetBreakpointNames(SBStringList &names) { 1242 LLDB_RECORD_METHOD(void, SBTarget, GetBreakpointNames, (lldb::SBStringList &), 1243 names); 1244 1245 names.Clear(); 1246 1247 TargetSP target_sp(GetSP()); 1248 if (target_sp) { 1249 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1250 1251 std::vector<std::string> name_vec; 1252 target_sp->GetBreakpointNames(name_vec); 1253 for (auto name : name_vec) 1254 names.AppendString(name.c_str()); 1255 } 1256 } 1257 1258 void SBTarget::DeleteBreakpointName(const char *name) { 1259 LLDB_RECORD_METHOD(void, SBTarget, DeleteBreakpointName, (const char *), 1260 name); 1261 1262 TargetSP target_sp(GetSP()); 1263 if (target_sp) { 1264 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1265 target_sp->DeleteBreakpointName(ConstString(name)); 1266 } 1267 } 1268 1269 bool SBTarget::EnableAllBreakpoints() { 1270 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllBreakpoints); 1271 1272 TargetSP target_sp(GetSP()); 1273 if (target_sp) { 1274 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1275 target_sp->EnableAllowedBreakpoints(); 1276 return true; 1277 } 1278 return false; 1279 } 1280 1281 bool SBTarget::DisableAllBreakpoints() { 1282 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllBreakpoints); 1283 1284 TargetSP target_sp(GetSP()); 1285 if (target_sp) { 1286 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1287 target_sp->DisableAllowedBreakpoints(); 1288 return true; 1289 } 1290 return false; 1291 } 1292 1293 bool SBTarget::DeleteAllBreakpoints() { 1294 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllBreakpoints); 1295 1296 TargetSP target_sp(GetSP()); 1297 if (target_sp) { 1298 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1299 target_sp->RemoveAllowedBreakpoints(); 1300 return true; 1301 } 1302 return false; 1303 } 1304 1305 lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file, 1306 SBBreakpointList &new_bps) { 1307 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile, 1308 (lldb::SBFileSpec &, lldb::SBBreakpointList &), 1309 source_file, new_bps); 1310 1311 SBStringList empty_name_list; 1312 return LLDB_RECORD_RESULT( 1313 BreakpointsCreateFromFile(source_file, empty_name_list, new_bps)); 1314 } 1315 1316 lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file, 1317 SBStringList &matching_names, 1318 SBBreakpointList &new_bps) { 1319 LLDB_RECORD_METHOD( 1320 lldb::SBError, SBTarget, BreakpointsCreateFromFile, 1321 (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &), 1322 source_file, matching_names, new_bps); 1323 1324 SBError sberr; 1325 TargetSP target_sp(GetSP()); 1326 if (!target_sp) { 1327 sberr.SetErrorString( 1328 "BreakpointCreateFromFile called with invalid target."); 1329 return LLDB_RECORD_RESULT(sberr); 1330 } 1331 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1332 1333 BreakpointIDList bp_ids; 1334 1335 std::vector<std::string> name_vector; 1336 size_t num_names = matching_names.GetSize(); 1337 for (size_t i = 0; i < num_names; i++) 1338 name_vector.push_back(matching_names.GetStringAtIndex(i)); 1339 1340 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(), 1341 name_vector, bp_ids); 1342 if (sberr.Fail()) 1343 return LLDB_RECORD_RESULT(sberr); 1344 1345 size_t num_bkpts = bp_ids.GetSize(); 1346 for (size_t i = 0; i < num_bkpts; i++) { 1347 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i); 1348 new_bps.AppendByID(bp_id.GetBreakpointID()); 1349 } 1350 return LLDB_RECORD_RESULT(sberr); 1351 } 1352 1353 lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) { 1354 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile, 1355 (lldb::SBFileSpec &), dest_file); 1356 1357 SBError sberr; 1358 TargetSP target_sp(GetSP()); 1359 if (!target_sp) { 1360 sberr.SetErrorString("BreakpointWriteToFile called with invalid target."); 1361 return LLDB_RECORD_RESULT(sberr); 1362 } 1363 SBBreakpointList bkpt_list(*this); 1364 return LLDB_RECORD_RESULT(BreakpointsWriteToFile(dest_file, bkpt_list)); 1365 } 1366 1367 lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file, 1368 SBBreakpointList &bkpt_list, 1369 bool append) { 1370 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile, 1371 (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool), 1372 dest_file, bkpt_list, append); 1373 1374 SBError sberr; 1375 TargetSP target_sp(GetSP()); 1376 if (!target_sp) { 1377 sberr.SetErrorString("BreakpointWriteToFile called with invalid target."); 1378 return LLDB_RECORD_RESULT(sberr); 1379 } 1380 1381 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1382 BreakpointIDList bp_id_list; 1383 bkpt_list.CopyToBreakpointIDList(bp_id_list); 1384 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(), 1385 bp_id_list, append); 1386 return LLDB_RECORD_RESULT(sberr); 1387 } 1388 1389 uint32_t SBTarget::GetNumWatchpoints() const { 1390 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumWatchpoints); 1391 1392 TargetSP target_sp(GetSP()); 1393 if (target_sp) { 1394 // The watchpoint list is thread safe, no need to lock 1395 return target_sp->GetWatchpointList().GetSize(); 1396 } 1397 return 0; 1398 } 1399 1400 SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const { 1401 LLDB_RECORD_METHOD_CONST(lldb::SBWatchpoint, SBTarget, GetWatchpointAtIndex, 1402 (uint32_t), idx); 1403 1404 SBWatchpoint sb_watchpoint; 1405 TargetSP target_sp(GetSP()); 1406 if (target_sp) { 1407 // The watchpoint list is thread safe, no need to lock 1408 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx)); 1409 } 1410 return LLDB_RECORD_RESULT(sb_watchpoint); 1411 } 1412 1413 bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) { 1414 LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t), 1415 wp_id); 1416 1417 1418 bool result = false; 1419 TargetSP target_sp(GetSP()); 1420 if (target_sp) { 1421 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1422 std::unique_lock<std::recursive_mutex> lock; 1423 target_sp->GetWatchpointList().GetListMutex(lock); 1424 result = target_sp->RemoveWatchpointByID(wp_id); 1425 } 1426 1427 return result; 1428 } 1429 1430 SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) { 1431 LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID, 1432 (lldb::watch_id_t), wp_id); 1433 1434 1435 SBWatchpoint sb_watchpoint; 1436 lldb::WatchpointSP watchpoint_sp; 1437 TargetSP target_sp(GetSP()); 1438 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) { 1439 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1440 std::unique_lock<std::recursive_mutex> lock; 1441 target_sp->GetWatchpointList().GetListMutex(lock); 1442 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); 1443 sb_watchpoint.SetSP(watchpoint_sp); 1444 } 1445 1446 return LLDB_RECORD_RESULT(sb_watchpoint); 1447 } 1448 1449 lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, 1450 bool read, bool write, 1451 SBError &error) { 1452 LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress, 1453 (lldb::addr_t, size_t, bool, bool, lldb::SBError &), addr, 1454 size, read, write, error); 1455 1456 SBWatchpoint sb_watchpoint; 1457 lldb::WatchpointSP watchpoint_sp; 1458 TargetSP target_sp(GetSP()); 1459 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && 1460 size > 0) { 1461 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1462 uint32_t watch_type = 0; 1463 if (read) 1464 watch_type |= LLDB_WATCH_TYPE_READ; 1465 if (write) 1466 watch_type |= LLDB_WATCH_TYPE_WRITE; 1467 if (watch_type == 0) { 1468 error.SetErrorString( 1469 "Can't create a watchpoint that is neither read nor write."); 1470 return LLDB_RECORD_RESULT(sb_watchpoint); 1471 } 1472 1473 // Target::CreateWatchpoint() is thread safe. 1474 Status cw_error; 1475 // This API doesn't take in a type, so we can't figure out what it is. 1476 CompilerType *type = nullptr; 1477 watchpoint_sp = 1478 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error); 1479 error.SetError(cw_error); 1480 sb_watchpoint.SetSP(watchpoint_sp); 1481 } 1482 1483 return LLDB_RECORD_RESULT(sb_watchpoint); 1484 } 1485 1486 bool SBTarget::EnableAllWatchpoints() { 1487 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllWatchpoints); 1488 1489 TargetSP target_sp(GetSP()); 1490 if (target_sp) { 1491 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1492 std::unique_lock<std::recursive_mutex> lock; 1493 target_sp->GetWatchpointList().GetListMutex(lock); 1494 target_sp->EnableAllWatchpoints(); 1495 return true; 1496 } 1497 return false; 1498 } 1499 1500 bool SBTarget::DisableAllWatchpoints() { 1501 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllWatchpoints); 1502 1503 TargetSP target_sp(GetSP()); 1504 if (target_sp) { 1505 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1506 std::unique_lock<std::recursive_mutex> lock; 1507 target_sp->GetWatchpointList().GetListMutex(lock); 1508 target_sp->DisableAllWatchpoints(); 1509 return true; 1510 } 1511 return false; 1512 } 1513 1514 SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr, 1515 SBType type) { 1516 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress, 1517 (const char *, lldb::SBAddress, lldb::SBType), name, addr, 1518 type); 1519 1520 SBValue sb_value; 1521 lldb::ValueObjectSP new_value_sp; 1522 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) { 1523 lldb::addr_t load_addr(addr.GetLoadAddress(*this)); 1524 ExecutionContext exe_ctx( 1525 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); 1526 CompilerType ast_type(type.GetSP()->GetCompilerType(true)); 1527 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, 1528 exe_ctx, ast_type); 1529 } 1530 sb_value.SetSP(new_value_sp); 1531 return LLDB_RECORD_RESULT(sb_value); 1532 } 1533 1534 lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data, 1535 lldb::SBType type) { 1536 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromData, 1537 (const char *, lldb::SBData, lldb::SBType), name, data, 1538 type); 1539 1540 SBValue sb_value; 1541 lldb::ValueObjectSP new_value_sp; 1542 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) { 1543 DataExtractorSP extractor(*data); 1544 ExecutionContext exe_ctx( 1545 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); 1546 CompilerType ast_type(type.GetSP()->GetCompilerType(true)); 1547 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, 1548 exe_ctx, ast_type); 1549 } 1550 sb_value.SetSP(new_value_sp); 1551 return LLDB_RECORD_RESULT(sb_value); 1552 } 1553 1554 lldb::SBValue SBTarget::CreateValueFromExpression(const char *name, 1555 const char *expr) { 1556 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression, 1557 (const char *, const char *), name, expr); 1558 1559 SBValue sb_value; 1560 lldb::ValueObjectSP new_value_sp; 1561 if (IsValid() && name && *name && expr && *expr) { 1562 ExecutionContext exe_ctx( 1563 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); 1564 new_value_sp = 1565 ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx); 1566 } 1567 sb_value.SetSP(new_value_sp); 1568 return LLDB_RECORD_RESULT(sb_value); 1569 } 1570 1571 bool SBTarget::DeleteAllWatchpoints() { 1572 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints); 1573 1574 TargetSP target_sp(GetSP()); 1575 if (target_sp) { 1576 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 1577 std::unique_lock<std::recursive_mutex> lock; 1578 target_sp->GetWatchpointList().GetListMutex(lock); 1579 target_sp->RemoveAllWatchpoints(); 1580 return true; 1581 } 1582 return false; 1583 } 1584 1585 void SBTarget::AppendImageSearchPath(const char *from, const char *to, 1586 lldb::SBError &error) { 1587 LLDB_RECORD_METHOD(void, SBTarget, AppendImageSearchPath, 1588 (const char *, const char *, lldb::SBError &), from, to, 1589 error); 1590 1591 TargetSP target_sp(GetSP()); 1592 if (!target_sp) 1593 return error.SetErrorString("invalid target"); 1594 1595 const ConstString csFrom(from), csTo(to); 1596 if (!csFrom) 1597 return error.SetErrorString("<from> path can't be empty"); 1598 if (!csTo) 1599 return error.SetErrorString("<to> path can't be empty"); 1600 1601 target_sp->GetImageSearchPathList().Append(csFrom, csTo, true); 1602 } 1603 1604 lldb::SBModule SBTarget::AddModule(const char *path, const char *triple, 1605 const char *uuid_cstr) { 1606 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule, 1607 (const char *, const char *, const char *), path, triple, 1608 uuid_cstr); 1609 1610 return LLDB_RECORD_RESULT(AddModule(path, triple, uuid_cstr, nullptr)); 1611 } 1612 1613 lldb::SBModule SBTarget::AddModule(const char *path, const char *triple, 1614 const char *uuid_cstr, const char *symfile) { 1615 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule, 1616 (const char *, const char *, const char *, const char *), 1617 path, triple, uuid_cstr, symfile); 1618 1619 lldb::SBModule sb_module; 1620 TargetSP target_sp(GetSP()); 1621 if (target_sp) { 1622 ModuleSpec module_spec; 1623 if (path) 1624 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native); 1625 1626 if (uuid_cstr) 1627 module_spec.GetUUID().SetFromStringRef(uuid_cstr); 1628 1629 if (triple) 1630 module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec( 1631 target_sp->GetPlatform().get(), triple); 1632 else 1633 module_spec.GetArchitecture() = target_sp->GetArchitecture(); 1634 1635 if (symfile) 1636 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native); 1637 1638 sb_module.SetSP(target_sp->GetOrCreateModule(module_spec, true /* notify */)); 1639 } 1640 return LLDB_RECORD_RESULT(sb_module); 1641 } 1642 1643 lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) { 1644 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule, 1645 (const lldb::SBModuleSpec &), module_spec); 1646 1647 lldb::SBModule sb_module; 1648 TargetSP target_sp(GetSP()); 1649 if (target_sp) 1650 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up, 1651 true /* notify */)); 1652 return LLDB_RECORD_RESULT(sb_module); 1653 } 1654 1655 bool SBTarget::AddModule(lldb::SBModule &module) { 1656 LLDB_RECORD_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &), module); 1657 1658 TargetSP target_sp(GetSP()); 1659 if (target_sp) { 1660 target_sp->GetImages().AppendIfNeeded(module.GetSP()); 1661 return true; 1662 } 1663 return false; 1664 } 1665 1666 uint32_t SBTarget::GetNumModules() const { 1667 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumModules); 1668 1669 uint32_t num = 0; 1670 TargetSP target_sp(GetSP()); 1671 if (target_sp) { 1672 // The module list is thread safe, no need to lock 1673 num = target_sp->GetImages().GetSize(); 1674 } 1675 1676 return num; 1677 } 1678 1679 void SBTarget::Clear() { 1680 LLDB_RECORD_METHOD_NO_ARGS(void, SBTarget, Clear); 1681 1682 m_opaque_sp.reset(); 1683 } 1684 1685 SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) { 1686 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, FindModule, 1687 (const lldb::SBFileSpec &), sb_file_spec); 1688 1689 SBModule sb_module; 1690 TargetSP target_sp(GetSP()); 1691 if (target_sp && sb_file_spec.IsValid()) { 1692 ModuleSpec module_spec(*sb_file_spec); 1693 // The module list is thread safe, no need to lock 1694 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec)); 1695 } 1696 return LLDB_RECORD_RESULT(sb_module); 1697 } 1698 1699 SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) { 1700 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits, 1701 (const lldb::SBFileSpec &), sb_file_spec); 1702 1703 SBSymbolContextList sb_sc_list; 1704 const TargetSP target_sp(GetSP()); 1705 if (target_sp && sb_file_spec.IsValid()) 1706 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list); 1707 return LLDB_RECORD_RESULT(sb_sc_list); 1708 } 1709 1710 lldb::ByteOrder SBTarget::GetByteOrder() { 1711 LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBTarget, GetByteOrder); 1712 1713 TargetSP target_sp(GetSP()); 1714 if (target_sp) 1715 return target_sp->GetArchitecture().GetByteOrder(); 1716 return eByteOrderInvalid; 1717 } 1718 1719 const char *SBTarget::GetTriple() { 1720 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTarget, GetTriple); 1721 1722 TargetSP target_sp(GetSP()); 1723 if (target_sp) { 1724 std::string triple(target_sp->GetArchitecture().GetTriple().str()); 1725 // Unique the string so we don't run into ownership issues since the const 1726 // strings put the string into the string pool once and the strings never 1727 // comes out 1728 ConstString const_triple(triple.c_str()); 1729 return const_triple.GetCString(); 1730 } 1731 return nullptr; 1732 } 1733 1734 uint32_t SBTarget::GetDataByteSize() { 1735 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetDataByteSize); 1736 1737 TargetSP target_sp(GetSP()); 1738 if (target_sp) { 1739 return target_sp->GetArchitecture().GetDataByteSize(); 1740 } 1741 return 0; 1742 } 1743 1744 uint32_t SBTarget::GetCodeByteSize() { 1745 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetCodeByteSize); 1746 1747 TargetSP target_sp(GetSP()); 1748 if (target_sp) { 1749 return target_sp->GetArchitecture().GetCodeByteSize(); 1750 } 1751 return 0; 1752 } 1753 1754 uint32_t SBTarget::GetAddressByteSize() { 1755 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetAddressByteSize); 1756 1757 TargetSP target_sp(GetSP()); 1758 if (target_sp) 1759 return target_sp->GetArchitecture().GetAddressByteSize(); 1760 return sizeof(void *); 1761 } 1762 1763 SBModule SBTarget::GetModuleAtIndex(uint32_t idx) { 1764 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex, (uint32_t), 1765 idx); 1766 1767 SBModule sb_module; 1768 ModuleSP module_sp; 1769 TargetSP target_sp(GetSP()); 1770 if (target_sp) { 1771 // The module list is thread safe, no need to lock 1772 module_sp = target_sp->GetImages().GetModuleAtIndex(idx); 1773 sb_module.SetSP(module_sp); 1774 } 1775 1776 return LLDB_RECORD_RESULT(sb_module); 1777 } 1778 1779 bool SBTarget::RemoveModule(lldb::SBModule module) { 1780 LLDB_RECORD_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule), module); 1781 1782 TargetSP target_sp(GetSP()); 1783 if (target_sp) 1784 return target_sp->GetImages().Remove(module.GetSP()); 1785 return false; 1786 } 1787 1788 SBBroadcaster SBTarget::GetBroadcaster() const { 1789 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBTarget, 1790 GetBroadcaster); 1791 1792 1793 TargetSP target_sp(GetSP()); 1794 SBBroadcaster broadcaster(target_sp.get(), false); 1795 1796 1797 return LLDB_RECORD_RESULT(broadcaster); 1798 } 1799 1800 bool SBTarget::GetDescription(SBStream &description, 1801 lldb::DescriptionLevel description_level) { 1802 LLDB_RECORD_METHOD(bool, SBTarget, GetDescription, 1803 (lldb::SBStream &, lldb::DescriptionLevel), description, 1804 description_level); 1805 1806 Stream &strm = description.ref(); 1807 1808 TargetSP target_sp(GetSP()); 1809 if (target_sp) { 1810 target_sp->Dump(&strm, description_level); 1811 } else 1812 strm.PutCString("No value"); 1813 1814 return true; 1815 } 1816 1817 lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name, 1818 uint32_t name_type_mask) { 1819 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions, 1820 (const char *, uint32_t), name, name_type_mask); 1821 1822 lldb::SBSymbolContextList sb_sc_list; 1823 if (!name || !name[0]) 1824 return LLDB_RECORD_RESULT(sb_sc_list); 1825 1826 TargetSP target_sp(GetSP()); 1827 if (!target_sp) 1828 return LLDB_RECORD_RESULT(sb_sc_list); 1829 1830 ModuleFunctionSearchOptions function_options; 1831 function_options.include_symbols = true; 1832 function_options.include_inlines = true; 1833 1834 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask); 1835 target_sp->GetImages().FindFunctions(ConstString(name), mask, 1836 function_options, *sb_sc_list); 1837 return LLDB_RECORD_RESULT(sb_sc_list); 1838 } 1839 1840 lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name, 1841 uint32_t max_matches, 1842 MatchType matchtype) { 1843 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindGlobalFunctions, 1844 (const char *, uint32_t, lldb::MatchType), name, 1845 max_matches, matchtype); 1846 1847 lldb::SBSymbolContextList sb_sc_list; 1848 if (name && name[0]) { 1849 llvm::StringRef name_ref(name); 1850 TargetSP target_sp(GetSP()); 1851 if (target_sp) { 1852 ModuleFunctionSearchOptions function_options; 1853 function_options.include_symbols = true; 1854 function_options.include_inlines = true; 1855 1856 std::string regexstr; 1857 switch (matchtype) { 1858 case eMatchTypeRegex: 1859 target_sp->GetImages().FindFunctions(RegularExpression(name_ref), 1860 function_options, *sb_sc_list); 1861 break; 1862 case eMatchTypeStartsWith: 1863 regexstr = llvm::Regex::escape(name) + ".*"; 1864 target_sp->GetImages().FindFunctions(RegularExpression(regexstr), 1865 function_options, *sb_sc_list); 1866 break; 1867 default: 1868 target_sp->GetImages().FindFunctions(ConstString(name), 1869 eFunctionNameTypeAny, 1870 function_options, *sb_sc_list); 1871 break; 1872 } 1873 } 1874 } 1875 return LLDB_RECORD_RESULT(sb_sc_list); 1876 } 1877 1878 lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) { 1879 LLDB_RECORD_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *), 1880 typename_cstr); 1881 1882 TargetSP target_sp(GetSP()); 1883 if (typename_cstr && typename_cstr[0] && target_sp) { 1884 ConstString const_typename(typename_cstr); 1885 SymbolContext sc; 1886 const bool exact_match = false; 1887 1888 const ModuleList &module_list = target_sp->GetImages(); 1889 size_t count = module_list.GetSize(); 1890 for (size_t idx = 0; idx < count; idx++) { 1891 ModuleSP module_sp(module_list.GetModuleAtIndex(idx)); 1892 if (module_sp) { 1893 TypeSP type_sp( 1894 module_sp->FindFirstType(sc, const_typename, exact_match)); 1895 if (type_sp) 1896 return LLDB_RECORD_RESULT(SBType(type_sp)); 1897 } 1898 } 1899 1900 // Didn't find the type in the symbols; Try the loaded language runtimes 1901 if (auto process_sp = target_sp->GetProcessSP()) { 1902 for (auto *runtime : process_sp->GetLanguageRuntimes()) { 1903 if (auto vendor = runtime->GetDeclVendor()) { 1904 auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1); 1905 if (!types.empty()) 1906 return LLDB_RECORD_RESULT(SBType(types.front())); 1907 } 1908 } 1909 } 1910 1911 // No matches, search for basic typename matches 1912 for (auto *type_system : target_sp->GetScratchTypeSystems()) 1913 if (auto type = type_system->GetBuiltinTypeByName(const_typename)) 1914 return LLDB_RECORD_RESULT(SBType(type)); 1915 } 1916 1917 return LLDB_RECORD_RESULT(SBType()); 1918 } 1919 1920 SBType SBTarget::GetBasicType(lldb::BasicType type) { 1921 LLDB_RECORD_METHOD(lldb::SBType, SBTarget, GetBasicType, (lldb::BasicType), 1922 type); 1923 1924 TargetSP target_sp(GetSP()); 1925 if (target_sp) { 1926 for (auto *type_system : target_sp->GetScratchTypeSystems()) 1927 if (auto compiler_type = type_system->GetBasicTypeFromAST(type)) 1928 return LLDB_RECORD_RESULT(SBType(compiler_type)); 1929 } 1930 return LLDB_RECORD_RESULT(SBType()); 1931 } 1932 1933 lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) { 1934 LLDB_RECORD_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *), 1935 typename_cstr); 1936 1937 SBTypeList sb_type_list; 1938 TargetSP target_sp(GetSP()); 1939 if (typename_cstr && typename_cstr[0] && target_sp) { 1940 ModuleList &images = target_sp->GetImages(); 1941 ConstString const_typename(typename_cstr); 1942 bool exact_match = false; 1943 TypeList type_list; 1944 llvm::DenseSet<SymbolFile *> searched_symbol_files; 1945 images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX, 1946 searched_symbol_files, type_list); 1947 1948 for (size_t idx = 0; idx < type_list.GetSize(); idx++) { 1949 TypeSP type_sp(type_list.GetTypeAtIndex(idx)); 1950 if (type_sp) 1951 sb_type_list.Append(SBType(type_sp)); 1952 } 1953 1954 // Try the loaded language runtimes 1955 if (auto process_sp = target_sp->GetProcessSP()) { 1956 for (auto *runtime : process_sp->GetLanguageRuntimes()) { 1957 if (auto *vendor = runtime->GetDeclVendor()) { 1958 auto types = 1959 vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX); 1960 for (auto type : types) 1961 sb_type_list.Append(SBType(type)); 1962 } 1963 } 1964 } 1965 1966 if (sb_type_list.GetSize() == 0) { 1967 // No matches, search for basic typename matches 1968 for (auto *type_system : target_sp->GetScratchTypeSystems()) 1969 if (auto compiler_type = 1970 type_system->GetBuiltinTypeByName(const_typename)) 1971 sb_type_list.Append(SBType(compiler_type)); 1972 } 1973 } 1974 return LLDB_RECORD_RESULT(sb_type_list); 1975 } 1976 1977 SBValueList SBTarget::FindGlobalVariables(const char *name, 1978 uint32_t max_matches) { 1979 LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables, 1980 (const char *, uint32_t), name, max_matches); 1981 1982 SBValueList sb_value_list; 1983 1984 TargetSP target_sp(GetSP()); 1985 if (name && target_sp) { 1986 VariableList variable_list; 1987 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches, 1988 variable_list); 1989 if (!variable_list.Empty()) { 1990 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 1991 if (exe_scope == nullptr) 1992 exe_scope = target_sp.get(); 1993 for (const VariableSP &var_sp : variable_list) { 1994 lldb::ValueObjectSP valobj_sp( 1995 ValueObjectVariable::Create(exe_scope, var_sp)); 1996 if (valobj_sp) 1997 sb_value_list.Append(SBValue(valobj_sp)); 1998 } 1999 } 2000 } 2001 2002 return LLDB_RECORD_RESULT(sb_value_list); 2003 } 2004 2005 SBValueList SBTarget::FindGlobalVariables(const char *name, 2006 uint32_t max_matches, 2007 MatchType matchtype) { 2008 LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables, 2009 (const char *, uint32_t, lldb::MatchType), name, 2010 max_matches, matchtype); 2011 2012 SBValueList sb_value_list; 2013 2014 TargetSP target_sp(GetSP()); 2015 if (name && target_sp) { 2016 llvm::StringRef name_ref(name); 2017 VariableList variable_list; 2018 2019 std::string regexstr; 2020 switch (matchtype) { 2021 case eMatchTypeNormal: 2022 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches, 2023 variable_list); 2024 break; 2025 case eMatchTypeRegex: 2026 target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref), 2027 max_matches, variable_list); 2028 break; 2029 case eMatchTypeStartsWith: 2030 regexstr = llvm::Regex::escape(name) + ".*"; 2031 target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr), 2032 max_matches, variable_list); 2033 break; 2034 } 2035 if (!variable_list.Empty()) { 2036 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 2037 if (exe_scope == nullptr) 2038 exe_scope = target_sp.get(); 2039 for (const VariableSP &var_sp : variable_list) { 2040 lldb::ValueObjectSP valobj_sp( 2041 ValueObjectVariable::Create(exe_scope, var_sp)); 2042 if (valobj_sp) 2043 sb_value_list.Append(SBValue(valobj_sp)); 2044 } 2045 } 2046 } 2047 2048 return LLDB_RECORD_RESULT(sb_value_list); 2049 } 2050 2051 lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) { 2052 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable, 2053 (const char *), name); 2054 2055 SBValueList sb_value_list(FindGlobalVariables(name, 1)); 2056 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 2057 return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0)); 2058 return LLDB_RECORD_RESULT(SBValue()); 2059 } 2060 2061 SBSourceManager SBTarget::GetSourceManager() { 2062 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBTarget, GetSourceManager); 2063 2064 SBSourceManager source_manager(*this); 2065 return LLDB_RECORD_RESULT(source_manager); 2066 } 2067 2068 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr, 2069 uint32_t count) { 2070 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions, 2071 (lldb::SBAddress, uint32_t), base_addr, count); 2072 2073 return LLDB_RECORD_RESULT(ReadInstructions(base_addr, count, nullptr)); 2074 } 2075 2076 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr, 2077 uint32_t count, 2078 const char *flavor_string) { 2079 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions, 2080 (lldb::SBAddress, uint32_t, const char *), base_addr, 2081 count, flavor_string); 2082 2083 SBInstructionList sb_instructions; 2084 2085 TargetSP target_sp(GetSP()); 2086 if (target_sp) { 2087 Address *addr_ptr = base_addr.get(); 2088 2089 if (addr_ptr) { 2090 DataBufferHeap data( 2091 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0); 2092 bool force_live_memory = true; 2093 lldb_private::Status error; 2094 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; 2095 const size_t bytes_read = 2096 target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.GetByteSize(), 2097 error, force_live_memory, &load_addr); 2098 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS; 2099 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes( 2100 target_sp->GetArchitecture(), nullptr, flavor_string, *addr_ptr, 2101 data.GetBytes(), bytes_read, count, data_from_file)); 2102 } 2103 } 2104 2105 return LLDB_RECORD_RESULT(sb_instructions); 2106 } 2107 2108 lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr, 2109 const void *buf, 2110 size_t size) { 2111 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions, 2112 (lldb::SBAddress, const void *, size_t), base_addr, buf, 2113 size); 2114 2115 return LLDB_RECORD_RESULT( 2116 GetInstructionsWithFlavor(base_addr, nullptr, buf, size)); 2117 } 2118 2119 lldb::SBInstructionList 2120 SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr, 2121 const char *flavor_string, const void *buf, 2122 size_t size) { 2123 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, 2124 GetInstructionsWithFlavor, 2125 (lldb::SBAddress, const char *, const void *, size_t), 2126 base_addr, flavor_string, buf, size); 2127 2128 SBInstructionList sb_instructions; 2129 2130 TargetSP target_sp(GetSP()); 2131 if (target_sp) { 2132 Address addr; 2133 2134 if (base_addr.get()) 2135 addr = *base_addr.get(); 2136 2137 const bool data_from_file = true; 2138 2139 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes( 2140 target_sp->GetArchitecture(), nullptr, flavor_string, addr, buf, size, 2141 UINT32_MAX, data_from_file)); 2142 } 2143 2144 return LLDB_RECORD_RESULT(sb_instructions); 2145 } 2146 2147 lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr, 2148 const void *buf, 2149 size_t size) { 2150 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions, 2151 (lldb::addr_t, const void *, size_t), base_addr, buf, 2152 size); 2153 2154 return LLDB_RECORD_RESULT(GetInstructionsWithFlavor( 2155 ResolveLoadAddress(base_addr), nullptr, buf, size)); 2156 } 2157 2158 lldb::SBInstructionList 2159 SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr, 2160 const char *flavor_string, const void *buf, 2161 size_t size) { 2162 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, 2163 GetInstructionsWithFlavor, 2164 (lldb::addr_t, const char *, const void *, size_t), 2165 base_addr, flavor_string, buf, size); 2166 2167 return LLDB_RECORD_RESULT(GetInstructionsWithFlavor( 2168 ResolveLoadAddress(base_addr), flavor_string, buf, size)); 2169 } 2170 2171 SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section, 2172 lldb::addr_t section_base_addr) { 2173 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress, 2174 (lldb::SBSection, lldb::addr_t), section, 2175 section_base_addr); 2176 2177 SBError sb_error; 2178 TargetSP target_sp(GetSP()); 2179 if (target_sp) { 2180 if (!section.IsValid()) { 2181 sb_error.SetErrorStringWithFormat("invalid section"); 2182 } else { 2183 SectionSP section_sp(section.GetSP()); 2184 if (section_sp) { 2185 if (section_sp->IsThreadSpecific()) { 2186 sb_error.SetErrorString( 2187 "thread specific sections are not yet supported"); 2188 } else { 2189 ProcessSP process_sp(target_sp->GetProcessSP()); 2190 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) { 2191 ModuleSP module_sp(section_sp->GetModule()); 2192 if (module_sp) { 2193 ModuleList module_list; 2194 module_list.Append(module_sp); 2195 target_sp->ModulesDidLoad(module_list); 2196 } 2197 // Flush info in the process (stack frames, etc) 2198 if (process_sp) 2199 process_sp->Flush(); 2200 } 2201 } 2202 } 2203 } 2204 } else { 2205 sb_error.SetErrorString("invalid target"); 2206 } 2207 return LLDB_RECORD_RESULT(sb_error); 2208 } 2209 2210 SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) { 2211 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress, 2212 (lldb::SBSection), section); 2213 2214 SBError sb_error; 2215 2216 TargetSP target_sp(GetSP()); 2217 if (target_sp) { 2218 if (!section.IsValid()) { 2219 sb_error.SetErrorStringWithFormat("invalid section"); 2220 } else { 2221 SectionSP section_sp(section.GetSP()); 2222 if (section_sp) { 2223 ProcessSP process_sp(target_sp->GetProcessSP()); 2224 if (target_sp->SetSectionUnloaded(section_sp)) { 2225 ModuleSP module_sp(section_sp->GetModule()); 2226 if (module_sp) { 2227 ModuleList module_list; 2228 module_list.Append(module_sp); 2229 target_sp->ModulesDidUnload(module_list, false); 2230 } 2231 // Flush info in the process (stack frames, etc) 2232 if (process_sp) 2233 process_sp->Flush(); 2234 } 2235 } else { 2236 sb_error.SetErrorStringWithFormat("invalid section"); 2237 } 2238 } 2239 } else { 2240 sb_error.SetErrorStringWithFormat("invalid target"); 2241 } 2242 return LLDB_RECORD_RESULT(sb_error); 2243 } 2244 2245 SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module, 2246 int64_t slide_offset) { 2247 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress, 2248 (lldb::SBModule, int64_t), module, slide_offset); 2249 2250 SBError sb_error; 2251 2252 TargetSP target_sp(GetSP()); 2253 if (target_sp) { 2254 ModuleSP module_sp(module.GetSP()); 2255 if (module_sp) { 2256 bool changed = false; 2257 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) { 2258 // The load was successful, make sure that at least some sections 2259 // changed before we notify that our module was loaded. 2260 if (changed) { 2261 ModuleList module_list; 2262 module_list.Append(module_sp); 2263 target_sp->ModulesDidLoad(module_list); 2264 // Flush info in the process (stack frames, etc) 2265 ProcessSP process_sp(target_sp->GetProcessSP()); 2266 if (process_sp) 2267 process_sp->Flush(); 2268 } 2269 } 2270 } else { 2271 sb_error.SetErrorStringWithFormat("invalid module"); 2272 } 2273 2274 } else { 2275 sb_error.SetErrorStringWithFormat("invalid target"); 2276 } 2277 return LLDB_RECORD_RESULT(sb_error); 2278 } 2279 2280 SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) { 2281 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress, 2282 (lldb::SBModule), module); 2283 2284 SBError sb_error; 2285 2286 char path[PATH_MAX]; 2287 TargetSP target_sp(GetSP()); 2288 if (target_sp) { 2289 ModuleSP module_sp(module.GetSP()); 2290 if (module_sp) { 2291 ObjectFile *objfile = module_sp->GetObjectFile(); 2292 if (objfile) { 2293 SectionList *section_list = objfile->GetSectionList(); 2294 if (section_list) { 2295 ProcessSP process_sp(target_sp->GetProcessSP()); 2296 2297 bool changed = false; 2298 const size_t num_sections = section_list->GetSize(); 2299 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) { 2300 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx)); 2301 if (section_sp) 2302 changed |= target_sp->SetSectionUnloaded(section_sp); 2303 } 2304 if (changed) { 2305 ModuleList module_list; 2306 module_list.Append(module_sp); 2307 target_sp->ModulesDidUnload(module_list, false); 2308 // Flush info in the process (stack frames, etc) 2309 ProcessSP process_sp(target_sp->GetProcessSP()); 2310 if (process_sp) 2311 process_sp->Flush(); 2312 } 2313 } else { 2314 module_sp->GetFileSpec().GetPath(path, sizeof(path)); 2315 sb_error.SetErrorStringWithFormat("no sections in object file '%s'", 2316 path); 2317 } 2318 } else { 2319 module_sp->GetFileSpec().GetPath(path, sizeof(path)); 2320 sb_error.SetErrorStringWithFormat("no object file for module '%s'", 2321 path); 2322 } 2323 } else { 2324 sb_error.SetErrorStringWithFormat("invalid module"); 2325 } 2326 } else { 2327 sb_error.SetErrorStringWithFormat("invalid target"); 2328 } 2329 return LLDB_RECORD_RESULT(sb_error); 2330 } 2331 2332 lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name, 2333 lldb::SymbolType symbol_type) { 2334 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols, 2335 (const char *, lldb::SymbolType), name, symbol_type); 2336 2337 SBSymbolContextList sb_sc_list; 2338 if (name && name[0]) { 2339 TargetSP target_sp(GetSP()); 2340 if (target_sp) 2341 target_sp->GetImages().FindSymbolsWithNameAndType( 2342 ConstString(name), symbol_type, *sb_sc_list); 2343 } 2344 return LLDB_RECORD_RESULT(sb_sc_list); 2345 } 2346 2347 lldb::SBValue SBTarget::EvaluateExpression(const char *expr) { 2348 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression, 2349 (const char *), expr); 2350 2351 TargetSP target_sp(GetSP()); 2352 if (!target_sp) 2353 return LLDB_RECORD_RESULT(SBValue()); 2354 2355 SBExpressionOptions options; 2356 lldb::DynamicValueType fetch_dynamic_value = 2357 target_sp->GetPreferDynamicValue(); 2358 options.SetFetchDynamicValue(fetch_dynamic_value); 2359 options.SetUnwindOnError(true); 2360 return LLDB_RECORD_RESULT(EvaluateExpression(expr, options)); 2361 } 2362 2363 lldb::SBValue SBTarget::EvaluateExpression(const char *expr, 2364 const SBExpressionOptions &options) { 2365 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression, 2366 (const char *, const lldb::SBExpressionOptions &), expr, 2367 options); 2368 2369 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); 2370 SBValue expr_result; 2371 ValueObjectSP expr_value_sp; 2372 TargetSP target_sp(GetSP()); 2373 StackFrame *frame = nullptr; 2374 if (target_sp) { 2375 if (expr == nullptr || expr[0] == '\0') { 2376 return LLDB_RECORD_RESULT(expr_result); 2377 } 2378 2379 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 2380 ExecutionContext exe_ctx(m_opaque_sp.get()); 2381 2382 2383 frame = exe_ctx.GetFramePtr(); 2384 Target *target = exe_ctx.GetTargetPtr(); 2385 2386 if (target) { 2387 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref()); 2388 2389 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 2390 } 2391 } 2392 LLDB_LOGF(expr_log, 2393 "** [SBTarget::EvaluateExpression] Expression result is " 2394 "%s, summary %s **", 2395 expr_result.GetValue(), expr_result.GetSummary()); 2396 return LLDB_RECORD_RESULT(expr_result); 2397 } 2398 2399 lldb::addr_t SBTarget::GetStackRedZoneSize() { 2400 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBTarget, GetStackRedZoneSize); 2401 2402 TargetSP target_sp(GetSP()); 2403 if (target_sp) { 2404 ABISP abi_sp; 2405 ProcessSP process_sp(target_sp->GetProcessSP()); 2406 if (process_sp) 2407 abi_sp = process_sp->GetABI(); 2408 else 2409 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture()); 2410 if (abi_sp) 2411 return abi_sp->GetRedZoneSize(); 2412 } 2413 return 0; 2414 } 2415 2416 bool SBTarget::IsLoaded(const SBModule &module) const { 2417 LLDB_RECORD_METHOD_CONST(bool, SBTarget, IsLoaded, (const lldb::SBModule &), 2418 module); 2419 2420 TargetSP target_sp(GetSP()); 2421 if (!target_sp) 2422 return false; 2423 2424 ModuleSP module_sp(module.GetSP()); 2425 if (!module_sp) 2426 return false; 2427 2428 return module_sp->IsLoadedInTarget(target_sp.get()); 2429 } 2430 2431 lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const { 2432 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo); 2433 2434 lldb::SBLaunchInfo launch_info(nullptr); 2435 TargetSP target_sp(GetSP()); 2436 if (target_sp) 2437 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo()); 2438 return LLDB_RECORD_RESULT(launch_info); 2439 } 2440 2441 void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) { 2442 LLDB_RECORD_METHOD(void, SBTarget, SetLaunchInfo, 2443 (const lldb::SBLaunchInfo &), launch_info); 2444 2445 TargetSP target_sp(GetSP()); 2446 if (target_sp) 2447 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref()); 2448 } 2449 2450 SBEnvironment SBTarget::GetEnvironment() { 2451 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBTarget, GetEnvironment); 2452 TargetSP target_sp(GetSP()); 2453 2454 if (target_sp) { 2455 return LLDB_RECORD_RESULT(SBEnvironment(target_sp->GetEnvironment())); 2456 } 2457 2458 return LLDB_RECORD_RESULT(SBEnvironment()); 2459 } 2460 2461 lldb::SBTrace SBTarget::GetTrace() { 2462 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTrace, SBTarget, GetTrace); 2463 TargetSP target_sp(GetSP()); 2464 2465 if (target_sp) 2466 return LLDB_RECORD_RESULT(SBTrace(target_sp->GetTrace())); 2467 2468 return LLDB_RECORD_RESULT(SBTrace()); 2469 } 2470 2471 lldb::SBTrace SBTarget::CreateTrace(lldb::SBError &error) { 2472 LLDB_RECORD_METHOD(lldb::SBTrace, SBTarget, CreateTrace, (lldb::SBError &), 2473 error); 2474 TargetSP target_sp(GetSP()); 2475 error.Clear(); 2476 2477 if (target_sp) { 2478 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) { 2479 return LLDB_RECORD_RESULT(SBTrace(*trace_sp)); 2480 } else { 2481 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str()); 2482 } 2483 } else { 2484 error.SetErrorString("missing target"); 2485 } 2486 return LLDB_RECORD_RESULT(SBTrace()); 2487 } 2488 2489 namespace lldb_private { 2490 namespace repro { 2491 2492 template <> 2493 void RegisterMethods<SBTarget>(Registry &R) { 2494 LLDB_REGISTER_CONSTRUCTOR(SBTarget, ()); 2495 LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &)); 2496 LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &)); 2497 LLDB_REGISTER_METHOD(const lldb::SBTarget &, 2498 SBTarget, operator=,(const lldb::SBTarget &)); 2499 LLDB_REGISTER_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent, 2500 (const lldb::SBEvent &)); 2501 LLDB_REGISTER_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent, 2502 (const lldb::SBEvent &)); 2503 LLDB_REGISTER_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent, 2504 (const lldb::SBEvent &)); 2505 LLDB_REGISTER_STATIC_METHOD(lldb::SBModule, SBTarget, 2506 GetModuleAtIndexFromEvent, 2507 (const uint32_t, const lldb::SBEvent &)); 2508 LLDB_REGISTER_STATIC_METHOD(const char *, SBTarget, GetBroadcasterClassName, 2509 ()); 2510 LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsValid, ()); 2511 LLDB_REGISTER_METHOD_CONST(bool, SBTarget, operator bool, ()); 2512 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, GetProcess, ()); 2513 LLDB_REGISTER_METHOD(lldb::SBPlatform, SBTarget, GetPlatform, ()); 2514 LLDB_REGISTER_METHOD_CONST(lldb::SBDebugger, SBTarget, GetDebugger, ()); 2515 LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBTarget, GetStatistics, ()); 2516 LLDB_REGISTER_METHOD(void, SBTarget, SetCollectingStats, (bool)); 2517 LLDB_REGISTER_METHOD(bool, SBTarget, GetCollectingStats, ()); 2518 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *)); 2519 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore, 2520 (const char *, lldb::SBError &)); 2521 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LaunchSimple, 2522 (const char **, const char **, const char *)); 2523 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, Install, ()); 2524 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch, 2525 (lldb::SBListener &, const char **, const char **, 2526 const char *, const char *, const char *, 2527 const char *, uint32_t, bool, lldb::SBError &)); 2528 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch, 2529 (lldb::SBLaunchInfo &, lldb::SBError &)); 2530 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Attach, 2531 (lldb::SBAttachInfo &, lldb::SBError &)); 2532 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID, 2533 (lldb::SBListener &, lldb::pid_t, lldb::SBError &)); 2534 LLDB_REGISTER_METHOD( 2535 lldb::SBProcess, SBTarget, AttachToProcessWithName, 2536 (lldb::SBListener &, const char *, bool, lldb::SBError &)); 2537 LLDB_REGISTER_METHOD( 2538 lldb::SBProcess, SBTarget, ConnectRemote, 2539 (lldb::SBListener &, const char *, const char *, lldb::SBError &)); 2540 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBTarget, GetExecutable, ()); 2541 LLDB_REGISTER_METHOD_CONST(bool, 2542 SBTarget, operator==,(const lldb::SBTarget &)); 2543 LLDB_REGISTER_METHOD_CONST(bool, 2544 SBTarget, operator!=,(const lldb::SBTarget &)); 2545 LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress, 2546 (lldb::addr_t)); 2547 LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress, 2548 (lldb::addr_t)); 2549 LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress, 2550 (uint32_t, lldb::addr_t)); 2551 LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBTarget, 2552 ResolveSymbolContextForAddress, 2553 (const lldb::SBAddress &, uint32_t)); 2554 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2555 BreakpointCreateByLocation, (const char *, uint32_t)); 2556 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2557 BreakpointCreateByLocation, 2558 (const lldb::SBFileSpec &, uint32_t)); 2559 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2560 BreakpointCreateByLocation, 2561 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t)); 2562 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2563 BreakpointCreateByLocation, 2564 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t, 2565 lldb::SBFileSpecList &)); 2566 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2567 BreakpointCreateByLocation, 2568 (const lldb::SBFileSpec &, uint32_t, uint32_t, 2569 lldb::addr_t, lldb::SBFileSpecList &)); 2570 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation, 2571 (const lldb::SBFileSpec &, uint32_t, uint32_t, 2572 lldb::addr_t, lldb::SBFileSpecList &, bool)); 2573 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 2574 (const char *, const char *)); 2575 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 2576 (const char *, const lldb::SBFileSpecList &, 2577 const lldb::SBFileSpecList &)); 2578 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 2579 (const char *, uint32_t, const lldb::SBFileSpecList &, 2580 const lldb::SBFileSpecList &)); 2581 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName, 2582 (const char *, uint32_t, lldb::LanguageType, 2583 const lldb::SBFileSpecList &, 2584 const lldb::SBFileSpecList &)); 2585 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames, 2586 (const char **, uint32_t, uint32_t, 2587 const lldb::SBFileSpecList &, 2588 const lldb::SBFileSpecList &)); 2589 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames, 2590 (const char **, uint32_t, uint32_t, lldb::LanguageType, 2591 const lldb::SBFileSpecList &, 2592 const lldb::SBFileSpecList &)); 2593 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames, 2594 (const char **, uint32_t, uint32_t, lldb::LanguageType, 2595 lldb::addr_t, const lldb::SBFileSpecList &, 2596 const lldb::SBFileSpecList &)); 2597 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex, 2598 (const char *, const char *)); 2599 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex, 2600 (const char *, const lldb::SBFileSpecList &, 2601 const lldb::SBFileSpecList &)); 2602 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex, 2603 (const char *, lldb::LanguageType, 2604 const lldb::SBFileSpecList &, 2605 const lldb::SBFileSpecList &)); 2606 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2607 BreakpointCreateByAddress, (lldb::addr_t)); 2608 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2609 BreakpointCreateBySBAddress, (lldb::SBAddress &)); 2610 LLDB_REGISTER_METHOD( 2611 lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex, 2612 (const char *, const lldb::SBFileSpec &, const char *)); 2613 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2614 BreakpointCreateBySourceRegex, 2615 (const char *, const lldb::SBFileSpecList &, 2616 const lldb::SBFileSpecList &)); 2617 LLDB_REGISTER_METHOD( 2618 lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex, 2619 (const char *, const lldb::SBFileSpecList &, 2620 const lldb::SBFileSpecList &, const lldb::SBStringList &)); 2621 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, 2622 BreakpointCreateForException, 2623 (lldb::LanguageType, bool, bool)); 2624 LLDB_REGISTER_METHOD( 2625 lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript, 2626 (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &, 2627 const lldb::SBFileSpecList &, bool)); 2628 LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumBreakpoints, ()); 2629 LLDB_REGISTER_METHOD_CONST(lldb::SBBreakpoint, SBTarget, 2630 GetBreakpointAtIndex, (uint32_t)); 2631 LLDB_REGISTER_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t)); 2632 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID, 2633 (lldb::break_id_t)); 2634 LLDB_REGISTER_METHOD(bool, SBTarget, FindBreakpointsByName, 2635 (const char *, lldb::SBBreakpointList &)); 2636 LLDB_REGISTER_METHOD(void, SBTarget, GetBreakpointNames, 2637 (lldb::SBStringList &)); 2638 LLDB_REGISTER_METHOD(void, SBTarget, DeleteBreakpointName, (const char *)); 2639 LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllBreakpoints, ()); 2640 LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllBreakpoints, ()); 2641 LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllBreakpoints, ()); 2642 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile, 2643 (lldb::SBFileSpec &, lldb::SBBreakpointList &)); 2644 LLDB_REGISTER_METHOD( 2645 lldb::SBError, SBTarget, BreakpointsCreateFromFile, 2646 (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &)); 2647 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile, 2648 (lldb::SBFileSpec &)); 2649 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile, 2650 (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool)); 2651 LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumWatchpoints, ()); 2652 LLDB_REGISTER_METHOD_CONST(lldb::SBWatchpoint, SBTarget, 2653 GetWatchpointAtIndex, (uint32_t)); 2654 LLDB_REGISTER_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t)); 2655 LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID, 2656 (lldb::watch_id_t)); 2657 LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress, 2658 (lldb::addr_t, size_t, bool, bool, lldb::SBError &)); 2659 LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllWatchpoints, ()); 2660 LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllWatchpoints, ()); 2661 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress, 2662 (const char *, lldb::SBAddress, lldb::SBType)); 2663 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromData, 2664 (const char *, lldb::SBData, lldb::SBType)); 2665 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression, 2666 (const char *, const char *)); 2667 LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllWatchpoints, ()); 2668 LLDB_REGISTER_METHOD(void, SBTarget, AppendImageSearchPath, 2669 (const char *, const char *, lldb::SBError &)); 2670 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule, 2671 (const char *, const char *, const char *)); 2672 LLDB_REGISTER_METHOD( 2673 lldb::SBModule, SBTarget, AddModule, 2674 (const char *, const char *, const char *, const char *)); 2675 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule, 2676 (const lldb::SBModuleSpec &)); 2677 LLDB_REGISTER_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &)); 2678 LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumModules, ()); 2679 LLDB_REGISTER_METHOD(void, SBTarget, Clear, ()); 2680 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, FindModule, 2681 (const lldb::SBFileSpec &)); 2682 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits, 2683 (const lldb::SBFileSpec &)); 2684 LLDB_REGISTER_METHOD(lldb::ByteOrder, SBTarget, GetByteOrder, ()); 2685 LLDB_REGISTER_METHOD(const char *, SBTarget, GetTriple, ()); 2686 LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetDataByteSize, ()); 2687 LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetCodeByteSize, ()); 2688 LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetAddressByteSize, ()); 2689 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex, 2690 (uint32_t)); 2691 LLDB_REGISTER_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule)); 2692 LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBTarget, GetBroadcaster, 2693 ()); 2694 LLDB_REGISTER_METHOD(bool, SBTarget, GetDescription, 2695 (lldb::SBStream &, lldb::DescriptionLevel)); 2696 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions, 2697 (const char *, uint32_t)); 2698 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, 2699 FindGlobalFunctions, 2700 (const char *, uint32_t, lldb::MatchType)); 2701 LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *)); 2702 LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, GetBasicType, 2703 (lldb::BasicType)); 2704 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *)); 2705 LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables, 2706 (const char *, uint32_t)); 2707 LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables, 2708 (const char *, uint32_t, lldb::MatchType)); 2709 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable, 2710 (const char *)); 2711 LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBTarget, GetSourceManager, ()); 2712 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions, 2713 (lldb::SBAddress, uint32_t)); 2714 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions, 2715 (lldb::SBAddress, uint32_t, const char *)); 2716 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress, 2717 (lldb::SBSection, lldb::addr_t)); 2718 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress, 2719 (lldb::SBSection)); 2720 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress, 2721 (lldb::SBModule, int64_t)); 2722 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress, 2723 (lldb::SBModule)); 2724 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols, 2725 (const char *, lldb::SymbolType)); 2726 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression, 2727 (const char *)); 2728 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression, 2729 (const char *, const lldb::SBExpressionOptions &)); 2730 LLDB_REGISTER_METHOD(lldb::addr_t, SBTarget, GetStackRedZoneSize, ()); 2731 LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsLoaded, 2732 (const lldb::SBModule &)); 2733 LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ()); 2734 LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo, 2735 (const lldb::SBLaunchInfo &)); 2736 LLDB_REGISTER_METHOD( 2737 size_t, SBTarget, ReadMemory, 2738 (const lldb::SBAddress, void *, size_t, lldb::SBError &)); 2739 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions, 2740 (lldb::SBAddress, const void *, size_t)); 2741 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, 2742 GetInstructionsWithFlavor, 2743 (lldb::SBAddress, const char *, const void *, size_t)); 2744 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions, 2745 (lldb::addr_t, const void *, size_t)); 2746 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, 2747 GetInstructionsWithFlavor, 2748 (lldb::addr_t, const char *, const void *, size_t)); 2749 LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBTarget, GetEnvironment, ()); 2750 LLDB_REGISTER_METHOD(lldb::SBTrace, SBTarget, GetTrace, ()); 2751 LLDB_REGISTER_METHOD(lldb::SBTrace, SBTarget, CreateTrace, (lldb::SBError &)); 2752 } 2753 2754 } 2755 } 2756