14#include "llvm/ADT/ScopeExit.h"
15#include "llvm/Support/ScopedPrinter.h"
16#include "llvm/Support/Threading.h"
80using namespace std::chrono;
84#define ENABLE_MEMORY_CACHING
86#ifdef ENABLE_MEMORY_CACHING
87#define DISABLE_MEM_CACHE_DEFAULT false
89#define DISABLE_MEM_CACHE_DEFAULT true
93 :
public Cloneable<ProcessOptionValueProperties, OptionValueProperties> {
109 if (
this != instance_properties)
121 "Continue tracing the parent process and detach the child.",
126 "Trace the child process and detach the parent.",
130#define LLDB_PROPERTIES_process
131#include "TargetProperties.inc"
134#define LLDB_PROPERTIES_process
135#include "TargetPropertiesEnum.inc"
139#define LLDB_PROPERTIES_process_experimental
140#include "TargetProperties.inc"
143#define LLDB_PROPERTIES_process_experimental
144#include "TargetPropertiesEnum.inc"
148 :
public Cloneable<ProcessExperimentalOptionValueProperties,
149 OptionValueProperties> {
165 if (process ==
nullptr) {
167 m_collection_sp = std::make_shared<ProcessOptionValueProperties>(
"process");
170 "thread",
"Settings specific to threads.",
true,
176 ePropertyPythonOSPluginPath,
181 std::make_unique<ProcessExperimentalProperties>();
184 "Experimental settings - setting these won't produce "
185 "errors if the setting is not present.",
192 const uint32_t idx = ePropertyDisableMemCache;
193 return GetPropertyAtIndexAs<bool>(
194 idx, g_process_properties[idx].default_uint_value != 0);
198 const uint32_t idx = ePropertyMemCacheLineSize;
199 return GetPropertyAtIndexAs<uint64_t>(
200 idx, g_process_properties[idx].default_uint_value);
205 const uint32_t idx = ePropertyExtraStartCommand;
211 const uint32_t idx = ePropertyExtraStartCommand;
216 const uint32_t idx = ePropertyPythonOSPluginPath;
217 return GetPropertyAtIndexAs<FileSpec>(idx, {});
221 const uint32_t idx = ePropertyVirtualAddressableBits;
222 return GetPropertyAtIndexAs<uint64_t>(
223 idx, g_process_properties[idx].default_uint_value);
227 const uint32_t idx = ePropertyVirtualAddressableBits;
232 const uint32_t idx = ePropertyHighmemVirtualAddressableBits;
233 return GetPropertyAtIndexAs<uint64_t>(
234 idx, g_process_properties[idx].default_uint_value);
238 const uint32_t idx = ePropertyHighmemVirtualAddressableBits;
243 const uint32_t idx = ePropertyPythonOSPluginPath;
248 const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions;
249 return GetPropertyAtIndexAs<bool>(
250 idx, g_process_properties[idx].default_uint_value != 0);
254 const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions;
259 const uint32_t idx = ePropertyUnwindOnErrorInExpressions;
260 return GetPropertyAtIndexAs<bool>(
261 idx, g_process_properties[idx].default_uint_value != 0);
265 const uint32_t idx = ePropertyUnwindOnErrorInExpressions;
270 const uint32_t idx = ePropertyStopOnSharedLibraryEvents;
271 return GetPropertyAtIndexAs<bool>(
272 idx, g_process_properties[idx].default_uint_value != 0);
276 const uint32_t idx = ePropertyStopOnSharedLibraryEvents;
281 const uint32_t idx = ePropertyDisableLangRuntimeUnwindPlans;
282 return GetPropertyAtIndexAs<bool>(
283 idx, g_process_properties[idx].default_uint_value != 0);
287 const uint32_t idx = ePropertyDisableLangRuntimeUnwindPlans;
293 const uint32_t idx = ePropertyDetachKeepsStopped;
294 return GetPropertyAtIndexAs<bool>(
295 idx, g_process_properties[idx].default_uint_value != 0);
299 const uint32_t idx = ePropertyDetachKeepsStopped;
304 const uint32_t idx = ePropertyWarningOptimization;
305 return GetPropertyAtIndexAs<bool>(
306 idx, g_process_properties[idx].default_uint_value != 0);
310 const uint32_t idx = ePropertyWarningUnsupportedLanguage;
311 return GetPropertyAtIndexAs<bool>(
312 idx, g_process_properties[idx].default_uint_value != 0);
316 const uint32_t idx = ePropertyStopOnExec;
317 return GetPropertyAtIndexAs<bool>(
318 idx, g_process_properties[idx].default_uint_value != 0);
322 const uint32_t idx = ePropertyUtilityExpressionTimeout;
323 uint64_t value = GetPropertyAtIndexAs<uint64_t>(
324 idx, g_process_properties[idx].default_uint_value);
325 return std::chrono::seconds(value);
329 const uint32_t idx = ePropertyInterruptTimeout;
330 uint64_t value = GetPropertyAtIndexAs<uint64_t>(
331 idx, g_process_properties[idx].default_uint_value);
332 return std::chrono::seconds(value);
336 const uint32_t idx = ePropertySteppingRunsAllThreads;
337 return GetPropertyAtIndexAs<bool>(
338 idx, g_process_properties[idx].default_uint_value != 0);
342 const bool fail_value =
true;
346 exp_property->
GetValue()->GetAsProperties();
352 .value_or(fail_value);
359 exp_property->
GetValue()->GetAsProperties();
366 const uint32_t idx = ePropertyFollowForkMode;
367 return GetPropertyAtIndexAs<FollowForkMode>(
369 g_process_properties[idx].default_uint_value));
373 llvm::StringRef plugin_name,
377 static uint32_t g_process_unique_id = 0;
381 if (!plugin_name.empty()) {
384 if (create_callback) {
385 process_sp = create_callback(target_sp, listener_sp, crash_file_path,
388 if (process_sp->CanDebug(target_sp,
true)) {
389 process_sp->m_process_unique_id = ++g_process_unique_id;
395 for (uint32_t idx = 0;
399 process_sp = create_callback(target_sp, listener_sp, crash_file_path,
402 if (process_sp->CanDebug(target_sp,
false)) {
403 process_sp->m_process_unique_id = ++g_process_unique_id;
414 static constexpr llvm::StringLiteral class_name(
"lldb.process");
427 Broadcaster((target_sp->GetDebugger().GetBroadcasterManager()),
428 Process::GetStaticBroadcasterClass().str()),
431 m_private_state_broadcaster(nullptr,
432 "lldb.process.internal_state_broadcaster"),
433 m_private_state_control_broadcaster(
434 nullptr,
"lldb.process.internal_state_control_broadcaster"),
435 m_private_state_listener_sp(
436 Listener::MakeListener(
"lldb.process.internal_state_listener")),
437 m_mod_id(), m_process_unique_id(0), m_thread_index_id(0),
438 m_thread_id_to_index_id_map(), m_exit_status(-1),
439 m_thread_list_real(*this), m_thread_list(*this), m_thread_plans(*this),
440 m_extended_thread_list(*this), m_extended_thread_stop_id(0),
441 m_queue_list(this), m_queue_list_stop_id(0),
442 m_unix_signals_sp(unix_signals_sp), m_abi_sp(), m_process_input_reader(),
443 m_stdio_communication(
"process.stdio"), m_stdio_communication_mutex(),
444 m_stdin_forward(false), m_stdout_data(), m_stderr_data(),
445 m_profile_data_comm_mutex(), m_profile_data(), m_iohandler_sync(0),
446 m_memory_cache(*this), m_allocated_memory_cache(*this),
447 m_should_detach(false), m_next_event_action_up(), m_public_run_lock(),
448 m_private_run_lock(), m_currently_handling_do_on_removals(false),
450 m_finalizing(false), m_destructing(false),
451 m_clear_thread_plans_on_stop(false), m_force_next_event_delivery(false),
452 m_last_broadcast_state(
eStateInvalid), m_destroy_in_process(false),
453 m_can_interpret_function_calls(false), m_run_thread_plan_lock(),
454 m_can_jit(eCanJITDontKnow),
459 LLDB_LOGF(log,
"%p Process::Process()",
static_cast<void *
>(
this));
497 uint64_t platform_cache_line_size =
498 target_sp->GetPlatform()->GetDefaultMemoryCacheLineSize();
499 if (!value_sp->OptionWasSet() && platform_cache_line_size != 0)
500 value_sp->SetValueAs(platform_cache_line_size);
511 LLDB_LOGF(log,
"%p Process::~Process()",
static_cast<void *
>(
this));
525 return *g_settings_ptr;
560 std::vector<Notifications> empty_notifications;
594 if (pos->baton == callbacks.
baton &&
605 std::vector<Notifications>::iterator notification_pos,
608 notification_pos != notification_end; ++notification_pos) {
609 if (notification_pos->process_state_changed)
610 notification_pos->process_state_changed(notification_pos->baton,
this,
629 std::chrono::seconds(0)) &&
649 "waited from m_iohandler_sync to change from {0}. New value is {1}.",
650 iohandler_id, *Result);
652 LLDB_LOG(log,
"timed out waiting for m_iohandler_sync to change from {0}.",
665 event_sp_ptr->reset();
673 LLDB_LOG(log,
"timeout = {0}", timeout);
678 "Process::%s returning without waiting for events; process "
679 "private and public states are already 'stopped'.",
683 if (hijack_listener_sp && use_run_lock)
691 if (event_sp_ptr && event_sp)
692 *event_sp_ptr = event_sp;
694 bool pop_process_io_handler = (hijack_listener_sp.get() !=
nullptr);
696 event_sp, stream, select_most_relevant, pop_process_io_handler);
705 if (hijack_listener_sp && use_run_lock)
714 if (hijack_listener_sp && use_run_lock)
728 bool &pop_process_io_handler) {
729 const bool handle_pop = pop_process_io_handler;
731 pop_process_io_handler =
false;
743 switch (event_state) {
751 stream->
Printf(
"Process %" PRIu64
" %s\n", process_sp->GetID(),
754 pop_process_io_handler =
true;
764 process_sp->GetStatus(*stream);
765 pop_process_io_handler =
true;
776 if (num_reasons > 0) {
779 if (num_reasons == 1) {
783 stream->
Printf(
"Process %" PRIu64
" stopped and restarted: %s\n",
785 reason ? reason :
"<UNKNOWN REASON>");
787 stream->
Printf(
"Process %" PRIu64
788 " stopped and restarted, reasons:\n",
789 process_sp->GetID());
791 for (
size_t i = 0; i < num_reasons; i++) {
795 stream->
Printf(
"\t%s\n", reason ? reason :
"<UNKNOWN REASON>");
805 ThreadList &thread_list = process_sp->GetThreadList();
806 std::lock_guard<std::recursive_mutex> guard(thread_list.
GetMutex());
811 bool prefer_curr_thread =
false;
812 if (curr_thread && curr_thread->IsValid()) {
813 curr_thread_stop_reason = curr_thread->GetStopReason();
814 switch (curr_thread_stop_reason) {
823 uint64_t signo = curr_thread->GetStopInfo()->GetValue();
824 if (process_sp->GetUnixSignals()->GetShouldStop(signo))
825 prefer_curr_thread =
true;
828 prefer_curr_thread =
true;
831 curr_thread_stop_info_sp = curr_thread->GetStopInfo();
834 if (!prefer_curr_thread) {
840 const size_t num_threads = thread_list.
GetSize();
842 for (i = 0; i < num_threads; ++i) {
844 StopReason thread_stop_reason = thread->GetStopReason();
845 switch (thread_stop_reason) {
854 uint64_t signo = thread->GetStopInfo()->GetValue();
855 if (process_sp->GetUnixSignals()->GetShouldStop(signo)) {
857 other_thread = thread;
874 other_thread = thread;
878 plan_thread = thread;
884 else if (other_thread)
887 if (curr_thread && curr_thread->IsValid())
888 thread = curr_thread;
902 Debugger &debugger = process_sp->GetTarget().GetDebugger();
904 &process_sp->GetTarget()) {
905 ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
907 if (!thread_sp || !thread_sp->IsValid())
910 const bool only_threads_with_stop_reason =
true;
911 const uint32_t start_frame =
912 thread_sp->GetSelectedFrameIndex(select_most_relevant);
913 const uint32_t num_frames = 1;
914 const uint32_t num_frames_with_source = 1;
915 const bool stop_format =
true;
917 process_sp->GetStatus(*stream);
918 process_sp->GetThreadStatus(*stream, only_threads_with_stop_reason,
919 start_frame, num_frames,
920 num_frames_with_source,
922 if (curr_thread_stop_info_sp) {
925 curr_thread_stop_info_sp, &crashing_address);
931 valobj_sp->GetExpressionPath(*stream, format);
932 stream->
Printf(
" accessed 0x%" PRIx64
"\n", crashing_address);
937 process_sp->GetTarget().shared_from_this());
939 stream->
Printf(
"Target %d: (", target_idx);
941 stream->
Printf(
"Target <unknown index>: (");
943 stream->
Printf(
") stopped.\n");
948 pop_process_io_handler =
true;
953 if (handle_pop && pop_process_io_handler)
954 process_sp->PopProcessIOHandler();
973 LLDB_LOG(log,
"timeout = {0}, event_sp)...", timeout);
980 if (listener_sp->GetEventForBroadcasterWithType(
986 LLDB_LOG(log,
"got no event or was interrupted.");
989 LLDB_LOG(log,
"timeout = {0}, event_sp) => {1}", timeout, state);
996 LLDB_LOGF(log,
"Process::%s...", __FUNCTION__);
1003 LLDB_LOGF(log,
"Process::%s (event_ptr) => %s", __FUNCTION__,
1006 LLDB_LOGF(log,
"Process::%s no events found", __FUNCTION__);
1016 LLDB_LOG(log,
"timeout = {0}, event_sp)...", timeout);
1026 LLDB_LOG(log,
"timeout = {0}, event_sp) => {1}", timeout,
1033 bool control_only) {
1035 LLDB_LOG(log,
"timeout = {0}, event_sp)...", timeout);
1069 LLDB_LOG(log,
"(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
1076 "(plugin = {0}) ignoring exit status because state was already set "
1083 if (!exit_string.empty())
1127 "Process::SetProcessExitStatus (pid=%" PRIu64
1128 ", exited=%i, signal=%i, exit_status=%i)\n",
1129 pid, exited, signo, exit_status);
1134 ProcessSP process_sp(target_sp->GetProcessSP());
1136 llvm::StringRef signal_str =
1137 process_sp->GetUnixSignals()->GetSignalAsStringRef(signo);
1138 process_sp->SetExitStatus(exit_status, signal_str);
1156 bool clear_unused_threads =
true;
1179 size_t num_old_threads = old_thread_list.
GetSize(
false);
1180 for (
size_t i = 0; i < num_old_threads; ++i)
1213 new_thread_list = real_thread_list;
1253 bool internal,
bool condense_trivial,
1254 bool skip_unreported_plans) {
1256 strm, tid, desc_level, internal, condense_trivial, skip_unreported_plans);
1259 bool internal,
bool condense_trivial,
1260 bool skip_unreported_plans) {
1262 skip_unreported_plans);
1295 uint32_t result = 0;
1296 std::map<uint64_t, uint32_t>::iterator iterator =
1302 result = iterator->second;
1317 if (new_state_is_stopped) {
1328 LLDB_LOGF(log,
"(plugin = %s, state = %s, restarted = %i)",
1339 "(plugin = %s, state = %s) -- unlocking run lock for detach",
1344 if ((old_state_is_stopped != new_state_is_stopped)) {
1345 if (new_state_is_stopped && !restarted) {
1346 LLDB_LOGF(log,
"(plugin = %s, state = %s) -- unlocking run lock",
1359 LLDB_LOGF(log,
"(plugin = %s) -- TrySetRunning failed, not resuming.",
1362 "Resume request failed - process still running.");
1365 if (!
error.Success()) {
1374 LLDB_LOGF(log,
"Process::ResumeSynchronous -- locking run lock");
1376 LLDB_LOGF(log,
"Process::Resume: -- TrySetRunning failed, not resuming.");
1378 "Resume request failed - process still running.");
1386 if (
error.Success()) {
1390 const bool must_be_alive =
1394 "process not in stopped state after synchronous resume: %s",
1410 if (!hijacking_name.starts_with(
"lldb.internal"))
1438 bool state_changed =
false;
1447 state_changed = old_state != new_state;
1451 if (old_state_is_stopped != new_state_is_stopped) {
1452 if (new_state_is_stopped)
1458 if (state_changed) {
1482 LLDB_LOGF(log,
"(plugin = %s, state = %s, stop_id = %u",
1489 LLDB_LOGF(log,
"(plugin = %s, state = %s) state didn't change. Ignoring...",
1511 std::vector<LanguageRuntime *> language_runtimes;
1514 return language_runtimes;
1524 language_runtimes.emplace_back(runtime);
1527 return language_runtimes;
1537 LanguageRuntimeCollection::iterator pos;
1544 runtime = runtime_sp.get();
1546 runtime = pos->second.get();
1572 if (runtime->CouldHaveDynamicValue(in_value))
1602 if (
error.Success())
1612 if (bp_site_sp->IsEnabled())
1616 "invalid breakpoint site ID: %" PRIu64, break_id);
1626 if (!bp_site_sp->IsEnabled())
1630 "invalid breakpoint site ID: %" PRIu64, break_id);
1637 bool use_hardware) {
1640 bool show_error =
true;
1663 constituent->SetIsIndirect(
false);
1665 if (constituent->ShouldResolveIndirectFunctions()) {
1671 if (!
error.Success() && show_error) {
1673 "warning: failed to resolve indirect function at 0x%" PRIx64
1674 " for breakpoint %i.%i: %s\n",
1676 constituent->GetBreakpoint().GetID(), constituent->GetID(),
1677 error.AsCString() ?
error.AsCString() :
"unknown error");
1680 Address resolved_address(load_addr);
1682 constituent->SetIsIndirect(
true);
1684 load_addr = constituent->GetAddress().GetOpcodeLoadAddress(&
GetTarget());
1686 load_addr = constituent->GetAddress().GetOpcodeLoadAddress(&
GetTarget());
1697 bp_site_sp->AddConstituent(constituent);
1698 constituent->SetBreakpointSite(bp_site_sp);
1699 return bp_site_sp->GetID();
1705 if (
error.Success()) {
1706 constituent->SetBreakpointSite(bp_site_sp);
1709 if (show_error || use_hardware) {
1712 "warning: failed to set breakpoint site at 0x%" PRIx64
1713 " for breakpoint %i.%i: %s\n",
1714 load_addr, constituent->GetBreakpoint().GetID(),
1715 constituent->GetID(),
1716 error.AsCString() ?
error.AsCString() :
"unknown error");
1729 uint32_t num_constituents =
1730 bp_site_sp->RemoveConstituent(constituent_id, constituent_loc_id);
1731 if (num_constituents == 0) {
1740 uint8_t *buf)
const {
1741 size_t bytes_removed = 0;
1745 bp_sites_in_range)) {
1746 bp_sites_in_range.
ForEach([bp_addr, size,
1749 addr_t intersect_addr;
1750 size_t intersect_size;
1751 size_t opcode_offset;
1752 if (bp_site->IntersectsRange(bp_addr, size, &intersect_addr,
1753 &intersect_size, &opcode_offset)) {
1754 assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size);
1755 assert(bp_addr < intersect_addr + intersect_size &&
1756 intersect_addr + intersect_size <= bp_addr + size);
1757 assert(opcode_offset + intersect_size <= bp_site->GetByteSize());
1758 size_t buf_offset = intersect_addr - bp_addr;
1759 ::memcpy(buf + buf_offset,
1760 bp_site->GetSavedOpcodeBytes() + opcode_offset,
1766 return bytes_removed;
1772 return platform_sp->GetSoftwareBreakpointTrapOpcode(
GetTarget(), bp_site);
1778 assert(bp_site !=
nullptr);
1782 log,
"Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64,
1783 bp_site->
GetID(), (uint64_t)bp_addr);
1787 "Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1788 " -- already enabled",
1789 bp_site->
GetID(), (uint64_t)bp_addr);
1795 "BreakpointSite contains an invalid load address.");
1802 if (bp_opcode_size == 0) {
1804 "Process::GetSoftwareBreakpointTrapOpcode() "
1805 "returned zero, unable to get breakpoint "
1806 "trap for address 0x%" PRIx64,
1811 if (bp_opcode_bytes ==
nullptr) {
1813 "BreakpointSite doesn't contain a valid breakpoint trap opcode.");
1819 error) == bp_opcode_size) {
1823 uint8_t verify_bp_opcode_bytes[64];
1824 if (
DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size,
1825 error) == bp_opcode_size) {
1826 if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes,
1827 bp_opcode_size) == 0) {
1831 "Process::EnableSoftwareBreakpoint (site_id = %d) "
1832 "addr = 0x%" PRIx64
" -- SUCCESS",
1833 bp_site->
GetID(), (uint64_t)bp_addr);
1836 "failed to verify the breakpoint trap in memory.");
1839 "Unable to read memory to verify breakpoint trap.");
1842 "Unable to write breakpoint trap to memory.");
1845 "Unable to read memory at breakpoint address.");
1847 if (log &&
error.Fail())
1850 "Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1852 bp_site->
GetID(), (uint64_t)bp_addr,
error.AsCString());
1858 assert(bp_site !=
nullptr);
1863 "Process::DisableSoftwareBreakpoint (breakID = %" PRIu64
1864 ") addr = 0x%" PRIx64,
1865 breakID, (uint64_t)bp_addr);
1871 const size_t break_op_size = bp_site->
GetByteSize();
1873 if (break_op_size > 0) {
1875 uint8_t curr_break_op[8];
1876 assert(break_op_size <=
sizeof(curr_break_op));
1877 bool break_op_found =
false;
1882 bool verify =
false;
1884 if (::memcmp(curr_break_op, break_op, break_op_size) == 0) {
1885 break_op_found =
true;
1889 break_op_size,
error) == break_op_size) {
1893 "Memory write failed when restoring original opcode.");
1896 "Original breakpoint trap is no longer in memory.");
1903 uint8_t verify_opcode[8];
1904 assert(break_op_size <
sizeof(verify_opcode));
1910 break_op_size) == 0) {
1914 "Process::DisableSoftwareBreakpoint (site_id = %d) "
1915 "addr = 0x%" PRIx64
" -- SUCCESS",
1916 bp_site->
GetID(), (uint64_t)bp_addr);
1921 "Failed to restore original opcode.");
1926 "breakpoint trap was restored.");
1930 "Unable to read memory that should contain the breakpoint trap.");
1935 "Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1936 " -- already disabled",
1937 bp_site->
GetID(), (uint64_t)bp_addr);
1943 "Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1945 bp_site->
GetID(), (uint64_t)bp_addr,
error.AsCString());
1955 addr = abi_sp->FixAnyAddress(addr);
1959#if defined(VERIFY_MEMORY_READS)
1971 std::string verify_buf(size,
'\0');
1972 assert(verify_buf.size() == size);
1973 const size_t cache_bytes_read =
1976 const size_t verify_bytes_read =
1978 verify_buf.size(), verify_error);
1979 assert(cache_bytes_read == verify_bytes_read);
1980 assert(memcmp(buf, verify_buf.data(), verify_buf.size()) == 0);
1982 return cache_bytes_read;
1998 const uint8_t *buf,
size_t size,
2000 size_t max_matches) {
2002 assert(buf !=
nullptr);
2004 assert(alignment > 0);
2005 assert(max_matches > 0);
2008 assert(start_addr < end_addr);
2010 lldb::addr_t start = llvm::alignTo(start_addr, alignment);
2011 while (matches.size() < max_matches && (start + size) < end_addr) {
2016 if (found_addr % alignment) {
2019 start = llvm::alignTo(start + 1, alignment);
2023 matches.emplace_back(found_addr, size);
2024 start = found_addr + alignment;
2030 size_t alignment,
size_t max_matches,
2033 if (buf ==
nullptr) {
2041 if (ranges.empty()) {
2045 if (alignment == 0) {
2049 if (max_matches == 0) {
2054 int resolved_ranges = 0;
2056 for (
size_t i = 0; i < ranges.size(); ++i) {
2057 if (matches.size() >= max_matches)
2070 DoFindInMemory(start_addr, end_addr, buf, size, matches, alignment,
2074 if (resolved_ranges > 0)
2085 if (buf ==
nullptr) {
2097 if (alignment == 0) {
2112 DoFindInMemory(start_addr, end_addr, buf, size, matches, alignment, 1);
2113 if (matches.empty())
2117 return matches[0].GetBaseAddress().GetLoadAddress(&target);
2129 out_str.append(buf, length);
2132 if (length ==
sizeof(buf) - 1)
2133 curr_addr += length;
2137 return out_str.size();
2145 size_t total_cstr_len = 0;
2146 if (dst && dst_max_len) {
2147 result_error.
Clear();
2149 memset(dst, 0, dst_max_len);
2152 size_t bytes_left = dst_max_len - 1;
2153 char *curr_dst = dst;
2155 while (bytes_left > 0) {
2156 addr_t cache_line_bytes_left =
2157 cache_line_size - (curr_addr % cache_line_size);
2159 std::min<addr_t>(bytes_left, cache_line_bytes_left);
2161 size_t bytes_read =
ReadMemory(curr_addr, curr_dst, bytes_to_read,
error);
2163 if (bytes_read == 0) {
2164 result_error = std::move(
error);
2165 dst[total_cstr_len] =
'\0';
2168 const size_t len = strlen(curr_dst);
2170 total_cstr_len += len;
2172 if (len < bytes_to_read)
2175 curr_dst += bytes_read;
2176 curr_addr += bytes_read;
2177 bytes_left -= bytes_read;
2183 result_error.
Clear();
2185 return total_cstr_len;
2193 addr = abi_sp->FixAnyAddress(addr);
2195 if (buf ==
nullptr || size == 0)
2198 size_t bytes_read = 0;
2199 uint8_t *bytes = (uint8_t *)buf;
2201 while (bytes_read < size) {
2202 const size_t curr_size = size - bytes_read;
2203 const size_t curr_bytes_read =
2205 bytes_read += curr_bytes_read;
2206 if (curr_bytes_read == curr_size || curr_bytes_read == 0)
2218 size_t integer_byte_size,
2219 uint64_t fail_value,
2229 size_t integer_byte_size,
2251 if (addr_byte_size <= 4)
2252 scalar = (uint32_t)ptr_value;
2261 size_t bytes_written = 0;
2262 const uint8_t *bytes = (
const uint8_t *)buf;
2264 while (bytes_written < size) {
2265 const size_t curr_size = size - bytes_written;
2267 addr + bytes_written, bytes + bytes_written, curr_size,
error);
2268 bytes_written += curr_bytes_written;
2269 if (curr_bytes_written == curr_size || curr_bytes_written == 0)
2272 return bytes_written;
2278 addr = abi_sp->FixAnyAddress(addr);
2280#if defined(ENABLE_MEMORY_CACHING)
2284 if (buf ==
nullptr || size == 0)
2298 if (bp_sites_in_range.
IsEmpty())
2301 const uint8_t *ubuf = (
const uint8_t *)buf;
2302 uint64_t bytes_written = 0;
2304 bp_sites_in_range.
ForEach([
this, addr, size, &bytes_written, &ubuf,
2313 size_t intersect_size;
2314 size_t opcode_offset;
2316 addr, size, &intersect_addr, &intersect_size, &opcode_offset);
2319 assert(addr <= intersect_addr && intersect_addr < addr + size);
2320 assert(addr < intersect_addr + intersect_size &&
2321 intersect_addr + intersect_size <= addr + size);
2322 assert(opcode_offset + intersect_size <= bp->GetByteSize());
2325 const addr_t curr_addr = addr + bytes_written;
2326 if (intersect_addr > curr_addr) {
2329 size_t curr_size = intersect_addr - curr_addr;
2330 size_t curr_bytes_written =
2332 bytes_written += curr_bytes_written;
2333 if (curr_bytes_written != curr_size) {
2337 if (
error.Success())
2345 bytes_written += intersect_size;
2349 if (bytes_written < size)
2352 size - bytes_written,
error);
2354 return bytes_written;
2361 if (byte_size > 0) {
2363 const size_t mem_size =
2376 bool is_signed,
Scalar &scalar,
2379 if (byte_size == 0) {
2381 }
else if (byte_size & (byte_size - 1)) {
2383 "byte size %u is not a power of 2", byte_size);
2384 }
else if (byte_size <=
sizeof(uval)) {
2386 if (bytes_read == byte_size) {
2391 scalar = data.
GetMaxU32(&offset, byte_size);
2393 scalar = data.
GetMaxU64(&offset, byte_size);
2400 "byte size of %u is too large for integer scalar type", byte_size);
2407 for (
const auto &
Entry : entries) {
2410 if (!
error.Success())
2416#define USE_ALLOCATE_MEMORY_CACHE 1
2421 "cannot allocate memory while process is running");
2425#if defined(USE_ALLOCATE_MEMORY_CACHE)
2431 "Process::AllocateMemory(size=%" PRIu64
2432 ", permissions=%s) => 0x%16.16" PRIx64
2433 " (m_stop_id = %u m_memory_id = %u)",
2437 return allocated_addr;
2444 if (
error.Success()) {
2445 std::string buffer(size, 0);
2457 8, ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable,
2463 "Process::%s pid %" PRIu64
2464 " allocation test passed, CanJIT () is true",
2465 __FUNCTION__,
GetID());
2469 "Process::%s pid %" PRIu64
2470 " allocation test failed, CanJIT () is false: %s",
2491#if defined(USE_ALLOCATE_MEMORY_CACHE)
2494 "deallocation of memory at 0x%" PRIx64
" failed.", (uint64_t)ptr);
2501 "Process::DeallocateMemory(addr=0x%16.16" PRIx64
2502 ") => err = %s (m_stop_id = %u, m_memory_id = %u)",
2511 return *subclass_override;
2513 bool reported_after =
true;
2516 return reported_after;
2519 if (triple.isMIPS() || triple.isPPC64() || triple.isRISCV() ||
2520 triple.isAArch64() || triple.isArmMClass() || triple.isARM() ||
2521 triple.isLoongArch())
2522 reported_after =
false;
2524 return reported_after;
2529 size_t size_to_read) {
2533 "Process::ReadModuleFromMemory reading %s binary from memory",
2539 std::unique_ptr<Progress> progress_up;
2544 progress_up = std::make_unique<Progress>(
2547 ObjectFile *objfile = module_sp->GetMemoryObjectFile(
2548 shared_from_this(), header_addr,
error, size_to_read);
2556 uint32_t &permissions) {
2560 if (!
error.Success())
2618 LaunchPrivate(launch_info, state_after_launch, first_stop_event_sp);
2640 if (launch_info.
GetFlags().
Test(eLaunchFlagStopAtEntry))
2698 std::string local_exec_file_path = exe_spec_to_use.
GetPath();
2700 local_exec_file_path.c_str());
2703 const bool restarted =
false;
2718 const char *error_string =
error.AsCString();
2719 if (error_string ==
nullptr)
2720 error_string =
"launch failed";
2776 "Unexpected process state after the launch: %s, expected %s, "
2785 if (
error.Success()) {
2820 LLDB_LOGF(log,
"Process::Halt() failed to stop, state is: %s",
2823 "Did not get stopped event after loading the core file.");
2861 uint32_t exec_count)
2866 "Process::AttachCompletionHandler::%s process=%p, exec_count=%" PRIu32,
2867 __FUNCTION__,
static_cast<void *
>(process), exec_count);
2876 "Process::AttachCompletionHandler::%s called with state %s (%d)",
2881 return eEventActionSuccess;
2885 return eEventActionRetry;
2896 if (m_exec_count > 0) {
2900 "Process::AttachCompletionHandler::%s state %s: reduced "
2901 "remaining exec count to %" PRIu32
", requesting resume",
2905 return eEventActionRetry;
2908 "Process::AttachCompletionHandler::%s state %s: no more "
2909 "execs expected to start, continuing with attach",
2913 return eEventActionSuccess;
2924 return eEventActionExit;
2929 return eEventActionSuccess;
2938 return m_listener_sp;
2952 bool wait_for_launch) {
2973 sizeof(process_name))) {
2976 if (wait_for_launch) {
2978 if (
error.Success()) {
2981 const bool restarted =
false;
2994 if (
error.AsCString() ==
nullptr)
3014 platform_sp->FindProcesses(match_info, process_infos);
3015 const uint32_t num_matches = process_infos.size();
3016 if (num_matches == 1) {
3017 attach_pid = process_infos[0].GetProcessID();
3021 process_name,
sizeof(process_name));
3022 if (num_matches > 1) {
3025 for (
size_t i = 0; i < num_matches; i++) {
3026 process_infos[i].DumpAsTableRow(
3027 s, platform_sp->GetUserIDResolver(),
true,
false);
3030 "more than one process named %s:\n%s", process_name,
3034 "could not find a process named %s", process_name);
3038 "invalid platform, can't find processes by name");
3049 if (
error.Success()) {
3054 const bool restarted =
false;
3062 if (
error.Success()) {
3070 const char *error_string =
error.AsCString();
3071 if (error_string ==
nullptr)
3072 error_string =
"attach failed";
3083 LLDB_LOGF(log,
"Process::%s()", __FUNCTION__);
3092 "Process::{0} replacing process architecture with DidAttach() "
3093 "architecture: \"{1}\"",
3094 __FUNCTION__, process_arch.
GetTriple().getTriple());
3102 assert(platform_sp);
3106 if (target_arch.
IsValid() && !platform_sp->IsCompatibleArchitecture(
3107 target_arch, process_host_arch,
3111 target_arch, process_host_arch, &platform_arch);
3116 "switching platform to {0} and architecture to {1} based on "
3118 platform_sp->GetName(), platform_arch.
GetTriple().getTriple());
3120 }
else if (!process_arch.
IsValid()) {
3130 "Process::%s switching architecture to %s based on info "
3131 "the platform retrieved for pid %" PRIu64,
3132 __FUNCTION__, process_arch.
GetTriple().getTriple().c_str(),
3152 "after DynamicLoader::DidAttach(), target "
3153 "executable is {0} (using {1} plugin)",
3154 exe_module_sp ? exe_module_sp->GetFileSpec() :
FileSpec(),
3162 if (system_runtime) {
3167 "after SystemRuntime::DidAttach(), target "
3168 "executable is {0} (using {1} plugin)",
3169 exe_module_sp ? exe_module_sp->GetFileSpec() :
FileSpec(),
3187 if (module_sp && module_sp->IsExecutable()) {
3188 if (
GetTarget().GetExecutableModulePointer() != module_sp.get())
3189 new_executable_module_sp = module_sp;
3193 if (new_executable_module_sp) {
3200 "Process::%s after looping through modules, target executable is %s",
3202 exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str()
3219 if (
error.Success()) {
3246 "Process::PrivateResume() m_stop_id = %u, public state: %s "
3247 "private state: %s",
3256 if (!
GetModID().IsLastResumeForUserExpression())
3261 if (
error.Success()) {
3273 "Process::PrivateResume PreResumeActions failed, not resuming.");
3277 if (
error.Success()) {
3280 LLDB_LOGF(log,
"Process thinks the process has resumed.");
3282 LLDB_LOGF(log,
"Process::PrivateResume() DoResume failed.");
3292 "Process::PrivateResume() asked to simulate a start & stop.");
3298 LLDB_LOGF(log,
"Process::PrivateResume() got an error \"%s\".",
3299 error.AsCString(
"<unknown error>"));
3334 halt_listener_sp,
nullptr,
3335 use_run_lock, select_most_relevant);
3350 const uint8_t *buf,
size_t size) {
3351 const size_t region_size = high - low;
3353 if (region_size < size)
3357 std::vector<size_t> bad_char_heuristic(256, size);
3358 for (
size_t idx = 0; idx < size - 1; idx++) {
3359 decltype(bad_char_heuristic)::size_type bcu_idx = buf[idx];
3360 bad_char_heuristic[bcu_idx] = size - idx - 1;
3364 llvm::SmallVector<uint8_t, 0> mem;
3369 const size_t max_read_size = std::max<size_t>(size, 0x10000);
3371 for (
addr_t cur_addr = low; cur_addr <= (high - size);) {
3372 if (cur_addr + size > mem_pos + mem.size()) {
3378 mem.resize_for_overwrite(max_read_size);
3381 std::min<addr_t>(mem.size(), high - cur_addr),
3384 if (size > mem.size()) {
3394 int64_t j = size - 1;
3395 while (j >= 0 && buf[j] == mem[cur_addr + j - mem_pos])
3399 cur_addr += bad_char_heuristic[mem[cur_addr + size - 1 - mem_pos]];
3414 LLDB_LOGF(log,
"Process::%s() About to stop.", __FUNCTION__);
3424 &exit_event_sp,
true, listener_sp);
3434 LLDB_LOGF(log,
"Process::%s() Process exited while waiting to stop.",
3438 exit_event_sp.reset();
3441 LLDB_LOGF(log,
"Process::%s() failed to stop, state is: %s", __FUNCTION__,
3449 "Attempt to stop the target in order to detach timed out. "
3465 if (
error.Success()) {
3468 if (!
error.Success()) {
3471 }
else if (exit_event_sp) {
3484 if (
error.Success()) {
3495 if (exit_event_sp) {
3530 bool keep_stopped =
false;
3537 if (
error.Success()) {
3554 if (
error.Success()) {
3573 if (exit_event_sp) {
3593 if (
error.Success()) {
3595 if (
error.Success())
3602 assert(signals_sp &&
"null signals_sp");
3622 bool return_value =
true;
3640 return_value =
true;
3644 return_value =
false;
3656 return_value =
true;
3662 return_value =
false;
3675 return_value =
true;
3678 return_value =
false;
3697 "Process::ShouldBroadcastEvent (%p) stopped due to an "
3698 "interrupt, state: %s",
3703 return_value =
true;
3706 bool should_resume =
false;
3718 "Process::ShouldBroadcastEvent: should_resume: %i state: "
3719 "%s was_restarted: %i report_stop_vote: %d.",
3723 switch (report_stop_vote) {
3725 return_value =
true;
3729 return_value =
false;
3733 if (!was_restarted) {
3735 "Process::ShouldBroadcastEvent (%p) Restarting process "
3742 return_value =
true;
3765 "Process::ShouldBroadcastEvent (%p) => new state: %s, last "
3766 "broadcast state: %s - %s",
3769 return_value ?
"YES" :
"NO");
3770 return return_value;
3777 LLDB_LOGF(log,
"Process::%s()%s ", __FUNCTION__,
3778 already_running ?
" already running"
3779 :
" starting private state thread");
3781 if (!is_secondary_thread && already_running)
3786 char thread_name[1024];
3787 uint32_t max_len = llvm::get_max_thread_name_length();
3788 if (max_len > 0 && max_len <= 30) {
3791 if (already_running)
3792 snprintf(thread_name,
sizeof(thread_name),
"intern-state-OV");
3794 snprintf(thread_name,
sizeof(thread_name),
"intern-state");
3796 if (already_running)
3797 snprintf(thread_name,
sizeof(thread_name),
3798 "<lldb.process.internal-state-override(pid=%" PRIu64
")>",
3801 snprintf(thread_name,
sizeof(thread_name),
3802 "<lldb.process.internal-state(pid=%" PRIu64
")>",
GetID());
3805 llvm::Expected<HostThread> private_state_thread =
3808 [
this, is_secondary_thread] {
3812 if (!private_state_thread) {
3814 "failed to launch host thread: {0}");
3818 assert(private_state_thread->IsJoinable());
3839 "Went to stop the private state thread, but it was already invalid.");
3850 LLDB_LOGF(log,
"Process::%s (signal = %d)", __FUNCTION__, signal);
3859 LLDB_LOGF(log,
"Sending control event of type: %d.", signal);
3860 std::shared_ptr<EventDataReceipt> event_receipt_sp(
new EventDataReceipt());
3865 bool receipt_received =
false;
3867 while (!receipt_received) {
3872 if (!receipt_received) {
3889 "Private state thread already dead, no need to signal it to stop.");
3894 if (thread !=
nullptr)
3916 LLDB_LOGF(log,
"Ran next event action, result was %d.", action_result);
3918 switch (action_result) {
3944 if (should_broadcast) {
3948 "Process::%s (pid = %" PRIu64
3949 ") broadcasting new state %s (old state %s) to %s",
3952 is_hijacked ?
"hijacked" :
"public");
3959 if (!
GetTarget().GetDebugger().IsForwardingEvents() &&
3964 LLDB_LOGF(log,
"Process::%s updated m_iohandler_sync to %d",
3998 if (is_hijacked || !
GetTarget().GetDebugger().IsHandlingEvents())
4008 "Process::%s (pid = %" PRIu64
4009 ") suppressing state %s (old state %s): should_broadcast == false",
4031 bool control_only =
true;
4034 LLDB_LOGF(log,
"Process::%s (arg = %p, pid = %" PRIu64
") thread starting...",
4035 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
4037 bool exit_now =
false;
4038 bool interrupt_requested =
false;
4044 "Process::%s (arg = %p, pid = %" PRIu64
4045 ") got a control event: %d",
4046 __FUNCTION__,
static_cast<void *
>(
this),
GetID(),
4047 event_sp->GetType());
4049 switch (event_sp->GetType()) {
4055 control_only =
true;
4059 control_only =
false;
4067 "Process::%s (arg = %p, pid = %" PRIu64
4068 ") woke up with an interrupt while attaching - "
4069 "forwarding interrupt.",
4070 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
4081 "Process::%s (arg = %p, pid = %" PRIu64
4082 ") woke up with an interrupt - Halting.",
4083 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
4085 if (
error.Fail() && log)
4087 "Process::%s (arg = %p, pid = %" PRIu64
4088 ") failed to halt the process: %s",
4089 __FUNCTION__,
static_cast<void *
>(
this),
GetID(),
4096 interrupt_requested =
true;
4105 "Process::%s ignoring interrupt as we have already stopped.",
4121 if (interrupt_requested) {
4131 interrupt_requested =
false;
4134 "Process::%s interrupt_requested, but a non-stopped "
4135 "state '%s' received.",
4146 "Process::%s (arg = %p, pid = %" PRIu64
4147 ") about to exit with internal state %s...",
4148 __FUNCTION__,
static_cast<void *
>(
this),
GetID(),
4156 LLDB_LOGF(log,
"Process::%s (arg = %p, pid = %" PRIu64
") thread exiting...",
4157 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
4162 if (!is_secondary_thread)
4173 :
EventData(), m_process_wp(), m_state(state) {
4181 return "Process::ProcessEventData";
4189 bool &found_valid_stopinfo) {
4190 found_valid_stopinfo =
false;
4192 ProcessSP process_sp(m_process_wp.lock());
4196 ThreadList &curr_thread_list = process_sp->GetThreadList();
4197 uint32_t num_threads = curr_thread_list.
GetSize();
4209 std::vector<std::pair<ThreadSP, size_t>> not_suspended_threads;
4210 for (uint32_t idx = 0; idx < num_threads; ++idx) {
4218 not_suspended_threads.emplace_back(thread_sp, thread_sp->GetIndexID());
4226 bool still_should_stop =
false;
4234 for (
auto [thread_sp, thread_index] : not_suspended_threads) {
4235 if (curr_thread_list.
GetSize() != num_threads) {
4239 "Number of threads changed from %u to %u while processing event.",
4240 num_threads, curr_thread_list.
GetSize());
4244 if (thread_sp->GetIndexID() != thread_index) {
4247 "The thread {0} changed from {1} to {2} while processing event.",
4248 thread_sp.get(), thread_index, thread_sp->GetIndexID());
4252 StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
4253 if (stop_info_sp && stop_info_sp->IsValid()) {
4254 found_valid_stopinfo =
true;
4255 bool this_thread_wants_to_stop;
4256 if (stop_info_sp->GetOverrideShouldStop()) {
4257 this_thread_wants_to_stop =
4258 stop_info_sp->GetOverriddenShouldStopValue();
4260 stop_info_sp->PerformAction(event_ptr);
4268 if (stop_info_sp->HasTargetRunSinceMe()) {
4273 this_thread_wants_to_stop = stop_info_sp->ShouldStop(event_ptr);
4276 if (!still_should_stop)
4277 still_should_stop = this_thread_wants_to_stop;
4281 return still_should_stop;
4292 return m_update_state == 1;
4300 ProcessSP process_sp(m_process_wp.lock());
4313 if (m_update_state != 1)
4316 process_sp->SetPublicState(
4323 process_sp->WillPublicStop();
4338 bool does_anybody_have_an_opinion =
false;
4339 bool still_should_stop = ShouldStop(event_ptr, does_anybody_have_an_opinion);
4341 if (GetRestarted()) {
4345 if (!still_should_stop && does_anybody_have_an_opinion) {
4350 process_sp->PrivateResume();
4353 !process_sp->StateChangedIsHijackedForSynchronousResume();
4361 if (process_sp->GetTarget().RunStopHooks())
4368 ProcessSP process_sp(m_process_wp.lock());
4371 s->
Printf(
" process = %p (pid = %" PRIu64
"), ",
4372 static_cast<void *
>(process_sp.get()), process_sp->GetID());
4401 if (data ==
nullptr)
4409 if (data ==
nullptr)
4419 if (data !=
nullptr)
4427 if (data !=
nullptr)
4438 if (data !=
nullptr)
4445 const char *reason) {
4448 if (data !=
nullptr)
4453 const Event *event_ptr) {
4455 if (data ==
nullptr)
4465 if (data !=
nullptr)
4508 auto event_data_sp =
4509 std::make_shared<ProcessEventData>(shared_from_this(),
GetState());
4510 return std::make_shared<Event>(event_type, event_data_sp);
4536 auto data_sp = std::make_shared<EventDataStructuredData>(
4537 shared_from_this(), object_sp, plugin_sp);
4545 return find_it->second;
4556 size_t bytes_available = one_profile_data.size();
4557 if (bytes_available > 0) {
4559 LLDB_LOGF(log,
"Process::GetProfileData (buf = %p, size = %" PRIu64
")",
4560 static_cast<void *
>(buf),
static_cast<uint64_t
>(buf_size));
4561 if (bytes_available > buf_size) {
4562 memcpy(buf, one_profile_data.c_str(), buf_size);
4563 one_profile_data.erase(0, buf_size);
4564 bytes_available = buf_size;
4566 memcpy(buf, one_profile_data.c_str(), bytes_available);
4570 return bytes_available;
4578 if (bytes_available > 0) {
4580 LLDB_LOGF(log,
"Process::GetSTDOUT (buf = %p, size = %" PRIu64
")",
4581 static_cast<void *
>(buf),
static_cast<uint64_t
>(buf_size));
4582 if (bytes_available > buf_size) {
4585 bytes_available = buf_size;
4591 return bytes_available;
4597 if (bytes_available > 0) {
4599 LLDB_LOGF(log,
"Process::GetSTDERR (buf = %p, size = %" PRIu64
")",
4600 static_cast<void *
>(buf),
static_cast<uint64_t
>(buf_size));
4601 if (bytes_available > buf_size) {
4604 bytes_available = buf_size;
4610 return bytes_available;
4616 process->
AppendSTDOUT(
static_cast<const char *
>(src), src_len);
4622 :
IOHandler(process->GetTarget().GetDebugger(),
4625 m_read_file(GetInputFD(),
File::eOpenOptionReadOnly, false),
4626 m_write_file(write_fd,
File::eOpenOptionWriteOnly, false) {
4627 m_pipe.CreateNew(
false);
4633 std::lock_guard<std::mutex> guard(m_mutex);
4634 SetIsDone(!running);
4635 m_is_running = running;
4641 if (!m_read_file.IsValid() || !m_write_file.IsValid() ||
4642 !m_pipe.CanRead() || !m_pipe.CanWrite()) {
4648 const int read_fd = m_read_file.GetDescriptor();
4653 llvm::consumeError(terminal.
SetEcho(
false));
4656 const int pipe_read_fd = m_pipe.GetReadFileDescriptor();
4660 std::lock_guard<std::mutex> guard(m_mutex);
4677 if (m_read_file.Read(&ch, n).Success() && n == 1) {
4678 if (m_write_file.Write(&ch, n).Fail() || n != 1)
4688 if (
error.Success()) {
4693 m_process->SendAsyncInterrupt();
4697 SetIsRunning(
false);
4702 std::lock_guard<std::mutex> guard(m_mutex);
4717 size_t bytes_written = 0;
4718 m_pipe.Write(&ch, 1, bytes_written);
4730 size_t bytes_written = 0;
4731 Status result = m_pipe.Write(&ch, 1, bytes_written);
4744 m_process->SendAsyncInterrupt();
4760 bool m_is_running =
false;
4766 std::make_unique<ConnectionFileDescriptor>(fd,
true));
4777 std::make_shared<IOHandlerProcessSTDIO>(
this, fd);
4793 if (io_handler_sp) {
4795 LLDB_LOGF(log,
"Process::%s pushing IO handler", __FUNCTION__);
4797 io_handler_sp->SetIsDone(
false);
4804 cancel_top_handler);
4830class RestorePlanState {
4833 : m_thread_plan_sp(thread_plan_sp) {
4834 if (m_thread_plan_sp) {
4835 m_private = m_thread_plan_sp->GetPrivate();
4836 m_is_controlling = m_thread_plan_sp->IsControllingPlan();
4837 m_okay_to_discard = m_thread_plan_sp->OkayToDiscard();
4841 ~RestorePlanState() { Clean(); }
4844 if (!m_already_reset && m_thread_plan_sp) {
4845 m_already_reset =
true;
4846 m_thread_plan_sp->SetPrivate(m_private);
4847 m_thread_plan_sp->SetIsControllingPlan(m_is_controlling);
4848 m_thread_plan_sp->SetOkayToDiscard(m_okay_to_discard);
4854 bool m_already_reset =
false;
4855 bool m_private =
false;
4856 bool m_is_controlling =
false;
4857 bool m_okay_to_discard =
false;
4863 const milliseconds default_one_thread_timeout(250);
4868 : default_one_thread_timeout;
4877 return std::min<microseconds>(default_one_thread_timeout,
4883 bool before_first_timeout) {
4889 if (before_first_timeout)
4893 return std::nullopt;
4898static std::optional<ExpressionResults>
4900 RestorePlanState &restorer,
const EventSP &event_sp,
4901 EventSP &event_to_broadcast_sp,
4903 bool handle_interrupts) {
4906 ThreadSP thread_sp = thread_plan_sp->GetTarget()
4909 .FindThreadByID(thread_id);
4912 "The thread on which we were running the "
4913 "expression: tid = {0}, exited while "
4914 "the expression was running.",
4920 if (plan == thread_plan_sp && plan->PlanSucceeded()) {
4921 LLDB_LOG(log,
"execution completed successfully");
4929 StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
4931 stop_info_sp->ShouldNotify(event_sp.get())) {
4932 LLDB_LOG(log,
"stopped for breakpoint: {0}.", stop_info_sp->GetDescription());
4939 thread_plan_sp->SetPrivate(
false);
4940 event_to_broadcast_sp = event_sp;
4945 if (!handle_interrupts &&
4947 return std::nullopt;
4949 LLDB_LOG(log,
"thread plan did not successfully complete");
4951 event_to_broadcast_sp = event_sp;
4964 if (!thread_plan_sp) {