15ffd83dbSDimitry Andric //===-- SBProcess.cpp -----------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/API/SBProcess.h"
100b57cec5SDimitry Andric #include "SBReproducerPrivate.h"
110b57cec5SDimitry Andric
12*5f7ddb14SDimitry Andric #include <cinttypes>
130b57cec5SDimitry Andric
140b57cec5SDimitry Andric #include "lldb/lldb-defines.h"
150b57cec5SDimitry Andric #include "lldb/lldb-types.h"
160b57cec5SDimitry Andric
170b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
180b57cec5SDimitry Andric #include "lldb/Core/Module.h"
190b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
200b57cec5SDimitry Andric #include "lldb/Core/StreamFile.h"
215ffd83dbSDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
220b57cec5SDimitry Andric #include "lldb/Target/MemoryRegionInfo.h"
230b57cec5SDimitry Andric #include "lldb/Target/Process.h"
240b57cec5SDimitry Andric #include "lldb/Target/RegisterContext.h"
250b57cec5SDimitry Andric #include "lldb/Target/SystemRuntime.h"
260b57cec5SDimitry Andric #include "lldb/Target/Target.h"
270b57cec5SDimitry Andric #include "lldb/Target/Thread.h"
280b57cec5SDimitry Andric #include "lldb/Utility/Args.h"
290b57cec5SDimitry Andric #include "lldb/Utility/ProcessInfo.h"
300b57cec5SDimitry Andric #include "lldb/Utility/State.h"
310b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric #include "lldb/API/SBBroadcaster.h"
340b57cec5SDimitry Andric #include "lldb/API/SBCommandReturnObject.h"
350b57cec5SDimitry Andric #include "lldb/API/SBDebugger.h"
360b57cec5SDimitry Andric #include "lldb/API/SBEvent.h"
379dba64beSDimitry Andric #include "lldb/API/SBFile.h"
380b57cec5SDimitry Andric #include "lldb/API/SBFileSpec.h"
390b57cec5SDimitry Andric #include "lldb/API/SBMemoryRegionInfo.h"
400b57cec5SDimitry Andric #include "lldb/API/SBMemoryRegionInfoList.h"
410b57cec5SDimitry Andric #include "lldb/API/SBStream.h"
420b57cec5SDimitry Andric #include "lldb/API/SBStringList.h"
430b57cec5SDimitry Andric #include "lldb/API/SBStructuredData.h"
440b57cec5SDimitry Andric #include "lldb/API/SBThread.h"
450b57cec5SDimitry Andric #include "lldb/API/SBThreadCollection.h"
460b57cec5SDimitry Andric #include "lldb/API/SBTrace.h"
470b57cec5SDimitry Andric #include "lldb/API/SBUnixSignals.h"
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric using namespace lldb;
500b57cec5SDimitry Andric using namespace lldb_private;
510b57cec5SDimitry Andric
SBProcess()520b57cec5SDimitry Andric SBProcess::SBProcess() : m_opaque_wp() {
530b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBProcess);
540b57cec5SDimitry Andric }
550b57cec5SDimitry Andric
560b57cec5SDimitry Andric // SBProcess constructor
570b57cec5SDimitry Andric
SBProcess(const SBProcess & rhs)580b57cec5SDimitry Andric SBProcess::SBProcess(const SBProcess &rhs) : m_opaque_wp(rhs.m_opaque_wp) {
590b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBProcess, (const lldb::SBProcess &), rhs);
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric
SBProcess(const lldb::ProcessSP & process_sp)620b57cec5SDimitry Andric SBProcess::SBProcess(const lldb::ProcessSP &process_sp)
630b57cec5SDimitry Andric : m_opaque_wp(process_sp) {
640b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBProcess, (const lldb::ProcessSP &), process_sp);
650b57cec5SDimitry Andric }
660b57cec5SDimitry Andric
operator =(const SBProcess & rhs)670b57cec5SDimitry Andric const SBProcess &SBProcess::operator=(const SBProcess &rhs) {
680b57cec5SDimitry Andric LLDB_RECORD_METHOD(const lldb::SBProcess &,
690b57cec5SDimitry Andric SBProcess, operator=,(const lldb::SBProcess &), rhs);
700b57cec5SDimitry Andric
710b57cec5SDimitry Andric if (this != &rhs)
720b57cec5SDimitry Andric m_opaque_wp = rhs.m_opaque_wp;
730b57cec5SDimitry Andric return LLDB_RECORD_RESULT(*this);
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric
760b57cec5SDimitry Andric // Destructor
775ffd83dbSDimitry Andric SBProcess::~SBProcess() = default;
780b57cec5SDimitry Andric
GetBroadcasterClassName()790b57cec5SDimitry Andric const char *SBProcess::GetBroadcasterClassName() {
800b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBProcess,
810b57cec5SDimitry Andric GetBroadcasterClassName);
820b57cec5SDimitry Andric
830b57cec5SDimitry Andric return Process::GetStaticBroadcasterClass().AsCString();
840b57cec5SDimitry Andric }
850b57cec5SDimitry Andric
GetPluginName()860b57cec5SDimitry Andric const char *SBProcess::GetPluginName() {
870b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetPluginName);
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
900b57cec5SDimitry Andric if (process_sp) {
910b57cec5SDimitry Andric return process_sp->GetPluginName().GetCString();
920b57cec5SDimitry Andric }
930b57cec5SDimitry Andric return "<Unknown>";
940b57cec5SDimitry Andric }
950b57cec5SDimitry Andric
GetShortPluginName()960b57cec5SDimitry Andric const char *SBProcess::GetShortPluginName() {
970b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetShortPluginName);
980b57cec5SDimitry Andric
990b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
1000b57cec5SDimitry Andric if (process_sp) {
1010b57cec5SDimitry Andric return process_sp->GetPluginName().GetCString();
1020b57cec5SDimitry Andric }
1030b57cec5SDimitry Andric return "<Unknown>";
1040b57cec5SDimitry Andric }
1050b57cec5SDimitry Andric
GetSP() const1060b57cec5SDimitry Andric lldb::ProcessSP SBProcess::GetSP() const { return m_opaque_wp.lock(); }
1070b57cec5SDimitry Andric
SetSP(const ProcessSP & process_sp)1080b57cec5SDimitry Andric void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
1090b57cec5SDimitry Andric
Clear()1100b57cec5SDimitry Andric void SBProcess::Clear() {
1110b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(void, SBProcess, Clear);
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andric m_opaque_wp.reset();
1140b57cec5SDimitry Andric }
1150b57cec5SDimitry Andric
IsValid() const1160b57cec5SDimitry Andric bool SBProcess::IsValid() const {
1170b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcess, IsValid);
1180b57cec5SDimitry Andric return this->operator bool();
1190b57cec5SDimitry Andric }
operator bool() const1200b57cec5SDimitry Andric SBProcess::operator bool() const {
1210b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcess, operator bool);
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric ProcessSP process_sp(m_opaque_wp.lock());
1240b57cec5SDimitry Andric return ((bool)process_sp && process_sp->IsValid());
1250b57cec5SDimitry Andric }
1260b57cec5SDimitry Andric
RemoteLaunch(char const ** argv,char const ** envp,const char * stdin_path,const char * stdout_path,const char * stderr_path,const char * working_directory,uint32_t launch_flags,bool stop_at_entry,lldb::SBError & error)1270b57cec5SDimitry Andric bool SBProcess::RemoteLaunch(char const **argv, char const **envp,
1280b57cec5SDimitry Andric const char *stdin_path, const char *stdout_path,
1290b57cec5SDimitry Andric const char *stderr_path,
1300b57cec5SDimitry Andric const char *working_directory,
1310b57cec5SDimitry Andric uint32_t launch_flags, bool stop_at_entry,
1320b57cec5SDimitry Andric lldb::SBError &error) {
1330b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, RemoteLaunch,
1340b57cec5SDimitry Andric (const char **, const char **, const char *, const char *,
1350b57cec5SDimitry Andric const char *, const char *, uint32_t, bool,
1360b57cec5SDimitry Andric lldb::SBError &),
1370b57cec5SDimitry Andric argv, envp, stdin_path, stdout_path, stderr_path,
1380b57cec5SDimitry Andric working_directory, launch_flags, stop_at_entry, error);
1390b57cec5SDimitry Andric
1400b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
1410b57cec5SDimitry Andric if (process_sp) {
1420b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1430b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1440b57cec5SDimitry Andric if (process_sp->GetState() == eStateConnected) {
1450b57cec5SDimitry Andric if (stop_at_entry)
1460b57cec5SDimitry Andric launch_flags |= eLaunchFlagStopAtEntry;
1470b57cec5SDimitry Andric ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
1480b57cec5SDimitry Andric FileSpec(stderr_path),
1490b57cec5SDimitry Andric FileSpec(working_directory), launch_flags);
1500b57cec5SDimitry Andric Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1510b57cec5SDimitry Andric if (exe_module)
1520b57cec5SDimitry Andric launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
1530b57cec5SDimitry Andric if (argv)
1540b57cec5SDimitry Andric launch_info.GetArguments().AppendArguments(argv);
1550b57cec5SDimitry Andric if (envp)
1560b57cec5SDimitry Andric launch_info.GetEnvironment() = Environment(envp);
1570b57cec5SDimitry Andric error.SetError(process_sp->Launch(launch_info));
1580b57cec5SDimitry Andric } else {
1590b57cec5SDimitry Andric error.SetErrorString("must be in eStateConnected to call RemoteLaunch");
1600b57cec5SDimitry Andric }
1610b57cec5SDimitry Andric } else {
1620b57cec5SDimitry Andric error.SetErrorString("unable to attach pid");
1630b57cec5SDimitry Andric }
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric return error.Success();
1660b57cec5SDimitry Andric }
1670b57cec5SDimitry Andric
RemoteAttachToProcessWithID(lldb::pid_t pid,lldb::SBError & error)1680b57cec5SDimitry Andric bool SBProcess::RemoteAttachToProcessWithID(lldb::pid_t pid,
1690b57cec5SDimitry Andric lldb::SBError &error) {
1700b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, RemoteAttachToProcessWithID,
1710b57cec5SDimitry Andric (lldb::pid_t, lldb::SBError &), pid, error);
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
1740b57cec5SDimitry Andric if (process_sp) {
1750b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1760b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1770b57cec5SDimitry Andric if (process_sp->GetState() == eStateConnected) {
1780b57cec5SDimitry Andric ProcessAttachInfo attach_info;
1790b57cec5SDimitry Andric attach_info.SetProcessID(pid);
1800b57cec5SDimitry Andric error.SetError(process_sp->Attach(attach_info));
1810b57cec5SDimitry Andric } else {
1820b57cec5SDimitry Andric error.SetErrorString(
1830b57cec5SDimitry Andric "must be in eStateConnected to call RemoteAttachToProcessWithID");
1840b57cec5SDimitry Andric }
1850b57cec5SDimitry Andric } else {
1860b57cec5SDimitry Andric error.SetErrorString("unable to attach pid");
1870b57cec5SDimitry Andric }
1880b57cec5SDimitry Andric
1890b57cec5SDimitry Andric return error.Success();
1900b57cec5SDimitry Andric }
1910b57cec5SDimitry Andric
GetNumThreads()1920b57cec5SDimitry Andric uint32_t SBProcess::GetNumThreads() {
1930b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumThreads);
1940b57cec5SDimitry Andric
1950b57cec5SDimitry Andric uint32_t num_threads = 0;
1960b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
1970b57cec5SDimitry Andric if (process_sp) {
1980b57cec5SDimitry Andric Process::StopLocker stop_locker;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
2010b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
2020b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
2030b57cec5SDimitry Andric num_threads = process_sp->GetThreadList().GetSize(can_update);
2040b57cec5SDimitry Andric }
2050b57cec5SDimitry Andric
2060b57cec5SDimitry Andric return num_threads;
2070b57cec5SDimitry Andric }
2080b57cec5SDimitry Andric
GetSelectedThread() const2090b57cec5SDimitry Andric SBThread SBProcess::GetSelectedThread() const {
2100b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBProcess,
2110b57cec5SDimitry Andric GetSelectedThread);
2120b57cec5SDimitry Andric
2130b57cec5SDimitry Andric SBThread sb_thread;
2140b57cec5SDimitry Andric ThreadSP thread_sp;
2150b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
2160b57cec5SDimitry Andric if (process_sp) {
2170b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
2180b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
2190b57cec5SDimitry Andric thread_sp = process_sp->GetThreadList().GetSelectedThread();
2200b57cec5SDimitry Andric sb_thread.SetThread(thread_sp);
2210b57cec5SDimitry Andric }
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_thread);
2240b57cec5SDimitry Andric }
2250b57cec5SDimitry Andric
CreateOSPluginThread(lldb::tid_t tid,lldb::addr_t context)2260b57cec5SDimitry Andric SBThread SBProcess::CreateOSPluginThread(lldb::tid_t tid,
2270b57cec5SDimitry Andric lldb::addr_t context) {
2280b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, CreateOSPluginThread,
2290b57cec5SDimitry Andric (lldb::tid_t, lldb::addr_t), tid, context);
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andric SBThread sb_thread;
2320b57cec5SDimitry Andric ThreadSP thread_sp;
2330b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
2340b57cec5SDimitry Andric if (process_sp) {
2350b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
2360b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
2370b57cec5SDimitry Andric thread_sp = process_sp->CreateOSPluginThread(tid, context);
2380b57cec5SDimitry Andric sb_thread.SetThread(thread_sp);
2390b57cec5SDimitry Andric }
2400b57cec5SDimitry Andric
2410b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_thread);
2420b57cec5SDimitry Andric }
2430b57cec5SDimitry Andric
GetTarget() const2440b57cec5SDimitry Andric SBTarget SBProcess::GetTarget() const {
2450b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBProcess, GetTarget);
2460b57cec5SDimitry Andric
2470b57cec5SDimitry Andric SBTarget sb_target;
2480b57cec5SDimitry Andric TargetSP target_sp;
2490b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
2500b57cec5SDimitry Andric if (process_sp) {
2510b57cec5SDimitry Andric target_sp = process_sp->GetTarget().shared_from_this();
2520b57cec5SDimitry Andric sb_target.SetSP(target_sp);
2530b57cec5SDimitry Andric }
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_target);
2560b57cec5SDimitry Andric }
2570b57cec5SDimitry Andric
PutSTDIN(const char * src,size_t src_len)2580b57cec5SDimitry Andric size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
2590b57cec5SDimitry Andric LLDB_RECORD_METHOD(size_t, SBProcess, PutSTDIN, (const char *, size_t), src,
2600b57cec5SDimitry Andric src_len);
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andric size_t ret_val = 0;
2630b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
2640b57cec5SDimitry Andric if (process_sp) {
2650b57cec5SDimitry Andric Status error;
2660b57cec5SDimitry Andric ret_val = process_sp->PutSTDIN(src, src_len, error);
2670b57cec5SDimitry Andric }
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andric return ret_val;
2700b57cec5SDimitry Andric }
2710b57cec5SDimitry Andric
GetSTDOUT(char * dst,size_t dst_len) const2720b57cec5SDimitry Andric size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
2735ffd83dbSDimitry Andric LLDB_RECORD_CHAR_PTR_METHOD_CONST(size_t, SBProcess, GetSTDOUT,
2745ffd83dbSDimitry Andric (char *, size_t), dst, "", dst_len);
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andric size_t bytes_read = 0;
2770b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
2780b57cec5SDimitry Andric if (process_sp) {
2790b57cec5SDimitry Andric Status error;
2800b57cec5SDimitry Andric bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
2810b57cec5SDimitry Andric }
2820b57cec5SDimitry Andric
2830b57cec5SDimitry Andric return bytes_read;
2840b57cec5SDimitry Andric }
2850b57cec5SDimitry Andric
GetSTDERR(char * dst,size_t dst_len) const2860b57cec5SDimitry Andric size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
2875ffd83dbSDimitry Andric LLDB_RECORD_CHAR_PTR_METHOD_CONST(size_t, SBProcess, GetSTDERR,
2885ffd83dbSDimitry Andric (char *, size_t), dst, "", dst_len);
2890b57cec5SDimitry Andric
2900b57cec5SDimitry Andric size_t bytes_read = 0;
2910b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
2920b57cec5SDimitry Andric if (process_sp) {
2930b57cec5SDimitry Andric Status error;
2940b57cec5SDimitry Andric bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
2950b57cec5SDimitry Andric }
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric return bytes_read;
2980b57cec5SDimitry Andric }
2990b57cec5SDimitry Andric
GetAsyncProfileData(char * dst,size_t dst_len) const3000b57cec5SDimitry Andric size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
3015ffd83dbSDimitry Andric LLDB_RECORD_CHAR_PTR_METHOD_CONST(size_t, SBProcess, GetAsyncProfileData,
3025ffd83dbSDimitry Andric (char *, size_t), dst, "", dst_len);
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric size_t bytes_read = 0;
3050b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
3060b57cec5SDimitry Andric if (process_sp) {
3070b57cec5SDimitry Andric Status error;
3080b57cec5SDimitry Andric bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
3090b57cec5SDimitry Andric }
3100b57cec5SDimitry Andric
3110b57cec5SDimitry Andric return bytes_read;
3120b57cec5SDimitry Andric }
3130b57cec5SDimitry Andric
ReportEventState(const SBEvent & event,SBFile out) const3149dba64beSDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
3159dba64beSDimitry Andric LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState,
3169dba64beSDimitry Andric (const SBEvent &, SBFile), event, out);
3179dba64beSDimitry Andric
3189dba64beSDimitry Andric return ReportEventState(event, out.m_opaque_sp);
3199dba64beSDimitry Andric }
3209dba64beSDimitry Andric
ReportEventState(const SBEvent & event,FILE * out) const3210b57cec5SDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
3220b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState,
3230b57cec5SDimitry Andric (const lldb::SBEvent &, FILE *), event, out);
3249dba64beSDimitry Andric FileSP outfile = std::make_shared<NativeFile>(out, false);
3259dba64beSDimitry Andric return ReportEventState(event, outfile);
3269dba64beSDimitry Andric }
3270b57cec5SDimitry Andric
ReportEventState(const SBEvent & event,FileSP out) const3289dba64beSDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
3299dba64beSDimitry Andric
3309dba64beSDimitry Andric LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState,
3319dba64beSDimitry Andric (const SBEvent &, FileSP), event, out);
3329dba64beSDimitry Andric
3339dba64beSDimitry Andric if (!out || !out->IsValid())
3340b57cec5SDimitry Andric return;
3350b57cec5SDimitry Andric
3360b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
3370b57cec5SDimitry Andric if (process_sp) {
3389dba64beSDimitry Andric StreamFile stream(out);
3390b57cec5SDimitry Andric const StateType event_state = SBProcess::GetStateFromEvent(event);
3409dba64beSDimitry Andric stream.Printf("Process %" PRIu64 " %s\n",
3410b57cec5SDimitry Andric process_sp->GetID(), SBDebugger::StateAsCString(event_state));
3420b57cec5SDimitry Andric }
3430b57cec5SDimitry Andric }
3440b57cec5SDimitry Andric
AppendEventStateReport(const SBEvent & event,SBCommandReturnObject & result)3450b57cec5SDimitry Andric void SBProcess::AppendEventStateReport(const SBEvent &event,
3460b57cec5SDimitry Andric SBCommandReturnObject &result) {
3470b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBProcess, AppendEventStateReport,
3480b57cec5SDimitry Andric (const lldb::SBEvent &, lldb::SBCommandReturnObject &),
3490b57cec5SDimitry Andric event, result);
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
3520b57cec5SDimitry Andric if (process_sp) {
3530b57cec5SDimitry Andric const StateType event_state = SBProcess::GetStateFromEvent(event);
3540b57cec5SDimitry Andric char message[1024];
3550b57cec5SDimitry Andric ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
3560b57cec5SDimitry Andric process_sp->GetID(), SBDebugger::StateAsCString(event_state));
3570b57cec5SDimitry Andric
3580b57cec5SDimitry Andric result.AppendMessage(message);
3590b57cec5SDimitry Andric }
3600b57cec5SDimitry Andric }
3610b57cec5SDimitry Andric
SetSelectedThread(const SBThread & thread)3620b57cec5SDimitry Andric bool SBProcess::SetSelectedThread(const SBThread &thread) {
3630b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThread,
3640b57cec5SDimitry Andric (const lldb::SBThread &), thread);
3650b57cec5SDimitry Andric
3660b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
3670b57cec5SDimitry Andric if (process_sp) {
3680b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
3690b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
3700b57cec5SDimitry Andric return process_sp->GetThreadList().SetSelectedThreadByID(
3710b57cec5SDimitry Andric thread.GetThreadID());
3720b57cec5SDimitry Andric }
3730b57cec5SDimitry Andric return false;
3740b57cec5SDimitry Andric }
3750b57cec5SDimitry Andric
SetSelectedThreadByID(lldb::tid_t tid)3760b57cec5SDimitry Andric bool SBProcess::SetSelectedThreadByID(lldb::tid_t tid) {
3770b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThreadByID, (lldb::tid_t),
3780b57cec5SDimitry Andric tid);
3790b57cec5SDimitry Andric
3800b57cec5SDimitry Andric
3810b57cec5SDimitry Andric bool ret_val = false;
3820b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
3830b57cec5SDimitry Andric if (process_sp) {
3840b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
3850b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
3860b57cec5SDimitry Andric ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
3870b57cec5SDimitry Andric }
3880b57cec5SDimitry Andric
3890b57cec5SDimitry Andric return ret_val;
3900b57cec5SDimitry Andric }
3910b57cec5SDimitry Andric
SetSelectedThreadByIndexID(uint32_t index_id)3920b57cec5SDimitry Andric bool SBProcess::SetSelectedThreadByIndexID(uint32_t index_id) {
3930b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, SetSelectedThreadByIndexID, (uint32_t),
3940b57cec5SDimitry Andric index_id);
3950b57cec5SDimitry Andric
3960b57cec5SDimitry Andric bool ret_val = false;
3970b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
3980b57cec5SDimitry Andric if (process_sp) {
3990b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4000b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4010b57cec5SDimitry Andric ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
4020b57cec5SDimitry Andric }
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric return ret_val;
4060b57cec5SDimitry Andric }
4070b57cec5SDimitry Andric
GetThreadAtIndex(size_t index)4080b57cec5SDimitry Andric SBThread SBProcess::GetThreadAtIndex(size_t index) {
4090b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadAtIndex, (size_t),
4100b57cec5SDimitry Andric index);
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andric SBThread sb_thread;
4130b57cec5SDimitry Andric ThreadSP thread_sp;
4140b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
4150b57cec5SDimitry Andric if (process_sp) {
4160b57cec5SDimitry Andric Process::StopLocker stop_locker;
4170b57cec5SDimitry Andric const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
4180b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4190b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4200b57cec5SDimitry Andric thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
4210b57cec5SDimitry Andric sb_thread.SetThread(thread_sp);
4220b57cec5SDimitry Andric }
4230b57cec5SDimitry Andric
4240b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_thread);
4250b57cec5SDimitry Andric }
4260b57cec5SDimitry Andric
GetNumQueues()4270b57cec5SDimitry Andric uint32_t SBProcess::GetNumQueues() {
4280b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumQueues);
4290b57cec5SDimitry Andric
4300b57cec5SDimitry Andric uint32_t num_queues = 0;
4310b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
4320b57cec5SDimitry Andric if (process_sp) {
4330b57cec5SDimitry Andric Process::StopLocker stop_locker;
4340b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
4350b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4360b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4370b57cec5SDimitry Andric num_queues = process_sp->GetQueueList().GetSize();
4380b57cec5SDimitry Andric }
4390b57cec5SDimitry Andric }
4400b57cec5SDimitry Andric
4410b57cec5SDimitry Andric return num_queues;
4420b57cec5SDimitry Andric }
4430b57cec5SDimitry Andric
GetQueueAtIndex(size_t index)4440b57cec5SDimitry Andric SBQueue SBProcess::GetQueueAtIndex(size_t index) {
4450b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBQueue, SBProcess, GetQueueAtIndex, (size_t),
4460b57cec5SDimitry Andric index);
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andric SBQueue sb_queue;
4490b57cec5SDimitry Andric QueueSP queue_sp;
4500b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
4510b57cec5SDimitry Andric if (process_sp) {
4520b57cec5SDimitry Andric Process::StopLocker stop_locker;
4530b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
4540b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4550b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4560b57cec5SDimitry Andric queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
4570b57cec5SDimitry Andric sb_queue.SetQueue(queue_sp);
4580b57cec5SDimitry Andric }
4590b57cec5SDimitry Andric }
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_queue);
4620b57cec5SDimitry Andric }
4630b57cec5SDimitry Andric
GetStopID(bool include_expression_stops)4640b57cec5SDimitry Andric uint32_t SBProcess::GetStopID(bool include_expression_stops) {
4650b57cec5SDimitry Andric LLDB_RECORD_METHOD(uint32_t, SBProcess, GetStopID, (bool),
4660b57cec5SDimitry Andric include_expression_stops);
4670b57cec5SDimitry Andric
4680b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
4690b57cec5SDimitry Andric if (process_sp) {
4700b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4710b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4720b57cec5SDimitry Andric if (include_expression_stops)
4730b57cec5SDimitry Andric return process_sp->GetStopID();
4740b57cec5SDimitry Andric else
4750b57cec5SDimitry Andric return process_sp->GetLastNaturalStopID();
4760b57cec5SDimitry Andric }
4770b57cec5SDimitry Andric return 0;
4780b57cec5SDimitry Andric }
4790b57cec5SDimitry Andric
GetStopEventForStopID(uint32_t stop_id)4800b57cec5SDimitry Andric SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) {
4810b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBEvent, SBProcess, GetStopEventForStopID,
4820b57cec5SDimitry Andric (uint32_t), stop_id);
4830b57cec5SDimitry Andric
4840b57cec5SDimitry Andric SBEvent sb_event;
4850b57cec5SDimitry Andric EventSP event_sp;
4860b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
4870b57cec5SDimitry Andric if (process_sp) {
4880b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4890b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4900b57cec5SDimitry Andric event_sp = process_sp->GetStopEventForStopID(stop_id);
4910b57cec5SDimitry Andric sb_event.reset(event_sp);
4920b57cec5SDimitry Andric }
4930b57cec5SDimitry Andric
4940b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_event);
4950b57cec5SDimitry Andric }
4960b57cec5SDimitry Andric
GetState()4970b57cec5SDimitry Andric StateType SBProcess::GetState() {
4980b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::StateType, SBProcess, GetState);
4990b57cec5SDimitry Andric
5000b57cec5SDimitry Andric StateType ret_val = eStateInvalid;
5010b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5020b57cec5SDimitry Andric if (process_sp) {
5030b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
5040b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
5050b57cec5SDimitry Andric ret_val = process_sp->GetState();
5060b57cec5SDimitry Andric }
5070b57cec5SDimitry Andric
5080b57cec5SDimitry Andric return ret_val;
5090b57cec5SDimitry Andric }
5100b57cec5SDimitry Andric
GetExitStatus()5110b57cec5SDimitry Andric int SBProcess::GetExitStatus() {
5120b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(int, SBProcess, GetExitStatus);
5130b57cec5SDimitry Andric
5140b57cec5SDimitry Andric int exit_status = 0;
5150b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5160b57cec5SDimitry Andric if (process_sp) {
5170b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
5180b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
5190b57cec5SDimitry Andric exit_status = process_sp->GetExitStatus();
5200b57cec5SDimitry Andric }
5210b57cec5SDimitry Andric
5220b57cec5SDimitry Andric return exit_status;
5230b57cec5SDimitry Andric }
5240b57cec5SDimitry Andric
GetExitDescription()5250b57cec5SDimitry Andric const char *SBProcess::GetExitDescription() {
5260b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcess, GetExitDescription);
5270b57cec5SDimitry Andric
5280b57cec5SDimitry Andric const char *exit_desc = nullptr;
5290b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5300b57cec5SDimitry Andric if (process_sp) {
5310b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
5320b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
5330b57cec5SDimitry Andric exit_desc = process_sp->GetExitDescription();
5340b57cec5SDimitry Andric }
5350b57cec5SDimitry Andric return exit_desc;
5360b57cec5SDimitry Andric }
5370b57cec5SDimitry Andric
GetProcessID()5380b57cec5SDimitry Andric lldb::pid_t SBProcess::GetProcessID() {
5390b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcess, GetProcessID);
5400b57cec5SDimitry Andric
5410b57cec5SDimitry Andric lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
5420b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5430b57cec5SDimitry Andric if (process_sp)
5440b57cec5SDimitry Andric ret_val = process_sp->GetID();
5450b57cec5SDimitry Andric
5460b57cec5SDimitry Andric return ret_val;
5470b57cec5SDimitry Andric }
5480b57cec5SDimitry Andric
GetUniqueID()5490b57cec5SDimitry Andric uint32_t SBProcess::GetUniqueID() {
5500b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetUniqueID);
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric uint32_t ret_val = 0;
5530b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5540b57cec5SDimitry Andric if (process_sp)
5550b57cec5SDimitry Andric ret_val = process_sp->GetUniqueID();
5560b57cec5SDimitry Andric return ret_val;
5570b57cec5SDimitry Andric }
5580b57cec5SDimitry Andric
GetByteOrder() const5590b57cec5SDimitry Andric ByteOrder SBProcess::GetByteOrder() const {
5600b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ByteOrder, SBProcess, GetByteOrder);
5610b57cec5SDimitry Andric
5620b57cec5SDimitry Andric ByteOrder byteOrder = eByteOrderInvalid;
5630b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5640b57cec5SDimitry Andric if (process_sp)
5650b57cec5SDimitry Andric byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
5660b57cec5SDimitry Andric
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andric return byteOrder;
5690b57cec5SDimitry Andric }
5700b57cec5SDimitry Andric
GetAddressByteSize() const5710b57cec5SDimitry Andric uint32_t SBProcess::GetAddressByteSize() const {
5720b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBProcess, GetAddressByteSize);
5730b57cec5SDimitry Andric
5740b57cec5SDimitry Andric uint32_t size = 0;
5750b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5760b57cec5SDimitry Andric if (process_sp)
5770b57cec5SDimitry Andric size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
5780b57cec5SDimitry Andric
5790b57cec5SDimitry Andric
5800b57cec5SDimitry Andric return size;
5810b57cec5SDimitry Andric }
5820b57cec5SDimitry Andric
Continue()5830b57cec5SDimitry Andric SBError SBProcess::Continue() {
5840b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Continue);
5850b57cec5SDimitry Andric
5860b57cec5SDimitry Andric SBError sb_error;
5870b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
5880b57cec5SDimitry Andric
5890b57cec5SDimitry Andric if (process_sp) {
5900b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
5910b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
5920b57cec5SDimitry Andric
5930b57cec5SDimitry Andric if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
5940b57cec5SDimitry Andric sb_error.ref() = process_sp->Resume();
5950b57cec5SDimitry Andric else
5960b57cec5SDimitry Andric sb_error.ref() = process_sp->ResumeSynchronous(nullptr);
5970b57cec5SDimitry Andric } else
5980b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
5990b57cec5SDimitry Andric
6000b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6010b57cec5SDimitry Andric }
6020b57cec5SDimitry Andric
Destroy()6030b57cec5SDimitry Andric SBError SBProcess::Destroy() {
6040b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Destroy);
6050b57cec5SDimitry Andric
6060b57cec5SDimitry Andric SBError sb_error;
6070b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
6080b57cec5SDimitry Andric if (process_sp) {
6090b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
6100b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
6110b57cec5SDimitry Andric sb_error.SetError(process_sp->Destroy(false));
6120b57cec5SDimitry Andric } else
6130b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
6140b57cec5SDimitry Andric
6150b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6160b57cec5SDimitry Andric }
6170b57cec5SDimitry Andric
Stop()6180b57cec5SDimitry Andric SBError SBProcess::Stop() {
6190b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Stop);
6200b57cec5SDimitry Andric
6210b57cec5SDimitry Andric SBError sb_error;
6220b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
6230b57cec5SDimitry Andric if (process_sp) {
6240b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
6250b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
6260b57cec5SDimitry Andric sb_error.SetError(process_sp->Halt());
6270b57cec5SDimitry Andric } else
6280b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
6290b57cec5SDimitry Andric
6300b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6310b57cec5SDimitry Andric }
6320b57cec5SDimitry Andric
Kill()6330b57cec5SDimitry Andric SBError SBProcess::Kill() {
6340b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Kill);
6350b57cec5SDimitry Andric
6360b57cec5SDimitry Andric SBError sb_error;
6370b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
6380b57cec5SDimitry Andric if (process_sp) {
6390b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
6400b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
6410b57cec5SDimitry Andric sb_error.SetError(process_sp->Destroy(true));
6420b57cec5SDimitry Andric } else
6430b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6460b57cec5SDimitry Andric }
6470b57cec5SDimitry Andric
Detach()6480b57cec5SDimitry Andric SBError SBProcess::Detach() {
6490b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBProcess, Detach);
6500b57cec5SDimitry Andric
6510b57cec5SDimitry Andric // FIXME: This should come from a process default.
6520b57cec5SDimitry Andric bool keep_stopped = false;
6530b57cec5SDimitry Andric return LLDB_RECORD_RESULT(Detach(keep_stopped));
6540b57cec5SDimitry Andric }
6550b57cec5SDimitry Andric
Detach(bool keep_stopped)6560b57cec5SDimitry Andric SBError SBProcess::Detach(bool keep_stopped) {
6570b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, Detach, (bool), keep_stopped);
6580b57cec5SDimitry Andric
6590b57cec5SDimitry Andric SBError sb_error;
6600b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
6610b57cec5SDimitry Andric if (process_sp) {
6620b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
6630b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
6640b57cec5SDimitry Andric sb_error.SetError(process_sp->Detach(keep_stopped));
6650b57cec5SDimitry Andric } else
6660b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
6670b57cec5SDimitry Andric
6680b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6690b57cec5SDimitry Andric }
6700b57cec5SDimitry Andric
Signal(int signo)6710b57cec5SDimitry Andric SBError SBProcess::Signal(int signo) {
6720b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, Signal, (int), signo);
6730b57cec5SDimitry Andric
6740b57cec5SDimitry Andric SBError sb_error;
6750b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
6760b57cec5SDimitry Andric if (process_sp) {
6770b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
6780b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
6790b57cec5SDimitry Andric sb_error.SetError(process_sp->Signal(signo));
6800b57cec5SDimitry Andric } else
6810b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
6820b57cec5SDimitry Andric
6830b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6840b57cec5SDimitry Andric }
6850b57cec5SDimitry Andric
GetUnixSignals()6860b57cec5SDimitry Andric SBUnixSignals SBProcess::GetUnixSignals() {
6870b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBUnixSignals, SBProcess, GetUnixSignals);
6880b57cec5SDimitry Andric
6890b57cec5SDimitry Andric if (auto process_sp = GetSP())
6900b57cec5SDimitry Andric return LLDB_RECORD_RESULT(SBUnixSignals{process_sp});
6910b57cec5SDimitry Andric
6920b57cec5SDimitry Andric return LLDB_RECORD_RESULT(SBUnixSignals{});
6930b57cec5SDimitry Andric }
6940b57cec5SDimitry Andric
SendAsyncInterrupt()6950b57cec5SDimitry Andric void SBProcess::SendAsyncInterrupt() {
6960b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(void, SBProcess, SendAsyncInterrupt);
6970b57cec5SDimitry Andric
6980b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
6990b57cec5SDimitry Andric if (process_sp) {
7000b57cec5SDimitry Andric process_sp->SendAsyncInterrupt();
7010b57cec5SDimitry Andric }
7020b57cec5SDimitry Andric }
7030b57cec5SDimitry Andric
GetThreadByID(tid_t tid)7040b57cec5SDimitry Andric SBThread SBProcess::GetThreadByID(tid_t tid) {
7050b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadByID, (lldb::tid_t),
7060b57cec5SDimitry Andric tid);
7070b57cec5SDimitry Andric
7080b57cec5SDimitry Andric SBThread sb_thread;
7090b57cec5SDimitry Andric ThreadSP thread_sp;
7100b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
7110b57cec5SDimitry Andric if (process_sp) {
7120b57cec5SDimitry Andric Process::StopLocker stop_locker;
7130b57cec5SDimitry Andric const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
7140b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
7150b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
7160b57cec5SDimitry Andric thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
7170b57cec5SDimitry Andric sb_thread.SetThread(thread_sp);
7180b57cec5SDimitry Andric }
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_thread);
7210b57cec5SDimitry Andric }
7220b57cec5SDimitry Andric
GetThreadByIndexID(uint32_t index_id)7230b57cec5SDimitry Andric SBThread SBProcess::GetThreadByIndexID(uint32_t index_id) {
7240b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBThread, SBProcess, GetThreadByIndexID, (uint32_t),
7250b57cec5SDimitry Andric index_id);
7260b57cec5SDimitry Andric
7270b57cec5SDimitry Andric SBThread sb_thread;
7280b57cec5SDimitry Andric ThreadSP thread_sp;
7290b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
7300b57cec5SDimitry Andric if (process_sp) {
7310b57cec5SDimitry Andric Process::StopLocker stop_locker;
7320b57cec5SDimitry Andric const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
7330b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
7340b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
7350b57cec5SDimitry Andric thread_sp =
7360b57cec5SDimitry Andric process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
7370b57cec5SDimitry Andric sb_thread.SetThread(thread_sp);
7380b57cec5SDimitry Andric }
7390b57cec5SDimitry Andric
7400b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_thread);
7410b57cec5SDimitry Andric }
7420b57cec5SDimitry Andric
GetStateFromEvent(const SBEvent & event)7430b57cec5SDimitry Andric StateType SBProcess::GetStateFromEvent(const SBEvent &event) {
7440b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(lldb::StateType, SBProcess, GetStateFromEvent,
7450b57cec5SDimitry Andric (const lldb::SBEvent &), event);
7460b57cec5SDimitry Andric
7470b57cec5SDimitry Andric StateType ret_val = Process::ProcessEventData::GetStateFromEvent(event.get());
7480b57cec5SDimitry Andric
7490b57cec5SDimitry Andric return ret_val;
7500b57cec5SDimitry Andric }
7510b57cec5SDimitry Andric
GetRestartedFromEvent(const SBEvent & event)7520b57cec5SDimitry Andric bool SBProcess::GetRestartedFromEvent(const SBEvent &event) {
7530b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(bool, SBProcess, GetRestartedFromEvent,
7540b57cec5SDimitry Andric (const lldb::SBEvent &), event);
7550b57cec5SDimitry Andric
7560b57cec5SDimitry Andric bool ret_val = Process::ProcessEventData::GetRestartedFromEvent(event.get());
7570b57cec5SDimitry Andric
7580b57cec5SDimitry Andric return ret_val;
7590b57cec5SDimitry Andric }
7600b57cec5SDimitry Andric
GetNumRestartedReasonsFromEvent(const lldb::SBEvent & event)7610b57cec5SDimitry Andric size_t SBProcess::GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event) {
7620b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(size_t, SBProcess, GetNumRestartedReasonsFromEvent,
7630b57cec5SDimitry Andric (const lldb::SBEvent &), event);
7640b57cec5SDimitry Andric
7650b57cec5SDimitry Andric return Process::ProcessEventData::GetNumRestartedReasons(event.get());
7660b57cec5SDimitry Andric }
7670b57cec5SDimitry Andric
7680b57cec5SDimitry Andric const char *
GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent & event,size_t idx)7690b57cec5SDimitry Andric SBProcess::GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event,
7700b57cec5SDimitry Andric size_t idx) {
7710b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(const char *, SBProcess,
7720b57cec5SDimitry Andric GetRestartedReasonAtIndexFromEvent,
7730b57cec5SDimitry Andric (const lldb::SBEvent &, size_t), event, idx);
7740b57cec5SDimitry Andric
7750b57cec5SDimitry Andric return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
7760b57cec5SDimitry Andric }
7770b57cec5SDimitry Andric
GetProcessFromEvent(const SBEvent & event)7780b57cec5SDimitry Andric SBProcess SBProcess::GetProcessFromEvent(const SBEvent &event) {
7790b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(lldb::SBProcess, SBProcess, GetProcessFromEvent,
7800b57cec5SDimitry Andric (const lldb::SBEvent &), event);
7810b57cec5SDimitry Andric
7820b57cec5SDimitry Andric ProcessSP process_sp =
7830b57cec5SDimitry Andric Process::ProcessEventData::GetProcessFromEvent(event.get());
7840b57cec5SDimitry Andric if (!process_sp) {
7850b57cec5SDimitry Andric // StructuredData events also know the process they come from. Try that.
7860b57cec5SDimitry Andric process_sp = EventDataStructuredData::GetProcessFromEvent(event.get());
7870b57cec5SDimitry Andric }
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andric return LLDB_RECORD_RESULT(SBProcess(process_sp));
7900b57cec5SDimitry Andric }
7910b57cec5SDimitry Andric
GetInterruptedFromEvent(const SBEvent & event)7920b57cec5SDimitry Andric bool SBProcess::GetInterruptedFromEvent(const SBEvent &event) {
7930b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(bool, SBProcess, GetInterruptedFromEvent,
7940b57cec5SDimitry Andric (const lldb::SBEvent &), event);
7950b57cec5SDimitry Andric
7960b57cec5SDimitry Andric return Process::ProcessEventData::GetInterruptedFromEvent(event.get());
7970b57cec5SDimitry Andric }
7980b57cec5SDimitry Andric
7990b57cec5SDimitry Andric lldb::SBStructuredData
GetStructuredDataFromEvent(const lldb::SBEvent & event)8000b57cec5SDimitry Andric SBProcess::GetStructuredDataFromEvent(const lldb::SBEvent &event) {
8010b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(lldb::SBStructuredData, SBProcess,
8020b57cec5SDimitry Andric GetStructuredDataFromEvent, (const lldb::SBEvent &),
8030b57cec5SDimitry Andric event);
8040b57cec5SDimitry Andric
8050b57cec5SDimitry Andric return LLDB_RECORD_RESULT(SBStructuredData(event.GetSP()));
8060b57cec5SDimitry Andric }
8070b57cec5SDimitry Andric
EventIsProcessEvent(const SBEvent & event)8080b57cec5SDimitry Andric bool SBProcess::EventIsProcessEvent(const SBEvent &event) {
8090b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(bool, SBProcess, EventIsProcessEvent,
8100b57cec5SDimitry Andric (const lldb::SBEvent &), event);
8110b57cec5SDimitry Andric
8120b57cec5SDimitry Andric return (event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass()) &&
8130b57cec5SDimitry Andric !EventIsStructuredDataEvent(event);
8140b57cec5SDimitry Andric }
8150b57cec5SDimitry Andric
EventIsStructuredDataEvent(const lldb::SBEvent & event)8160b57cec5SDimitry Andric bool SBProcess::EventIsStructuredDataEvent(const lldb::SBEvent &event) {
8170b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD(bool, SBProcess, EventIsStructuredDataEvent,
8180b57cec5SDimitry Andric (const lldb::SBEvent &), event);
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andric EventSP event_sp = event.GetSP();
8210b57cec5SDimitry Andric EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
8220b57cec5SDimitry Andric return event_data && (event_data->GetFlavor() ==
8230b57cec5SDimitry Andric EventDataStructuredData::GetFlavorString());
8240b57cec5SDimitry Andric }
8250b57cec5SDimitry Andric
GetBroadcaster() const8260b57cec5SDimitry Andric SBBroadcaster SBProcess::GetBroadcaster() const {
8270b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBProcess,
8280b57cec5SDimitry Andric GetBroadcaster);
8290b57cec5SDimitry Andric
8300b57cec5SDimitry Andric
8310b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
8320b57cec5SDimitry Andric
8330b57cec5SDimitry Andric SBBroadcaster broadcaster(process_sp.get(), false);
8340b57cec5SDimitry Andric
8350b57cec5SDimitry Andric
8360b57cec5SDimitry Andric return LLDB_RECORD_RESULT(broadcaster);
8370b57cec5SDimitry Andric }
8380b57cec5SDimitry Andric
GetBroadcasterClass()8390b57cec5SDimitry Andric const char *SBProcess::GetBroadcasterClass() {
8400b57cec5SDimitry Andric LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBProcess,
8410b57cec5SDimitry Andric GetBroadcasterClass);
8420b57cec5SDimitry Andric
8430b57cec5SDimitry Andric return Process::GetStaticBroadcasterClass().AsCString();
8440b57cec5SDimitry Andric }
8450b57cec5SDimitry Andric
ReadMemory(addr_t addr,void * dst,size_t dst_len,SBError & sb_error)8460b57cec5SDimitry Andric size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
8470b57cec5SDimitry Andric SBError &sb_error) {
8480b57cec5SDimitry Andric LLDB_RECORD_DUMMY(size_t, SBProcess, ReadMemory,
8490b57cec5SDimitry Andric (lldb::addr_t, void *, size_t, lldb::SBError &), addr, dst,
8500b57cec5SDimitry Andric dst_len, sb_error);
8510b57cec5SDimitry Andric
8520b57cec5SDimitry Andric size_t bytes_read = 0;
8530b57cec5SDimitry Andric
8540b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
8550b57cec5SDimitry Andric
8560b57cec5SDimitry Andric
8570b57cec5SDimitry Andric if (process_sp) {
8580b57cec5SDimitry Andric Process::StopLocker stop_locker;
8590b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
8600b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
8610b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
8620b57cec5SDimitry Andric bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
8630b57cec5SDimitry Andric } else {
8640b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
8650b57cec5SDimitry Andric }
8660b57cec5SDimitry Andric } else {
8670b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
8680b57cec5SDimitry Andric }
8690b57cec5SDimitry Andric
8700b57cec5SDimitry Andric return bytes_read;
8710b57cec5SDimitry Andric }
8720b57cec5SDimitry Andric
ReadCStringFromMemory(addr_t addr,void * buf,size_t size,lldb::SBError & sb_error)8730b57cec5SDimitry Andric size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
8740b57cec5SDimitry Andric lldb::SBError &sb_error) {
8750b57cec5SDimitry Andric LLDB_RECORD_DUMMY(size_t, SBProcess, ReadCStringFromMemory,
8760b57cec5SDimitry Andric (lldb::addr_t, void *, size_t, lldb::SBError &), addr, buf,
8770b57cec5SDimitry Andric size, sb_error);
8780b57cec5SDimitry Andric
8790b57cec5SDimitry Andric size_t bytes_read = 0;
8800b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
8810b57cec5SDimitry Andric if (process_sp) {
8820b57cec5SDimitry Andric Process::StopLocker stop_locker;
8830b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
8840b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
8850b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
8860b57cec5SDimitry Andric bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
8870b57cec5SDimitry Andric sb_error.ref());
8880b57cec5SDimitry Andric } else {
8890b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
8900b57cec5SDimitry Andric }
8910b57cec5SDimitry Andric } else {
8920b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
8930b57cec5SDimitry Andric }
8940b57cec5SDimitry Andric return bytes_read;
8950b57cec5SDimitry Andric }
8960b57cec5SDimitry Andric
ReadUnsignedFromMemory(addr_t addr,uint32_t byte_size,lldb::SBError & sb_error)8970b57cec5SDimitry Andric uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
8980b57cec5SDimitry Andric lldb::SBError &sb_error) {
8990b57cec5SDimitry Andric LLDB_RECORD_METHOD(uint64_t, SBProcess, ReadUnsignedFromMemory,
9000b57cec5SDimitry Andric (lldb::addr_t, uint32_t, lldb::SBError &), addr, byte_size,
9010b57cec5SDimitry Andric sb_error);
9020b57cec5SDimitry Andric
9030b57cec5SDimitry Andric uint64_t value = 0;
9040b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
9050b57cec5SDimitry Andric if (process_sp) {
9060b57cec5SDimitry Andric Process::StopLocker stop_locker;
9070b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
9080b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
9090b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
9100b57cec5SDimitry Andric value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
9110b57cec5SDimitry Andric sb_error.ref());
9120b57cec5SDimitry Andric } else {
9130b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
9140b57cec5SDimitry Andric }
9150b57cec5SDimitry Andric } else {
9160b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
9170b57cec5SDimitry Andric }
9180b57cec5SDimitry Andric return value;
9190b57cec5SDimitry Andric }
9200b57cec5SDimitry Andric
ReadPointerFromMemory(addr_t addr,lldb::SBError & sb_error)9210b57cec5SDimitry Andric lldb::addr_t SBProcess::ReadPointerFromMemory(addr_t addr,
9220b57cec5SDimitry Andric lldb::SBError &sb_error) {
9230b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, ReadPointerFromMemory,
9240b57cec5SDimitry Andric (lldb::addr_t, lldb::SBError &), addr, sb_error);
9250b57cec5SDimitry Andric
9260b57cec5SDimitry Andric lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
9270b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
9280b57cec5SDimitry Andric if (process_sp) {
9290b57cec5SDimitry Andric Process::StopLocker stop_locker;
9300b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
9310b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
9320b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
9330b57cec5SDimitry Andric ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref());
9340b57cec5SDimitry Andric } else {
9350b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
9360b57cec5SDimitry Andric }
9370b57cec5SDimitry Andric } else {
9380b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
9390b57cec5SDimitry Andric }
9400b57cec5SDimitry Andric return ptr;
9410b57cec5SDimitry Andric }
9420b57cec5SDimitry Andric
WriteMemory(addr_t addr,const void * src,size_t src_len,SBError & sb_error)9430b57cec5SDimitry Andric size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
9440b57cec5SDimitry Andric SBError &sb_error) {
9450b57cec5SDimitry Andric LLDB_RECORD_DUMMY(size_t, SBProcess, WriteMemory,
9460b57cec5SDimitry Andric (lldb::addr_t, const void *, size_t, lldb::SBError &), addr,
9470b57cec5SDimitry Andric src, src_len, sb_error);
9480b57cec5SDimitry Andric
9490b57cec5SDimitry Andric size_t bytes_written = 0;
9500b57cec5SDimitry Andric
9510b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
9520b57cec5SDimitry Andric
9530b57cec5SDimitry Andric if (process_sp) {
9540b57cec5SDimitry Andric Process::StopLocker stop_locker;
9550b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
9560b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
9570b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
9580b57cec5SDimitry Andric bytes_written =
9590b57cec5SDimitry Andric process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
9600b57cec5SDimitry Andric } else {
9610b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
9620b57cec5SDimitry Andric }
9630b57cec5SDimitry Andric }
9640b57cec5SDimitry Andric
9650b57cec5SDimitry Andric return bytes_written;
9660b57cec5SDimitry Andric }
9670b57cec5SDimitry Andric
GetDescription(SBStream & description)9680b57cec5SDimitry Andric bool SBProcess::GetDescription(SBStream &description) {
9690b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, GetDescription, (lldb::SBStream &),
9700b57cec5SDimitry Andric description);
9710b57cec5SDimitry Andric
9720b57cec5SDimitry Andric Stream &strm = description.ref();
9730b57cec5SDimitry Andric
9740b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
9750b57cec5SDimitry Andric if (process_sp) {
9760b57cec5SDimitry Andric char path[PATH_MAX];
9770b57cec5SDimitry Andric GetTarget().GetExecutable().GetPath(path, sizeof(path));
9780b57cec5SDimitry Andric Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
9790b57cec5SDimitry Andric const char *exe_name = nullptr;
9800b57cec5SDimitry Andric if (exe_module)
9810b57cec5SDimitry Andric exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
9820b57cec5SDimitry Andric
9830b57cec5SDimitry Andric strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
9840b57cec5SDimitry Andric process_sp->GetID(), lldb_private::StateAsCString(GetState()),
9850b57cec5SDimitry Andric GetNumThreads(), exe_name ? ", executable = " : "",
9860b57cec5SDimitry Andric exe_name ? exe_name : "");
9870b57cec5SDimitry Andric } else
9880b57cec5SDimitry Andric strm.PutCString("No value");
9890b57cec5SDimitry Andric
9900b57cec5SDimitry Andric return true;
9910b57cec5SDimitry Andric }
9920b57cec5SDimitry Andric
GetExtendedCrashInformation()9935ffd83dbSDimitry Andric SBStructuredData SBProcess::GetExtendedCrashInformation() {
9945ffd83dbSDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBProcess,
9955ffd83dbSDimitry Andric GetExtendedCrashInformation);
9965ffd83dbSDimitry Andric SBStructuredData data;
9975ffd83dbSDimitry Andric ProcessSP process_sp(GetSP());
9985ffd83dbSDimitry Andric if (!process_sp)
9995ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(data);
10005ffd83dbSDimitry Andric
10015ffd83dbSDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
10025ffd83dbSDimitry Andric
10035ffd83dbSDimitry Andric if (!platform_sp)
10045ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(data);
10055ffd83dbSDimitry Andric
10065ffd83dbSDimitry Andric auto expected_data =
10075ffd83dbSDimitry Andric platform_sp->FetchExtendedCrashInformation(*process_sp.get());
10085ffd83dbSDimitry Andric
10095ffd83dbSDimitry Andric if (!expected_data)
10105ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(data);
10115ffd83dbSDimitry Andric
10125ffd83dbSDimitry Andric StructuredData::ObjectSP fetched_data = *expected_data;
10135ffd83dbSDimitry Andric data.m_impl_up->SetObjectSP(fetched_data);
10145ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(data);
10155ffd83dbSDimitry Andric }
10165ffd83dbSDimitry Andric
10170b57cec5SDimitry Andric uint32_t
GetNumSupportedHardwareWatchpoints(lldb::SBError & sb_error) const10180b57cec5SDimitry Andric SBProcess::GetNumSupportedHardwareWatchpoints(lldb::SBError &sb_error) const {
10190b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST(uint32_t, SBProcess,
10200b57cec5SDimitry Andric GetNumSupportedHardwareWatchpoints,
10210b57cec5SDimitry Andric (lldb::SBError &), sb_error);
10220b57cec5SDimitry Andric
10230b57cec5SDimitry Andric uint32_t num = 0;
10240b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
10250b57cec5SDimitry Andric if (process_sp) {
10260b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
10270b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
10280b57cec5SDimitry Andric sb_error.SetError(process_sp->GetWatchpointSupportInfo(num));
10290b57cec5SDimitry Andric } else {
10300b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
10310b57cec5SDimitry Andric }
10320b57cec5SDimitry Andric return num;
10330b57cec5SDimitry Andric }
10340b57cec5SDimitry Andric
LoadImage(lldb::SBFileSpec & sb_remote_image_spec,lldb::SBError & sb_error)10350b57cec5SDimitry Andric uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
10360b57cec5SDimitry Andric lldb::SBError &sb_error) {
10370b57cec5SDimitry Andric LLDB_RECORD_METHOD(uint32_t, SBProcess, LoadImage,
10380b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBError &),
10390b57cec5SDimitry Andric sb_remote_image_spec, sb_error);
10400b57cec5SDimitry Andric
10410b57cec5SDimitry Andric return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
10420b57cec5SDimitry Andric }
10430b57cec5SDimitry Andric
LoadImage(const lldb::SBFileSpec & sb_local_image_spec,const lldb::SBFileSpec & sb_remote_image_spec,lldb::SBError & sb_error)10440b57cec5SDimitry Andric uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
10450b57cec5SDimitry Andric const lldb::SBFileSpec &sb_remote_image_spec,
10460b57cec5SDimitry Andric lldb::SBError &sb_error) {
10470b57cec5SDimitry Andric LLDB_RECORD_METHOD(
10480b57cec5SDimitry Andric uint32_t, SBProcess, LoadImage,
10490b57cec5SDimitry Andric (const lldb::SBFileSpec &, const lldb::SBFileSpec &, lldb::SBError &),
10500b57cec5SDimitry Andric sb_local_image_spec, sb_remote_image_spec, sb_error);
10510b57cec5SDimitry Andric
10520b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
10530b57cec5SDimitry Andric if (process_sp) {
10540b57cec5SDimitry Andric Process::StopLocker stop_locker;
10550b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
10560b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
10570b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
10580b57cec5SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
10590b57cec5SDimitry Andric return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
10600b57cec5SDimitry Andric *sb_remote_image_spec, sb_error.ref());
10610b57cec5SDimitry Andric } else {
10620b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
10630b57cec5SDimitry Andric }
10640b57cec5SDimitry Andric } else {
10650b57cec5SDimitry Andric sb_error.SetErrorString("process is invalid");
10660b57cec5SDimitry Andric }
10670b57cec5SDimitry Andric return LLDB_INVALID_IMAGE_TOKEN;
10680b57cec5SDimitry Andric }
10690b57cec5SDimitry Andric
LoadImageUsingPaths(const lldb::SBFileSpec & image_spec,SBStringList & paths,lldb::SBFileSpec & loaded_path,lldb::SBError & error)10700b57cec5SDimitry Andric uint32_t SBProcess::LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
10710b57cec5SDimitry Andric SBStringList &paths,
10720b57cec5SDimitry Andric lldb::SBFileSpec &loaded_path,
10730b57cec5SDimitry Andric lldb::SBError &error) {
10740b57cec5SDimitry Andric LLDB_RECORD_METHOD(uint32_t, SBProcess, LoadImageUsingPaths,
10750b57cec5SDimitry Andric (const lldb::SBFileSpec &, lldb::SBStringList &,
10760b57cec5SDimitry Andric lldb::SBFileSpec &, lldb::SBError &),
10770b57cec5SDimitry Andric image_spec, paths, loaded_path, error);
10780b57cec5SDimitry Andric
10790b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
10800b57cec5SDimitry Andric if (process_sp) {
10810b57cec5SDimitry Andric Process::StopLocker stop_locker;
10820b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
10830b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
10840b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
10850b57cec5SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
10860b57cec5SDimitry Andric size_t num_paths = paths.GetSize();
10870b57cec5SDimitry Andric std::vector<std::string> paths_vec;
10880b57cec5SDimitry Andric paths_vec.reserve(num_paths);
10890b57cec5SDimitry Andric for (size_t i = 0; i < num_paths; i++)
10900b57cec5SDimitry Andric paths_vec.push_back(paths.GetStringAtIndex(i));
10910b57cec5SDimitry Andric FileSpec loaded_spec;
10920b57cec5SDimitry Andric
10930b57cec5SDimitry Andric uint32_t token = platform_sp->LoadImageUsingPaths(
10940b57cec5SDimitry Andric process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
10950b57cec5SDimitry Andric if (token != LLDB_INVALID_IMAGE_TOKEN)
10960b57cec5SDimitry Andric loaded_path = loaded_spec;
10970b57cec5SDimitry Andric return token;
10980b57cec5SDimitry Andric } else {
10990b57cec5SDimitry Andric error.SetErrorString("process is running");
11000b57cec5SDimitry Andric }
11010b57cec5SDimitry Andric } else {
11020b57cec5SDimitry Andric error.SetErrorString("process is invalid");
11030b57cec5SDimitry Andric }
11040b57cec5SDimitry Andric
11050b57cec5SDimitry Andric return LLDB_INVALID_IMAGE_TOKEN;
11060b57cec5SDimitry Andric }
11070b57cec5SDimitry Andric
UnloadImage(uint32_t image_token)11080b57cec5SDimitry Andric lldb::SBError SBProcess::UnloadImage(uint32_t image_token) {
11090b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, UnloadImage, (uint32_t),
11100b57cec5SDimitry Andric image_token);
11110b57cec5SDimitry Andric
11120b57cec5SDimitry Andric lldb::SBError sb_error;
11130b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
11140b57cec5SDimitry Andric if (process_sp) {
11150b57cec5SDimitry Andric Process::StopLocker stop_locker;
11160b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
11170b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
11180b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
11190b57cec5SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
11200b57cec5SDimitry Andric sb_error.SetError(
11210b57cec5SDimitry Andric platform_sp->UnloadImage(process_sp.get(), image_token));
11220b57cec5SDimitry Andric } else {
11230b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
11240b57cec5SDimitry Andric }
11250b57cec5SDimitry Andric } else
11260b57cec5SDimitry Andric sb_error.SetErrorString("invalid process");
11270b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
11280b57cec5SDimitry Andric }
11290b57cec5SDimitry Andric
SendEventData(const char * event_data)11300b57cec5SDimitry Andric lldb::SBError SBProcess::SendEventData(const char *event_data) {
11310b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, SendEventData, (const char *),
11320b57cec5SDimitry Andric event_data);
11330b57cec5SDimitry Andric
11340b57cec5SDimitry Andric lldb::SBError sb_error;
11350b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
11360b57cec5SDimitry Andric if (process_sp) {
11370b57cec5SDimitry Andric Process::StopLocker stop_locker;
11380b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
11390b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
11400b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
11410b57cec5SDimitry Andric sb_error.SetError(process_sp->SendEventData(event_data));
11420b57cec5SDimitry Andric } else {
11430b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
11440b57cec5SDimitry Andric }
11450b57cec5SDimitry Andric } else
11460b57cec5SDimitry Andric sb_error.SetErrorString("invalid process");
11470b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
11480b57cec5SDimitry Andric }
11490b57cec5SDimitry Andric
GetNumExtendedBacktraceTypes()11500b57cec5SDimitry Andric uint32_t SBProcess::GetNumExtendedBacktraceTypes() {
11510b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcess, GetNumExtendedBacktraceTypes);
11520b57cec5SDimitry Andric
11530b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
11540b57cec5SDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
11550b57cec5SDimitry Andric SystemRuntime *runtime = process_sp->GetSystemRuntime();
11560b57cec5SDimitry Andric return runtime->GetExtendedBacktraceTypes().size();
11570b57cec5SDimitry Andric }
11580b57cec5SDimitry Andric return 0;
11590b57cec5SDimitry Andric }
11600b57cec5SDimitry Andric
GetExtendedBacktraceTypeAtIndex(uint32_t idx)11610b57cec5SDimitry Andric const char *SBProcess::GetExtendedBacktraceTypeAtIndex(uint32_t idx) {
11620b57cec5SDimitry Andric LLDB_RECORD_METHOD(const char *, SBProcess, GetExtendedBacktraceTypeAtIndex,
11630b57cec5SDimitry Andric (uint32_t), idx);
11640b57cec5SDimitry Andric
11650b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
11660b57cec5SDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
11670b57cec5SDimitry Andric SystemRuntime *runtime = process_sp->GetSystemRuntime();
11680b57cec5SDimitry Andric const std::vector<ConstString> &names =
11690b57cec5SDimitry Andric runtime->GetExtendedBacktraceTypes();
11700b57cec5SDimitry Andric if (idx < names.size()) {
11710b57cec5SDimitry Andric return names[idx].AsCString();
11720b57cec5SDimitry Andric }
11730b57cec5SDimitry Andric }
11740b57cec5SDimitry Andric return nullptr;
11750b57cec5SDimitry Andric }
11760b57cec5SDimitry Andric
GetHistoryThreads(addr_t addr)11770b57cec5SDimitry Andric SBThreadCollection SBProcess::GetHistoryThreads(addr_t addr) {
11780b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBThreadCollection, SBProcess, GetHistoryThreads,
11790b57cec5SDimitry Andric (lldb::addr_t), addr);
11800b57cec5SDimitry Andric
11810b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
11820b57cec5SDimitry Andric SBThreadCollection threads;
11830b57cec5SDimitry Andric if (process_sp) {
11840b57cec5SDimitry Andric threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
11850b57cec5SDimitry Andric }
11860b57cec5SDimitry Andric return LLDB_RECORD_RESULT(threads);
11870b57cec5SDimitry Andric }
11880b57cec5SDimitry Andric
IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)11890b57cec5SDimitry Andric bool SBProcess::IsInstrumentationRuntimePresent(
11900b57cec5SDimitry Andric InstrumentationRuntimeType type) {
11910b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBProcess, IsInstrumentationRuntimePresent,
11920b57cec5SDimitry Andric (lldb::InstrumentationRuntimeType), type);
11930b57cec5SDimitry Andric
11940b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
11950b57cec5SDimitry Andric if (!process_sp)
11960b57cec5SDimitry Andric return false;
11970b57cec5SDimitry Andric
11989dba64beSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
11999dba64beSDimitry Andric process_sp->GetTarget().GetAPIMutex());
12009dba64beSDimitry Andric
12010b57cec5SDimitry Andric InstrumentationRuntimeSP runtime_sp =
12020b57cec5SDimitry Andric process_sp->GetInstrumentationRuntime(type);
12030b57cec5SDimitry Andric
12040b57cec5SDimitry Andric if (!runtime_sp.get())
12050b57cec5SDimitry Andric return false;
12060b57cec5SDimitry Andric
12070b57cec5SDimitry Andric return runtime_sp->IsActive();
12080b57cec5SDimitry Andric }
12090b57cec5SDimitry Andric
SaveCore(const char * file_name)12100b57cec5SDimitry Andric lldb::SBError SBProcess::SaveCore(const char *file_name) {
12110b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, SaveCore, (const char *),
12120b57cec5SDimitry Andric file_name);
12130b57cec5SDimitry Andric
12140b57cec5SDimitry Andric lldb::SBError error;
12150b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
12160b57cec5SDimitry Andric if (!process_sp) {
12170b57cec5SDimitry Andric error.SetErrorString("SBProcess is invalid");
12180b57cec5SDimitry Andric return LLDB_RECORD_RESULT(error);
12190b57cec5SDimitry Andric }
12200b57cec5SDimitry Andric
12210b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
12220b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
12230b57cec5SDimitry Andric
12240b57cec5SDimitry Andric if (process_sp->GetState() != eStateStopped) {
12250b57cec5SDimitry Andric error.SetErrorString("the process is not stopped");
12260b57cec5SDimitry Andric return LLDB_RECORD_RESULT(error);
12270b57cec5SDimitry Andric }
12280b57cec5SDimitry Andric
12290b57cec5SDimitry Andric FileSpec core_file(file_name);
1230*5f7ddb14SDimitry Andric SaveCoreStyle core_style = SaveCoreStyle::eSaveCoreFull;
1231*5f7ddb14SDimitry Andric error.ref() = PluginManager::SaveCore(process_sp, core_file, core_style);
12320b57cec5SDimitry Andric return LLDB_RECORD_RESULT(error);
12330b57cec5SDimitry Andric }
12340b57cec5SDimitry Andric
12350b57cec5SDimitry Andric lldb::SBError
GetMemoryRegionInfo(lldb::addr_t load_addr,SBMemoryRegionInfo & sb_region_info)12360b57cec5SDimitry Andric SBProcess::GetMemoryRegionInfo(lldb::addr_t load_addr,
12370b57cec5SDimitry Andric SBMemoryRegionInfo &sb_region_info) {
12380b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, GetMemoryRegionInfo,
12390b57cec5SDimitry Andric (lldb::addr_t, lldb::SBMemoryRegionInfo &), load_addr,
12400b57cec5SDimitry Andric sb_region_info);
12410b57cec5SDimitry Andric
12420b57cec5SDimitry Andric lldb::SBError sb_error;
12430b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
12440b57cec5SDimitry Andric if (process_sp) {
12450b57cec5SDimitry Andric Process::StopLocker stop_locker;
12460b57cec5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
12470b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
12480b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
12490b57cec5SDimitry Andric
12500b57cec5SDimitry Andric sb_error.ref() =
12510b57cec5SDimitry Andric process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
12520b57cec5SDimitry Andric } else {
12530b57cec5SDimitry Andric sb_error.SetErrorString("process is running");
12540b57cec5SDimitry Andric }
12550b57cec5SDimitry Andric } else {
12560b57cec5SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
12570b57cec5SDimitry Andric }
12580b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
12590b57cec5SDimitry Andric }
12600b57cec5SDimitry Andric
GetMemoryRegions()12610b57cec5SDimitry Andric lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() {
12620b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBMemoryRegionInfoList, SBProcess,
12630b57cec5SDimitry Andric GetMemoryRegions);
12640b57cec5SDimitry Andric
12650b57cec5SDimitry Andric lldb::SBMemoryRegionInfoList sb_region_list;
12660b57cec5SDimitry Andric
12670b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
12680b57cec5SDimitry Andric Process::StopLocker stop_locker;
12690b57cec5SDimitry Andric if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
12700b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
12710b57cec5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
12720b57cec5SDimitry Andric
12730b57cec5SDimitry Andric process_sp->GetMemoryRegions(sb_region_list.ref());
12740b57cec5SDimitry Andric }
12750b57cec5SDimitry Andric
12760b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_region_list);
12770b57cec5SDimitry Andric }
12780b57cec5SDimitry Andric
GetProcessInfo()12790b57cec5SDimitry Andric lldb::SBProcessInfo SBProcess::GetProcessInfo() {
12800b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcessInfo, SBProcess, GetProcessInfo);
12810b57cec5SDimitry Andric
12820b57cec5SDimitry Andric lldb::SBProcessInfo sb_proc_info;
12830b57cec5SDimitry Andric ProcessSP process_sp(GetSP());
12840b57cec5SDimitry Andric ProcessInstanceInfo proc_info;
12850b57cec5SDimitry Andric if (process_sp && process_sp->GetProcessInfo(proc_info)) {
12860b57cec5SDimitry Andric sb_proc_info.SetProcessInfo(proc_info);
12870b57cec5SDimitry Andric }
12880b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_proc_info);
12890b57cec5SDimitry Andric }
12900b57cec5SDimitry Andric
AllocateMemory(size_t size,uint32_t permissions,lldb::SBError & sb_error)1291*5f7ddb14SDimitry Andric lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1292*5f7ddb14SDimitry Andric lldb::SBError &sb_error) {
1293*5f7ddb14SDimitry Andric LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, AllocateMemory,
1294*5f7ddb14SDimitry Andric (size_t, uint32_t, lldb::SBError &), size, permissions,
1295*5f7ddb14SDimitry Andric sb_error);
1296*5f7ddb14SDimitry Andric
1297*5f7ddb14SDimitry Andric lldb::addr_t addr = LLDB_INVALID_ADDRESS;
1298*5f7ddb14SDimitry Andric ProcessSP process_sp(GetSP());
1299*5f7ddb14SDimitry Andric if (process_sp) {
1300*5f7ddb14SDimitry Andric Process::StopLocker stop_locker;
1301*5f7ddb14SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1302*5f7ddb14SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1303*5f7ddb14SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1304*5f7ddb14SDimitry Andric addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1305*5f7ddb14SDimitry Andric } else {
1306*5f7ddb14SDimitry Andric sb_error.SetErrorString("process is running");
1307*5f7ddb14SDimitry Andric }
1308*5f7ddb14SDimitry Andric } else {
1309*5f7ddb14SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
1310*5f7ddb14SDimitry Andric }
1311*5f7ddb14SDimitry Andric return addr;
1312*5f7ddb14SDimitry Andric }
1313*5f7ddb14SDimitry Andric
DeallocateMemory(lldb::addr_t ptr)1314*5f7ddb14SDimitry Andric lldb::SBError SBProcess::DeallocateMemory(lldb::addr_t ptr) {
1315*5f7ddb14SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBProcess, DeallocateMemory, (lldb::addr_t),
1316*5f7ddb14SDimitry Andric ptr);
1317*5f7ddb14SDimitry Andric
1318*5f7ddb14SDimitry Andric lldb::SBError sb_error;
1319*5f7ddb14SDimitry Andric ProcessSP process_sp(GetSP());
1320*5f7ddb14SDimitry Andric if (process_sp) {
1321*5f7ddb14SDimitry Andric Process::StopLocker stop_locker;
1322*5f7ddb14SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1323*5f7ddb14SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1324*5f7ddb14SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1325*5f7ddb14SDimitry Andric Status error = process_sp->DeallocateMemory(ptr);
1326*5f7ddb14SDimitry Andric sb_error.SetError(error);
1327*5f7ddb14SDimitry Andric } else {
1328*5f7ddb14SDimitry Andric sb_error.SetErrorString("process is running");
1329*5f7ddb14SDimitry Andric }
1330*5f7ddb14SDimitry Andric } else {
1331*5f7ddb14SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
1332*5f7ddb14SDimitry Andric }
1333*5f7ddb14SDimitry Andric return sb_error;
1334*5f7ddb14SDimitry Andric }
1335*5f7ddb14SDimitry Andric
13360b57cec5SDimitry Andric namespace lldb_private {
13370b57cec5SDimitry Andric namespace repro {
13380b57cec5SDimitry Andric
13390b57cec5SDimitry Andric template <>
RegisterMethods(Registry & R)13400b57cec5SDimitry Andric void RegisterMethods<SBProcess>(Registry &R) {
13410b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBProcess, ());
13420b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBProcess, (const lldb::SBProcess &));
13430b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBProcess, (const lldb::ProcessSP &));
13440b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const lldb::SBProcess &,
13450b57cec5SDimitry Andric SBProcess, operator=,(const lldb::SBProcess &));
13460b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess,
13470b57cec5SDimitry Andric GetBroadcasterClassName, ());
13480b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBProcess, GetPluginName, ());
13490b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBProcess, GetShortPluginName, ());
13500b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBProcess, Clear, ());
13510b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBProcess, IsValid, ());
13520b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBProcess, operator bool, ());
13530b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, RemoteLaunch,
13540b57cec5SDimitry Andric (const char **, const char **, const char *,
13550b57cec5SDimitry Andric const char *, const char *, const char *, uint32_t,
13560b57cec5SDimitry Andric bool, lldb::SBError &));
13570b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, RemoteAttachToProcessWithID,
13580b57cec5SDimitry Andric (lldb::pid_t, lldb::SBError &));
13590b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumThreads, ());
13600b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBProcess, GetSelectedThread,
13610b57cec5SDimitry Andric ());
13620b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, CreateOSPluginThread,
13630b57cec5SDimitry Andric (lldb::tid_t, lldb::addr_t));
13640b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBProcess, GetTarget, ());
13650b57cec5SDimitry Andric LLDB_REGISTER_METHOD(size_t, SBProcess, PutSTDIN, (const char *, size_t));
13660b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState,
13670b57cec5SDimitry Andric (const lldb::SBEvent &, FILE *));
13689dba64beSDimitry Andric LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState,
13699dba64beSDimitry Andric (const lldb::SBEvent &, FileSP));
13709dba64beSDimitry Andric LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState,
13719dba64beSDimitry Andric (const lldb::SBEvent &, SBFile));
13720b57cec5SDimitry Andric LLDB_REGISTER_METHOD(
13730b57cec5SDimitry Andric void, SBProcess, AppendEventStateReport,
13740b57cec5SDimitry Andric (const lldb::SBEvent &, lldb::SBCommandReturnObject &));
13750b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThread,
13760b57cec5SDimitry Andric (const lldb::SBThread &));
13770b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThreadByID, (lldb::tid_t));
13780b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, SetSelectedThreadByIndexID,
13790b57cec5SDimitry Andric (uint32_t));
13800b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadAtIndex, (size_t));
13810b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumQueues, ());
13820b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBQueue, SBProcess, GetQueueAtIndex, (size_t));
13830b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetStopID, (bool));
13840b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBEvent, SBProcess, GetStopEventForStopID,
13850b57cec5SDimitry Andric (uint32_t));
13860b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::StateType, SBProcess, GetState, ());
13870b57cec5SDimitry Andric LLDB_REGISTER_METHOD(int, SBProcess, GetExitStatus, ());
13880b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBProcess, GetExitDescription, ());
13890b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::pid_t, SBProcess, GetProcessID, ());
13900b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetUniqueID, ());
13910b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(lldb::ByteOrder, SBProcess, GetByteOrder, ());
13920b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(uint32_t, SBProcess, GetAddressByteSize, ());
13930b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Continue, ());
13940b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Destroy, ());
13950b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Stop, ());
13960b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Kill, ());
13970b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Detach, ());
13980b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Detach, (bool));
13990b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, Signal, (int));
14000b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBUnixSignals, SBProcess, GetUnixSignals, ());
14010b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBProcess, SendAsyncInterrupt, ());
14020b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadByID,
14030b57cec5SDimitry Andric (lldb::tid_t));
14040b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBThread, SBProcess, GetThreadByIndexID,
14050b57cec5SDimitry Andric (uint32_t));
14060b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(lldb::StateType, SBProcess, GetStateFromEvent,
14070b57cec5SDimitry Andric (const lldb::SBEvent &));
14080b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, GetRestartedFromEvent,
14090b57cec5SDimitry Andric (const lldb::SBEvent &));
14100b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(size_t, SBProcess,
14110b57cec5SDimitry Andric GetNumRestartedReasonsFromEvent,
14120b57cec5SDimitry Andric (const lldb::SBEvent &));
14130b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess,
14140b57cec5SDimitry Andric GetRestartedReasonAtIndexFromEvent,
14150b57cec5SDimitry Andric (const lldb::SBEvent &, size_t));
14160b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(lldb::SBProcess, SBProcess, GetProcessFromEvent,
14170b57cec5SDimitry Andric (const lldb::SBEvent &));
14180b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, GetInterruptedFromEvent,
14190b57cec5SDimitry Andric (const lldb::SBEvent &));
14200b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(lldb::SBStructuredData, SBProcess,
14210b57cec5SDimitry Andric GetStructuredDataFromEvent,
14220b57cec5SDimitry Andric (const lldb::SBEvent &));
14230b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, EventIsProcessEvent,
14240b57cec5SDimitry Andric (const lldb::SBEvent &));
14250b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(bool, SBProcess, EventIsStructuredDataEvent,
14260b57cec5SDimitry Andric (const lldb::SBEvent &));
14270b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBProcess, GetBroadcaster,
14280b57cec5SDimitry Andric ());
14290b57cec5SDimitry Andric LLDB_REGISTER_STATIC_METHOD(const char *, SBProcess, GetBroadcasterClass,
14300b57cec5SDimitry Andric ());
14310b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint64_t, SBProcess, ReadUnsignedFromMemory,
14320b57cec5SDimitry Andric (lldb::addr_t, uint32_t, lldb::SBError &));
14330b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::addr_t, SBProcess, ReadPointerFromMemory,
14340b57cec5SDimitry Andric (lldb::addr_t, lldb::SBError &));
14350b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, GetDescription, (lldb::SBStream &));
14365ffd83dbSDimitry Andric LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBProcess,
14375ffd83dbSDimitry Andric GetExtendedCrashInformation, ());
14380b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(uint32_t, SBProcess,
14390b57cec5SDimitry Andric GetNumSupportedHardwareWatchpoints,
14400b57cec5SDimitry Andric (lldb::SBError &));
14410b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, LoadImage,
14420b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBError &));
14430b57cec5SDimitry Andric LLDB_REGISTER_METHOD(
14440b57cec5SDimitry Andric uint32_t, SBProcess, LoadImage,
14450b57cec5SDimitry Andric (const lldb::SBFileSpec &, const lldb::SBFileSpec &, lldb::SBError &));
14460b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, LoadImageUsingPaths,
14470b57cec5SDimitry Andric (const lldb::SBFileSpec &, lldb::SBStringList &,
14480b57cec5SDimitry Andric lldb::SBFileSpec &, lldb::SBError &));
14490b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, UnloadImage, (uint32_t));
14500b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, SendEventData,
14510b57cec5SDimitry Andric (const char *));
14520b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcess, GetNumExtendedBacktraceTypes, ());
14530b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBProcess,
14540b57cec5SDimitry Andric GetExtendedBacktraceTypeAtIndex, (uint32_t));
14550b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBThreadCollection, SBProcess, GetHistoryThreads,
14560b57cec5SDimitry Andric (lldb::addr_t));
14570b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcess, IsInstrumentationRuntimePresent,
14580b57cec5SDimitry Andric (lldb::InstrumentationRuntimeType));
14590b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, SaveCore, (const char *));
14600b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, GetMemoryRegionInfo,
14610b57cec5SDimitry Andric (lldb::addr_t, lldb::SBMemoryRegionInfo &));
14620b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBMemoryRegionInfoList, SBProcess,
14630b57cec5SDimitry Andric GetMemoryRegions, ());
14640b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBProcessInfo, SBProcess, GetProcessInfo, ());
1465*5f7ddb14SDimitry Andric LLDB_REGISTER_METHOD(lldb::addr_t, SBProcess, AllocateMemory,
1466*5f7ddb14SDimitry Andric (size_t, uint32_t, lldb::SBError &));
1467*5f7ddb14SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBProcess, DeallocateMemory,
1468*5f7ddb14SDimitry Andric (lldb::addr_t));
14695ffd83dbSDimitry Andric
14705ffd83dbSDimitry Andric LLDB_REGISTER_CHAR_PTR_METHOD_CONST(size_t, SBProcess, GetSTDOUT);
14715ffd83dbSDimitry Andric LLDB_REGISTER_CHAR_PTR_METHOD_CONST(size_t, SBProcess, GetSTDERR);
14725ffd83dbSDimitry Andric LLDB_REGISTER_CHAR_PTR_METHOD_CONST(size_t, SBProcess, GetAsyncProfileData);
14730b57cec5SDimitry Andric }
14740b57cec5SDimitry Andric
14750b57cec5SDimitry Andric }
14760b57cec5SDimitry Andric }
1477