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 #include "lldb/API/SBBroadcaster.h" 33 #include "lldb/API/SBCommandReturnObject.h" 34 #include "lldb/API/SBDebugger.h" 35 #include "lldb/API/SBEvent.h" 36 #include "lldb/API/SBFile.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, SBFile out) const { 335 LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState, 336 (const SBEvent &, SBFile), event, out); 337 338 return ReportEventState(event, out.m_opaque_sp); 339 } 340 341 void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const { 342 LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState, 343 (const lldb::SBEvent &, FILE *), event, out); 344 FileSP outfile = std::make_shared<NativeFile>(out, false); 345 return ReportEventState(event, outfile); 346 } 347 348 void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const { 349 350 LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState, 351 (const SBEvent &, FileSP), event, out); 352 353 if (!out || !out->IsValid()) 354 return; 355 356 ProcessSP process_sp(GetSP()); 357 if (process_sp) { 358 StreamFile stream(out); 359 const StateType event_state = SBProcess::GetStateFromEvent(event); 360 stream.Printf("Process %" PRIu64 " %s\n", 361 process_sp->GetID(), SBDebugger::StateAsCString(event_state)); 362 } 363 } 364 365 void SBProcess::AppendEventStateReport(const SBEvent &event, 366 SBCommandReturnObject &result) { 367 LLDB_RECORD_METHOD(void, SBProcess, AppendEventStateReport, 368 (const lldb::SBEvent &, lldb::SBCommandReturnObject &), 369 event, result); 370 371 ProcessSP process_sp(GetSP()); 372 if (process_sp) { 373 const StateType event_state = SBProcess::GetStateFromEvent(event); 374 char message[1024]; 375 ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n", 376 process_sp->GetID(), SBDebugger::StateAsCString(event_state)); 377 378 result.AppendMessage(message); 379 } 380 } 381 382 bool SBProcess::SetSelectedThread(const SBThread &thread) { 383 LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThread, 384 (const lldb::SBThread &), thread); 385 386 ProcessSP process_sp(GetSP()); 387 if (process_sp) { 388 std::lock_guard<std::recursive_mutex> guard( 389 process_sp->GetTarget().GetAPIMutex()); 390 return process_sp->GetThreadList().SetSelectedThreadByID( 391 thread.GetThreadID()); 392 } 393 return false; 394 } 395 396 bool SBProcess::SetSelectedThreadByID(lldb::tid_t tid) { 397 LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThreadByID, (lldb::tid_t), 398 tid); 399 400 401 bool ret_val = false; 402 ProcessSP process_sp(GetSP()); 403 if (process_sp) { 404 std::lock_guard<std::recursive_mutex> guard( 405 process_sp->GetTarget().GetAPIMutex()); 406 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid); 407 } 408 409 return ret_val; 410 } 411 412 bool SBProcess::SetSelectedThreadByIndexID(uint32_t index_id) { 413 LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThreadByIndexID, (uint32_t), 414 index_id); 415 416 bool ret_val = false; 417 ProcessSP process_sp(GetSP()); 418 if (process_sp) { 419 std::lock_guard<std::recursive_mutex> guard( 420 process_sp->GetTarget().GetAPIMutex()); 421 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id); 422 } 423 424 425 return ret_val; 426 } 427 428 SBThread SBProcess::GetThreadAtIndex(size_t index) { 429 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadAtIndex, (size_t), 430 index); 431 432 SBThread sb_thread; 433 ThreadSP thread_sp; 434 ProcessSP process_sp(GetSP()); 435 if (process_sp) { 436 Process::StopLocker stop_locker; 437 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 438 std::lock_guard<std::recursive_mutex> guard( 439 process_sp->GetTarget().GetAPIMutex()); 440 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update); 441 sb_thread.SetThread(thread_sp); 442 } 443 444 return LLDB_RECORD_RESULT(sb_thread); 445 } 446 447 uint32_t SBProcess::GetNumQueues() { 448 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumQueues); 449 450 uint32_t num_queues = 0; 451 ProcessSP process_sp(GetSP()); 452 if (process_sp) { 453 Process::StopLocker stop_locker; 454 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 455 std::lock_guard<std::recursive_mutex> guard( 456 process_sp->GetTarget().GetAPIMutex()); 457 num_queues = process_sp->GetQueueList().GetSize(); 458 } 459 } 460 461 return num_queues; 462 } 463 464 SBQueue SBProcess::GetQueueAtIndex(size_t index) { 465 LLDB_RECORD_METHOD(lldb::SBQueue, SBProcess, GetQueueAtIndex, (size_t), 466 index); 467 468 SBQueue sb_queue; 469 QueueSP queue_sp; 470 ProcessSP process_sp(GetSP()); 471 if (process_sp) { 472 Process::StopLocker stop_locker; 473 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 474 std::lock_guard<std::recursive_mutex> guard( 475 process_sp->GetTarget().GetAPIMutex()); 476 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index); 477 sb_queue.SetQueue(queue_sp); 478 } 479 } 480 481 return LLDB_RECORD_RESULT(sb_queue); 482 } 483 484 uint32_t SBProcess::GetStopID(bool include_expression_stops) { 485 LLDB_RECORD_METHOD(uint32_t, SBProcess, GetStopID, (bool), 486 include_expression_stops); 487 488 ProcessSP process_sp(GetSP()); 489 if (process_sp) { 490 std::lock_guard<std::recursive_mutex> guard( 491 process_sp->GetTarget().GetAPIMutex()); 492 if (include_expression_stops) 493 return process_sp->GetStopID(); 494 else 495 return process_sp->GetLastNaturalStopID(); 496 } 497 return 0; 498 } 499 500 SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) { 501 LLDB_RECORD_METHOD(lldb::SBEvent, SBProcess, GetStopEventForStopID, 502 (uint32_t), stop_id); 503 504 SBEvent sb_event; 505 EventSP event_sp; 506 ProcessSP process_sp(GetSP()); 507 if (process_sp) { 508 std::lock_guard<std::recursive_mutex> guard( 509 process_sp->GetTarget().GetAPIMutex()); 510 event_sp = process_sp->GetStopEventForStopID(stop_id); 511 sb_event.reset(event_sp); 512 } 513 514 return LLDB_RECORD_RESULT(sb_event); 515 } 516 517 StateType SBProcess::GetState() { 518 LLDB_RECORD_METHOD_NO_ARGS(lldb::StateType, SBProcess, GetState); 519 520 StateType ret_val = eStateInvalid; 521 ProcessSP process_sp(GetSP()); 522 if (process_sp) { 523 std::lock_guard<std::recursive_mutex> guard( 524 process_sp->GetTarget().GetAPIMutex()); 525 ret_val = process_sp->GetState(); 526 } 527 528 return ret_val; 529 } 530 531 int SBProcess::GetExitStatus() { 532 LLDB_RECORD_METHOD_NO_ARGS(int, SBProcess, GetExitStatus); 533 534 int exit_status = 0; 535 ProcessSP process_sp(GetSP()); 536 if (process_sp) { 537 std::lock_guard<std::recursive_mutex> guard( 538 process_sp->GetTarget().GetAPIMutex()); 539 exit_status = process_sp->GetExitStatus(); 540 } 541 542 return exit_status; 543 } 544 545 const char *SBProcess::GetExitDescription() { 546 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetExitDescription); 547 548 const char *exit_desc = nullptr; 549 ProcessSP process_sp(GetSP()); 550 if (process_sp) { 551 std::lock_guard<std::recursive_mutex> guard( 552 process_sp->GetTarget().GetAPIMutex()); 553 exit_desc = process_sp->GetExitDescription(); 554 } 555 return exit_desc; 556 } 557 558 lldb::pid_t SBProcess::GetProcessID() { 559 LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcess, GetProcessID); 560 561 lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; 562 ProcessSP process_sp(GetSP()); 563 if (process_sp) 564 ret_val = process_sp->GetID(); 565 566 return ret_val; 567 } 568 569 uint32_t SBProcess::GetUniqueID() { 570 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetUniqueID); 571 572 uint32_t ret_val = 0; 573 ProcessSP process_sp(GetSP()); 574 if (process_sp) 575 ret_val = process_sp->GetUniqueID(); 576 return ret_val; 577 } 578 579 ByteOrder SBProcess::GetByteOrder() const { 580 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ByteOrder, SBProcess, GetByteOrder); 581 582 ByteOrder byteOrder = eByteOrderInvalid; 583 ProcessSP process_sp(GetSP()); 584 if (process_sp) 585 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); 586 587 588 return byteOrder; 589 } 590 591 uint32_t SBProcess::GetAddressByteSize() const { 592 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBProcess, GetAddressByteSize); 593 594 uint32_t size = 0; 595 ProcessSP process_sp(GetSP()); 596 if (process_sp) 597 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); 598 599 600 return size; 601 } 602 603 SBError SBProcess::Continue() { 604 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Continue); 605 606 SBError sb_error; 607 ProcessSP process_sp(GetSP()); 608 609 if (process_sp) { 610 std::lock_guard<std::recursive_mutex> guard( 611 process_sp->GetTarget().GetAPIMutex()); 612 613 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution()) 614 sb_error.ref() = process_sp->Resume(); 615 else 616 sb_error.ref() = process_sp->ResumeSynchronous(nullptr); 617 } else 618 sb_error.SetErrorString("SBProcess is invalid"); 619 620 return LLDB_RECORD_RESULT(sb_error); 621 } 622 623 SBError SBProcess::Destroy() { 624 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Destroy); 625 626 SBError sb_error; 627 ProcessSP process_sp(GetSP()); 628 if (process_sp) { 629 std::lock_guard<std::recursive_mutex> guard( 630 process_sp->GetTarget().GetAPIMutex()); 631 sb_error.SetError(process_sp->Destroy(false)); 632 } else 633 sb_error.SetErrorString("SBProcess is invalid"); 634 635 return LLDB_RECORD_RESULT(sb_error); 636 } 637 638 SBError SBProcess::Stop() { 639 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Stop); 640 641 SBError sb_error; 642 ProcessSP process_sp(GetSP()); 643 if (process_sp) { 644 std::lock_guard<std::recursive_mutex> guard( 645 process_sp->GetTarget().GetAPIMutex()); 646 sb_error.SetError(process_sp->Halt()); 647 } else 648 sb_error.SetErrorString("SBProcess is invalid"); 649 650 return LLDB_RECORD_RESULT(sb_error); 651 } 652 653 SBError SBProcess::Kill() { 654 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Kill); 655 656 SBError sb_error; 657 ProcessSP process_sp(GetSP()); 658 if (process_sp) { 659 std::lock_guard<std::recursive_mutex> guard( 660 process_sp->GetTarget().GetAPIMutex()); 661 sb_error.SetError(process_sp->Destroy(true)); 662 } else 663 sb_error.SetErrorString("SBProcess is invalid"); 664 665 return LLDB_RECORD_RESULT(sb_error); 666 } 667 668 SBError SBProcess::Detach() { 669 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Detach); 670 671 // FIXME: This should come from a process default. 672 bool keep_stopped = false; 673 return LLDB_RECORD_RESULT(Detach(keep_stopped)); 674 } 675 676 SBError SBProcess::Detach(bool keep_stopped) { 677 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, Detach, (bool), keep_stopped); 678 679 SBError sb_error; 680 ProcessSP process_sp(GetSP()); 681 if (process_sp) { 682 std::lock_guard<std::recursive_mutex> guard( 683 process_sp->GetTarget().GetAPIMutex()); 684 sb_error.SetError(process_sp->Detach(keep_stopped)); 685 } else 686 sb_error.SetErrorString("SBProcess is invalid"); 687 688 return LLDB_RECORD_RESULT(sb_error); 689 } 690 691 SBError SBProcess::Signal(int signo) { 692 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, Signal, (int), signo); 693 694 SBError sb_error; 695 ProcessSP process_sp(GetSP()); 696 if (process_sp) { 697 std::lock_guard<std::recursive_mutex> guard( 698 process_sp->GetTarget().GetAPIMutex()); 699 sb_error.SetError(process_sp->Signal(signo)); 700 } else 701 sb_error.SetErrorString("SBProcess is invalid"); 702 703 return LLDB_RECORD_RESULT(sb_error); 704 } 705 706 SBUnixSignals SBProcess::GetUnixSignals() { 707 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBUnixSignals, SBProcess, GetUnixSignals); 708 709 if (auto process_sp = GetSP()) 710 return LLDB_RECORD_RESULT(SBUnixSignals{process_sp}); 711 712 return LLDB_RECORD_RESULT(SBUnixSignals{}); 713 } 714 715 void SBProcess::SendAsyncInterrupt() { 716 LLDB_RECORD_METHOD_NO_ARGS(void, SBProcess, SendAsyncInterrupt); 717 718 ProcessSP process_sp(GetSP()); 719 if (process_sp) { 720 process_sp->SendAsyncInterrupt(); 721 } 722 } 723 724 SBThread SBProcess::GetThreadByID(tid_t tid) { 725 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadByID, (lldb::tid_t), 726 tid); 727 728 SBThread sb_thread; 729 ThreadSP thread_sp; 730 ProcessSP process_sp(GetSP()); 731 if (process_sp) { 732 Process::StopLocker stop_locker; 733 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 734 std::lock_guard<std::recursive_mutex> guard( 735 process_sp->GetTarget().GetAPIMutex()); 736 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update); 737 sb_thread.SetThread(thread_sp); 738 } 739 740 return LLDB_RECORD_RESULT(sb_thread); 741 } 742 743 SBThread SBProcess::GetThreadByIndexID(uint32_t index_id) { 744 LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadByIndexID, (uint32_t), 745 index_id); 746 747 SBThread sb_thread; 748 ThreadSP thread_sp; 749 ProcessSP process_sp(GetSP()); 750 if (process_sp) { 751 Process::StopLocker stop_locker; 752 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock()); 753 std::lock_guard<std::recursive_mutex> guard( 754 process_sp->GetTarget().GetAPIMutex()); 755 thread_sp = 756 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update); 757 sb_thread.SetThread(thread_sp); 758 } 759 760 return LLDB_RECORD_RESULT(sb_thread); 761 } 762 763 StateType SBProcess::GetStateFromEvent(const SBEvent &event) { 764 LLDB_RECORD_STATIC_METHOD(lldb::StateType, SBProcess, GetStateFromEvent, 765 (const lldb::SBEvent &), event); 766 767 StateType ret_val = Process::ProcessEventData::GetStateFromEvent(event.get()); 768 769 return ret_val; 770 } 771 772 bool SBProcess::GetRestartedFromEvent(const SBEvent &event) { 773 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, GetRestartedFromEvent, 774 (const lldb::SBEvent &), event); 775 776 bool ret_val = Process::ProcessEventData::GetRestartedFromEvent(event.get()); 777 778 return ret_val; 779 } 780 781 size_t SBProcess::GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event) { 782 LLDB_RECORD_STATIC_METHOD(size_t, SBProcess, GetNumRestartedReasonsFromEvent, 783 (const lldb::SBEvent &), event); 784 785 return Process::ProcessEventData::GetNumRestartedReasons(event.get()); 786 } 787 788 const char * 789 SBProcess::GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, 790 size_t idx) { 791 LLDB_RECORD_STATIC_METHOD(const char *, SBProcess, 792 GetRestartedReasonAtIndexFromEvent, 793 (const lldb::SBEvent &, size_t), event, idx); 794 795 return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx); 796 } 797 798 SBProcess SBProcess::GetProcessFromEvent(const SBEvent &event) { 799 LLDB_RECORD_STATIC_METHOD(lldb::SBProcess, SBProcess, GetProcessFromEvent, 800 (const lldb::SBEvent &), event); 801 802 ProcessSP process_sp = 803 Process::ProcessEventData::GetProcessFromEvent(event.get()); 804 if (!process_sp) { 805 // StructuredData events also know the process they come from. Try that. 806 process_sp = EventDataStructuredData::GetProcessFromEvent(event.get()); 807 } 808 809 return LLDB_RECORD_RESULT(SBProcess(process_sp)); 810 } 811 812 bool SBProcess::GetInterruptedFromEvent(const SBEvent &event) { 813 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, GetInterruptedFromEvent, 814 (const lldb::SBEvent &), event); 815 816 return Process::ProcessEventData::GetInterruptedFromEvent(event.get()); 817 } 818 819 lldb::SBStructuredData 820 SBProcess::GetStructuredDataFromEvent(const lldb::SBEvent &event) { 821 LLDB_RECORD_STATIC_METHOD(lldb::SBStructuredData, SBProcess, 822 GetStructuredDataFromEvent, (const lldb::SBEvent &), 823 event); 824 825 return LLDB_RECORD_RESULT(SBStructuredData(event.GetSP())); 826 } 827 828 bool SBProcess::EventIsProcessEvent(const SBEvent &event) { 829 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, EventIsProcessEvent, 830 (const lldb::SBEvent &), event); 831 832 return (event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass()) && 833 !EventIsStructuredDataEvent(event); 834 } 835 836 bool SBProcess::EventIsStructuredDataEvent(const lldb::SBEvent &event) { 837 LLDB_RECORD_STATIC_METHOD(bool, SBProcess, EventIsStructuredDataEvent, 838 (const lldb::SBEvent &), event); 839 840 EventSP event_sp = event.GetSP(); 841 EventData *event_data = event_sp ? event_sp->GetData() : nullptr; 842 return event_data && (event_data->GetFlavor() == 843 EventDataStructuredData::GetFlavorString()); 844 } 845 846 SBBroadcaster SBProcess::GetBroadcaster() const { 847 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBProcess, 848 GetBroadcaster); 849 850 851 ProcessSP process_sp(GetSP()); 852 853 SBBroadcaster broadcaster(process_sp.get(), false); 854 855 856 return LLDB_RECORD_RESULT(broadcaster); 857 } 858 859 const char *SBProcess::GetBroadcasterClass() { 860 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBProcess, 861 GetBroadcasterClass); 862 863 return Process::GetStaticBroadcasterClass().AsCString(); 864 } 865 866 size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len, 867 SBError &sb_error) { 868 LLDB_RECORD_DUMMY(size_t, SBProcess, ReadMemory, 869 (lldb::addr_t, void *, size_t, lldb::SBError &), addr, dst, 870 dst_len, sb_error); 871 872 size_t bytes_read = 0; 873 874 ProcessSP process_sp(GetSP()); 875 876 877 if (process_sp) { 878 Process::StopLocker stop_locker; 879 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 880 std::lock_guard<std::recursive_mutex> guard( 881 process_sp->GetTarget().GetAPIMutex()); 882 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref()); 883 } else { 884 sb_error.SetErrorString("process is running"); 885 } 886 } else { 887 sb_error.SetErrorString("SBProcess is invalid"); 888 } 889 890 return bytes_read; 891 } 892 893 size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size, 894 lldb::SBError &sb_error) { 895 LLDB_RECORD_DUMMY(size_t, SBProcess, ReadCStringFromMemory, 896 (lldb::addr_t, void *, size_t, lldb::SBError &), addr, buf, 897 size, sb_error); 898 899 size_t bytes_read = 0; 900 ProcessSP process_sp(GetSP()); 901 if (process_sp) { 902 Process::StopLocker stop_locker; 903 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 904 std::lock_guard<std::recursive_mutex> guard( 905 process_sp->GetTarget().GetAPIMutex()); 906 bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size, 907 sb_error.ref()); 908 } else { 909 sb_error.SetErrorString("process is running"); 910 } 911 } else { 912 sb_error.SetErrorString("SBProcess is invalid"); 913 } 914 return bytes_read; 915 } 916 917 uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size, 918 lldb::SBError &sb_error) { 919 LLDB_RECORD_METHOD(uint64_t, SBProcess, ReadUnsignedFromMemory, 920 (lldb::addr_t, uint32_t, lldb::SBError &), addr, byte_size, 921 sb_error); 922 923 uint64_t value = 0; 924 ProcessSP process_sp(GetSP()); 925 if (process_sp) { 926 Process::StopLocker stop_locker; 927 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 928 std::lock_guard<std::recursive_mutex> guard( 929 process_sp->GetTarget().GetAPIMutex()); 930 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0, 931 sb_error.ref()); 932 } else { 933 sb_error.SetErrorString("process is running"); 934 } 935 } else { 936 sb_error.SetErrorString("SBProcess is invalid"); 937 } 938 return value; 939 } 940 941 lldb::addr_t SBProcess::ReadPointerFromMemory(addr_t addr, 942 lldb::SBError &sb_error) { 943 LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, ReadPointerFromMemory, 944 (lldb::addr_t, lldb::SBError &), addr, sb_error); 945 946 lldb::addr_t ptr = LLDB_INVALID_ADDRESS; 947 ProcessSP process_sp(GetSP()); 948 if (process_sp) { 949 Process::StopLocker stop_locker; 950 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 951 std::lock_guard<std::recursive_mutex> guard( 952 process_sp->GetTarget().GetAPIMutex()); 953 ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref()); 954 } else { 955 sb_error.SetErrorString("process is running"); 956 } 957 } else { 958 sb_error.SetErrorString("SBProcess is invalid"); 959 } 960 return ptr; 961 } 962 963 size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len, 964 SBError &sb_error) { 965 LLDB_RECORD_DUMMY(size_t, SBProcess, WriteMemory, 966 (lldb::addr_t, const void *, size_t, lldb::SBError &), addr, 967 src, src_len, sb_error); 968 969 size_t bytes_written = 0; 970 971 ProcessSP process_sp(GetSP()); 972 973 if (process_sp) { 974 Process::StopLocker stop_locker; 975 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 976 std::lock_guard<std::recursive_mutex> guard( 977 process_sp->GetTarget().GetAPIMutex()); 978 bytes_written = 979 process_sp->WriteMemory(addr, src, src_len, sb_error.ref()); 980 } else { 981 sb_error.SetErrorString("process is running"); 982 } 983 } 984 985 return bytes_written; 986 } 987 988 bool SBProcess::GetDescription(SBStream &description) { 989 LLDB_RECORD_METHOD(bool, SBProcess, GetDescription, (lldb::SBStream &), 990 description); 991 992 Stream &strm = description.ref(); 993 994 ProcessSP process_sp(GetSP()); 995 if (process_sp) { 996 char path[PATH_MAX]; 997 GetTarget().GetExecutable().GetPath(path, sizeof(path)); 998 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); 999 const char *exe_name = nullptr; 1000 if (exe_module) 1001 exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); 1002 1003 strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s", 1004 process_sp->GetID(), lldb_private::StateAsCString(GetState()), 1005 GetNumThreads(), exe_name ? ", executable = " : "", 1006 exe_name ? exe_name : ""); 1007 } else 1008 strm.PutCString("No value"); 1009 1010 return true; 1011 } 1012 1013 uint32_t 1014 SBProcess::GetNumSupportedHardwareWatchpoints(lldb::SBError &sb_error) const { 1015 LLDB_RECORD_METHOD_CONST(uint32_t, SBProcess, 1016 GetNumSupportedHardwareWatchpoints, 1017 (lldb::SBError &), sb_error); 1018 1019 uint32_t num = 0; 1020 ProcessSP process_sp(GetSP()); 1021 if (process_sp) { 1022 std::lock_guard<std::recursive_mutex> guard( 1023 process_sp->GetTarget().GetAPIMutex()); 1024 sb_error.SetError(process_sp->GetWatchpointSupportInfo(num)); 1025 } else { 1026 sb_error.SetErrorString("SBProcess is invalid"); 1027 } 1028 return num; 1029 } 1030 1031 uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec, 1032 lldb::SBError &sb_error) { 1033 LLDB_RECORD_METHOD(uint32_t, SBProcess, LoadImage, 1034 (lldb::SBFileSpec &, lldb::SBError &), 1035 sb_remote_image_spec, sb_error); 1036 1037 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error); 1038 } 1039 1040 uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec, 1041 const lldb::SBFileSpec &sb_remote_image_spec, 1042 lldb::SBError &sb_error) { 1043 LLDB_RECORD_METHOD( 1044 uint32_t, SBProcess, LoadImage, 1045 (const lldb::SBFileSpec &, const lldb::SBFileSpec &, lldb::SBError &), 1046 sb_local_image_spec, sb_remote_image_spec, sb_error); 1047 1048 ProcessSP process_sp(GetSP()); 1049 if (process_sp) { 1050 Process::StopLocker stop_locker; 1051 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1052 std::lock_guard<std::recursive_mutex> guard( 1053 process_sp->GetTarget().GetAPIMutex()); 1054 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform(); 1055 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec, 1056 *sb_remote_image_spec, sb_error.ref()); 1057 } else { 1058 sb_error.SetErrorString("process is running"); 1059 } 1060 } else { 1061 sb_error.SetErrorString("process is invalid"); 1062 } 1063 return LLDB_INVALID_IMAGE_TOKEN; 1064 } 1065 1066 uint32_t SBProcess::LoadImageUsingPaths(const lldb::SBFileSpec &image_spec, 1067 SBStringList &paths, 1068 lldb::SBFileSpec &loaded_path, 1069 lldb::SBError &error) { 1070 LLDB_RECORD_METHOD(uint32_t, SBProcess, LoadImageUsingPaths, 1071 (const lldb::SBFileSpec &, lldb::SBStringList &, 1072 lldb::SBFileSpec &, lldb::SBError &), 1073 image_spec, paths, loaded_path, error); 1074 1075 ProcessSP process_sp(GetSP()); 1076 if (process_sp) { 1077 Process::StopLocker stop_locker; 1078 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1079 std::lock_guard<std::recursive_mutex> guard( 1080 process_sp->GetTarget().GetAPIMutex()); 1081 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform(); 1082 size_t num_paths = paths.GetSize(); 1083 std::vector<std::string> paths_vec; 1084 paths_vec.reserve(num_paths); 1085 for (size_t i = 0; i < num_paths; i++) 1086 paths_vec.push_back(paths.GetStringAtIndex(i)); 1087 FileSpec loaded_spec; 1088 1089 uint32_t token = platform_sp->LoadImageUsingPaths( 1090 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec); 1091 if (token != LLDB_INVALID_IMAGE_TOKEN) 1092 loaded_path = loaded_spec; 1093 return token; 1094 } else { 1095 error.SetErrorString("process is running"); 1096 } 1097 } else { 1098 error.SetErrorString("process is invalid"); 1099 } 1100 1101 return LLDB_INVALID_IMAGE_TOKEN; 1102 } 1103 1104 lldb::SBError SBProcess::UnloadImage(uint32_t image_token) { 1105 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, UnloadImage, (uint32_t), 1106 image_token); 1107 1108 lldb::SBError sb_error; 1109 ProcessSP process_sp(GetSP()); 1110 if (process_sp) { 1111 Process::StopLocker stop_locker; 1112 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1113 std::lock_guard<std::recursive_mutex> guard( 1114 process_sp->GetTarget().GetAPIMutex()); 1115 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform(); 1116 sb_error.SetError( 1117 platform_sp->UnloadImage(process_sp.get(), image_token)); 1118 } else { 1119 sb_error.SetErrorString("process is running"); 1120 } 1121 } else 1122 sb_error.SetErrorString("invalid process"); 1123 return LLDB_RECORD_RESULT(sb_error); 1124 } 1125 1126 lldb::SBError SBProcess::SendEventData(const char *event_data) { 1127 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, SendEventData, (const char *), 1128 event_data); 1129 1130 lldb::SBError sb_error; 1131 ProcessSP process_sp(GetSP()); 1132 if (process_sp) { 1133 Process::StopLocker stop_locker; 1134 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1135 std::lock_guard<std::recursive_mutex> guard( 1136 process_sp->GetTarget().GetAPIMutex()); 1137 sb_error.SetError(process_sp->SendEventData(event_data)); 1138 } else { 1139 sb_error.SetErrorString("process is running"); 1140 } 1141 } else 1142 sb_error.SetErrorString("invalid process"); 1143 return LLDB_RECORD_RESULT(sb_error); 1144 } 1145 1146 uint32_t SBProcess::GetNumExtendedBacktraceTypes() { 1147 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumExtendedBacktraceTypes); 1148 1149 ProcessSP process_sp(GetSP()); 1150 if (process_sp && process_sp->GetSystemRuntime()) { 1151 SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1152 return runtime->GetExtendedBacktraceTypes().size(); 1153 } 1154 return 0; 1155 } 1156 1157 const char *SBProcess::GetExtendedBacktraceTypeAtIndex(uint32_t idx) { 1158 LLDB_RECORD_METHOD(const char *, SBProcess, GetExtendedBacktraceTypeAtIndex, 1159 (uint32_t), idx); 1160 1161 ProcessSP process_sp(GetSP()); 1162 if (process_sp && process_sp->GetSystemRuntime()) { 1163 SystemRuntime *runtime = process_sp->GetSystemRuntime(); 1164 const std::vector<ConstString> &names = 1165 runtime->GetExtendedBacktraceTypes(); 1166 if (idx < names.size()) { 1167 return names[idx].AsCString(); 1168 } 1169 } 1170 return nullptr; 1171 } 1172 1173 SBThreadCollection SBProcess::GetHistoryThreads(addr_t addr) { 1174 LLDB_RECORD_METHOD(lldb::SBThreadCollection, SBProcess, GetHistoryThreads, 1175 (lldb::addr_t), addr); 1176 1177 ProcessSP process_sp(GetSP()); 1178 SBThreadCollection threads; 1179 if (process_sp) { 1180 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr)); 1181 } 1182 return LLDB_RECORD_RESULT(threads); 1183 } 1184 1185 bool SBProcess::IsInstrumentationRuntimePresent( 1186 InstrumentationRuntimeType type) { 1187 LLDB_RECORD_METHOD(bool, SBProcess, IsInstrumentationRuntimePresent, 1188 (lldb::InstrumentationRuntimeType), type); 1189 1190 ProcessSP process_sp(GetSP()); 1191 if (!process_sp) 1192 return false; 1193 1194 std::lock_guard<std::recursive_mutex> guard( 1195 process_sp->GetTarget().GetAPIMutex()); 1196 1197 InstrumentationRuntimeSP runtime_sp = 1198 process_sp->GetInstrumentationRuntime(type); 1199 1200 if (!runtime_sp.get()) 1201 return false; 1202 1203 return runtime_sp->IsActive(); 1204 } 1205 1206 lldb::SBError SBProcess::SaveCore(const char *file_name) { 1207 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, SaveCore, (const char *), 1208 file_name); 1209 1210 lldb::SBError error; 1211 ProcessSP process_sp(GetSP()); 1212 if (!process_sp) { 1213 error.SetErrorString("SBProcess is invalid"); 1214 return LLDB_RECORD_RESULT(error); 1215 } 1216 1217 std::lock_guard<std::recursive_mutex> guard( 1218 process_sp->GetTarget().GetAPIMutex()); 1219 1220 if (process_sp->GetState() != eStateStopped) { 1221 error.SetErrorString("the process is not stopped"); 1222 return LLDB_RECORD_RESULT(error); 1223 } 1224 1225 FileSpec core_file(file_name); 1226 error.ref() = PluginManager::SaveCore(process_sp, core_file); 1227 return LLDB_RECORD_RESULT(error); 1228 } 1229 1230 lldb::SBError 1231 SBProcess::GetMemoryRegionInfo(lldb::addr_t load_addr, 1232 SBMemoryRegionInfo &sb_region_info) { 1233 LLDB_RECORD_METHOD(lldb::SBError, SBProcess, GetMemoryRegionInfo, 1234 (lldb::addr_t, lldb::SBMemoryRegionInfo &), load_addr, 1235 sb_region_info); 1236 1237 lldb::SBError sb_error; 1238 ProcessSP process_sp(GetSP()); 1239 if (process_sp) { 1240 Process::StopLocker stop_locker; 1241 if (stop_locker.TryLock(&process_sp->GetRunLock())) { 1242 std::lock_guard<std::recursive_mutex> guard( 1243 process_sp->GetTarget().GetAPIMutex()); 1244 1245 sb_error.ref() = 1246 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref()); 1247 } else { 1248 sb_error.SetErrorString("process is running"); 1249 } 1250 } else { 1251 sb_error.SetErrorString("SBProcess is invalid"); 1252 } 1253 return LLDB_RECORD_RESULT(sb_error); 1254 } 1255 1256 lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() { 1257 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBMemoryRegionInfoList, SBProcess, 1258 GetMemoryRegions); 1259 1260 lldb::SBMemoryRegionInfoList sb_region_list; 1261 1262 ProcessSP process_sp(GetSP()); 1263 Process::StopLocker stop_locker; 1264 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) { 1265 std::lock_guard<std::recursive_mutex> guard( 1266 process_sp->GetTarget().GetAPIMutex()); 1267 1268 process_sp->GetMemoryRegions(sb_region_list.ref()); 1269 } 1270 1271 return LLDB_RECORD_RESULT(sb_region_list); 1272 } 1273 1274 lldb::SBProcessInfo SBProcess::GetProcessInfo() { 1275 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcessInfo, SBProcess, GetProcessInfo); 1276 1277 lldb::SBProcessInfo sb_proc_info; 1278 ProcessSP process_sp(GetSP()); 1279 ProcessInstanceInfo proc_info; 1280 if (process_sp && process_sp->GetProcessInfo(proc_info)) { 1281 sb_proc_info.SetProcessInfo(proc_info); 1282 } 1283 return LLDB_RECORD_RESULT(sb_proc_info); 1284 } 1285 1286 namespace lldb_private { 1287 namespace repro { 1288 1289 template <> 1290 void RegisterMethods<SBProcess>(Registry &R) { 1291 LLDB_REGISTER_CONSTRUCTOR(SBProcess, ()); 1292 LLDB_REGISTER_CONSTRUCTOR(SBProcess, (const lldb::SBProcess &)); 1293 LLDB_REGISTER_CONSTRUCTOR(SBProcess, (const lldb::ProcessSP &)); 1294 LLDB_REGISTER_METHOD(const lldb::SBProcess &, 1295 SBProcess, operator=,(const lldb::SBProcess &)); 1296 LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, 1297 GetBroadcasterClassName, ()); 1298 LLDB_REGISTER_METHOD(const char *, SBProcess, GetPluginName, ()); 1299 LLDB_REGISTER_METHOD(const char *, SBProcess, GetShortPluginName, ()); 1300 LLDB_REGISTER_METHOD(void, SBProcess, Clear, ()); 1301 LLDB_REGISTER_METHOD_CONST(bool, SBProcess, IsValid, ()); 1302 LLDB_REGISTER_METHOD_CONST(bool, SBProcess, operator bool, ()); 1303 LLDB_REGISTER_METHOD(bool, SBProcess, RemoteLaunch, 1304 (const char **, const char **, const char *, 1305 const char *, const char *, const char *, uint32_t, 1306 bool, lldb::SBError &)); 1307 LLDB_REGISTER_METHOD(bool, SBProcess, RemoteAttachToProcessWithID, 1308 (lldb::pid_t, lldb::SBError &)); 1309 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumThreads, ()); 1310 LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBProcess, GetSelectedThread, 1311 ()); 1312 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, CreateOSPluginThread, 1313 (lldb::tid_t, lldb::addr_t)); 1314 LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBProcess, GetTarget, ()); 1315 LLDB_REGISTER_METHOD(size_t, SBProcess, PutSTDIN, (const char *, size_t)); 1316 LLDB_REGISTER_METHOD_CONST(size_t, SBProcess, GetSTDOUT, (char *, size_t)); 1317 LLDB_REGISTER_METHOD_CONST(size_t, SBProcess, GetSTDERR, (char *, size_t)); 1318 LLDB_REGISTER_METHOD_CONST(size_t, SBProcess, GetAsyncProfileData, 1319 (char *, size_t)); 1320 LLDB_REGISTER_METHOD(lldb::SBTrace, SBProcess, StartTrace, 1321 (lldb::SBTraceOptions &, lldb::SBError &)); 1322 LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState, 1323 (const lldb::SBEvent &, FILE *)); 1324 LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState, 1325 (const lldb::SBEvent &, FileSP)); 1326 LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState, 1327 (const lldb::SBEvent &, SBFile)); 1328 LLDB_REGISTER_METHOD( 1329 void, SBProcess, AppendEventStateReport, 1330 (const lldb::SBEvent &, lldb::SBCommandReturnObject &)); 1331 LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThread, 1332 (const lldb::SBThread &)); 1333 LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThreadByID, (lldb::tid_t)); 1334 LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThreadByIndexID, 1335 (uint32_t)); 1336 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadAtIndex, (size_t)); 1337 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumQueues, ()); 1338 LLDB_REGISTER_METHOD(lldb::SBQueue, SBProcess, GetQueueAtIndex, (size_t)); 1339 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetStopID, (bool)); 1340 LLDB_REGISTER_METHOD(lldb::SBEvent, SBProcess, GetStopEventForStopID, 1341 (uint32_t)); 1342 LLDB_REGISTER_METHOD(lldb::StateType, SBProcess, GetState, ()); 1343 LLDB_REGISTER_METHOD(int, SBProcess, GetExitStatus, ()); 1344 LLDB_REGISTER_METHOD(const char *, SBProcess, GetExitDescription, ()); 1345 LLDB_REGISTER_METHOD(lldb::pid_t, SBProcess, GetProcessID, ()); 1346 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetUniqueID, ()); 1347 LLDB_REGISTER_METHOD_CONST(lldb::ByteOrder, SBProcess, GetByteOrder, ()); 1348 LLDB_REGISTER_METHOD_CONST(uint32_t, SBProcess, GetAddressByteSize, ()); 1349 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Continue, ()); 1350 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Destroy, ()); 1351 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Stop, ()); 1352 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Kill, ()); 1353 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Detach, ()); 1354 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Detach, (bool)); 1355 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Signal, (int)); 1356 LLDB_REGISTER_METHOD(lldb::SBUnixSignals, SBProcess, GetUnixSignals, ()); 1357 LLDB_REGISTER_METHOD(void, SBProcess, SendAsyncInterrupt, ()); 1358 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadByID, 1359 (lldb::tid_t)); 1360 LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadByIndexID, 1361 (uint32_t)); 1362 LLDB_REGISTER_STATIC_METHOD(lldb::StateType, SBProcess, GetStateFromEvent, 1363 (const lldb::SBEvent &)); 1364 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, GetRestartedFromEvent, 1365 (const lldb::SBEvent &)); 1366 LLDB_REGISTER_STATIC_METHOD(size_t, SBProcess, 1367 GetNumRestartedReasonsFromEvent, 1368 (const lldb::SBEvent &)); 1369 LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, 1370 GetRestartedReasonAtIndexFromEvent, 1371 (const lldb::SBEvent &, size_t)); 1372 LLDB_REGISTER_STATIC_METHOD(lldb::SBProcess, SBProcess, GetProcessFromEvent, 1373 (const lldb::SBEvent &)); 1374 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, GetInterruptedFromEvent, 1375 (const lldb::SBEvent &)); 1376 LLDB_REGISTER_STATIC_METHOD(lldb::SBStructuredData, SBProcess, 1377 GetStructuredDataFromEvent, 1378 (const lldb::SBEvent &)); 1379 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, EventIsProcessEvent, 1380 (const lldb::SBEvent &)); 1381 LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, EventIsStructuredDataEvent, 1382 (const lldb::SBEvent &)); 1383 LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBProcess, GetBroadcaster, 1384 ()); 1385 LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, GetBroadcasterClass, 1386 ()); 1387 LLDB_REGISTER_METHOD(uint64_t, SBProcess, ReadUnsignedFromMemory, 1388 (lldb::addr_t, uint32_t, lldb::SBError &)); 1389 LLDB_REGISTER_METHOD(lldb::addr_t, SBProcess, ReadPointerFromMemory, 1390 (lldb::addr_t, lldb::SBError &)); 1391 LLDB_REGISTER_METHOD(bool, SBProcess, GetDescription, (lldb::SBStream &)); 1392 LLDB_REGISTER_METHOD_CONST(uint32_t, SBProcess, 1393 GetNumSupportedHardwareWatchpoints, 1394 (lldb::SBError &)); 1395 LLDB_REGISTER_METHOD(uint32_t, SBProcess, LoadImage, 1396 (lldb::SBFileSpec &, lldb::SBError &)); 1397 LLDB_REGISTER_METHOD( 1398 uint32_t, SBProcess, LoadImage, 1399 (const lldb::SBFileSpec &, const lldb::SBFileSpec &, lldb::SBError &)); 1400 LLDB_REGISTER_METHOD(uint32_t, SBProcess, LoadImageUsingPaths, 1401 (const lldb::SBFileSpec &, lldb::SBStringList &, 1402 lldb::SBFileSpec &, lldb::SBError &)); 1403 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, UnloadImage, (uint32_t)); 1404 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, SendEventData, 1405 (const char *)); 1406 LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumExtendedBacktraceTypes, ()); 1407 LLDB_REGISTER_METHOD(const char *, SBProcess, 1408 GetExtendedBacktraceTypeAtIndex, (uint32_t)); 1409 LLDB_REGISTER_METHOD(lldb::SBThreadCollection, SBProcess, GetHistoryThreads, 1410 (lldb::addr_t)); 1411 LLDB_REGISTER_METHOD(bool, SBProcess, IsInstrumentationRuntimePresent, 1412 (lldb::InstrumentationRuntimeType)); 1413 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, SaveCore, (const char *)); 1414 LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, GetMemoryRegionInfo, 1415 (lldb::addr_t, lldb::SBMemoryRegionInfo &)); 1416 LLDB_REGISTER_METHOD(lldb::SBMemoryRegionInfoList, SBProcess, 1417 GetMemoryRegions, ()); 1418 LLDB_REGISTER_METHOD(lldb::SBProcessInfo, SBProcess, GetProcessInfo, ()); 1419 } 1420 1421 } 1422 } 1423