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