brintos

brintos / llvm-project-archived public Read only

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