14#include "llvm/ADT/ScopeExit.h"
15#include "llvm/Support/ScopedPrinter.h"
16#include "llvm/Support/Threading.h"
77using namespace std::chrono;
81#define ENABLE_MEMORY_CACHING
83#ifdef ENABLE_MEMORY_CACHING
84#define DISABLE_MEM_CACHE_DEFAULT false
86#define DISABLE_MEM_CACHE_DEFAULT true
90 :
public Cloneable<ProcessOptionValueProperties, OptionValueProperties> {
106 if (
this != instance_properties)
118 "Continue tracing the parent process and detach the child.",
123 "Trace the child process and detach the parent.",
127#define LLDB_PROPERTIES_process
128#include "TargetProperties.inc"
131#define LLDB_PROPERTIES_process
132#include "TargetPropertiesEnum.inc"
136#define LLDB_PROPERTIES_process_experimental
137#include "TargetProperties.inc"
140#define LLDB_PROPERTIES_process_experimental
141#include "TargetPropertiesEnum.inc"
145 :
public Cloneable<ProcessExperimentalOptionValueProperties,
146 OptionValueProperties> {
162 if (process ==
nullptr) {
164 m_collection_sp = std::make_shared<ProcessOptionValueProperties>(
"process");
167 "thread",
"Settings specific to threads.",
true,
173 ePropertyPythonOSPluginPath,
178 std::make_unique<ProcessExperimentalProperties>();
181 "Experimental settings - setting these won't produce "
182 "errors if the setting is not present.",
189 const uint32_t idx = ePropertyDisableMemCache;
190 return GetPropertyAtIndexAs<bool>(
191 idx, g_process_properties[idx].default_uint_value != 0);
195 const uint32_t idx = ePropertyMemCacheLineSize;
196 return GetPropertyAtIndexAs<uint64_t>(
197 idx, g_process_properties[idx].default_uint_value);
202 const uint32_t idx = ePropertyExtraStartCommand;
208 const uint32_t idx = ePropertyExtraStartCommand;
213 const uint32_t idx = ePropertyPythonOSPluginPath;
214 return GetPropertyAtIndexAs<FileSpec>(idx, {});
218 const uint32_t idx = ePropertyVirtualAddressableBits;
219 return GetPropertyAtIndexAs<uint64_t>(
220 idx, g_process_properties[idx].default_uint_value);
224 const uint32_t idx = ePropertyVirtualAddressableBits;
229 const uint32_t idx = ePropertyHighmemVirtualAddressableBits;
230 return GetPropertyAtIndexAs<uint64_t>(
231 idx, g_process_properties[idx].default_uint_value);
235 const uint32_t idx = ePropertyHighmemVirtualAddressableBits;
240 const uint32_t idx = ePropertyPythonOSPluginPath;
245 const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions;
246 return GetPropertyAtIndexAs<bool>(
247 idx, g_process_properties[idx].default_uint_value != 0);
251 const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions;
256 const uint32_t idx = ePropertyUnwindOnErrorInExpressions;
257 return GetPropertyAtIndexAs<bool>(
258 idx, g_process_properties[idx].default_uint_value != 0);
262 const uint32_t idx = ePropertyUnwindOnErrorInExpressions;
267 const uint32_t idx = ePropertyStopOnSharedLibraryEvents;
268 return GetPropertyAtIndexAs<bool>(
269 idx, g_process_properties[idx].default_uint_value != 0);
273 const uint32_t idx = ePropertyStopOnSharedLibraryEvents;
278 const uint32_t idx = ePropertyDisableLangRuntimeUnwindPlans;
279 return GetPropertyAtIndexAs<bool>(
280 idx, g_process_properties[idx].default_uint_value != 0);
284 const uint32_t idx = ePropertyDisableLangRuntimeUnwindPlans;
290 const uint32_t idx = ePropertyDetachKeepsStopped;
291 return GetPropertyAtIndexAs<bool>(
292 idx, g_process_properties[idx].default_uint_value != 0);
296 const uint32_t idx = ePropertyDetachKeepsStopped;
301 const uint32_t idx = ePropertyWarningOptimization;
302 return GetPropertyAtIndexAs<bool>(
303 idx, g_process_properties[idx].default_uint_value != 0);
307 const uint32_t idx = ePropertyWarningUnsupportedLanguage;
308 return GetPropertyAtIndexAs<bool>(
309 idx, g_process_properties[idx].default_uint_value != 0);
313 const uint32_t idx = ePropertyStopOnExec;
314 return GetPropertyAtIndexAs<bool>(
315 idx, g_process_properties[idx].default_uint_value != 0);
319 const uint32_t idx = ePropertyUtilityExpressionTimeout;
320 uint64_t value = GetPropertyAtIndexAs<uint64_t>(
321 idx, g_process_properties[idx].default_uint_value);
322 return std::chrono::seconds(value);
326 const uint32_t idx = ePropertyInterruptTimeout;
327 uint64_t value = GetPropertyAtIndexAs<uint64_t>(
328 idx, g_process_properties[idx].default_uint_value);
329 return std::chrono::seconds(value);
333 const uint32_t idx = ePropertySteppingRunsAllThreads;
334 return GetPropertyAtIndexAs<bool>(
335 idx, g_process_properties[idx].default_uint_value != 0);
339 const bool fail_value =
true;
343 exp_property->
GetValue()->GetAsProperties();
349 .value_or(fail_value);
356 exp_property->
GetValue()->GetAsProperties();
363 const uint32_t idx = ePropertyFollowForkMode;
364 return GetPropertyAtIndexAs<FollowForkMode>(
366 g_process_properties[idx].default_uint_value));
370 llvm::StringRef plugin_name,
374 static uint32_t g_process_unique_id = 0;
378 if (!plugin_name.empty()) {
381 if (create_callback) {
382 process_sp = create_callback(target_sp, listener_sp, crash_file_path,
385 if (process_sp->CanDebug(target_sp,
true)) {
386 process_sp->m_process_unique_id = ++g_process_unique_id;
392 for (uint32_t idx = 0;
396 process_sp = create_callback(target_sp, listener_sp, crash_file_path,
399 if (process_sp->CanDebug(target_sp,
false)) {
400 process_sp->m_process_unique_id = ++g_process_unique_id;
424 Broadcaster((target_sp->GetDebugger().GetBroadcasterManager()),
425 Process::GetStaticBroadcasterClass().AsCString()),
428 m_private_state_broadcaster(nullptr,
429 "lldb.process.internal_state_broadcaster"),
430 m_private_state_control_broadcaster(
431 nullptr,
"lldb.process.internal_state_control_broadcaster"),
432 m_private_state_listener_sp(
433 Listener::MakeListener(
"lldb.process.internal_state_listener")),
434 m_mod_id(), m_process_unique_id(0), m_thread_index_id(0),
435 m_thread_id_to_index_id_map(), m_exit_status(-1), m_exit_string(),
436 m_exit_status_mutex(), m_thread_mutex(), m_thread_list_real(this),
437 m_thread_list(this), m_thread_plans(*this), m_extended_thread_list(this),
438 m_extended_thread_stop_id(0), m_queue_list(this), m_queue_list_stop_id(0),
439 m_notifications(), m_image_tokens(),
440 m_breakpoint_site_list(), m_dynamic_checkers_up(),
441 m_unix_signals_sp(unix_signals_sp), m_abi_sp(), m_process_input_reader(),
442 m_stdio_communication(
"process.stdio"), m_stdio_communication_mutex(),
443 m_stdin_forward(false), m_stdout_data(), m_stderr_data(),
444 m_profile_data_comm_mutex(), m_profile_data(), m_iohandler_sync(0),
445 m_memory_cache(*this), m_allocated_memory_cache(*this),
446 m_should_detach(false), m_next_event_action_up(), m_public_run_lock(),
447 m_private_run_lock(), m_currently_handling_do_on_removals(false),
448 m_resume_requested(false), m_finalizing(false),
449 m_clear_thread_plans_on_stop(false), m_force_next_event_delivery(false),
450 m_last_broadcast_state(
eStateInvalid), m_destroy_in_process(false),
451 m_can_interpret_function_calls(false), m_run_thread_plan_lock(),
452 m_can_jit(eCanJITDontKnow) {
456 LLDB_LOGF(log,
"%p Process::Process()",
static_cast<void *
>(
this));
494 uint64_t platform_cache_line_size =
495 target_sp->GetPlatform()->GetDefaultMemoryCacheLineSize();
496 if (!value_sp->OptionWasSet() && platform_cache_line_size != 0)
497 value_sp->SetValueAs(platform_cache_line_size);
504 LLDB_LOGF(log,
"%p Process::~Process()",
static_cast<void *
>(
this));
518 return *g_settings_ptr;
550 std::vector<Notifications> empty_notifications;
584 if (pos->baton == callbacks.
baton &&
595 std::vector<Notifications>::iterator notification_pos,
598 notification_pos != notification_end; ++notification_pos) {
599 if (notification_pos->process_state_changed)
600 notification_pos->process_state_changed(notification_pos->baton,
this,
619 std::chrono::seconds(0)) &&
639 "waited from m_iohandler_sync to change from {0}. New value is {1}.",
640 iohandler_id, *Result);
642 LLDB_LOG(log,
"timed out waiting for m_iohandler_sync to change from {0}.",
655 event_sp_ptr->reset();
663 LLDB_LOG(log,
"timeout = {0}", timeout);
668 "Process::%s returning without waiting for events; process "
669 "private and public states are already 'stopped'.",
673 if (hijack_listener_sp && use_run_lock)
681 if (event_sp_ptr && event_sp)
682 *event_sp_ptr = event_sp;
684 bool pop_process_io_handler = (hijack_listener_sp.get() !=
nullptr);
686 event_sp, stream, select_most_relevant, pop_process_io_handler);
695 if (hijack_listener_sp && use_run_lock)
704 if (hijack_listener_sp && use_run_lock)
718 bool &pop_process_io_handler) {
719 const bool handle_pop = pop_process_io_handler;
721 pop_process_io_handler =
false;
733 switch (event_state) {
741 stream->
Printf(
"Process %" PRIu64
" %s\n", process_sp->GetID(),
744 pop_process_io_handler =
true;
754 process_sp->GetStatus(*stream);
755 pop_process_io_handler =
true;
766 if (num_reasons > 0) {
769 if (num_reasons == 1) {
773 stream->
Printf(
"Process %" PRIu64
" stopped and restarted: %s\n",
775 reason ? reason :
"<UNKNOWN REASON>");
777 stream->
Printf(
"Process %" PRIu64
778 " stopped and restarted, reasons:\n",
779 process_sp->GetID());
781 for (
size_t i = 0; i < num_reasons; i++) {
785 stream->
Printf(
"\t%s\n", reason ? reason :
"<UNKNOWN REASON>");
795 ThreadList &thread_list = process_sp->GetThreadList();
796 std::lock_guard<std::recursive_mutex> guard(thread_list.
GetMutex());
801 bool prefer_curr_thread =
false;
802 if (curr_thread && curr_thread->IsValid()) {
803 curr_thread_stop_reason = curr_thread->GetStopReason();
804 switch (curr_thread_stop_reason) {
813 uint64_t signo = curr_thread->GetStopInfo()->GetValue();
814 if (process_sp->GetUnixSignals()->GetShouldStop(signo))
815 prefer_curr_thread =
true;
818 prefer_curr_thread =
true;
821 curr_thread_stop_info_sp = curr_thread->GetStopInfo();
824 if (!prefer_curr_thread) {
830 const size_t num_threads = thread_list.
GetSize();
832 for (i = 0; i < num_threads; ++i) {
834 StopReason thread_stop_reason = thread->GetStopReason();
835 switch (thread_stop_reason) {
844 uint64_t signo = thread->GetStopInfo()->GetValue();
845 if (process_sp->GetUnixSignals()->GetShouldStop(signo)) {
847 other_thread = thread;
863 other_thread = thread;
867 plan_thread = thread;
873 else if (other_thread)
876 if (curr_thread && curr_thread->IsValid())
877 thread = curr_thread;
891 Debugger &debugger = process_sp->GetTarget().GetDebugger();
893 &process_sp->GetTarget()) {
894 ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
896 if (!thread_sp || !thread_sp->IsValid())
899 const bool only_threads_with_stop_reason =
true;
900 const uint32_t start_frame =
901 thread_sp->GetSelectedFrameIndex(select_most_relevant);
902 const uint32_t num_frames = 1;
903 const uint32_t num_frames_with_source = 1;
904 const bool stop_format =
true;
906 process_sp->GetStatus(*stream);
907 process_sp->GetThreadStatus(*stream, only_threads_with_stop_reason,
908 start_frame, num_frames,
909 num_frames_with_source,
911 if (curr_thread_stop_info_sp) {
914 curr_thread_stop_info_sp, &crashing_address);
920 valobj_sp->GetExpressionPath(*stream, format);
921 stream->
Printf(
" accessed 0x%" PRIx64
"\n", crashing_address);
926 process_sp->GetTarget().shared_from_this());
928 stream->
Printf(
"Target %d: (", target_idx);
930 stream->
Printf(
"Target <unknown index>: (");
932 stream->
Printf(
") stopped.\n");
937 pop_process_io_handler =
true;
942 if (handle_pop && pop_process_io_handler)
943 process_sp->PopProcessIOHandler();
962 LLDB_LOG(log,
"timeout = {0}, event_sp)...", timeout);
969 if (listener_sp->GetEventForBroadcasterWithType(
975 LLDB_LOG(log,
"got no event or was interrupted.");
978 LLDB_LOG(log,
"timeout = {0}, event_sp) => {1}", timeout, state);
985 LLDB_LOGF(log,
"Process::%s...", __FUNCTION__);
992 LLDB_LOGF(log,
"Process::%s (event_ptr) => %s", __FUNCTION__,
995 LLDB_LOGF(log,
"Process::%s no events found", __FUNCTION__);
1005 LLDB_LOG(log,
"timeout = {0}, event_sp)...", timeout);
1015 LLDB_LOG(log,
"timeout = {0}, event_sp) => {1}", timeout,
1022 bool control_only) {
1024 LLDB_LOG(log,
"timeout = {0}, event_sp)...", timeout);
1058 LLDB_LOG(log,
"(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
1065 "(plugin = {0}) ignoring exit status because state was already set "
1072 if (!exit_string.empty())
1116 "Process::SetProcessExitStatus (pid=%" PRIu64
1117 ", exited=%i, signal=%i, exit_status=%i)\n",
1118 pid, exited, signo, exit_status);
1123 ProcessSP process_sp(target_sp->GetProcessSP());
1125 llvm::StringRef signal_str =
1126 process_sp->GetUnixSignals()->GetSignalAsStringRef(signo);
1127 process_sp->SetExitStatus(exit_status, signal_str);
1145 bool clear_unused_threads =
true;
1168 size_t num_old_threads = old_thread_list.
GetSize(
false);
1169 for (
size_t i = 0; i < num_old_threads; ++i)
1202 new_thread_list = real_thread_list;
1242 bool internal,
bool condense_trivial,
1243 bool skip_unreported_plans) {
1245 strm, tid, desc_level, internal, condense_trivial, skip_unreported_plans);
1248 bool internal,
bool condense_trivial,
1249 bool skip_unreported_plans) {
1251 skip_unreported_plans);
1284 uint32_t result = 0;
1285 std::map<uint64_t, uint32_t>::iterator iterator =
1291 result = iterator->second;
1306 if (new_state_is_stopped) {
1317 LLDB_LOGF(log,
"(plugin = %s, state = %s, restarted = %i)",
1328 "(plugin = %s, state = %s) -- unlocking run lock for detach",
1333 if ((old_state_is_stopped != new_state_is_stopped)) {
1334 if (new_state_is_stopped && !restarted) {
1335 LLDB_LOGF(log,
"(plugin = %s, state = %s) -- unlocking run lock",
1348 Status error(
"Resume request failed - process still running.");
1349 LLDB_LOGF(log,
"(plugin = %s) -- TrySetRunning failed, not resuming.",
1354 if (!
error.Success()) {
1363 LLDB_LOGF(log,
"Process::ResumeSynchronous -- locking run lock");
1365 Status error(
"Resume request failed - process still running.");
1366 LLDB_LOGF(log,
"Process::Resume: -- TrySetRunning failed, not resuming.");
1375 if (
error.Success()) {
1379 const bool must_be_alive =
1382 error.SetErrorStringWithFormat(
1383 "process not in stopped state after synchronous resume: %s",
1399 if (!hijacking_name.starts_with(
"lldb.internal"))
1421 bool state_changed =
false;
1430 state_changed = old_state != new_state;
1434 if (old_state_is_stopped != new_state_is_stopped) {
1435 if (new_state_is_stopped)
1441 if (state_changed) {
1465 LLDB_LOGF(log,
"(plugin = %s, state = %s, stop_id = %u",
1472 LLDB_LOGF(log,
"(plugin = %s, state = %s) state didn't change. Ignoring...",
1494 std::vector<LanguageRuntime *> language_runtimes;
1497 return language_runtimes;
1507 language_runtimes.emplace_back(runtime);
1510 return language_runtimes;
1520 LanguageRuntimeCollection::iterator pos;
1527 runtime = runtime_sp.get();
1529 runtime = pos->second.get();
1555 if (runtime->CouldHaveDynamicValue(in_value))
1584 if (
error.Success())
1594 if (bp_site_sp->IsEnabled())
1597 error.SetErrorStringWithFormat(
"invalid breakpoint site ID: %" PRIu64,
1608 if (!bp_site_sp->IsEnabled())
1611 error.SetErrorStringWithFormat(
"invalid breakpoint site ID: %" PRIu64,
1619 bool use_hardware) {
1622 bool show_error =
true;
1645 owner->SetIsIndirect(
false);
1647 if (owner->ShouldResolveIndirectFunctions()) {
1653 if (!
error.Success() && show_error) {
1655 "warning: failed to resolve indirect function at 0x%" PRIx64
1656 " for breakpoint %i.%i: %s\n",
1658 owner->GetBreakpoint().GetID(), owner->GetID(),
1659 error.AsCString() ?
error.AsCString() :
"unknown error");
1662 Address resolved_address(load_addr);
1664 owner->SetIsIndirect(
true);
1666 load_addr = owner->GetAddress().GetOpcodeLoadAddress(&
GetTarget());
1668 load_addr = owner->GetAddress().GetOpcodeLoadAddress(&
GetTarget());
1679 bp_site_sp->AddOwner(owner);
1680 owner->SetBreakpointSite(bp_site_sp);
1681 return bp_site_sp->GetID();
1684 load_addr, use_hardware));
1687 if (
error.Success()) {
1688 owner->SetBreakpointSite(bp_site_sp);
1691 if (show_error || use_hardware) {
1694 "warning: failed to set breakpoint site at 0x%" PRIx64
1695 " for breakpoint %i.%i: %s\n",
1696 load_addr, owner->GetBreakpoint().GetID(), owner->GetID(),
1697 error.AsCString() ?
error.AsCString() :
"unknown error");
1710 uint32_t num_owners = bp_site_sp->RemoveOwner(owner_id, owner_loc_id);
1711 if (num_owners == 0) {
1720 uint8_t *buf)
const {
1721 size_t bytes_removed = 0;
1725 bp_sites_in_range)) {
1726 bp_sites_in_range.
ForEach([bp_addr, size,
1729 addr_t intersect_addr;
1730 size_t intersect_size;
1731 size_t opcode_offset;
1732 if (bp_site->IntersectsRange(bp_addr, size, &intersect_addr,
1733 &intersect_size, &opcode_offset)) {
1734 assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size);
1735 assert(bp_addr < intersect_addr + intersect_size &&
1736 intersect_addr + intersect_size <= bp_addr + size);
1737 assert(opcode_offset + intersect_size <= bp_site->GetByteSize());
1738 size_t buf_offset = intersect_addr - bp_addr;
1739 ::memcpy(buf + buf_offset,
1740 bp_site->GetSavedOpcodeBytes() + opcode_offset,
1746 return bytes_removed;
1752 return platform_sp->GetSoftwareBreakpointTrapOpcode(
GetTarget(), bp_site);
1758 assert(bp_site !=
nullptr);
1762 log,
"Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64,
1763 bp_site->
GetID(), (uint64_t)bp_addr);
1767 "Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1768 " -- already enabled",
1769 bp_site->
GetID(), (uint64_t)bp_addr);
1774 error.SetErrorString(
"BreakpointSite contains an invalid load address.");
1781 if (bp_opcode_size == 0) {
1782 error.SetErrorStringWithFormat(
"Process::GetSoftwareBreakpointTrapOpcode() "
1783 "returned zero, unable to get breakpoint "
1784 "trap for address 0x%" PRIx64,
1789 if (bp_opcode_bytes ==
nullptr) {
1790 error.SetErrorString(
1791 "BreakpointSite doesn't contain a valid breakpoint trap opcode.");
1797 error) == bp_opcode_size) {
1801 uint8_t verify_bp_opcode_bytes[64];
1802 if (
DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size,
1803 error) == bp_opcode_size) {
1804 if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes,
1805 bp_opcode_size) == 0) {
1809 "Process::EnableSoftwareBreakpoint (site_id = %d) "
1810 "addr = 0x%" PRIx64
" -- SUCCESS",
1811 bp_site->
GetID(), (uint64_t)bp_addr);
1813 error.SetErrorString(
1814 "failed to verify the breakpoint trap in memory.");
1816 error.SetErrorString(
1817 "Unable to read memory to verify breakpoint trap.");
1819 error.SetErrorString(
"Unable to write breakpoint trap to memory.");
1821 error.SetErrorString(
"Unable to read memory at breakpoint address.");
1823 if (log &&
error.Fail())
1826 "Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1828 bp_site->
GetID(), (uint64_t)bp_addr,
error.AsCString());
1834 assert(bp_site !=
nullptr);
1839 "Process::DisableSoftwareBreakpoint (breakID = %" PRIu64
1840 ") addr = 0x%" PRIx64,
1841 breakID, (uint64_t)bp_addr);
1844 error.SetErrorString(
"Breakpoint site is a hardware breakpoint.");
1846 const size_t break_op_size = bp_site->
GetByteSize();
1848 if (break_op_size > 0) {
1850 uint8_t curr_break_op[8];
1851 assert(break_op_size <=
sizeof(curr_break_op));
1852 bool break_op_found =
false;
1857 bool verify =
false;
1859 if (::memcmp(curr_break_op, break_op, break_op_size) == 0) {
1860 break_op_found =
true;
1864 break_op_size,
error) == break_op_size) {
1867 error.SetErrorString(
1868 "Memory write failed when restoring original opcode.");
1870 error.SetErrorString(
1871 "Original breakpoint trap is no longer in memory.");
1878 uint8_t verify_opcode[8];
1879 assert(break_op_size <
sizeof(verify_opcode));
1885 break_op_size) == 0) {
1889 "Process::DisableSoftwareBreakpoint (site_id = %d) "
1890 "addr = 0x%" PRIx64
" -- SUCCESS",
1891 bp_site->
GetID(), (uint64_t)bp_addr);
1895 error.SetErrorString(
"Failed to restore original opcode.");
1898 error.SetErrorString(
"Failed to read memory to verify that "
1899 "breakpoint trap was restored.");
1902 error.SetErrorString(
1903 "Unable to read memory that should contain the breakpoint trap.");
1908 "Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1909 " -- already disabled",
1910 bp_site->
GetID(), (uint64_t)bp_addr);
1916 "Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64
1918 bp_site->
GetID(), (uint64_t)bp_addr,
error.AsCString());
1928 addr = abi_sp->FixAnyAddress(addr);
1932#if defined(VERIFY_MEMORY_READS)
1944 std::string verify_buf(size,
'\0');
1945 assert(verify_buf.size() == size);
1946 const size_t cache_bytes_read =
1949 const size_t verify_bytes_read =
1951 verify_buf.size(), verify_error);
1952 assert(cache_bytes_read == verify_bytes_read);
1953 assert(memcmp(buf, verify_buf.data(), verify_buf.size()) == 0);
1955 return cache_bytes_read;
1979 out_str.append(buf, length);
1982 if (length ==
sizeof(buf) - 1)
1983 curr_addr += length;
1987 return out_str.size();
1995 size_t total_cstr_len = 0;
1996 if (dst && dst_max_len) {
1997 result_error.
Clear();
1999 memset(dst, 0, dst_max_len);
2003 size_t bytes_left = dst_max_len - 1;
2004 char *curr_dst = dst;
2006 while (bytes_left > 0) {
2007 addr_t cache_line_bytes_left =
2008 cache_line_size - (curr_addr % cache_line_size);
2010 std::min<addr_t>(bytes_left, cache_line_bytes_left);
2011 size_t bytes_read =
ReadMemory(curr_addr, curr_dst, bytes_to_read,
error);
2013 if (bytes_read == 0) {
2014 result_error =
error;
2015 dst[total_cstr_len] =
'\0';
2018 const size_t len = strlen(curr_dst);
2020 total_cstr_len += len;
2022 if (len < bytes_to_read)
2025 curr_dst += bytes_read;
2026 curr_addr += bytes_read;
2027 bytes_left -= bytes_read;
2033 result_error.
Clear();
2035 return total_cstr_len;
2043 addr = abi_sp->FixAnyAddress(addr);
2045 if (buf ==
nullptr || size == 0)
2048 size_t bytes_read = 0;
2049 uint8_t *bytes = (uint8_t *)buf;
2051 while (bytes_read < size) {
2052 const size_t curr_size = size - bytes_read;
2053 const size_t curr_bytes_read =
2055 bytes_read += curr_bytes_read;
2056 if (curr_bytes_read == curr_size || curr_bytes_read == 0)
2068 size_t integer_byte_size,
2069 uint64_t fail_value,
2079 size_t integer_byte_size,
2101 if (addr_byte_size <= 4)
2102 scalar = (uint32_t)ptr_value;
2111 size_t bytes_written = 0;
2112 const uint8_t *bytes = (
const uint8_t *)buf;
2114 while (bytes_written < size) {
2115 const size_t curr_size = size - bytes_written;
2117 addr + bytes_written, bytes + bytes_written, curr_size,
error);
2118 bytes_written += curr_bytes_written;
2119 if (curr_bytes_written == curr_size || curr_bytes_written == 0)
2122 return bytes_written;
2128 addr = abi_sp->FixAnyAddress(addr);
2130#if defined(ENABLE_MEMORY_CACHING)
2134 if (buf ==
nullptr || size == 0)
2148 if (bp_sites_in_range.
IsEmpty())
2151 const uint8_t *ubuf = (
const uint8_t *)buf;
2152 uint64_t bytes_written = 0;
2154 bp_sites_in_range.
ForEach([
this, addr, size, &bytes_written, &ubuf,
2163 size_t intersect_size;
2164 size_t opcode_offset;
2166 addr, size, &intersect_addr, &intersect_size, &opcode_offset);
2169 assert(addr <= intersect_addr && intersect_addr < addr + size);
2170 assert(addr < intersect_addr + intersect_size &&
2171 intersect_addr + intersect_size <= addr + size);
2172 assert(opcode_offset + intersect_size <= bp->GetByteSize());
2175 const addr_t curr_addr = addr + bytes_written;
2176 if (intersect_addr > curr_addr) {
2179 size_t curr_size = intersect_addr - curr_addr;
2180 size_t curr_bytes_written =
2182 bytes_written += curr_bytes_written;
2183 if (curr_bytes_written != curr_size) {
2187 if (
error.Success())
2188 error.SetErrorToGenericError();
2195 bytes_written += intersect_size;
2199 if (bytes_written < size)
2202 size - bytes_written,
error);
2204 return bytes_written;
2211 if (byte_size > 0) {
2213 const size_t mem_size =
2218 error.SetErrorString(
"failed to get scalar as memory data");
2220 error.SetErrorString(
"invalid scalar value");
2226 bool is_signed,
Scalar &scalar,
2229 if (byte_size == 0) {
2230 error.SetErrorString(
"byte size is zero");
2231 }
else if (byte_size & (byte_size - 1)) {
2232 error.SetErrorStringWithFormat(
"byte size %u is not a power of 2",
2234 }
else if (byte_size <=
sizeof(uval)) {
2236 if (bytes_read == byte_size) {
2241 scalar = data.
GetMaxU32(&offset, byte_size);
2243 scalar = data.
GetMaxU64(&offset, byte_size);
2249 error.SetErrorStringWithFormat(
2250 "byte size of %u is too large for integer scalar type", byte_size);
2257 for (
const auto &
Entry : entries) {
2260 if (!
error.Success())
2266#define USE_ALLOCATE_MEMORY_CACHE 1
2270 error.SetErrorToGenericError();
2274#if defined(USE_ALLOCATE_MEMORY_CACHE)
2280 "Process::AllocateMemory(size=%" PRIu64
2281 ", permissions=%s) => 0x%16.16" PRIx64
2282 " (m_stop_id = %u m_memory_id = %u)",
2286 return allocated_addr;
2293 if (
error.Success()) {
2294 std::string buffer(size, 0);
2306 8, ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable,
2312 "Process::%s pid %" PRIu64
2313 " allocation test passed, CanJIT () is true",
2314 __FUNCTION__,
GetID());
2318 "Process::%s pid %" PRIu64
2319 " allocation test failed, CanJIT () is false: %s",
2340#if defined(USE_ALLOCATE_MEMORY_CACHE)
2342 error.SetErrorStringWithFormat(
2343 "deallocation of memory at 0x%" PRIx64
" failed.", (uint64_t)ptr);
2350 "Process::DeallocateMemory(addr=0x%16.16" PRIx64
2351 ") => err = %s (m_stop_id = %u, m_memory_id = %u)",
2360 return *subclass_override;
2362 bool reported_after =
true;
2365 return reported_after;
2368 if (triple.isMIPS() || triple.isPPC64() || triple.isRISCV() ||
2369 triple.isAArch64() || triple.isArmMClass() || triple.isARM())
2370 reported_after =
false;
2372 return reported_after;
2377 size_t size_to_read) {
2381 "Process::ReadModuleFromMemory reading %s binary from memory",
2387 ObjectFile *objfile = module_sp->GetMemoryObjectFile(
2388 shared_from_this(), header_addr,
error, size_to_read);
2396 uint32_t &permissions) {
2400 if (!
error.Success())
2409 permissions |= lldb::ePermissionsReadable;
2412 permissions |= lldb::ePermissionsWritable;
2415 permissions |= lldb::ePermissionsExecutable;
2422 error.SetErrorString(
"watchpoints are not supported");
2428 error.SetErrorString(
"watchpoints are not supported");
2467 LaunchPrivate(launch_info, state_after_launch, first_stop_event_sp);
2489 if (launch_info.
GetFlags().
Test(eLaunchFlagStopAtEntry))
2521 error.SetErrorString(
"executable module does not exist");
2547 std::string local_exec_file_path = exe_spec_to_use.
GetPath();
2548 return Status(
"file doesn't exist: '%s'", local_exec_file_path.c_str());
2551 const bool restarted =
false;
2560 error.SetErrorString(
"failed to acquire process run lock");
2566 const char *error_string =
error.AsCString();
2567 if (error_string ==
nullptr)
2568 error_string =
"launch failed";
2581 error.SetErrorString(
"failed to catch stop after launch");
2623 return Status(
"Unexpected process state after the launch: %s, expected %s, "
2632 if (
error.Success()) {
2667 LLDB_LOGF(log,
"Process::Halt() failed to stop, state is: %s",
2669 error.SetErrorString(
2670 "Did not get stopped event after loading the core file.");
2708 uint32_t exec_count)
2713 "Process::AttachCompletionHandler::%s process=%p, exec_count=%" PRIu32,
2714 __FUNCTION__,
static_cast<void *
>(process), exec_count);
2723 "Process::AttachCompletionHandler::%s called with state %s (%d)",
2728 return eEventActionSuccess;
2732 return eEventActionRetry;
2743 if (m_exec_count > 0) {
2747 "Process::AttachCompletionHandler::%s state %s: reduced "
2748 "remaining exec count to %" PRIu32
", requesting resume",
2752 return eEventActionRetry;
2755 "Process::AttachCompletionHandler::%s state %s: no more "
2756 "execs expected to start, continuing with attach",
2760 return eEventActionSuccess;
2771 return eEventActionExit;
2776 return eEventActionSuccess;
2785 return m_listener_sp;
2799 bool wait_for_launch) {
2820 sizeof(process_name))) {
2823 if (wait_for_launch) {
2825 if (
error.Success()) {
2828 const bool restarted =
false;
2834 error.SetErrorString(
"failed to acquire process run lock");
2840 if (
error.AsCString() ==
nullptr)
2841 error.SetErrorString(
"attach failed");
2860 platform_sp->FindProcesses(match_info, process_infos);
2861 const uint32_t num_matches = process_infos.size();
2862 if (num_matches == 1) {
2863 attach_pid = process_infos[0].GetProcessID();
2867 process_name,
sizeof(process_name));
2868 if (num_matches > 1) {
2871 for (
size_t i = 0; i < num_matches; i++) {
2872 process_infos[i].DumpAsTableRow(
2873 s, platform_sp->GetUserIDResolver(),
true,
false);
2875 error.SetErrorStringWithFormat(
2876 "more than one process named %s:\n%s", process_name,
2879 error.SetErrorStringWithFormat(
2880 "could not find a process named %s", process_name);
2883 error.SetErrorString(
2884 "invalid platform, can't find processes by name");
2889 error.SetErrorString(
"invalid process name");
2895 if (
error.Success()) {
2900 const bool restarted =
false;
2905 error.SetErrorString(
"failed to acquire process run lock");
2908 if (
error.Success()) {
2916 const char *error_string =
error.AsCString();
2917 if (error_string ==
nullptr)
2918 error_string =
"attach failed";
2929 LLDB_LOGF(log,
"Process::%s()", __FUNCTION__);
2939 const char *triple_str = process_arch.
GetTriple().getTriple().c_str();
2941 "Process::%s replacing process architecture with DidAttach() "
2943 __FUNCTION__, triple_str ? triple_str :
"<null>");
2951 assert(platform_sp);
2955 if (target_arch.
IsValid() && !platform_sp->IsCompatibleArchitecture(
2956 target_arch, process_host_arch,
2960 target_arch, process_host_arch, &platform_arch);
2965 "switching platform to {0} and architecture to {1} based on "
2967 platform_sp->GetName(), platform_arch.
GetTriple().getTriple());
2969 }
else if (!process_arch.
IsValid()) {
2979 "Process::%s switching architecture to %s based on info "
2980 "the platform retrieved for pid %" PRIu64,
2981 __FUNCTION__, process_arch.
GetTriple().getTriple().c_str(),
3001 "after DynamicLoader::DidAttach(), target "
3002 "executable is {0} (using {1} plugin)",
3003 exe_module_sp ? exe_module_sp->GetFileSpec() :
FileSpec(),
3011 if (system_runtime) {
3016 "after SystemRuntime::DidAttach(), target "
3017 "executable is {0} (using {1} plugin)",
3018 exe_module_sp ? exe_module_sp->GetFileSpec() :
FileSpec(),
3036 if (module_sp && module_sp->IsExecutable()) {
3037 if (
GetTarget().GetExecutableModulePointer() != module_sp.get())
3038 new_executable_module_sp = module_sp;
3042 if (new_executable_module_sp) {
3049 "Process::%s after looping through modules, target executable is %s",
3051 exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str()
3068 if (
error.Success()) {
3095 "Process::PrivateResume() m_stop_id = %u, public state: %s "
3096 "private state: %s",
3106 if (
error.Success()) {
3117 error.SetErrorString(
3118 "Process::PrivateResume PreResumeActions failed, not resuming.");
3122 if (
error.Success()) {
3125 LLDB_LOGF(log,
"Process thinks the process has resumed.");
3127 LLDB_LOGF(log,
"Process::PrivateResume() DoResume failed.");
3137 "Process::PrivateResume() asked to simulate a start & stop.");
3143 LLDB_LOGF(log,
"Process::PrivateResume() got an error \"%s\".",
3144 error.AsCString(
"<unknown error>"));
3150 return Status(
"Process is not running.");
3179 halt_listener_sp,
nullptr,
3180 use_run_lock, select_most_relevant);
3202 LLDB_LOGF(log,
"Process::%s() About to stop.", __FUNCTION__);
3212 &exit_event_sp,
true, listener_sp);
3222 LLDB_LOGF(log,
"Process::%s() Process exited while waiting to stop.",
3226 exit_event_sp.reset();
3229 LLDB_LOGF(log,
"Process::%s() failed to stop, state is: %s", __FUNCTION__,
3237 "Attempt to stop the target in order to detach timed out. "
3253 if (
error.Success()) {
3256 if (!
error.Success()) {
3259 }
else if (exit_event_sp) {
3272 if (
error.Success()) {
3283 if (exit_event_sp) {
3318 bool keep_stopped =
false;
3325 if (
error.Success()) {
3342 if (
error.Success()) {
3361 if (exit_event_sp) {
3381 if (
error.Success()) {
3383 if (
error.Success())
3390 assert(signals_sp &&
"null signals_sp");
3410 bool return_value =
true;
3428 return_value =
true;
3432 return_value =
false;
3444 return_value =
true;
3450 return_value =
false;
3463 return_value =
true;
3466 return_value =
false;
3485 "Process::ShouldBroadcastEvent (%p) stopped due to an "
3486 "interrupt, state: %s",
3491 return_value =
true;
3494 bool should_resume =
false;
3506 "Process::ShouldBroadcastEvent: should_resume: %i state: "
3507 "%s was_restarted: %i report_stop_vote: %d.",
3511 switch (report_stop_vote) {
3513 return_value =
true;
3517 return_value =
false;
3521 if (!was_restarted) {
3523 "Process::ShouldBroadcastEvent (%p) Restarting process "
3530 return_value =
true;
3553 "Process::ShouldBroadcastEvent (%p) => new state: %s, last "
3554 "broadcast state: %s - %s",
3557 return_value ?
"YES" :
"NO");
3558 return return_value;
3565 LLDB_LOGF(log,
"Process::%s()%s ", __FUNCTION__,
3566 already_running ?
" already running"
3567 :
" starting private state thread");
3569 if (!is_secondary_thread && already_running)
3574 char thread_name[1024];
3575 uint32_t max_len = llvm::get_max_thread_name_length();
3576 if (max_len > 0 && max_len <= 30) {
3579 if (already_running)
3580 snprintf(thread_name,
sizeof(thread_name),
"intern-state-OV");
3582 snprintf(thread_name,
sizeof(thread_name),
"intern-state");
3584 if (already_running)
3585 snprintf(thread_name,
sizeof(thread_name),
3586 "<lldb.process.internal-state-override(pid=%" PRIu64
")>",
3589 snprintf(thread_name,
sizeof(thread_name),
3590 "<lldb.process.internal-state(pid=%" PRIu64
")>",
GetID());
3593 llvm::Expected<HostThread> private_state_thread =
3596 [
this, is_secondary_thread] {
3600 if (!private_state_thread) {
3602 "failed to launch host thread: {0}");
3606 assert(private_state_thread->IsJoinable());
3627 "Went to stop the private state thread, but it was already invalid.");
3638 LLDB_LOGF(log,
"Process::%s (signal = %d)", __FUNCTION__, signal);
3647 LLDB_LOGF(log,
"Sending control event of type: %d.", signal);
3648 std::shared_ptr<EventDataReceipt> event_receipt_sp(
new EventDataReceipt());
3653 bool receipt_received =
false;
3655 while (!receipt_received) {
3660 if (!receipt_received) {
3677 "Private state thread already dead, no need to signal it to stop.");
3700 LLDB_LOGF(log,
"Ran next event action, result was %d.", action_result);
3702 switch (action_result) {
3728 if (should_broadcast) {
3732 "Process::%s (pid = %" PRIu64
3733 ") broadcasting new state %s (old state %s) to %s",
3736 is_hijacked ?
"hijacked" :
"public");
3743 if (!
GetTarget().GetDebugger().IsForwardingEvents() &&
3748 LLDB_LOGF(log,
"Process::%s updated m_iohandler_sync to %d",
3782 if (is_hijacked || !
GetTarget().GetDebugger().IsHandlingEvents())
3792 "Process::%s (pid = %" PRIu64
3793 ") suppressing state %s (old state %s): should_broadcast == false",
3815 bool control_only =
true;
3818 LLDB_LOGF(log,
"Process::%s (arg = %p, pid = %" PRIu64
") thread starting...",
3819 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
3821 bool exit_now =
false;
3822 bool interrupt_requested =
false;
3828 "Process::%s (arg = %p, pid = %" PRIu64
3829 ") got a control event: %d",
3830 __FUNCTION__,
static_cast<void *
>(
this),
GetID(),
3831 event_sp->GetType());
3833 switch (event_sp->GetType()) {
3839 control_only =
true;
3843 control_only =
false;
3851 "Process::%s (arg = %p, pid = %" PRIu64
3852 ") woke up with an interrupt while attaching - "
3853 "forwarding interrupt.",
3854 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
3858 "Process::%s (arg = %p, pid = %" PRIu64
3859 ") woke up with an interrupt - Halting.",
3860 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
3862 if (
error.Fail() && log)
3864 "Process::%s (arg = %p, pid = %" PRIu64
3865 ") failed to halt the process: %s",
3866 __FUNCTION__,
static_cast<void *
>(
this),
GetID(),
3873 interrupt_requested =
true;
3882 "Process::%s ignoring interrupt as we have already stopped.",
3898 if (interrupt_requested) {
3903 interrupt_requested =
false;
3906 "Process::%s interrupt_requested, but a non-stopped "
3907 "state '%s' received.",
3918 "Process::%s (arg = %p, pid = %" PRIu64
3919 ") about to exit with internal state %s...",
3920 __FUNCTION__,
static_cast<void *
>(
this),
GetID(),
3928 LLDB_LOGF(log,
"Process::%s (arg = %p, pid = %" PRIu64
") thread exiting...",
3929 __FUNCTION__,
static_cast<void *
>(
this),
GetID());
3934 if (!is_secondary_thread)
3945 :
EventData(), m_process_wp(), m_state(state) {
3953 return "Process::ProcessEventData";
3961 bool &found_valid_stopinfo) {
3962 found_valid_stopinfo =
false;
3964 ProcessSP process_sp(m_process_wp.lock());
3968 ThreadList &curr_thread_list = process_sp->GetThreadList();
3969 uint32_t num_threads = curr_thread_list.
GetSize();
3982 ThreadList not_suspended_thread_list(process_sp.get());
3983 std::vector<uint32_t> thread_index_array(num_threads);
3984 uint32_t not_suspended_idx = 0;
3985 for (idx = 0; idx < num_threads; ++idx) {
3993 not_suspended_thread_list.
AddThread(thread_sp);
3994 thread_index_array[not_suspended_idx] = thread_sp->GetIndexID();
3995 not_suspended_idx++;
4004 bool still_should_stop =
false;
4012 for (idx = 0; idx < not_suspended_thread_list.
GetSize(); ++idx) {
4013 curr_thread_list = process_sp->GetThreadList();
4014 if (curr_thread_list.
GetSize() != num_threads) {
4018 "Number of threads changed from %u to %u while processing event.",
4019 num_threads, curr_thread_list.
GetSize());
4025 if (thread_sp->GetIndexID() != thread_index_array[idx]) {
4028 "The thread at position %u changed from %u to %u while "
4029 "processing event.",
4030 idx, thread_index_array[idx], thread_sp->GetIndexID());
4034 StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
4035 if (stop_info_sp && stop_info_sp->IsValid()) {
4036 found_valid_stopinfo =
true;
4037 bool this_thread_wants_to_stop;
4038 if (stop_info_sp->GetOverrideShouldStop()) {
4039 this_thread_wants_to_stop =
4040 stop_info_sp->GetOverriddenShouldStopValue();
4042 stop_info_sp->PerformAction(event_ptr);
4050 if (stop_info_sp->HasTargetRunSinceMe()) {
4055 this_thread_wants_to_stop = stop_info_sp->ShouldStop(event_ptr);
4058 if (!still_should_stop)
4059 still_should_stop = this_thread_wants_to_stop;
4063 return still_should_stop;
4067 ProcessSP process_sp(m_process_wp.lock());
4080 if (m_update_state != 1)
4083 process_sp->SetPublicState(
4090 process_sp->WillPublicStop();
4105 bool does_anybody_have_an_opinion =
false;
4106 bool still_should_stop = ShouldStop(event_ptr, does_anybody_have_an_opinion);
4108 if (GetRestarted()) {
4112 if (!still_should_stop && does_anybody_have_an_opinion) {
4117 process_sp->PrivateResume();
4120 !process_sp->StateChangedIsHijackedForSynchronousResume();
4128 if (process_sp->GetTarget().RunStopHooks())
4135 ProcessSP process_sp(m_process_wp.lock());
4138 s->
Printf(
" process = %p (pid = %" PRIu64
"), ",
4139 static_cast<void *
>(process_sp.get()), process_sp->GetID());
4168 if (data ==
nullptr)
4176 if (data ==
nullptr)
4186 if (data !=
nullptr)
4194 if (data !=
nullptr)
4205 if (data !=
nullptr)
4212 const char *reason) {
4215 if (data !=
nullptr)
4220 const Event *event_ptr) {
4222 if (data ==
nullptr)
4232 if (data !=
nullptr)
4306 return find_it->second;
4317 size_t bytes_available = one_profile_data.size();
4318 if (bytes_available > 0) {
4320 LLDB_LOGF(log,
"Process::GetProfileData (buf = %p, size = %" PRIu64
")",
4321 static_cast<void *
>(buf),
static_cast<uint64_t
>(buf_size));
4322 if (bytes_available > buf_size) {
4323 memcpy(buf, one_profile_data.c_str(), buf_size);
4324 one_profile_data.erase(0, buf_size);
4325 bytes_available = buf_size;
4327 memcpy(buf, one_profile_data.c_str(), bytes_available);
4331 return bytes_available;
4339 if (bytes_available > 0) {
4341 LLDB_LOGF(log,
"Process::GetSTDOUT (buf = %p, size = %" PRIu64
")",
4342 static_cast<void *
>(buf),
static_cast<uint64_t
>(buf_size));
4343 if (bytes_available > buf_size) {
4346 bytes_available = buf_size;
4352 return bytes_available;
4358 if (bytes_available > 0) {
4360 LLDB_LOGF(log,
"Process::GetSTDERR (buf = %p, size = %" PRIu64
")",
4361 static_cast<void *
>(buf),
static_cast<uint64_t
>(buf_size));
4362 if (bytes_available > buf_size) {
4365 bytes_available = buf_size;
4371 return bytes_available;
4377 process->
AppendSTDOUT(
static_cast<const char *
>(src), src_len);
4383 :
IOHandler(process->GetTarget().GetDebugger(),
4386 m_read_file(GetInputFD(),
File::eOpenOptionReadOnly, false),
4387 m_write_file(write_fd,
File::eOpenOptionWriteOnly, false) {
4388 m_pipe.CreateNew(
false);
4394 std::lock_guard<std::mutex> guard(m_mutex);
4395 SetIsDone(!running);
4396 m_is_running = running;
4402 if (!m_read_file.IsValid() || !m_write_file.IsValid() ||
4403 !m_pipe.CanRead() || !m_pipe.CanWrite()) {
4409 const int read_fd = m_read_file.GetDescriptor();
4414 llvm::consumeError(terminal.
SetEcho(
false));
4417 const int pipe_read_fd = m_pipe.GetReadFileDescriptor();
4421 std::lock_guard<std::mutex> guard(m_mutex);
4438 if (m_read_file.Read(&ch, n).Success() && n == 1) {
4439 if (m_write_file.Write(&ch, n).Fail() || n != 1)
4449 if (
error.Success()) {
4454 m_process->SendAsyncInterrupt();
4458 SetIsRunning(
false);
4463 std::lock_guard<std::mutex> guard(m_mutex);
4478 size_t bytes_written = 0;
4479 m_pipe.Write(&ch, 1, bytes_written);
4491 size_t bytes_written = 0;
4492 Status result = m_pipe.Write(&ch, 1, bytes_written);
4505 m_process->SendAsyncInterrupt();
4521 bool m_is_running =
false;
4527 std::make_unique<ConnectionFileDescriptor>(fd,
true));
4538 std::make_shared<IOHandlerProcessSTDIO>(
this, fd);
4554 if (io_handler_sp) {
4556 LLDB_LOGF(log,
"Process::%s pushing IO handler", __FUNCTION__);
4558 io_handler_sp->SetIsDone(
false);
4565 cancel_top_handler);
4591class RestorePlanState {
4594 : m_thread_plan_sp(thread_plan_sp) {
4595 if (m_thread_plan_sp) {
4596 m_private = m_thread_plan_sp->GetPrivate();
4597 m_is_controlling = m_thread_plan_sp->IsControllingPlan();
4598 m_okay_to_discard = m_thread_plan_sp->OkayToDiscard();
4602 ~RestorePlanState() { Clean(); }
4605 if (!m_already_reset && m_thread_plan_sp) {
4606 m_already_reset =
true;
4607 m_thread_plan_sp->SetPrivate(m_private);
4608 m_thread_plan_sp->SetIsControllingPlan(m_is_controlling);
4609 m_thread_plan_sp->SetOkayToDiscard(m_okay_to_discard);
4615 bool m_already_reset =
false;
4616 bool m_private =
false;
4617 bool m_is_controlling =
false;
4618 bool m_okay_to_discard =
false;
4624 const milliseconds default_one_thread_timeout(250);
4629 : default_one_thread_timeout;
4638 return std::min<microseconds>(default_one_thread_timeout,
4644 bool before_first_timeout) {
4650 if (before_first_timeout)
4654 return std::nullopt;
4659static std::optional<ExpressionResults>
4661 RestorePlanState &restorer,
const EventSP &event_sp,
4662 EventSP &event_to_broadcast_sp,
4664 bool handle_interrupts) {
4667 ThreadSP thread_sp = thread_plan_sp->GetTarget()
4670 .FindThreadByID(thread_id);
4673 "The thread on which we were running the "
4674 "expression: tid = {0}, exited while "
4675 "the expression was running.",
4681 if (plan == thread_plan_sp && plan->PlanSucceeded()) {
4682 LLDB_LOG(log,
"execution completed successfully");
4690 StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
4692 stop_info_sp->ShouldNotify(event_sp.get())) {
4693 LLDB_LOG(log,
"stopped for breakpoint: {0}.", stop_info_sp->GetDescription());
4700 thread_plan_sp->SetPrivate(
false);
4701 event_to_broadcast_sp = event_sp;
4706 if (!handle_interrupts &&
4708 return std::nullopt;
4710 LLDB_LOG(log,
"thread plan did not successfully complete");
4712 event_to_broadcast_sp = event_sp;
4725 if (!thread_plan_sp) {
4728 "RunThreadPlan called with empty thread plan.");
4732 if (!thread_plan_sp->ValidatePlan(
nullptr)) {
4735 "RunThreadPlan called with an invalid thread plan.");
4741 "RunThreadPlan called on wrong process.");
4746 if (thread ==
nullptr) {
4748 "RunThreadPlan called with invalid thread.");
4759 RestorePlanState thread_plan_restorer(thread_plan_sp);
4766 thread_plan_sp->SetPrivate(
false);
4772 thread_plan_sp->SetIsControllingPlan(
true);
4773 thread_plan_sp->SetOkayToDiscard(
false);
4783 "RunThreadPlan called while the private state was not stopped.");
4788 const uint32_t thread_idx_id = thread->
GetIndexID();
4791 if (!selected_frame_sp) {
4794 if (!selected_frame_sp) {
4795 diagnostic_manager.
Printf(
4797 "RunThreadPlan called without a selected frame on thread %d",
4808 "RunThreadPlan called with one thread "
4809 "timeout greater than total timeout");
4813 StackID ctx_frame_id = selected_frame_sp->GetStackID();
4821 uint32_t selected_tid;
4823 if (selected_thread_sp) {
4824 selected_tid = selected_thread_sp->GetIndexID();
4843 LLDB_LOGF(log,
"Running thread plan on private state thread, spinning up "
4844 "another state thread to handle the events.");
4867 thread_plan_sp,
false);
4900 "Process::RunThreadPlan(): Resuming thread %u - 0x%4.4" PRIx64
4901 " to run thread plan \"%s\".",
4902 thread_idx_id, expr_thread_id, s.
GetData());
4909 bool before_first_timeout =
true;
4911 bool do_resume =
true;
4912 bool handle_running_event =
true;
4915 uint32_t num_resumes = 0;
4921 before_first_timeout =
false;
4923 LLDB_LOGF(log,
"Stop others: %u, try all: %u, before_first: %u.\n",
4925 before_first_timeout);
4932 Event *other_events = listener_sp->PeekAtNextEvent();
4933 if (other_events !=
nullptr) {
4936 "RunThreadPlan called with pending events on the queue.");
4949#ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT
4957 bool miss_first_event =
true;
4965 "Top of while loop: do_resume: %i handle_running_event: %i "
4966 "before_first_timeout: %i.",
4967 do_resume, handle_running_event, before_first_timeout);
4969 if (do_resume || handle_running_event) {
4976 if (!resume_error.
Success()) {
4977 diagnostic_manager.
Printf(
4979 "couldn't resume inferior the %d time: \"%s\".", num_resumes,
4990 "Process::RunThreadPlan(): didn't get any event after "