1 //===-- SBProcess.cpp -------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBProcess.h" 10 #include "SBReproducerPrivate.h" 11 12 #include <inttypes.h> 13 14 #include "lldb/lldb-defines.h" 15 #include "lldb/lldb-types.h" 16 17 #include "lldb/Core/Debugger.h" 18 #include "lldb/Core/Module.h" 19 #include "lldb/Core/PluginManager.h" 20 #include "lldb/Core/StreamFile.h" 21 #include "lldb/Target/MemoryRegionInfo.h" 22 #include "lldb/Target/Process.h" 23 #include "lldb/Target/RegisterContext.h" 24 #include "lldb/Target/SystemRuntime.h" 25 #include "lldb/Target/Target.h" 26 #include "lldb/Target/Thread.h" 27 #include "lldb/Utility/Args.h" 28 #include "lldb/Utility/ProcessInfo.h" 29 #include "lldb/Utility/State.h" 30 #include "lldb/Utility/Stream.h" 31 32 33 #include "lldb/API/SBBroadcaster.h" 34 #include "lldb/API/SBCommandReturnObject.h" 35 #include "lldb/API/SBDebugger.h" 36 #include "lldb/API/SBEvent.h" 37 #include "lldb/API/SBFileSpec.h" 38 #include "lldb/API/SBMemoryRegionInfo.h" 39 #include "lldb/API/SBMemoryRegionInfoList.h" 40 #include "lldb/API/SBStream.h" 41 #include "lldb/API/SBStringList.h" 42 #include "lldb/API/SBStructuredData.h" 43 #include "lldb/API/SBThread.h" 44 #include "lldb/API/SBThreadCollection.h" 45 #include "lldb/API/SBTrace.h" 46 #include "lldb/API/SBTraceOptions.h" 47 #include "lldb/API/SBUnixSignals.h" 48 49 using namespace lldb; 50 using namespace lldb_private; 51 52 SBProcess::SBProcess() : m_opaque_wp() { 53 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBProcess); 54 } 55 56 // SBProcess constructor 57 58 SBProcess::SBProcess(const SBProcess &rhs) : m_opaque_wp(rhs.m_opaque_wp) { 59 LLDB_RECORD_CONSTRUCTOR(SBProcess, (const lldb::SBProcess &), rhs); 60 } 61 62 SBProcess::SBProcess(const lldb::ProcessSP &process_sp) 63 : m_opaque_wp(process_sp) { 64 LLDB_RECORD_CONSTRUCTOR(SBProcess, (const lldb::ProcessSP &), process_sp); 65 } 66 67 const SBProcess &SBProcess::operator=(const SBProcess &rhs) { 68 LLDB_RECORD_METHOD(const lldb::SBProcess &, 69 SBProcess, operator=,(const lldb::SBProcess &), rhs); 70 71 if (this != &rhs) 72 m_opaque_wp = rhs.m_opaque_wp; 73 return LLDB_RECORD_RESULT(*this); 74 } 75 76 // Destructor 77 SBProcess::~SBProcess() {} 78 79 const char *SBProcess::GetBroadcasterClassName() { 80 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBProcess, 81 GetBroadcasterClassName); 82 83 return Process::GetStaticBroadcasterClass().AsCString(); 84 } 85 86 const char *SBProcess::GetPluginName() { 87 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetPluginName); 88 89 ProcessSP process_sp(GetSP()); 90 if (process_sp) { 91 return process_sp->GetPluginName().GetCString(); 92 } 93 return "<Unknown>"; 94 } 95 96 const char *SBProcess::GetShortPluginName() { 97 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetShortPluginName); 98 99 ProcessSP process_sp(GetSP()); 100 if (process_sp) { 101 return process_sp->GetPluginName().GetCString(); 102 } 103 return "<Unknown>"; 104 } 105 106 lldb::ProcessSP SBProcess::GetSP() const { return m_opaque_wp.lock(); } 107 108 void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; } 109 110 void SBProcess::Clear() { 111 LLDB_RECORD_METHOD_NO_ARGS(void, SBProcess, Clear); 112 113 m_opaque_wp.reset(); 114 } 115 116 bool SBProcess::IsValid() const { 117 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcess, IsValid); 118 return this->operator bool(); 119 } 120 SBProcess::operator bool() const { 121 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcess, operator bool); 122 123 ProcessSP process_sp(m_opaque_wp.lock()); 124 return ((bool)process_sp && process_sp->IsValid()); 125 } 126 127 bool SBProcess::RemoteLaunch(char const **argv, char const **envp, 128 const char *stdin_path, const char *stdout_path, 129 const char *stderr_path, 130 const char *working_directory, 131 uint32_t launch_flags, bool stop_at_entry, 132 lldb::SBError &error) { 133 LLDB_RECORD_METHOD(bool, SBProcess, RemoteLaunch, 134 (const char **, const char **, const char *, const char *, 135 const char *, const char *, uint32_t, bool, 136 lldb::SBError &), 137 argv, envp, stdin_path, stdout_path, stderr_path, 138 working_directory, launch_flags, stop_at_entry, error); 139 140 ProcessSP process_sp(GetSP()); 141 if (process_sp) { 142 std::lock_guard<std::recursive_mutex> guard( 143 process_sp->GetTarget().GetAPIMutex()); 144 if (process_sp->GetState() == eStateConnected) { 145 if (stop_at_entry) 146 launch_flags |= eLaunchFlagStopAtEntry; 147 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path), 148 FileSpec(stderr_path), 149 FileSpec(working_directory), launch_flags); 150 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 151 if (exe_module) 152 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 153 if (argv) 154 launch_info.GetArguments().AppendArguments(argv); 155 if (envp) 156 launch_info.GetEnvironment() = Environment(envp); 157 error.SetError(process_sp->Launch(launch_info)); 158 } else { 159 error.SetErrorString("must be in eStateConnected to call RemoteLaunch"); 160 } 161 } else { 162 error.SetErrorString("unable to attach pid"); 163 } 164 165 return error.Success(); 166 } 167 168 bool SBProcess::RemoteAttachToProcessWithID(lldb::pid_t pid, 169 lldb::SBError &error) { 170 LLDB_RECORD_METHOD(bool, SBProcess, RemoteAttachToProcessWithID, 171 (lldb::pid_t, lldb::SBError &), pid, error); 172 173 ProcessSP process_sp(GetSP()); 174 if (process_sp) { 175 std::lock_guard<std::recursive_mutex> guard( 176 process_sp->GetTarget().GetAPIMutex()); 177 if (process_sp->GetState() == eStateConnected) { 178 ProcessAttachInfo attach_info; 179 attach_info.SetProcessID(pid); 180 error.SetError(process_sp->Attach(attach_info)); 181 } else { 182 error.SetErrorString( 183 "must be in eStateConnected to call RemoteAttachToProcessWithID"); 184 } 185 } else { 186 error.SetErrorString("unable to attach pid"); 187 } 188 189 return error.Success(); 190 } 191 192 uint32_t SBProcess::GetNumThreads() { 193 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumThreads); 194 195 uint32_t num_threads = 0; 196 ProcessSP process_sp(GetSP()); 197 if (process_sp) { 198 Process::StopLocker stop_locker; 199 200 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 201 std::lock_guard<std::recursive_mutex> guard( 202 process_sp->GetTarget().GetAPIMutex()); 203 num_threads = process_sp->GetThreadList().GetSize(can_update); 204 } 205 206 return num_threads; 207 } 208 209 SBThread SBProcess::GetSelectedThread() const { 210 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBProcess, 211 GetSelectedThread); 212 213 SBThread sb_thread; 214 ThreadSP thread_sp; 215 ProcessSP process_sp(GetSP()); 216 if (process_sp) { 217 std::lock_guard<std::recursive_mutex> guard( 218 process_sp->GetTarget().GetAPIMutex()); 219 thread_sp = process_sp->GetThreadList().GetSelectedThread(); 220 sb_thread.SetThread(thread_sp); 221 } 222 223 return LLDB_RECORD_RESULT(sb_thread); 224 } 225 226 SBThread SBProcess::CreateOSPluginThread(lldb::tid_t tid, 227 lldb::addr_t context) { 228 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, CreateOSPluginThread, 229 (lldb::tid_t, lldb::addr_t), tid, context); 230 231 SBThread sb_thread; 232 ThreadSP thread_sp; 233 ProcessSP process_sp(GetSP()); 234 if (process_sp) { 235 std::lock_guard<std::recursive_mutex> guard( 236 process_sp->GetTarget().GetAPIMutex()); 237 thread_sp = process_sp->CreateOSPluginThread(tid, context); 238 sb_thread.SetThread(thread_sp); 239 } 240 241 return LLDB_RECORD_RESULT(sb_thread); 242 } 243 244 SBTarget SBProcess::GetTarget() const { 245 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBProcess, GetTarget); 246 247 SBTarget sb_target; 248 TargetSP target_sp; 249 ProcessSP process_sp(GetSP()); 250 if (process_sp) { 251 target_sp = process_sp->GetTarget().shared_from_this(); 252 sb_target.SetSP(target_sp); 253 } 254 255 return LLDB_RECORD_RESULT(sb_target); 256 } 257 258 size_t SBProcess::PutSTDIN(const char *src, size_t src_len) { 259 LLDB_RECORD_METHOD(size_t, SBProcess, PutSTDIN, (const char *, size_t), src, 260 src_len); 261 262 size_t ret_val = 0; 263 ProcessSP process_sp(GetSP()); 264 if (process_sp) { 265 Status error; 266 ret_val = process_sp->PutSTDIN(src, src_len, error); 267 } 268 269 return ret_val; 270 } 271 272 size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const { 273 LLDB_RECORD_METHOD_CONST(size_t, SBProcess, GetSTDOUT, (char *, size_t), dst, 274 dst_len); 275 276 size_t bytes_read = 0; 277 ProcessSP process_sp(GetSP()); 278 if (process_sp) { 279 Status error; 280 bytes_read = process_sp->GetSTDOUT(dst, dst_len, error); 281 } 282 283 return bytes_read; 284 } 285 286 size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const { 287 LLDB_RECORD_METHOD_CONST(size_t, SBProcess, GetSTDERR, (char *, size_t), dst, 288 dst_len); 289 290 size_t bytes_read = 0; 291 ProcessSP process_sp(GetSP()); 292 if (process_sp) { 293 Status error; 294 bytes_read = process_sp->GetSTDERR(dst, dst_len, error); 295 } 296 297 return bytes_read; 298 } 299 300 size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const { 301 LLDB_RECORD_METHOD_CONST(size_t, SBProcess, GetAsyncProfileData, 302 (char *, size_t), dst, dst_len); 303 304 size_t bytes_read = 0; 305 ProcessSP process_sp(GetSP()); 306 if (process_sp) { 307 Status error; 308 bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error); 309 } 310 311 return bytes_read; 312 } 313 314 lldb::SBTrace SBProcess::StartTrace(SBTraceOptions &options, 315 lldb::SBError &error) { 316 LLDB_RECORD_METHOD(lldb::SBTrace, SBProcess, StartTrace, 317 (lldb::SBTraceOptions &, lldb::SBError &), options, error); 318 319 ProcessSP process_sp(GetSP()); 320 error.Clear(); 321 SBTrace trace_instance; 322 trace_instance.SetSP(process_sp); 323 lldb::user_id_t uid = LLDB_INVALID_UID; 324 325 if (!process_sp) { 326 error.SetErrorString("invalid process"); 327 } else { 328 uid = process_sp->StartTrace(*(options.m_traceoptions_sp), error.ref()); 329 trace_instance.SetTraceUID(uid); 330 } 331 return LLDB_RECORD_RESULT(trace_instance); 332 } 333 334 void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const { 335 LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState, 336 (const lldb::SBEvent &, FILE *), event, out); 337 338 if (out == nullptr) 339 return; 340 341 ProcessSP process_sp(GetSP()); 342 if (process_sp) { 343 const StateType event_state = SBProcess::GetStateFromEvent(event); 344 char message[1024]; 345 int message_len = ::snprintf( 346 message, sizeof(message), "Process %" PRIu64 " %s\n", 347 process_sp->GetID(), SBDebugger::StateAsCString(event_state)); 348 349 if (message_len > 0) 350 ::fwrite(message, 1, message_len, out); 351 } 352 } 353 354 void SBProcess::AppendEventStateReport(const SBEvent &event, 355 SBCommandReturnObject &result) { 356 LLDB_RECORD_METHOD(void, SBProcess, AppendEventStateReport, 357 (const lldb::SBEvent &, lldb::SBCommandReturnObject &), 358 event, result); 359 360 ProcessSP process_sp(GetSP()); 361 if (process_sp) { 362 const StateType event_state = SBProcess::GetStateFromEvent(event); 363 char message[1024]; 364 ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n", 365 process_sp->GetID(), SBDebugger::StateAsCString(event_state)); 366 367 result.AppendMessage(message); 368 } 369 } 370 371 bool SBProcess::SetSelectedThread(const SBThread &thread) { 372 LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThread, 373 (const lldb::SBThread &), thread); 374 375 ProcessSP process_sp(GetSP()); 376 if (process_sp) { 377 std::lock_guard<std::recursive_mutex> guard( 378 process_sp->GetTarget().GetAPIMutex()); 379 return process_sp->GetThreadList().SetSelectedThreadByID( 380 thread.GetThreadID()); 381 } 382 return false; 383 } 384 385 bool SBProcess::SetSelectedThreadByID(lldb::tid_t tid) { 386 LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThreadByID, (lldb::tid_t), 387 tid); 388 389 390 bool ret_val = false; 391 ProcessSP process_sp(GetSP()); 392 if (process_sp) { 393 std::lock_guard<std::recursive_mutex> guard( 394 process_sp->GetTarget().GetAPIMutex()); 395 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid); 396 } 397 398 return ret_val; 399 } 400 401 bool SBProcess::SetSelectedThreadByIndexID(uint32_t index_id) { 402 LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThreadByIndexID, (uint32_t), 403 index_id); 404 405 bool ret_val = false; 406 ProcessSP process_sp(GetSP()); 407 if (process_sp) { 408 std::lock_guard<std::recursive_mutex> guard( 409 process_sp->GetTarget().GetAPIMutex()); 410 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id); 411 } 412 413 414 return ret_val; 415 } 416 417 SBThread SBProcess::GetThreadAtIndex(size_t index) { 418 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadAtIndex, (size_t), 419 index); 420 421 SBThread sb_thread; 422 ThreadSP thread_sp; 423 ProcessSP process_sp(GetSP()); 424 if (process_sp) { 425 Process::StopLocker stop_locker; 426 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 427 std::lock_guard<std::recursive_mutex> guard( 428 process_sp->GetTarget().GetAPIMutex()); 429 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update); 430 sb_thread.SetThread(thread_sp); 431 } 432 433 return LLDB_RECORD_RESULT(sb_thread); 434 } 435 436 uint32_t SBProcess::GetNumQueues() { 437 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumQueues); 438 439 uint32_t num_queues = 0; 440 ProcessSP process_sp(GetSP()); 441 if (process_sp) { 442 Process::StopLocker stop_locker; 443 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 444 std::lock_guard<std::recursive_mutex> guard( 445 process_sp->GetTarget().GetAPIMutex()); 446 num_queues = process_sp->GetQueueList().GetSize(); 447 } 448 } 449 450 return num_queues; 451 } 452 453 SBQueue SBProcess::GetQueueAtIndex(size_t index) { 454 LLDB_RECORD_METHOD(lldb::SBQueue, SBProcess, GetQueueAtIndex, (size_t), 455 index); 456 457 SBQueue sb_queue; 458 QueueSP queue_sp; 459 ProcessSP process_sp(GetSP()); 460 if (process_sp) { 461 Process::StopLocker stop_locker; 462 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 463 std::lock_guard<std::recursive_mutex> guard( 464 process_sp->GetTarget().GetAPIMutex()); 465 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index); 466 sb_queue.SetQueue(queue_sp); 467 } 468 } 469 470 return LLDB_RECORD_RESULT(sb_queue); 471 } 472 473 uint32_t SBProcess::GetStopID(bool include_expression_stops) { 474 LLDB_RECORD_METHOD(uint32_t, SBProcess, GetStopID, (bool), 475 include_expression_stops); 476 477 ProcessSP process_sp(GetSP()); 478 if (process_sp) { 479 std::lock_guard<std::recursive_mutex> guard( 480 process_sp->GetTarget().GetAPIMutex()); 481 if (include_expression_stops) 482 return process_sp->GetStopID(); 483 else 484 return process_sp->GetLastNaturalStopID(); 485 } 486 return 0; 487 } 488 489 SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) { 490 LLDB_RECORD_METHOD(lldb::SBEvent, SBProcess, GetStopEventForStopID, 491 (uint32_t), stop_id); 492 493 SBEvent sb_event; 494 EventSP event_sp; 495 ProcessSP process_sp(GetSP()); 496 if (process_sp) { 497 std::lock_guard<std::recursive_mutex> guard( 498 process_sp->GetTarget().GetAPIMutex()); 499 event_sp = process_sp->GetStopEventForStopID(stop_id); 500 sb_event.reset(event_sp); 501 } 502 503 return LLDB_RECORD_RESULT(sb_event); 504 } 505 506 StateType SBProcess::GetState() { 507 LLDB_RECORD_METHOD_NO_ARGS(lldb::StateType, SBProcess, GetState); 508 509 StateType ret_val = eStateInvalid; 510 ProcessSP process_sp(GetSP()); 511 if (process_sp) { 512 std::lock_guard<std::recursive_mutex> guard( 513 process_sp->GetTarget().GetAPIMutex()); 514 ret_val = process_sp->GetState(); 515 } 516 517 return ret_val; 518 } 519 520 int SBProcess::GetExitStatus() { 521 LLDB_RECORD_METHOD_NO_ARGS(int, SBProcess, GetExitStatus); 522 523 int exit_status = 0; 524 ProcessSP process_sp(GetSP()); 525 if (process_sp) { 526 std::lock_guard<std::recursive_mutex> guard( 527 process_sp->GetTarget().GetAPIMutex()); 528 exit_status = process_sp->GetExitStatus(); 529 } 530 531 return exit_status; 532 } 533 534 const char *SBProcess::GetExitDescription() { 535 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetExitDescription); 536 537 const char *exit_desc = nullptr; 538 ProcessSP process_sp(GetSP()); 539 if (process_sp) { 540 std::lock_guard<std::recursive_mutex> guard( 541 process_sp->GetTarget().GetAPIMutex()); 542 exit_desc = process_sp->GetExitDescription(); 543 } 544 return exit_desc; 545 } 546 547 lldb::pid_t SBProcess::GetProcessID() { 548 LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcess, GetProcessID); 549 550 lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; 551 ProcessSP process_sp(GetSP()); 552 if (process_sp) 553 ret_val = process_sp->GetID(); 554 555 return ret_val; 556 } 557 558 uint32_t SBProcess::GetUniqueID() { 559 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetUniqueID); 560 561 uint32_t ret_val = 0; 562 ProcessSP process_sp(GetSP()); 563 if (process_sp) 564 ret_val = process_sp->GetUniqueID(); 565 return ret_val; 566 } 567 568 ByteOrder SBProcess::GetByteOrder() const { 569 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ByteOrder, SBProcess, GetByteOrder); 570 571 ByteOrder byteOrder = eByteOrderInvalid; 572 ProcessSP process_sp(GetSP()); 573 if (process_sp) 574 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); 575 576 577 return byteOrder; 578 } 579 580 uint32_t SBProcess::GetAddressByteSize() const { 581 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBProcess, GetAddressByteSize); 582 583 uint32_t size = 0; 584 ProcessSP process_sp(GetSP()); 585 if (process_sp) 586 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); 587 588 589 return size; 590 } 591 592 SBError SBProcess::Continue() { 593 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Continue); 594 595 SBError sb_error; 596 ProcessSP process_sp(GetSP()); 597 598 if (process_sp) { 599 std::lock_guard<std::recursive_mutex> guard( 600 process_sp->GetTarget().GetAPIMutex()); 601 602 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution()) 603 sb_error.ref() = process_sp->Resume(); 604 else 605 sb_error.ref() = process_sp->ResumeSynchronous(nullptr); 606 } else 607 sb_error.SetErrorString("SBProcess is invalid"); 608 609 return LLDB_RECORD_RESULT(sb_error); 610 } 611 612 SBError SBProcess::Destroy() { 613 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Destroy); 614 615 SBError sb_error; 616 ProcessSP process_sp(GetSP()); 617 if (process_sp) { 618 std::lock_guard<std::recursive_mutex> guard( 619 process_sp->GetTarget().GetAPIMutex()); 620 sb_error.SetError(process_sp->Destroy(false)); 621 } else 622 sb_error.SetErrorString("SBProcess is invalid"); 623 624 return LLDB_RECORD_RESULT(sb_error); 625 } 626 627 SBError SBProcess::Stop() { 628 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Stop); 629 630 SBError sb_error; 631 ProcessSP process_sp(GetSP()); 632 if (process_sp) { 633 std::lock_guard<std::recursive_mutex> guard( 634 process_sp->GetTarget().GetAPIMutex()); 635 sb_error.SetError(process_sp->Halt()); 636 } else 637 sb_error.SetErrorString("SBProcess is invalid"); 638 639 return LLDB_RECORD_RESULT(sb_error); 640 } 641 642 SBError SBProcess::Kill() { 643 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Kill); 644 645 SBError sb_error; 646 ProcessSP process_sp(GetSP()); 647 if (process_sp) { 648 std::lock_guard<std::recursive_mutex> guard( 649 process_sp->GetTarget().GetAPIMutex()); 650 sb_error.SetError(process_sp->Destroy(true)); 651 } else 652 sb_error.SetErrorString("SBProcess is invalid"); 653 654 return LLDB_RECORD_RESULT(sb_error); 655 } 656 657 SBError SBProcess::Detach() { 658 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Detach); 659 660 // FIXME: This should come from a process default. 661 bool keep_stopped = false; 662 return LLDB_RECORD_RESULT(Detach(keep_stopped)); 663 } 664 665 SBError SBProcess::Detach(bool keep_stopped) { 666 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, Detach, (bool), keep_stopped); 667 668 SBError sb_error; 669 ProcessSP process_sp(GetSP()); 670 if (process_sp) { 671 std::lock_guard<std::recursive_mutex> guard( 672 process_sp->GetTarget().GetAPIMutex()); 673 sb_error.SetError(process_sp->Detach(keep_stopped)); 674 } else 675 sb_error.SetErrorString("SBProcess is invalid"); 676 677 return LLDB_RECORD_RESULT(sb_error); 678 } 679 680 SBError SBProcess::Signal(int signo) { 681 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, Signal, (int), signo); 682 683 SBError sb_error; 684 ProcessSP process_sp(GetSP()); 685 if (process_sp) { 686 std::lock_guard<std::recursive_mutex> guard( 687 process_sp->GetTarget().GetAPIMutex()); 688 sb_error.SetError(process_sp->Signal(signo)); 689 } else 690 sb_error.SetErrorString("SBProcess is invalid"); 691 692 return LLDB_RECORD_RESULT(sb_error); 693 } 694 695 SBUnixSignals SBProcess::GetUnixSignals() { 696 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBUnixSignals, SBProcess, GetUnixSignals); 697 698 if (auto process_sp = GetSP()) 699 return LLDB_RECORD_RESULT(SBUnixSignals{process_sp}); 700 701 return LLDB_RECORD_RESULT(SBUnixSignals{}); 702 } 703 704 void SBProcess::SendAsyncInterrupt() { 705 LLDB_RECORD_METHOD_NO_ARGS(void, SBProcess, SendAsyncInterrupt); 706 707 ProcessSP process_sp(GetSP()); 708 if (process_sp) { 709 process_sp->SendAsyncInterrupt(); 710 } 711 } 712 713 SBThread SBProcess::GetThreadByID(tid_t tid) { 714 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadByID, (lldb::tid_t), 715 tid); 716 717 SBThread sb_thread; 718 ThreadSP thread_sp; 719 ProcessSP process_sp(GetSP()); 720 if (process_sp) { 721 Process::StopLocker stop_locker; 722 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 723 std::lock_guard<std::recursive_mutex> guard( 724 process_sp->GetTarget().GetAPIMutex()); 725 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update); 726 sb_thread.SetThread(thread_sp); 727 } 728 729 return LLDB_RECORD_RESULT(sb_thread); 730 } 731 732 SBThread SBProcess::GetThreadByIndexID(uint32_t index_id) { 733 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadByIndexID, (uint32_t), 734 index_id); 735 736 SBThread sb_thread; 737 ThreadSP thread_sp; 738 ProcessSP process_sp(GetSP()); 739 if (process_sp) { 740 Process::StopLocker stop_locker; 741 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 742 std::lock_guard<std::recursive_mutex> guard( 743 process_sp->GetTarget().GetAPIMutex()); 744 thread_sp = 745 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update); 746 sb_thread.SetThread(thread_sp); 747 } 748 749 return LLDB_RECORD_RESULT(sb_thread); 750 } 751 752 StateType SBProcess::GetStateFromEvent(const SBEvent &event) { 753 LLDB_RECORD_STATIC_METHOD(lldb::StateType, SBProcess, GetStateFromEvent, 754 (const lldb::SBEvent &), event); 755 756 StateType ret_val = Process::ProcessEventData::GetStateFromEvent(event.get()); 757 758 return ret_val; 759 } 760 761 bool SBProcess::GetRestartedFromEvent(const SBEvent &event) { 762 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, GetRestartedFromEvent, 763 (const lldb::SBEvent &), event); 764 765 bool ret_val = Process::ProcessEventData::GetRestartedFromEvent(event.get()); 766 767 return ret_val; 768 } 769 770 size_t SBProcess::GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event) { 771 LLDB_RECORD_STATIC_METHOD(size_t, SBProcess, GetNumRestartedReasonsFromEvent, 772 (const lldb::SBEvent &), event); 773 774 return Process::ProcessEventData::GetNumRestartedReasons(event.get()); 775 } 776 777 const char * 778 SBProcess::GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, 779 size_t idx) { 780 LLDB_RECORD_STATIC_METHOD(const char *, SBProcess, 781 GetRestartedReasonAtIndexFromEvent, 782 (const lldb::SBEvent &, size_t), event, idx); 783 784 return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx); 785 } 786 787 SBProcess SBProcess::GetProcessFromEvent(const SBEvent &event) { 788 LLDB_RECORD_STATIC_METHOD(lldb::SBProcess, SBProcess, GetProcessFromEvent, 789 (const lldb::SBEvent &), event); 790 791 ProcessSP process_sp = 792 Process::ProcessEventData::GetProcessFromEvent(event.get()); 793 if (!process_sp) { 794 // StructuredData events also know the process they come from. Try that. 795 process_sp = EventDataStructuredData::GetProcessFromEvent(event.get()); 796 } 797 798 return LLDB_RECORD_RESULT(SBProcess(process_sp)); 799 } 800 801 bool SBProcess::GetInterruptedFromEvent(const SBEvent &event) { 802 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, GetInterruptedFromEvent, 803 (const lldb::SBEvent &), event); 804 805 return Process::ProcessEventData::GetInterruptedFromEvent(event.get()); 806 } 807 808 lldb::SBStructuredData 809 SBProcess::GetStructuredDataFromEvent(const lldb::SBEvent &event) { 810 LLDB_RECORD_STATIC_METHOD(lldb::SBStructuredData, SBProcess, 811 GetStructuredDataFromEvent, (const lldb::SBEvent &), 812 event); 813 814 return LLDB_RECORD_RESULT(SBStructuredData(event.GetSP())); 815 } 816 817 bool SBProcess::EventIsProcessEvent(const SBEvent &event) { 818 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, EventIsProcessEvent, 819 (const lldb::SBEvent &), event); 820 821 return (event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass()) && 822 !EventIsStructuredDataEvent(event); 823 } 824 825 bool SBProcess::EventIsStructuredDataEvent(const lldb::SBEvent &event) { 826 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, EventIsStructuredDataEvent, 827 (const lldb::SBEvent &), event); 828 829 EventSP event_sp = event.GetSP(); 830 EventData *event_data = event_sp ? event_sp->GetData() : nullptr; 831 return event_data && (event_data->GetFlavor() == 832 EventDataStructuredData::GetFlavorString()); 833 } 834 835 SBBroadcaster SBProcess::GetBroadcaster() const { 836 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBProcess, 837 GetBroadcaster); 838 839 840 ProcessSP process_sp(GetSP()); 841 842 SBBroadcaster broadcaster(process_sp.get(), false); 843 844 845 return LLDB_RECORD_RESULT(broadcaster); 846 } 847 848 const char *SBProcess::GetBroadcasterClass() { 849 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBProcess, 850 GetBroadcasterClass); 851 852 return Process::GetStaticBroadcasterClass().AsCString(); 853 } 854 855 size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len, 856 SBError &sb_error) { 857 LLDB_RECORD_DUMMY(size_t, SBProcess, ReadMemory, 858 (lldb::addr_t, void *, size_t, lldb::SBError &), addr, dst, 859 dst_len, sb_error); 860 861 size_t bytes_read = 0; 862 863 ProcessSP process_sp(GetSP()); 864 865 866 if (process_sp) { 867 Process::StopLocker stop_locker; 868 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 869 std::lock_guard<std::recursive_mutex> guard( 870 process_sp->GetTarget().GetAPIMutex()); 871 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref()); 872 } else { 873 sb_error.SetErrorString("process is running"); 874 } 875 } else { 876 sb_error.SetErrorString("SBProcess is invalid"); 877 } 878 879 return bytes_read; 880 } 881 882 size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size, 883 lldb::SBError &sb_error) { 884 LLDB_RECORD_DUMMY(size_t, SBProcess, ReadCStringFromMemory, 885 (lldb::addr_t, void *, size_t, lldb::SBError &), addr, buf, 886 size, sb_error); 887 888 size_t bytes_read = 0; 889 ProcessSP process_sp(GetSP()); 890 if (process_sp) { 891 Process::StopLocker stop_locker; 892 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 893 std::lock_guard<std::recursive_mutex> guard( 894 process_sp->GetTarget().GetAPIMutex()); 895 bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size, 896 sb_error.ref()); 897 } else { 898 sb_error.SetErrorString("process is running"); 899 } 900 } else { 901 sb_error.SetErrorString("SBProcess is invalid"); 902 } 903 return bytes_read; 904 } 905 906 uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size, 907 lldb::SBError &sb_error) { 908 LLDB_RECORD_METHOD(uint64_t, SBProcess, ReadUnsignedFromMemory, 909 (lldb::addr_t, uint32_t, lldb::SBError &), addr, byte_size, 910 sb_error); 911 912 uint64_t value = 0; 913 ProcessSP process_sp(GetSP()); 914 if (process_sp) { 915 Process::StopLocker stop_locker; 916 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 917 std::lock_guard<std::recursive_mutex> guard( 918 process_sp->GetTarget().GetAPIMutex()); 919 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0, 920 sb_error.ref()); 921 } else { 922 sb_error.SetErrorString("process is running"); 923 } 924 } else { 925 sb_error.SetErrorString("SBProcess is invalid"); 926 } 927 return value; 928 } 929 930 lldb::addr_t SBProcess::ReadPointerFromMemory(addr_t addr, 931 lldb::SBError &sb_error) { 932 LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, ReadPointerFromMemory, 933 (lldb::addr_t, lldb::SBError &), addr, sb_error); 934 935 lldb::addr_t ptr = LLDB_INVALID_ADDRESS; 936 ProcessSP process_sp(GetSP()); 937 if (process_sp) { 938 Process::StopLocker stop_locker; 939 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 940 std::lock_guard<std::recursive_mutex> guard( 941 process_sp->GetTarget().GetAPIMutex()); 942 ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref()); 943 } else { 944 sb_error.SetErrorString("process is running"); 945 } 946 } else { 947 sb_error.SetErrorString("SBProcess is invalid"); 948 } 949 return ptr; 950 } 951 952 size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len, 953 SBError &sb_error) { 954 LLDB_RECORD_DUMMY(size_t, SBProcess, WriteMemory, 955 (lldb::addr_t, const void *, size_t, lldb::SBError &), addr, 956 src, src_len, sb_error); 957 958 size_t bytes_written = 0; 959 960 ProcessSP process_sp(GetSP()); 961 962 if (process_sp) { 963 Process::StopLocker stop_locker; 964 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 965 std::lock_guard<std::recursive_mutex> guard( 966 process_sp->GetTarget().GetAPIMutex()); 967 bytes_written = 968 process_sp->WriteMemory(addr, src, src_len, sb_error.ref()); 969 } else { 970 sb_error.SetErrorString("process is running"); 971 } 972 } 973 974 return bytes_written; 975 } 976 977 bool SBProcess::GetDescription(SBStream &description) { 978 LLDB_RECORD_METHOD(bool, SBProcess, GetDescription, (lldb::SBStream &), 979 description); 980 981 Stream &strm = description.ref(); 982 983 ProcessSP process_sp(GetSP()); 984 if (process_sp) { 985 char path[PATH_MAX]; 986 GetTarget().GetExecutable().GetPath(path, sizeof(path)); 987 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 988 const char *exe_name = nullptr; 989 if (exe_module) 990 exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); 991 992 strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", 993 process_sp->GetID(), lldb_private::StateAsCString(GetState()), 994 GetNumThreads(), exe_name ? ", executable = " : "", 995 exe_name ? exe_name : ""); 996 } else 997 strm.PutCString("No value"); 998 999 return true; 1000 } 1001 1002 uint32_t 1003 SBProcess::GetNumSupportedHardwareWatchpoints(lldb::SBError &sb_error) const { 1004 LLDB_RECORD_METHOD_CONST(uint32_t, SBProcess, 1005 GetNumSupportedHardwareWatchpoints, 1006 (lldb::SBError &), sb_error); 1007 1008 uint32_t num = 0; 1009 ProcessSP process_sp(GetSP()); 1010 if (process_sp) { 1011 std::lock_guard<std::recursive_mutex> guard( 1012 process_sp->GetTarget().GetAPIMutex()); 1013 sb_error.SetError(process_sp->GetWatchpointSupportInfo(num)); 1014 } else { 1015 sb_error.SetErrorString("SBProcess is invalid"); 1016 } 1017 return num; 1018 } 1019 1020 uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec, 1021 lldb::SBError &sb_error) { 1022 LLDB_RECORD_METHOD(uint32_t, SBProcess, LoadImage, 1023 (lldb::SBFileSpec &, lldb::SBError &), 1024 sb_remote_image_spec, sb_error); 1025 1026 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error); 1027 } 1028 1029 uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec, 1030 const lldb::SBFileSpec &sb_remote_image_spec, 1031 lldb::SBError &sb_error) { 1032 LLDB_RECORD_METHOD( 1033 uint32_t, SBProcess, LoadImage, 1034 (const lldb::SBFileSpec &, const lldb::SBFileSpec &, lldb::SBError &), 1035 sb_local_image_spec, sb_remote_image_spec, sb_error); 1036 1037 ProcessSP process_sp(GetSP()); 1038 if (process_sp) { 1039 Process::StopLocker stop_locker; 1040 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1041 std::lock_guard<std::recursive_mutex> guard( 1042 process_sp->GetTarget().GetAPIMutex()); 1043 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform(); 1044 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec, 1045 *sb_remote_image_spec, sb_error.ref()); 1046 } else { 1047 sb_error.SetErrorString("process is running"); 1048 } 1049 } else { 1050 sb_error.SetErrorString("process is invalid"); 1051 } 1052 return LLDB_INVALID_IMAGE_TOKEN; 1053 } 1054 1055 uint32_t SBProcess::LoadImageUsingPaths(const lldb::SBFileSpec &image_spec, 1056 SBStringList &paths, 1057 lldb::SBFileSpec &loaded_path, 1058 lldb::SBError &error) { 1059 LLDB_RECORD_METHOD(uint32_t, SBProcess, LoadImageUsingPaths, 1060 (const lldb::SBFileSpec &, lldb::SBStringList &, 1061 lldb::SBFileSpec &, lldb::SBError &), 1062 image_spec, paths, loaded_path, error); 1063 1064 ProcessSP process_sp(GetSP()); 1065 if (process_sp) { 1066 Process::StopLocker stop_locker; 1067 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1068 std::lock_guard<std::recursive_mutex> guard( 1069 process_sp->GetTarget().GetAPIMutex()); 1070 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform(); 1071 size_t num_paths = paths.GetSize(); 1072 std::vector<std::string> paths_vec; 1073 paths_vec.reserve(num_paths); 1074 for (size_t i = 0; i < num_paths; i++) 1075 paths_vec.push_back(paths.GetStringAtIndex(i)); 1076 FileSpec loaded_spec; 1077 1078 uint32_t token = platform_sp->LoadImageUsingPaths( 1079 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec); 1080 if (token != LLDB_INVALID_IMAGE_TOKEN) 1081 loaded_path = loaded_spec; 1082 return token; 1083 } else { 1084 error.SetErrorString("process is running"); 1085 } 1086 } else { 1087 error.SetErrorString("process is invalid"); 1088 } 1089 1090 return LLDB_INVALID_IMAGE_TOKEN; 1091 } 1092 1093 lldb::SBError SBProcess::UnloadImage(uint32_t image_token) { 1094 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, UnloadImage, (uint32_t), 1095 image_token); 1096 1097 lldb::SBError sb_error; 1098 ProcessSP process_sp(GetSP()); 1099 if (process_sp) { 1100 Process::StopLocker stop_locker; 1101 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1102 std::lock_guard<std::recursive_mutex> guard( 1103 process_sp->GetTarget().GetAPIMutex()); 1104 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform(); 1105 sb_error.SetError( 1106 platform_sp->UnloadImage(process_sp.get(), image_token)); 1107 } else { 1108 sb_error.SetErrorString("process is running"); 1109 } 1110 } else 1111 sb_error.SetErrorString("invalid process"); 1112 return LLDB_RECORD_RESULT(sb_error); 1113 } 1114 1115 lldb::SBError SBProcess::SendEventData(const char *event_data) { 1116 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, SendEventData, (const char *), 1117 event_data); 1118 1119 lldb::SBError sb_error; 1120 ProcessSP process_sp(GetSP()); 1121 if (process_sp) { 1122 Process::StopLocker stop_locker; 1123 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1124 std::lock_guard<std::recursive_mutex> guard( 1125 process_sp->GetTarget().GetAPIMutex()); 1126 sb_error.SetError(process_sp->SendEventData(event_data)); 1127 } else { 1128 sb_error.SetErrorString("process is running"); 1129 } 1130 } else 1131 sb_error.SetErrorString("invalid process"); 1132 return LLDB_RECORD_RESULT(sb_error); 1133 } 1134 1135 uint32_t SBProcess::GetNumExtendedBacktraceTypes() { 1136 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumExtendedBacktraceTypes); 1137 1138 ProcessSP process_sp(GetSP()); 1139 if (process_sp && process_sp->GetSystemRuntime()) { 1140 SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1141 return runtime->GetExtendedBacktraceTypes().size(); 1142 } 1143 return 0; 1144 } 1145 1146 const char *SBProcess::GetExtendedBacktraceTypeAtIndex(uint32_t idx) { 1147 LLDB_RECORD_METHOD(const char *, SBProcess, GetExtendedBacktraceTypeAtIndex, 1148 (uint32_t), idx); 1149 1150 ProcessSP process_sp(GetSP()); 1151 if (process_sp && process_sp->GetSystemRuntime()) { 1152 SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1153 const std::vector<ConstString> &names = 1154 runtime->GetExtendedBacktraceTypes(); 1155 if (idx < names.size()) { 1156 return names[idx].AsCString(); 1157 } 1158 } 1159 return nullptr; 1160 } 1161 1162 SBThreadCollection SBProcess::GetHistoryThreads(addr_t addr) { 1163 LLDB_RECORD_METHOD(lldb::SBThreadCollection, SBProcess, GetHistoryThreads, 1164 (lldb::addr_t), addr); 1165 1166 ProcessSP process_sp(GetSP()); 1167 SBThreadCollection threads; 1168 if (process_sp) { 1169 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr)); 1170 } 1171 return LLDB_RECORD_RESULT(threads); 1172 } 1173 1174 bool SBProcess::IsInstrumentationRuntimePresent( 1175 InstrumentationRuntimeType type) { 1176 LLDB_RECORD_METHOD(bool, SBProcess, IsInstrumentationRuntimePresent, 1177 (lldb::InstrumentationRuntimeType), type); 1178 1179 ProcessSP process_sp(GetSP()); 1180 if (!process_sp) 1181 return false; 1182 1183 InstrumentationRuntimeSP runtime_sp = 1184 process_sp->GetInstrumentationRuntime(type); 1185 1186 if (!runtime_sp.get()) 1187 return false; 1188 1189 return runtime_sp->IsActive(); 1190 } 1191 1192 lldb::SBError SBProcess::SaveCore(const char *file_name) { 1193 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, SaveCore, (const char *), 1194 file_name); 1195 1196 lldb::SBError error; 1197 ProcessSP process_sp(GetSP()); 1198 if (!process_sp) { 1199 error.SetErrorString("SBProcess is invalid"); 1200 return LLDB_RECORD_RESULT(error); 1201 } 1202 1203 std::lock_guard<std::recursive_mutex> guard( 1204 process_sp->GetTarget().GetAPIMutex()); 1205 1206 if (process_sp->GetState() != eStateStopped) { 1207 error.SetErrorString("the process is not stopped"); 1208 return LLDB_RECORD_RESULT(error); 1209 } 1210 1211 FileSpec core_file(file_name); 1212 error.ref() = PluginManager::SaveCore(process_sp, core_file); 1213 return LLDB_RECORD_RESULT(error); 1214 } 1215 1216 lldb::SBError 1217 SBProcess::GetMemoryRegionInfo(lldb::addr_t load_addr, 1218 SBMemoryRegionInfo &sb_region_info) { 1219 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, GetMemoryRegionInfo, 1220 (lldb::addr_t, lldb::SBMemoryRegionInfo &), load_addr, 1221 sb_region_info); 1222 1223 lldb::SBError sb_error; 1224 ProcessSP process_sp(GetSP()); 1225 if (process_sp) { 1226 Process::StopLocker stop_locker; 1227 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1228 std::lock_guard<std::recursive_mutex> guard( 1229 process_sp->GetTarget().GetAPIMutex()); 1230 1231 sb_error.ref() = 1232 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref()); 1233 } else { 1234 sb_error.SetErrorString("process is running"); 1235 } 1236 } else { 1237 sb_error.SetErrorString("SBProcess is invalid"); 1238 } 1239 return LLDB_RECORD_RESULT(sb_error); 1240 } 1241 1242 lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() { 1243 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBMemoryRegionInfoList, SBProcess, 1244 GetMemoryRegions); 1245 1246 lldb::SBMemoryRegionInfoList sb_region_list; 1247 1248 ProcessSP process_sp(GetSP()); 1249 Process::StopLocker stop_locker; 1250 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 1251 std::lock_guard<std::recursive_mutex> guard( 1252 process_sp->GetTarget().GetAPIMutex()); 1253 1254 process_sp->GetMemoryRegions(sb_region_list.ref()); 1255 } 1256 1257 return LLDB_RECORD_RESULT(sb_region_list); 1258 } 1259 1260 lldb::SBProcessInfo SBProcess::GetProcessInfo() { 1261 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcessInfo, SBProcess, GetProcessInfo); 1262 1263 lldb::SBProcessInfo sb_proc_info; 1264 ProcessSP process_sp(GetSP()); 1265 ProcessInstanceInfo proc_info; 1266 if (process_sp && process_sp->GetProcessInfo(proc_info)) { 1267 sb_proc_info.SetProcessInfo(proc_info); 1268 } 1269 return LLDB_RECORD_RESULT(sb_proc_info); 1270 } 1271 1272 namespace lldb_private { 1273 namespace repro { 1274 1275 template <> 1276 void RegisterMethods<SBProcess>(Registry &R) { 1277 LLDB_REGISTER_CONSTRUCTOR(SBProcess, ()); 1278 LLDB_REGISTER_CONSTRUCTOR(SBProcess, (const lldb::SBProcess &)); 1279 LLDB_REGISTER_CONSTRUCTOR(SBProcess, (const lldb::ProcessSP &)); 1280 LLDB_REGISTER_METHOD(const lldb::SBProcess &, 1281 SBProcess, operator=,(const lldb::SBProcess &)); 1282 LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, 1283 GetBroadcasterClassName, ()); 1284 LLDB_REGISTER_METHOD(const char *, SBProcess, GetPluginName, ()); 1285 LLDB_REGISTER_METHOD(const char *, SBProcess, GetShortPluginName, ()); 1286 LLDB_REGISTER_METHOD(void, SBProcess, Clear, ()); 1287 LLDB_REGISTER_METHOD_CONST(bool, SBProcess, IsValid, ()); 1288 LLDB_REGISTER_METHOD_CONST(bool, SBProcess, operator bool, ()); 1289 LLDB_REGISTER_METHOD(bool, SBProcess, RemoteLaunch, 1290 (const char **, const char **, const char *, 1291 const char *, const char *, const char *, uint32_t, 1292 bool, lldb::SBError &)); 1293 LLDB_REGISTER_METHOD(bool, SBProcess, RemoteAttachToProcessWithID, 1294 (lldb::pid_t, lldb::SBError &)); 1295 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumThreads, ()); 1296 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBProcess, GetSelectedThread, 1297 ()); 1298 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, CreateOSPluginThread, 1299 (lldb::tid_t, lldb::addr_t)); 1300 LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBProcess, GetTarget, ()); 1301 LLDB_REGISTER_METHOD(size_t, SBProcess, PutSTDIN, (const char *, size_t)); 1302 LLDB_REGISTER_METHOD_CONST(size_t, SBProcess, GetSTDOUT, (char *, size_t)); 1303 LLDB_REGISTER_METHOD_CONST(size_t, SBProcess, GetSTDERR, (char *, size_t)); 1304 LLDB_REGISTER_METHOD_CONST(size_t, SBProcess, GetAsyncProfileData, 1305 (char *, size_t)); 1306 LLDB_REGISTER_METHOD(lldb::SBTrace, SBProcess, StartTrace, 1307 (lldb::SBTraceOptions &, lldb::SBError &)); 1308 LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState, 1309 (const lldb::SBEvent &, FILE *)); 1310 LLDB_REGISTER_METHOD( 1311 void, SBProcess, AppendEventStateReport, 1312 (const lldb::SBEvent &, lldb::SBCommandReturnObject &)); 1313 LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThread, 1314 (const lldb::SBThread &)); 1315 LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThreadByID, (lldb::tid_t)); 1316 LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThreadByIndexID, 1317 (uint32_t)); 1318 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadAtIndex, (size_t)); 1319 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumQueues, ()); 1320 LLDB_REGISTER_METHOD(lldb::SBQueue, SBProcess, GetQueueAtIndex, (size_t)); 1321 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetStopID, (bool)); 1322 LLDB_REGISTER_METHOD(lldb::SBEvent, SBProcess, GetStopEventForStopID, 1323 (uint32_t)); 1324 LLDB_REGISTER_METHOD(lldb::StateType, SBProcess, GetState, ()); 1325 LLDB_REGISTER_METHOD(int, SBProcess, GetExitStatus, ()); 1326 LLDB_REGISTER_METHOD(const char *, SBProcess, GetExitDescription, ()); 1327 LLDB_REGISTER_METHOD(lldb::pid_t, SBProcess, GetProcessID, ()); 1328 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetUniqueID, ()); 1329 LLDB_REGISTER_METHOD_CONST(lldb::ByteOrder, SBProcess, GetByteOrder, ()); 1330 LLDB_REGISTER_METHOD_CONST(uint32_t, SBProcess, GetAddressByteSize, ()); 1331 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Continue, ()); 1332 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Destroy, ()); 1333 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Stop, ()); 1334 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Kill, ()); 1335 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Detach, ()); 1336 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Detach, (bool)); 1337 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Signal, (int)); 1338 LLDB_REGISTER_METHOD(lldb::SBUnixSignals, SBProcess, GetUnixSignals, ()); 1339 LLDB_REGISTER_METHOD(void, SBProcess, SendAsyncInterrupt, ()); 1340 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadByID, 1341 (lldb::tid_t)); 1342 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadByIndexID, 1343 (uint32_t)); 1344 LLDB_REGISTER_STATIC_METHOD(lldb::StateType, SBProcess, GetStateFromEvent, 1345 (const lldb::SBEvent &)); 1346 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, GetRestartedFromEvent, 1347 (const lldb::SBEvent &)); 1348 LLDB_REGISTER_STATIC_METHOD(size_t, SBProcess, 1349 GetNumRestartedReasonsFromEvent, 1350 (const lldb::SBEvent &)); 1351 LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, 1352 GetRestartedReasonAtIndexFromEvent, 1353 (const lldb::SBEvent &, size_t)); 1354 LLDB_REGISTER_STATIC_METHOD(lldb::SBProcess, SBProcess, GetProcessFromEvent, 1355 (const lldb::SBEvent &)); 1356 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, GetInterruptedFromEvent, 1357 (const lldb::SBEvent &)); 1358 LLDB_REGISTER_STATIC_METHOD(lldb::SBStructuredData, SBProcess, 1359 GetStructuredDataFromEvent, 1360 (const lldb::SBEvent &)); 1361 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, EventIsProcessEvent, 1362 (const lldb::SBEvent &)); 1363 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, EventIsStructuredDataEvent, 1364 (const lldb::SBEvent &)); 1365 LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBProcess, GetBroadcaster, 1366 ()); 1367 LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, GetBroadcasterClass, 1368 ()); 1369 LLDB_REGISTER_METHOD(uint64_t, SBProcess, ReadUnsignedFromMemory, 1370 (lldb::addr_t, uint32_t, lldb::SBError &)); 1371 LLDB_REGISTER_METHOD(lldb::addr_t, SBProcess, ReadPointerFromMemory, 1372 (lldb::addr_t, lldb::SBError &)); 1373 LLDB_REGISTER_METHOD(bool, SBProcess, GetDescription, (lldb::SBStream &)); 1374 LLDB_REGISTER_METHOD_CONST(uint32_t, SBProcess, 1375 GetNumSupportedHardwareWatchpoints, 1376 (lldb::SBError &)); 1377 LLDB_REGISTER_METHOD(uint32_t, SBProcess, LoadImage, 1378 (lldb::SBFileSpec &, lldb::SBError &)); 1379 LLDB_REGISTER_METHOD( 1380 uint32_t, SBProcess, LoadImage, 1381 (const lldb::SBFileSpec &, const lldb::SBFileSpec &, lldb::SBError &)); 1382 LLDB_REGISTER_METHOD(uint32_t, SBProcess, LoadImageUsingPaths, 1383 (const lldb::SBFileSpec &, lldb::SBStringList &, 1384 lldb::SBFileSpec &, lldb::SBError &)); 1385 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, UnloadImage, (uint32_t)); 1386 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, SendEventData, 1387 (const char *)); 1388 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumExtendedBacktraceTypes, ()); 1389 LLDB_REGISTER_METHOD(const char *, SBProcess, 1390 GetExtendedBacktraceTypeAtIndex, (uint32_t)); 1391 LLDB_REGISTER_METHOD(lldb::SBThreadCollection, SBProcess, GetHistoryThreads, 1392 (lldb::addr_t)); 1393 LLDB_REGISTER_METHOD(bool, SBProcess, IsInstrumentationRuntimePresent, 1394 (lldb::InstrumentationRuntimeType)); 1395 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, SaveCore, (const char *)); 1396 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, GetMemoryRegionInfo, 1397 (lldb::addr_t, lldb::SBMemoryRegionInfo &)); 1398 LLDB_REGISTER_METHOD(lldb::SBMemoryRegionInfoList, SBProcess, 1399 GetMemoryRegions, ()); 1400 LLDB_REGISTER_METHOD(lldb::SBProcessInfo, SBProcess, GetProcessInfo, ()); 1401 } 1402 1403 } 1404 } 1405