62 : m_opaque_wp(process_sp) {
93const char *SBProcess::GetShortPluginName() {
115 return this->
operator bool();
117SBProcess::operator bool()
const {
120 ProcessSP process_sp(m_opaque_wp.lock());
121 return ((
bool)process_sp && process_sp->IsValid());
125 const char *stdin_path,
const char *stdout_path,
126 const char *stderr_path,
127 const char *working_directory,
128 uint32_t launch_flags,
bool stop_at_entry,
131 working_directory, launch_flags, stop_at_entry,
error);
135 std::lock_guard<std::recursive_mutex> guard(
136 process_sp->GetTarget().GetAPIMutex());
139 launch_flags |= eLaunchFlagStopAtEntry;
142 FileSpec(working_directory), launch_flags);
143 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
150 error.SetError(process_sp->Launch(launch_info));
152 error.SetErrorString(
"must be in eStateConnected to call RemoteLaunch");
155 error.SetErrorString(
"unable to attach pid");
158 return error.Success();
167 std::lock_guard<std::recursive_mutex> guard(
168 process_sp->GetTarget().GetAPIMutex());
172 error.SetError(process_sp->Attach(attach_info));
174 error.SetErrorString(
175 "must be in eStateConnected to call RemoteAttachToProcessWithID");
178 error.SetErrorString(
"unable to attach pid");
181 return error.Success();
187 uint32_t num_threads = 0;
192 const bool can_update = stop_locker.
TryLock(&process_sp->GetRunLock());
193 std::lock_guard<std::recursive_mutex> guard(
194 process_sp->GetTarget().GetAPIMutex());
195 num_threads = process_sp->GetThreadList().GetSize(can_update);
208 std::lock_guard<std::recursive_mutex> guard(
209 process_sp->GetTarget().GetAPIMutex());
210 thread_sp = process_sp->GetThreadList().GetSelectedThread();
225 std::lock_guard<std::recursive_mutex> guard(
226 process_sp->GetTarget().GetAPIMutex());
227 thread_sp = process_sp->CreateOSPluginThread(tid, context);
241 target_sp = process_sp->GetTarget().shared_from_this();
242 sb_target.
SetSP(target_sp);
255 ret_val = process_sp->PutSTDIN(src, src_len,
error);
264 size_t bytes_read = 0;
268 bytes_read = process_sp->GetSTDOUT(dst, dst_len,
error);
277 size_t bytes_read = 0;
281 bytes_read = process_sp->GetSTDERR(dst, dst_len,
error);
290 size_t bytes_read = 0;
294 bytes_read = process_sp->GetAsyncProfileData(dst, dst_len,
error);
308 FileSP outfile = std::make_shared<NativeFile>(out,
false);
316 if (!out || !out->IsValid())
323 stream.
Printf(
"Process %" PRIu64
" %s\n",
336 ::snprintf(message,
sizeof(message),
"Process %" PRIu64
" %s\n",
348 std::lock_guard<std::recursive_mutex> guard(
349 process_sp->GetTarget().GetAPIMutex());
350 return process_sp->GetThreadList().SetSelectedThreadByID(
359 bool ret_val =
false;
362 std::lock_guard<std::recursive_mutex> guard(
363 process_sp->GetTarget().GetAPIMutex());
364 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
373 bool ret_val =
false;
376 std::lock_guard<std::recursive_mutex> guard(
377 process_sp->GetTarget().GetAPIMutex());
378 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
393 const bool can_update = stop_locker.
TryLock(&process_sp->GetRunLock());
394 std::lock_guard<std::recursive_mutex> guard(
395 process_sp->GetTarget().GetAPIMutex());
396 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
406 uint32_t num_queues = 0;
410 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
411 std::lock_guard<std::recursive_mutex> guard(
412 process_sp->GetTarget().GetAPIMutex());
413 num_queues = process_sp->GetQueueList().GetSize();
428 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
429 std::lock_guard<std::recursive_mutex> guard(
430 process_sp->GetTarget().GetAPIMutex());
431 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
444 std::lock_guard<std::recursive_mutex> guard(
445 process_sp->GetTarget().GetAPIMutex());
446 if (include_expression_stops)
447 return process_sp->GetStopID();
449 return process_sp->GetLastNaturalStopID();
461 std::lock_guard<std::recursive_mutex> guard(
462 process_sp->GetTarget().GetAPIMutex());
463 event_sp = process_sp->GetStopEventForStopID(stop_id);
464 sb_event.
reset(event_sp);
474 std::lock_guard<std::recursive_mutex> guard(
475 process_sp->GetTarget().GetAPIMutex());
476 process_sp->ForceScriptedState(new_state);
486 std::lock_guard<std::recursive_mutex> guard(
487 process_sp->GetTarget().GetAPIMutex());
488 ret_val = process_sp->GetState();
500 std::lock_guard<std::recursive_mutex> guard(
501 process_sp->GetTarget().GetAPIMutex());
502 exit_status = process_sp->GetExitStatus();
515 std::lock_guard<std::recursive_mutex> guard(
516 process_sp->GetTarget().GetAPIMutex());
526 ret_val = process_sp->GetID();
534 uint32_t ret_val = 0;
537 ret_val = process_sp->GetUniqueID();
547 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
559 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
572 std::lock_guard<std::recursive_mutex> guard(
573 process_sp->GetTarget().GetAPIMutex());
575 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
576 sb_error.
ref() = process_sp->Resume();
578 sb_error.
ref() = process_sp->ResumeSynchronous(
nullptr);
591 std::lock_guard<std::recursive_mutex> guard(
592 process_sp->GetTarget().GetAPIMutex());
593 sb_error.
SetError(process_sp->Destroy(
false));
606 std::lock_guard<std::recursive_mutex> guard(
607 process_sp->GetTarget().GetAPIMutex());
608 sb_error.
SetError(process_sp->Halt());
621 std::lock_guard<std::recursive_mutex> guard(
622 process_sp->GetTarget().GetAPIMutex());
623 sb_error.
SetError(process_sp->Destroy(
true));
634 bool keep_stopped =
false;
635 return Detach(keep_stopped);
644 std::lock_guard<std::recursive_mutex> guard(
645 process_sp->GetTarget().GetAPIMutex());
646 sb_error.
SetError(process_sp->Detach(keep_stopped));
659 std::lock_guard<std::recursive_mutex> guard(
660 process_sp->GetTarget().GetAPIMutex());
661 sb_error.
SetError(process_sp->Signal(signo));
671 if (
auto process_sp =
GetSP())
682 process_sp->SendAsyncInterrupt();
694 const bool can_update = stop_locker.
TryLock(&process_sp->GetRunLock());
695 std::lock_guard<std::recursive_mutex> guard(
696 process_sp->GetTarget().GetAPIMutex());
697 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
712 const bool can_update = stop_locker.
TryLock(&process_sp->GetRunLock());
713 std::lock_guard<std::recursive_mutex> guard(
714 process_sp->GetTarget().GetAPIMutex());
716 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
791 EventSP event_sp =
event.GetSP();
792 EventData *event_data = event_sp ? event_sp->GetData() :
nullptr;
793 return event_data && (event_data->
GetFlavor() ==
818 sb_error.SetErrorStringWithFormat(
819 "no buffer provided to read %zu bytes into", dst_len);
823 size_t bytes_read = 0;
829 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
830 std::lock_guard<std::recursive_mutex> guard(
831 process_sp->GetTarget().GetAPIMutex());
832 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.
ref());
847 size_t bytes_read = 0;
851 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
852 std::lock_guard<std::recursive_mutex> guard(
853 process_sp->GetTarget().GetAPIMutex());
854 bytes_read = process_sp->ReadCStringFromMemory(addr, (
char *)buf, size,
873 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
874 std::lock_guard<std::recursive_mutex> guard(
875 process_sp->GetTarget().GetAPIMutex());
876 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
895 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
896 std::lock_guard<std::recursive_mutex> guard(
897 process_sp->GetTarget().GetAPIMutex());
898 ptr = process_sp->ReadPointerFromMemory(addr, sb_error.
ref());
912 size_t bytes_written = 0;
918 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
919 std::lock_guard<std::recursive_mutex> guard(
920 process_sp->GetTarget().GetAPIMutex());
922 process_sp->WriteMemory(addr, src, src_len, sb_error.
ref());
928 return bytes_written;
940 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
941 const char *exe_name =
nullptr;
945 strm.
Printf(
"SBProcess: pid = %" PRIu64
", state = %s, threads = %d%s%s",
948 exe_name ? exe_name :
"");
962 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
968 platform_sp->FetchExtendedCrashInformation(*process_sp.get());
974 data.
m_impl_up->SetObjectSP(fetched_data);
985 std::lock_guard<std::recursive_mutex> guard(
986 process_sp->GetTarget().GetAPIMutex());
987 std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
991 sb_error.
SetErrorString(
"Unable to determine number of watchpoints");
1014 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1015 std::lock_guard<std::recursive_mutex> guard(
1016 process_sp->GetTarget().GetAPIMutex());
1017 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1018 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1019 *sb_remote_image_spec, sb_error.
ref());
1038 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1039 std::lock_guard<std::recursive_mutex> guard(
1040 process_sp->GetTarget().GetAPIMutex());
1041 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1042 size_t num_paths = paths.
GetSize();
1043 std::vector<std::string> paths_vec;
1044 paths_vec.reserve(num_paths);
1045 for (
size_t i = 0; i < num_paths; i++)
1049 uint32_t token = platform_sp->LoadImageUsingPaths(
1050 process_sp.get(), *image_spec, paths_vec,
error.ref(), &loaded_spec);
1052 loaded_path = loaded_spec;
1055 error.SetErrorString(
"process is running");
1058 error.SetErrorString(
"process is invalid");
1071 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1072 std::lock_guard<std::recursive_mutex> guard(
1073 process_sp->GetTarget().GetAPIMutex());
1074 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1076 platform_sp->UnloadImage(process_sp.get(), image_token));
1092 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1093 std::lock_guard<std::recursive_mutex> guard(
1094 process_sp->GetTarget().GetAPIMutex());
1095 sb_error.
SetError(process_sp->SendEventData(event_data));
1108 if (process_sp && process_sp->GetSystemRuntime()) {
1119 if (process_sp && process_sp->GetSystemRuntime()) {
1121 const std::vector<ConstString> &names =
1123 if (idx < names.size()) {
1124 return names[idx].AsCString();
1149 std::lock_guard<std::recursive_mutex> guard(
1150 process_sp->GetTarget().GetAPIMutex());
1153 process_sp->GetInstrumentationRuntime(type);
1155 if (!runtime_sp.get())
1158 return runtime_sp->IsActive();
1174 error.SetErrorString(
"SBProcess is invalid");
1178 std::lock_guard<std::recursive_mutex> guard(
1179 process_sp->GetTarget().GetAPIMutex());
1182 error.SetErrorString(
"the process is not stopped");
1203 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1204 std::lock_guard<std::recursive_mutex> guard(
1205 process_sp->GetTarget().GetAPIMutex());
1208 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.
ref());
1225 if (process_sp && stop_locker.
TryLock(&process_sp->GetRunLock())) {
1226 std::lock_guard<std::recursive_mutex> guard(
1227 process_sp->GetTarget().GetAPIMutex());
1229 process_sp->GetMemoryRegions(sb_region_list.
ref());
1232 return sb_region_list;
1241 if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1244 return sb_proc_info;
1255 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1256 std::lock_guard<std::recursive_mutex> guard(
1257 process_sp->GetTarget().GetAPIMutex());
1258 addr = process_sp->AllocateMemory(size, permissions, sb_error.
ref());
1275 if (stop_locker.
TryLock(&process_sp->GetRunLock())) {
1276 std::lock_guard<std::recursive_mutex> guard(
1277 process_sp->GetTarget().GetAPIMutex());
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
void AppendMessage(const char *message)
static const char * StateAsCString(lldb::StateType state)
void SetErrorString(const char *err_str)
void SetError(uint32_t err, lldb::ErrorType type)
lldb_private::Status & ref()
lldb_private::Event * get() const
void reset(lldb::EventSP &event_sp)
lldb::EventSP & GetSP() const
uint32_t GetPath(char *dst_path, size_t dst_len) const
lldb_private::MemoryRegionInfos & ref()
lldb_private::MemoryRegionInfo & ref()
void SetProcessInfo(const lldb_private::ProcessInstanceInfo &proc_info_ref)
const lldb::SBProcess & operator=(const lldb::SBProcess &rhs)
static size_t GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event)
lldb::SBError SendEventData(const char *data)
lldb::SBBroadcaster GetBroadcaster() const
lldb::SBThread GetThreadAtIndex(size_t index)
static const char * GetBroadcasterClassName()
void AppendEventStateReport(const lldb::SBEvent &event, lldb::SBCommandReturnObject &result)
uint32_t GetNumExtendedBacktraceTypes()
Return the number of different thread-origin extended backtraces this process can support.
size_t PutSTDIN(const char *src, size_t src_len)
lldb::SBQueue GetQueueAtIndex(size_t index)
void ReportEventState(const lldb::SBEvent &event, FILE *out) const
const char * GetExitDescription()
lldb::SBThread GetThreadByIndexID(uint32_t index_id)
static const char * GetBroadcasterClass()
static lldb::SBStructuredData GetStructuredDataFromEvent(const lldb::SBEvent &event)
lldb::ProcessSP GetSP() const
lldb::pid_t GetProcessID()
Gets the process ID.
lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, lldb::SBError &error)
Allocate memory within the process.
static bool EventIsStructuredDataEvent(const lldb::SBEvent &event)
lldb::SBError UnloadImage(uint32_t image_token)
lldb::SBProcessInfo GetProcessInfo()
Return information about the process.
uint32_t GetUniqueID()
Gets the unique ID associated with this process object.
bool GetDescription(lldb::SBStream &description)
size_t GetAsyncProfileData(char *dst, size_t dst_len) const
lldb::StateType GetState()
lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context)
lldb::SBScriptObject GetScriptedImplementation()
lldb::ByteOrder GetByteOrder() const
size_t ReadCStringFromMemory(addr_t addr, void *char_buf, size_t size, lldb::SBError &error)
lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error)
lldb::SBError DeallocateMemory(lldb::addr_t ptr)
Deallocate memory in the process.
static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event)
lldb::SBThread GetSelectedThread() const
bool SetSelectedThreadByIndexID(uint32_t index_id)
size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error)
const char * GetExtendedBacktraceTypeAtIndex(uint32_t idx)
Return the name of one of the thread-origin extended backtrace methods.
lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id)
bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error)
Remote connection related functions.
lldb::SBTarget GetTarget() const
const char * GetPluginName()
bool 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)
size_t GetSTDOUT(char *dst, size_t dst_len) const
lldb::SBEvent GetStopEventForStopID(uint32_t stop_id)
Gets the stop event corresponding to stop ID.
lldb::SBError Signal(int signal)
static bool GetInterruptedFromEvent(const lldb::SBEvent &event)
lldb::ProcessWP m_opaque_wp
uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const
uint32_t LoadImageUsingPaths(const lldb::SBFileSpec &image_spec, SBStringList &paths, lldb::SBFileSpec &loaded_path, lldb::SBError &error)
Load a shared library into this process, starting with a library name and a list of paths,...
uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error)
Load a shared library into this process.
static const char * GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx)
lldb::SBUnixSignals GetUnixSignals()
lldb::SBThreadCollection GetHistoryThreads(addr_t addr)
bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)
bool SetSelectedThread(const lldb::SBThread &thread)
bool SetSelectedThreadByID(lldb::tid_t tid)
void SendAsyncInterrupt()
static bool GetRestartedFromEvent(const lldb::SBEvent &event)
static bool EventIsProcessEvent(const lldb::SBEvent &event)
lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr, lldb::SBMemoryRegionInfo ®ion_info)
Query the address load_addr and store the details of the memory region that contains it in the suppli...
void SetSP(const lldb::ProcessSP &process_sp)
size_t WriteMemory(addr_t addr, const void *buf, size_t size, lldb::SBError &error)
lldb::SBError SaveCore(const char *file_name, const char *flavor, SaveCoreStyle core_style)
Save the state of the process in a core file.
lldb::SBMemoryRegionInfoList GetMemoryRegions()
Return the list of memory regions within the process.
uint32_t GetAddressByteSize() const
SBStructuredData GetExtendedCrashInformation()
uint32_t GetStopID(bool include_expression_stops=false)
uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size, lldb::SBError &error)
void ForceScriptedState(StateType new_state)
If the process is a scripted process, changes its state to the new state.
static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event)
size_t GetSTDERR(char *dst, size_t dst_len) const
void SetQueue(const lldb::QueueSP &queue_sp)
lldb_private::Stream & ref()
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
void SetSP(const lldb::TargetSP &target_sp)
lldb::SBFileSpec GetExecutable()
lldb::tid_t GetThreadID() const
void SetThread(const lldb::ThreadSP &lldb_object_sp)
void AppendArguments(const Args &rhs)
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
static llvm::StringRef GetFlavorString()
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
virtual llvm::StringRef GetFlavor() const =0
const ConstString & GetFilename() const
Filename string const get accessor.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
A class that describes an executable image and its associated object and symbol files.
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
static Status SaveCore(const lldb::ProcessSP &process_sp, const FileSpec &outfile, lldb::SaveCoreStyle &core_style, llvm::StringRef plugin_name)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
void SetProcessID(lldb::pid_t pid)
Environment & GetEnvironment()
bool TryLock(ProcessRunLock *lock)
static bool GetRestartedFromEvent(const Event *event_ptr)
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
size_t GetNumRestartedReasons()
static bool GetInterruptedFromEvent(const Event *event_ptr)
const char * GetRestartedReasonAtIndex(size_t idx)
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
static ConstString & GetStaticBroadcasterClass()
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
std::shared_ptr< Object > ObjectSP
A plug-in interface definition class for system runtimes.
virtual const std::vector< ConstString > & GetExtendedBacktraceTypes()
Return a list of thread origin extended backtraces that may be available.
#define LLDB_INVALID_IMAGE_TOKEN
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
std::shared_ptr< lldb_private::Queue > QueueSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Platform > PlatformSP
StateType
Process and Thread States.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateStopped
Process or thread is stopped and can be examined.
std::shared_ptr< lldb_private::Process > ProcessSP
InstrumentationRuntimeType
std::shared_ptr< lldb_private::Event > EventSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::File > FileSP
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP