summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/lldb/source/Target/Process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Target/Process.cpp')
-rw-r--r--contrib/llvm/tools/lldb/source/Target/Process.cpp437
1 files changed, 213 insertions, 224 deletions
diff --git a/contrib/llvm/tools/lldb/source/Target/Process.cpp b/contrib/llvm/tools/lldb/source/Target/Process.cpp
index c72662e..6cbe289 100644
--- a/contrib/llvm/tools/lldb/source/Target/Process.cpp
+++ b/contrib/llvm/tools/lldb/source/Target/Process.cpp
@@ -14,13 +14,14 @@
// Other libraries and framework includes
#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/Threading.h"
+
// Project includes
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Event.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
@@ -33,6 +34,7 @@
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
+#include "lldb/Host/OptionParser.h"
#include "lldb/Host/Pipe.h"
#include "lldb/Host/Terminal.h"
#include "lldb/Host/ThreadLauncher.h"
@@ -63,6 +65,7 @@
#include "lldb/Target/ThreadPlan.h"
#include "lldb/Target/ThreadPlanBase.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/Log.h"
#include "lldb/Utility/NameMatches.h"
#include "lldb/Utility/SelectHelper.h"
@@ -412,10 +415,10 @@ void ProcessInstanceInfo::DumpAsTableRow(Stream &s, Platform *platform,
}
}
-Error ProcessLaunchCommandOptions::SetOptionValue(
+Status ProcessLaunchCommandOptions::SetOptionValue(
uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) {
- Error error;
+ Status error;
const int short_option = m_getopt_table[option_idx].val;
switch (short_option) {
@@ -581,7 +584,7 @@ llvm::ArrayRef<OptionDefinition> ProcessLaunchCommandOptions::GetDefinitions() {
}
bool ProcessInstanceInfoMatch::NameMatches(const char *process_name) const {
- if (m_name_match_type == eNameMatchIgnore || process_name == nullptr)
+ if (m_name_match_type == NameMatch::Ignore || process_name == nullptr)
return true;
const char *match_name = m_match_info.GetName();
if (!match_name)
@@ -627,7 +630,7 @@ bool ProcessInstanceInfoMatch::Matches(
}
bool ProcessInstanceInfoMatch::MatchAllProcesses() const {
- if (m_name_match_type != eNameMatchIgnore)
+ if (m_name_match_type != NameMatch::Ignore)
return false;
if (m_match_info.ProcessIDIsValid())
@@ -659,7 +662,7 @@ bool ProcessInstanceInfoMatch::MatchAllProcesses() const {
void ProcessInstanceInfoMatch::Clear() {
m_match_info.Clear();
- m_name_match_type = eNameMatchIgnore;
+ m_name_match_type = NameMatch::Ignore;
m_match_all_users = false;
}
@@ -982,10 +985,7 @@ StateType Process::WaitForProcessToStop(const Timeout<std::micro> &timeout,
return state;
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf(
- "Process::%s (timeout = %llu)", __FUNCTION__,
- static_cast<unsigned long long>(timeout ? timeout->count() : -1));
+ LLDB_LOG(log, "timeout = {0}", timeout);
if (!wait_always && StateIsStoppedState(state, true) &&
StateIsStoppedState(GetPrivateState(), true)) {
@@ -1261,11 +1261,7 @@ StateType Process::GetStateChangedEvents(EventSP &event_sp,
const Timeout<std::micro> &timeout,
ListenerSP hijack_listener_sp) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
- if (log)
- log->Printf(
- "Process::%s (timeout = %llu, event_sp)...", __FUNCTION__,
- static_cast<unsigned long long>(timeout ? timeout->count() : -1));
+ LLDB_LOG(log, "timeout = {0}, event_sp)...", timeout);
ListenerSP listener_sp = hijack_listener_sp;
if (!listener_sp)
@@ -1277,15 +1273,11 @@ StateType Process::GetStateChangedEvents(EventSP &event_sp,
timeout)) {
if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged)
state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
- else if (log)
- log->Printf("Process::%s got no event or was interrupted.", __FUNCTION__);
+ else
+ LLDB_LOG(log, "got no event or was interrupted.");
}
- if (log)
- log->Printf(
- "Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__,
- static_cast<unsigned long long>(timeout ? timeout->count() : -1),
- StateAsCString(state));
+ LLDB_LOG(log, "timeout = {0}, event_sp) => {1}", timeout, state);
return state;
}
@@ -1314,11 +1306,7 @@ StateType
Process::GetStateChangedEventsPrivate(EventSP &event_sp,
const Timeout<std::micro> &timeout) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
- if (log)
- log->Printf(
- "Process::%s (timeout = %llu, event_sp)...", __FUNCTION__,
- static_cast<unsigned long long>(timeout ? timeout->count() : -1));
+ LLDB_LOG(log, "timeout = {0}, event_sp)...", timeout);
StateType state = eStateInvalid;
if (m_private_state_listener_sp->GetEventForBroadcasterWithType(
@@ -1328,14 +1316,8 @@ Process::GetStateChangedEventsPrivate(EventSP &event_sp,
if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged)
state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
- // This is a bit of a hack, but when we wait here we could very well return
- // to the command-line, and that could disable the log, which would render the
- // log we got above invalid.
- if (log)
- log->Printf(
- "Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__,
- static_cast<unsigned long long>(timeout ? timeout->count() : -1),
- state == eStateInvalid ? "TIMEOUT" : StateAsCString(state));
+ LLDB_LOG(log, "timeout = {0}, event_sp) => {1}", timeout,
+ state == eStateInvalid ? "TIMEOUT" : StateAsCString(state));
return state;
}
@@ -1343,11 +1325,7 @@ bool Process::GetEventsPrivate(EventSP &event_sp,
const Timeout<std::micro> &timeout,
bool control_only) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
-
- if (log)
- log->Printf(
- "Process::%s (timeout = %llu, event_sp)...", __FUNCTION__,
- static_cast<unsigned long long>(timeout ? timeout->count() : -1));
+ LLDB_LOG(log, "timeout = {0}, event_sp)...", timeout);
if (control_only)
return m_private_state_listener_sp->GetEventForBroadcaster(
@@ -1632,13 +1610,13 @@ void Process::SetPublicState(StateType new_state, bool restarted) {
}
}
-Error Process::Resume() {
+Status Process::Resume() {
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STATE |
LIBLLDB_LOG_PROCESS));
if (log)
log->Printf("Process::Resume -- locking run lock");
if (!m_public_run_lock.TrySetRunning()) {
- Error error("Resume request failed - process still running.");
+ Status error("Resume request failed - process still running.");
if (log)
log->Printf("Process::Resume: -- TrySetRunning failed, not resuming.");
return error;
@@ -1646,13 +1624,13 @@ Error Process::Resume() {
return PrivateResume();
}
-Error Process::ResumeSynchronous(Stream *stream) {
+Status Process::ResumeSynchronous(Stream *stream) {
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STATE |
LIBLLDB_LOG_PROCESS));
if (log)
log->Printf("Process::ResumeSynchronous -- locking run lock");
if (!m_public_run_lock.TrySetRunning()) {
- Error error("Resume request failed - process still running.");
+ Status error("Resume request failed - process still running.");
if (log)
log->Printf("Process::Resume: -- TrySetRunning failed, not resuming.");
return error;
@@ -1662,7 +1640,7 @@ Error Process::ResumeSynchronous(Stream *stream) {
Listener::MakeListener("lldb.Process.ResumeSynchronous.hijack"));
HijackProcessEvents(listener_sp);
- Error error = PrivateResume();
+ Status error = PrivateResume();
if (error.Success()) {
StateType state =
WaitForProcessToStop(llvm::None, NULL, true, listener_sp, stream);
@@ -1757,7 +1735,7 @@ addr_t Process::GetImageInfoAddress() { return LLDB_INVALID_ADDRESS; }
const lldb::ABISP &Process::GetABI() {
if (!m_abi_sp)
- m_abi_sp = ABI::FindPlugin(GetTarget().GetArchitecture());
+ m_abi_sp = ABI::FindPlugin(shared_from_this(), GetTarget().GetArchitecture());
return m_abi_sp;
}
@@ -1835,8 +1813,8 @@ void Process::DisableAllBreakpointSites() {
});
}
-Error Process::ClearBreakpointSiteByID(lldb::user_id_t break_id) {
- Error error(DisableBreakpointSiteByID(break_id));
+Status Process::ClearBreakpointSiteByID(lldb::user_id_t break_id) {
+ Status error(DisableBreakpointSiteByID(break_id));
if (error.Success())
m_breakpoint_site_list.Remove(break_id);
@@ -1844,8 +1822,8 @@ Error Process::ClearBreakpointSiteByID(lldb::user_id_t break_id) {
return error;
}
-Error Process::DisableBreakpointSiteByID(lldb::user_id_t break_id) {
- Error error;
+Status Process::DisableBreakpointSiteByID(lldb::user_id_t break_id) {
+ Status error;
BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID(break_id);
if (bp_site_sp) {
if (bp_site_sp->IsEnabled())
@@ -1858,8 +1836,8 @@ Error Process::DisableBreakpointSiteByID(lldb::user_id_t break_id) {
return error;
}
-Error Process::EnableBreakpointSiteByID(lldb::user_id_t break_id) {
- Error error;
+Status Process::EnableBreakpointSiteByID(lldb::user_id_t break_id) {
+ Status error;
BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID(break_id);
if (bp_site_sp) {
if (!bp_site_sp->IsEnabled())
@@ -1904,7 +1882,7 @@ Process::CreateBreakpointSite(const BreakpointLocationSP &owner,
if (owner->ShouldResolveIndirectFunctions()) {
Symbol *symbol = owner->GetAddress().CalculateSymbolContextSymbol();
if (symbol && symbol->IsIndirect()) {
- Error error;
+ Status error;
Address symbol_address = symbol->GetAddress();
load_addr = ResolveIndirectFunction(&symbol_address, error);
if (!error.Success() && show_error) {
@@ -1941,7 +1919,7 @@ Process::CreateBreakpointSite(const BreakpointLocationSP &owner,
bp_site_sp.reset(new BreakpointSite(&m_breakpoint_site_list, owner,
load_addr, use_hardware));
if (bp_site_sp) {
- Error error = EnableBreakpointSite(bp_site_sp.get());
+ Status error = EnableBreakpointSite(bp_site_sp.get());
if (error.Success()) {
owner->SetBreakpointSite(bp_site_sp);
return m_breakpoint_site_list.Add(bp_site_sp);
@@ -1981,8 +1959,8 @@ size_t Process::RemoveBreakpointOpcodesFromBuffer(addr_t bp_addr, size_t size,
if (m_breakpoint_site_list.FindInRange(bp_addr, bp_addr + size,
bp_sites_in_range)) {
- bp_sites_in_range.ForEach([bp_addr, size, buf, &bytes_removed](
- BreakpointSite *bp_site) -> void {
+ bp_sites_in_range.ForEach([bp_addr, size,
+ buf](BreakpointSite *bp_site) -> void {
if (bp_site->GetType() == BreakpointSite::eSoftware) {
addr_t intersect_addr;
size_t intersect_size;
@@ -2011,8 +1989,8 @@ size_t Process::GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site) {
return 0;
}
-Error Process::EnableSoftwareBreakpoint(BreakpointSite *bp_site) {
- Error error;
+Status Process::EnableSoftwareBreakpoint(BreakpointSite *bp_site) {
+ Status error;
assert(bp_site != nullptr);
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
const addr_t bp_addr = bp_site->GetLoadAddress();
@@ -2087,8 +2065,8 @@ Error Process::EnableSoftwareBreakpoint(BreakpointSite *bp_site) {
return error;
}
-Error Process::DisableSoftwareBreakpoint(BreakpointSite *bp_site) {
- Error error;
+Status Process::DisableSoftwareBreakpoint(BreakpointSite *bp_site) {
+ Status error;
assert(bp_site != nullptr);
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
addr_t bp_addr = bp_site->GetLoadAddress();
@@ -2180,7 +2158,7 @@ Error Process::DisableSoftwareBreakpoint(BreakpointSite *bp_site) {
// Uncomment to verify memory caching works after making changes to caching code
//#define VERIFY_MEMORY_READS
-size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Error &error) {
+size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status &error) {
error.Clear();
if (!GetDisableMemoryCache()) {
#if defined(VERIFY_MEMORY_READS)
@@ -2199,7 +2177,7 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Error &error) {
assert(verify_buf.size() == size);
const size_t cache_bytes_read =
m_memory_cache.Read(this, addr, buf, size, error);
- Error verify_error;
+ Status verify_error;
const size_t verify_bytes_read =
ReadMemoryFromInferior(addr, const_cast<char *>(verify_buf.data()),
verify_buf.size(), verify_error);
@@ -2222,7 +2200,7 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Error &error) {
}
size_t Process::ReadCStringFromMemory(addr_t addr, std::string &out_str,
- Error &error) {
+ Status &error) {
char buf[256];
out_str.clear();
addr_t curr_addr = addr;
@@ -2242,7 +2220,7 @@ size_t Process::ReadCStringFromMemory(addr_t addr, std::string &out_str,
}
size_t Process::ReadStringFromMemory(addr_t addr, char *dst, size_t max_bytes,
- Error &error, size_t type_width) {
+ Status &error, size_t type_width) {
size_t total_bytes_read = 0;
if (dst && max_bytes && type_width && max_bytes >= type_width) {
// Ensure a null terminator independent of the number of bytes that is read.
@@ -2295,13 +2273,14 @@ size_t Process::ReadStringFromMemory(addr_t addr, char *dst, size_t max_bytes,
// correct code to find
// null terminators.
size_t Process::ReadCStringFromMemory(addr_t addr, char *dst,
- size_t dst_max_len, Error &result_error) {
+ size_t dst_max_len,
+ Status &result_error) {
size_t total_cstr_len = 0;
if (dst && dst_max_len) {
result_error.Clear();
// NULL out everything just to be safe
memset(dst, 0, dst_max_len);
- Error error;
+ Status error;
addr_t curr_addr = addr;
const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize();
size_t bytes_left = dst_max_len - 1;
@@ -2340,7 +2319,7 @@ size_t Process::ReadCStringFromMemory(addr_t addr, char *dst,
}
size_t Process::ReadMemoryFromInferior(addr_t addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
if (buf == nullptr || size == 0)
return 0;
@@ -2366,7 +2345,7 @@ size_t Process::ReadMemoryFromInferior(addr_t addr, void *buf, size_t size,
uint64_t Process::ReadUnsignedIntegerFromMemory(lldb::addr_t vm_addr,
size_t integer_byte_size,
uint64_t fail_value,
- Error &error) {
+ Status &error) {
Scalar scalar;
if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, false, scalar,
error))
@@ -2376,7 +2355,8 @@ uint64_t Process::ReadUnsignedIntegerFromMemory(lldb::addr_t vm_addr,
int64_t Process::ReadSignedIntegerFromMemory(lldb::addr_t vm_addr,
size_t integer_byte_size,
- int64_t fail_value, Error &error) {
+ int64_t fail_value,
+ Status &error) {
Scalar scalar;
if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, true, scalar,
error))
@@ -2384,7 +2364,7 @@ int64_t Process::ReadSignedIntegerFromMemory(lldb::addr_t vm_addr,
return fail_value;
}
-addr_t Process::ReadPointerFromMemory(lldb::addr_t vm_addr, Error &error) {
+addr_t Process::ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error) {
Scalar scalar;
if (ReadScalarIntegerFromMemory(vm_addr, GetAddressByteSize(), false, scalar,
error))
@@ -2393,7 +2373,7 @@ addr_t Process::ReadPointerFromMemory(lldb::addr_t vm_addr, Error &error) {
}
bool Process::WritePointerToMemory(lldb::addr_t vm_addr, lldb::addr_t ptr_value,
- Error &error) {
+ Status &error) {
Scalar scalar;
const uint32_t addr_byte_size = GetAddressByteSize();
if (addr_byte_size <= 4)
@@ -2405,7 +2385,7 @@ bool Process::WritePointerToMemory(lldb::addr_t vm_addr, lldb::addr_t ptr_value,
}
size_t Process::WriteMemoryPrivate(addr_t addr, const void *buf, size_t size,
- Error &error) {
+ Status &error) {
size_t bytes_written = 0;
const uint8_t *bytes = (const uint8_t *)buf;
@@ -2421,7 +2401,7 @@ size_t Process::WriteMemoryPrivate(addr_t addr, const void *buf, size_t size,
}
size_t Process::WriteMemory(addr_t addr, const void *buf, size_t size,
- Error &error) {
+ Status &error) {
#if defined(ENABLE_MEMORY_CACHING)
m_memory_cache.Flush(addr, size);
#endif
@@ -2500,7 +2480,7 @@ size_t Process::WriteMemory(addr_t addr, const void *buf, size_t size,
}
size_t Process::WriteScalarToMemory(addr_t addr, const Scalar &scalar,
- size_t byte_size, Error &error) {
+ size_t byte_size, Status &error) {
if (byte_size == UINT32_MAX)
byte_size = scalar.GetByteSize();
if (byte_size > 0) {
@@ -2519,7 +2499,7 @@ size_t Process::WriteScalarToMemory(addr_t addr, const Scalar &scalar,
size_t Process::ReadScalarIntegerFromMemory(addr_t addr, uint32_t byte_size,
bool is_signed, Scalar &scalar,
- Error &error) {
+ Status &error) {
uint64_t uval = 0;
if (byte_size == 0) {
error.SetErrorString("byte size is zero");
@@ -2549,7 +2529,7 @@ size_t Process::ReadScalarIntegerFromMemory(addr_t addr, uint32_t byte_size,
#define USE_ALLOCATE_MEMORY_CACHE 1
addr_t Process::AllocateMemory(size_t size, uint32_t permissions,
- Error &error) {
+ Status &error) {
if (GetPrivateState() != eStateStopped)
return LLDB_INVALID_ADDRESS;
@@ -2570,7 +2550,7 @@ addr_t Process::AllocateMemory(size_t size, uint32_t permissions,
}
addr_t Process::CallocateMemory(size_t size, uint32_t permissions,
- Error &error) {
+ Status &error) {
addr_t return_addr = AllocateMemory(size, permissions, error);
if (error.Success()) {
std::string buffer(size, 0);
@@ -2582,7 +2562,7 @@ addr_t Process::CallocateMemory(size_t size, uint32_t permissions,
bool Process::CanJIT() {
if (m_can_jit == eCanJITDontKnow) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
- Error err;
+ Status err;
uint64_t allocated_memory = AllocateMemory(
8, ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable,
@@ -2617,8 +2597,8 @@ void Process::SetCanRunCode(bool can_run_code) {
m_can_interpret_function_calls = can_run_code;
}
-Error Process::DeallocateMemory(addr_t ptr) {
- Error error;
+Status Process::DeallocateMemory(addr_t ptr) {
+ Status error;
#if defined(USE_ALLOCATE_MEMORY_CACHE)
if (!m_allocated_memory_cache.DeallocateMemory(ptr)) {
error.SetErrorStringWithFormat(
@@ -2647,7 +2627,7 @@ ModuleSP Process::ReadModuleFromMemory(const FileSpec &file_spec,
}
ModuleSP module_sp(new Module(file_spec, ArchSpec()));
if (module_sp) {
- Error error;
+ Status error;
ObjectFile *objfile = module_sp->GetMemoryObjectFile(
shared_from_this(), header_addr, error, size_to_read);
if (objfile)
@@ -2660,7 +2640,7 @@ bool Process::GetLoadAddressPermissions(lldb::addr_t load_addr,
uint32_t &permissions) {
MemoryRegionInfo range_info;
permissions = 0;
- Error error(GetMemoryRegionInfo(load_addr, range_info));
+ Status error(GetMemoryRegionInfo(load_addr, range_info));
if (!error.Success())
return false;
if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow ||
@@ -2681,14 +2661,14 @@ bool Process::GetLoadAddressPermissions(lldb::addr_t load_addr,
return true;
}
-Error Process::EnableWatchpoint(Watchpoint *watchpoint, bool notify) {
- Error error;
+Status Process::EnableWatchpoint(Watchpoint *watchpoint, bool notify) {
+ Status error;
error.SetErrorString("watchpoints are not supported");
return error;
}
-Error Process::DisableWatchpoint(Watchpoint *watchpoint, bool notify) {
- Error error;
+Status Process::DisableWatchpoint(Watchpoint *watchpoint, bool notify) {
+ Status error;
error.SetErrorString("watchpoints are not supported");
return error;
}
@@ -2724,8 +2704,8 @@ void Process::LoadOperatingSystemPlugin(bool flush) {
Flush();
}
-Error Process::Launch(ProcessLaunchInfo &launch_info) {
- Error error;
+Status Process::Launch(ProcessLaunchInfo &launch_info) {
+ Status error;
m_abi_sp.reset();
m_dyld_ap.reset();
m_jit_loaders_ap.reset();
@@ -2798,7 +2778,12 @@ Error Process::Launch(ProcessLaunchInfo &launch_info) {
if (system_runtime)
system_runtime->DidLaunch();
- LoadOperatingSystemPlugin(false);
+ if (!m_os_ap)
+ LoadOperatingSystemPlugin(false);
+
+ // We successfully launched the process and stopped,
+ // now it the right time to set up signal filters before resuming.
+ UpdateAutomaticSignalFiltering();
// Note, the stop event was consumed above, but not handled. This
// was done
@@ -2840,8 +2825,8 @@ Error Process::Launch(ProcessLaunchInfo &launch_info) {
return error;
}
-Error Process::LoadCore() {
- Error error = DoLoadCore();
+Status Process::LoadCore() {
+ Status error = DoLoadCore();
if (error.Success()) {
ListenerSP listener_sp(
Listener::MakeListener("lldb.process.load_core_listener"));
@@ -2862,7 +2847,9 @@ Error Process::LoadCore() {
if (system_runtime)
system_runtime->DidAttach();
- m_os_ap.reset(OperatingSystem::FindPlugin(this, nullptr));
+ if (!m_os_ap)
+ LoadOperatingSystemPlugin(false);
+
// We successfully loaded a core file, now pretend we stopped so we can
// show all of the threads in the core file and explore the crashed
// state.
@@ -2992,7 +2979,7 @@ ListenerSP ProcessAttachInfo::GetListenerForProcess(Debugger &debugger) {
return debugger.GetListener();
}
-Error Process::Attach(ProcessAttachInfo &attach_info) {
+Status Process::Attach(ProcessAttachInfo &attach_info) {
m_abi_sp.reset();
m_process_input_reader.reset();
m_dyld_ap.reset();
@@ -3002,7 +2989,7 @@ Error Process::Attach(ProcessAttachInfo &attach_info) {
m_stop_info_override_callback = nullptr;
lldb::pid_t attach_pid = attach_info.GetProcessID();
- Error error;
+ Status error;
if (attach_pid == LLDB_INVALID_PROCESS_ID) {
char process_name[PATH_MAX];
@@ -3046,7 +3033,7 @@ Error Process::Attach(ProcessAttachInfo &attach_info) {
if (platform_sp) {
ProcessInstanceInfoMatch match_info;
match_info.GetProcessInfo() = attach_info;
- match_info.SetNameMatchType(eNameMatchEquals);
+ match_info.SetNameMatchType(NameMatch::Equals);
platform_sp->FindProcesses(match_info, process_infos);
const uint32_t num_matches = process_infos.GetSize();
if (num_matches == 1) {
@@ -3205,7 +3192,8 @@ void Process::CompleteAttach() {
}
}
- m_os_ap.reset(OperatingSystem::FindPlugin(this, nullptr));
+ if (!m_os_ap)
+ LoadOperatingSystemPlugin(false);
// Figure out which one is the executable, and set that in our target:
const ModuleList &target_modules = GetTarget().GetImages();
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
@@ -3235,14 +3223,14 @@ void Process::CompleteAttach() {
m_stop_info_override_callback = process_arch.GetStopInfoOverrideCallback();
}
-Error Process::ConnectRemote(Stream *strm, llvm::StringRef remote_url) {
+Status Process::ConnectRemote(Stream *strm, llvm::StringRef remote_url) {
m_abi_sp.reset();
m_process_input_reader.reset();
// Find the process and its architecture. Make sure it matches the
// architecture of the current Target, and if not adjust it.
- Error error(DoConnectRemote(strm, remote_url));
+ Status error(DoConnectRemote(strm, remote_url));
if (error.Success()) {
if (GetID() != LLDB_INVALID_PROCESS_ID) {
EventSP event_sp;
@@ -3267,7 +3255,7 @@ Error Process::ConnectRemote(Stream *strm, llvm::StringRef remote_url) {
return error;
}
-Error Process::PrivateResume() {
+Status Process::PrivateResume() {
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS |
LIBLLDB_LOG_STEP));
if (log)
@@ -3276,7 +3264,11 @@ Error Process::PrivateResume() {
m_mod_id.GetStopID(), StateAsCString(m_public_state.GetValue()),
StateAsCString(m_private_state.GetValue()));
- Error error(WillResume());
+ // If signals handing status changed we might want to update
+ // our signal filters before resuming.
+ UpdateAutomaticSignalFiltering();
+
+ Status error(WillResume());
// Tell the process it is about to resume before the thread list
if (error.Success()) {
// Now let the thread list know we are about to resume so it
@@ -3321,9 +3313,9 @@ Error Process::PrivateResume() {
return error;
}
-Error Process::Halt(bool clear_thread_plans, bool use_run_lock) {
+Status Process::Halt(bool clear_thread_plans, bool use_run_lock) {
if (!StateIsRunningState(m_public_state.GetValue()))
- return Error("Process is not running.");
+ return Status("Process is not running.");
// Don't clear the m_clear_thread_plans_on_stop, only set it to true if
// in case it was already set and some thread plan logic calls halt on its
@@ -3344,7 +3336,7 @@ Error Process::Halt(bool clear_thread_plans, bool use_run_lock) {
RestoreProcessEvents();
SetExitStatus(SIGKILL, "Cancelled async attach.");
Destroy(false);
- return Error();
+ return Status();
}
// Wait for 10 second for the process to stop.
@@ -3354,16 +3346,16 @@ Error Process::Halt(bool clear_thread_plans, bool use_run_lock) {
if (state == eStateInvalid || !event_sp) {
// We timed out and didn't get a stop event...
- return Error("Halt timed out. State = %s", StateAsCString(GetState()));
+ return Status("Halt timed out. State = %s", StateAsCString(GetState()));
}
BroadcastEvent(event_sp);
- return Error();
+ return Status();
}
-Error Process::StopForDestroyOrDetach(lldb::EventSP &exit_event_sp) {
- Error error;
+Status Process::StopForDestroyOrDetach(lldb::EventSP &exit_event_sp) {
+ Status error;
// Check both the public & private states here. If we're hung evaluating an
// expression, for instance, then
@@ -3410,18 +3402,19 @@ Error Process::StopForDestroyOrDetach(lldb::EventSP &exit_event_sp) {
// then continue on.
StateType private_state = m_private_state.GetValue();
if (private_state != eStateStopped) {
- return Error("Attempt to stop the target in order to detach timed out. "
- "State = %s",
- StateAsCString(GetState()));
+ return Status(
+ "Attempt to stop the target in order to detach timed out. "
+ "State = %s",
+ StateAsCString(GetState()));
}
}
}
return error;
}
-Error Process::Detach(bool keep_stopped) {
+Status Process::Detach(bool keep_stopped) {
EventSP exit_event_sp;
- Error error;
+ Status error;
m_destroy_in_process = true;
error = WillDetach();
@@ -3473,7 +3466,7 @@ Error Process::Detach(bool keep_stopped) {
return error;
}
-Error Process::Destroy(bool force_kill) {
+Status Process::Destroy(bool force_kill) {
// Tell ourselves we are in the process of destroying the process, so that we
// don't do any unnecessary work
@@ -3493,7 +3486,7 @@ Error Process::Destroy(bool force_kill) {
m_destroy_in_process = true;
- Error error(WillDestroy());
+ Status error(WillDestroy());
if (error.Success()) {
EventSP exit_event_sp;
if (DestroyRequiresHalt()) {
@@ -3548,8 +3541,8 @@ Error Process::Destroy(bool force_kill) {
return error;
}
-Error Process::Signal(int signal) {
- Error error(WillSignal());
+Status Process::Signal(int signal) {
+ Status error(WillSignal());
if (error.Success()) {
error = DoSignal(signal);
if (error.Success())
@@ -3754,8 +3747,8 @@ bool Process::StartPrivateStateThread(bool is_secondary_thread) {
// Create a thread that watches our internal state and controls which
// events make it to clients (into the DCProcess event queue).
char thread_name[1024];
-
- if (HostInfo::GetMaxThreadNameLength() <= 30) {
+ uint32_t max_len = llvm::get_max_thread_name_length();
+ if (max_len > 0 && max_len <= 30) {
// On platforms with abbreviated thread name lengths, choose thread names
// that fit within the limit.
if (already_running)
@@ -3977,9 +3970,9 @@ void Process::HandlePrivateEvent(EventSP &event_sp) {
}
}
-Error Process::HaltPrivate() {
+Status Process::HaltPrivate() {
EventSP event_sp;
- Error error(WillHalt());
+ Status error(WillHalt());
if (error.Fail())
return error;
@@ -4047,7 +4040,7 @@ thread_result_t Process::RunPrivateStateThread(bool is_secondary_thread) {
log->Printf("Process::%s (arg = %p, pid = %" PRIu64
") woke up with an interrupt - Halting.",
__FUNCTION__, static_cast<void *>(this), GetID());
- Error error = HaltPrivate();
+ Status error = HaltPrivate();
if (error.Fail() && log)
log->Printf("Process::%s (arg = %p, pid = %" PRIu64
") failed to halt the process: %s",
@@ -4487,7 +4480,7 @@ Process::GetStructuredDataPlugin(const ConstString &type_name) const {
return StructuredDataPluginSP();
}
-size_t Process::GetAsyncProfileData(char *buf, size_t buf_size, Error &error) {
+size_t Process::GetAsyncProfileData(char *buf, size_t buf_size, Status &error) {
std::lock_guard<std::recursive_mutex> guard(m_profile_data_comm_mutex);
if (m_profile_data.empty())
return 0;
@@ -4515,7 +4508,7 @@ size_t Process::GetAsyncProfileData(char *buf, size_t buf_size, Error &error) {
// Process STDIO
//------------------------------------------------------------------
-size_t Process::GetSTDOUT(char *buf, size_t buf_size, Error &error) {
+size_t Process::GetSTDOUT(char *buf, size_t buf_size, Status &error) {
std::lock_guard<std::recursive_mutex> guard(m_stdio_communication_mutex);
size_t bytes_available = m_stdout_data.size();
if (bytes_available > 0) {
@@ -4535,7 +4528,7 @@ size_t Process::GetSTDOUT(char *buf, size_t buf_size, Error &error) {
return bytes_available;
}
-size_t Process::GetSTDERR(char *buf, size_t buf_size, Error &error) {
+size_t Process::GetSTDERR(char *buf, size_t buf_size, Status &error) {
std::lock_guard<std::recursive_mutex> gaurd(m_stdio_communication_mutex);
size_t bytes_available = m_stderr_data.size();
if (bytes_available > 0) {
@@ -4598,7 +4591,7 @@ public:
SelectHelper select_helper;
select_helper.FDSetRead(read_fd);
select_helper.FDSetRead(pipe_read_fd);
- Error error = select_helper.Select();
+ Status error = select_helper.Select();
if (error.Fail()) {
SetIsDone(true);
@@ -4616,7 +4609,7 @@ public:
if (select_helper.FDIsSetRead(pipe_read_fd)) {
size_t bytes_read;
// Consume the interrupt byte
- Error error = m_pipe.Read(&ch, 1, bytes_read);
+ Status error = m_pipe.Read(&ch, 1, bytes_read);
if (error.Success()) {
switch (ch) {
case 'q':
@@ -4667,7 +4660,7 @@ public:
if (m_active) {
char ch = 'i'; // Send 'i' for interrupt
size_t bytes_written = 0;
- Error result = m_pipe.Write(&ch, 1, bytes_written);
+ Status result = m_pipe.Write(&ch, 1, bytes_written);
return result.Success();
} else {
// This IOHandler might be pushed on the stack, but not being run
@@ -4830,6 +4823,48 @@ GetExpressionTimeout(const EvaluateExpressionOptions &options,
return *options.GetTimeout() - GetOneThreadExpressionTimeout(options);
}
+static llvm::Optional<ExpressionResults>
+HandleStoppedEvent(Thread &thread, const ThreadPlanSP &thread_plan_sp,
+ RestorePlanState &restorer, const EventSP &event_sp,
+ EventSP &event_to_broadcast_sp,
+ const EvaluateExpressionOptions &options, bool handle_interrupts) {
+ Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS);
+
+ ThreadPlanSP plan = thread.GetCompletedPlan();
+ if (plan == thread_plan_sp && plan->PlanSucceeded()) {
+ LLDB_LOG(log, "execution completed successfully");
+
+ // Restore the plan state so it will get reported as intended when we are
+ // done.
+ restorer.Clean();
+ return eExpressionCompleted;
+ }
+
+ StopInfoSP stop_info_sp = thread.GetStopInfo();
+ if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint &&
+ stop_info_sp->ShouldNotify(event_sp.get())) {
+ LLDB_LOG(log, "stopped for breakpoint: {0}.", stop_info_sp->GetDescription());
+ if (!options.DoesIgnoreBreakpoints()) {
+ // Restore the plan state and then force Private to false. We are going
+ // to stop because of this plan so we need it to become a public plan or
+ // it won't report correctly when we continue to its termination later on.
+ restorer.Clean();
+ thread_plan_sp->SetPrivate(false);
+ event_to_broadcast_sp = event_sp;
+ }
+ return eExpressionHitBreakpoint;
+ }
+
+ if (!handle_interrupts &&
+ Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get()))
+ return llvm::None;
+
+ LLDB_LOG(log, "thread plan did not successfully complete");
+ if (!options.DoesUnwindOnError())
+ event_to_broadcast_sp = event_sp;
+ return eExpressionInterrupted;
+}
+
ExpressionResults
Process::RunThreadPlan(ExecutionContext &exe_ctx,
lldb::ThreadPlanSP &thread_plan_sp,
@@ -5092,7 +5127,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
if (do_resume) {
num_resumes++;
- Error resume_error = PrivateResume();
+ Status resume_error = PrivateResume();
if (!resume_error.Success()) {
diagnostic_manager.Printf(
eDiagnosticSeverityError,
@@ -5235,69 +5270,22 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
"but our thread (index-id=%u) has vanished.",
thread_idx_id);
return_value = eExpressionInterrupted;
- } else {
+ } else if (Process::ProcessEventData::GetRestartedFromEvent(
+ event_sp.get())) {
// If we were restarted, we just need to go back up to fetch
// another event.
- if (Process::ProcessEventData::GetRestartedFromEvent(
- event_sp.get())) {
- if (log) {
- log->Printf("Process::RunThreadPlan(): Got a stop and "
- "restart, so we'll continue waiting.");
- }
- keep_going = true;
- do_resume = false;
- handle_running_event = true;
- } else {
- StopInfoSP stop_info_sp(thread_sp->GetStopInfo());
- StopReason stop_reason = eStopReasonInvalid;
- if (stop_info_sp)
- stop_reason = stop_info_sp->GetStopReason();
-
- // FIXME: We only check if the stop reason is plan complete,
- // should we make sure that
- // it is OUR plan that is complete?
- if (stop_reason == eStopReasonPlanComplete) {
- if (log)
- log->PutCString("Process::RunThreadPlan(): execution "
- "completed successfully.");
-
- // Restore the plan state so it will get reported as
- // intended when we are done.
- thread_plan_restorer.Clean();
-
- return_value = eExpressionCompleted;
- } else {
- // Something restarted the target, so just wait for it to
- // stop for real.
- if (stop_reason == eStopReasonBreakpoint) {
- if (log)
- log->Printf("Process::RunThreadPlan() stopped for "
- "breakpoint: %s.",
- stop_info_sp->GetDescription());
- return_value = eExpressionHitBreakpoint;
- if (!options.DoesIgnoreBreakpoints()) {
- // Restore the plan state and then force Private to
- // false. We are
- // going to stop because of this plan so we need it to
- // become a public
- // plan or it won't report correctly when we continue to
- // its termination
- // later on.
- thread_plan_restorer.Clean();
- if (thread_plan_sp)
- thread_plan_sp->SetPrivate(false);
- event_to_broadcast_sp = event_sp;
- }
- } else {
- if (log)
- log->PutCString("Process::RunThreadPlan(): thread plan "
- "didn't successfully complete.");
- if (!options.DoesUnwindOnError())
- event_to_broadcast_sp = event_sp;
- return_value = eExpressionInterrupted;
- }
- }
+ if (log) {
+ log->Printf("Process::RunThreadPlan(): Got a stop and "
+ "restart, so we'll continue waiting.");
}
+ keep_going = true;
+ do_resume = false;
+ handle_running_event = true;
+ } else {
+ const bool handle_interrupts = true;
+ return_value = *HandleStoppedEvent(
+ *thread, thread_plan_sp, thread_plan_restorer, event_sp,
+ event_to_broadcast_sp, options, handle_interrupts);
}
} break;
@@ -5348,19 +5336,16 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
if (log) {
if (options.GetTryAllThreads()) {
if (before_first_timeout) {
- log->Printf("Process::RunThreadPlan(): Running function with "
- "one thread timeout timed out.");
+ LLDB_LOG(log,
+ "Running function with one thread timeout timed out.");
} else
- log->Printf("Process::RunThreadPlan(): Restarting function with "
- "all threads enabled "
- "and timeout: %" PRIu64
- " timed out, abandoning execution.",
- timeout ? timeout->count() : -1);
+ LLDB_LOG(log, "Restarting function with all threads enabled and "
+ "timeout: {0} timed out, abandoning execution.",
+ timeout);
} else
- log->Printf("Process::RunThreadPlan(): Running function with "
- "timeout: %" PRIu64 " timed out, "
- "abandoning execution.",
- timeout ? timeout->count() : -1);
+ LLDB_LOG(log, "Running function with timeout: {0} timed out, "
+ "abandoning execution.",
+ timeout);
}
// It is possible that between the time we issued the Halt, and we get
@@ -5378,7 +5363,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
bool do_halt = true;
const uint32_t num_retries = 5;
while (try_halt_again < num_retries) {
- Error halt_error;
+ Status halt_error;
if (do_halt) {
if (log)
log->Printf("Process::RunThreadPlan(): Running Halt.");
@@ -5406,20 +5391,6 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
}
if (stop_state == lldb::eStateStopped) {
- // Between the time we initiated the Halt and the time we
- // delivered it, the process could have
- // already finished its job. Check that here:
-
- if (thread->IsThreadPlanDone(thread_plan_sp.get())) {
- if (log)
- log->PutCString("Process::RunThreadPlan(): Even though we "
- "timed out, the call plan was done. "
- "Exiting wait loop.");
- return_value = eExpressionCompleted;
- back_to_top = false;
- break;
- }
-
if (Process::ProcessEventData::GetRestartedFromEvent(
event_sp.get())) {
if (log)
@@ -5433,6 +5404,18 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
continue;
}
+ // Between the time we initiated the Halt and the time we
+ // delivered it, the process could have
+ // already finished its job. Check that here:
+ const bool handle_interrupts = false;
+ if (auto result = HandleStoppedEvent(
+ *thread, thread_plan_sp, thread_plan_restorer, event_sp,
+ event_to_broadcast_sp, options, handle_interrupts)) {
+ return_value = *result;
+ back_to_top = false;
+ break;
+ }
+
if (!options.GetTryAllThreads()) {
if (log)
log->PutCString("Process::RunThreadPlan(): try_all_threads "
@@ -5490,7 +5473,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
// plan, shut it down now.
if (backup_private_state_thread.IsJoinable()) {
StopPrivateStateThread();
- Error error;
+ Status error;
m_private_state_thread = backup_private_state_thread;
if (stopper_base_plan_sp) {
thread->DiscardThreadPlansUpToPlan(stopper_base_plan_sp);
@@ -5879,7 +5862,7 @@ void Process::DidExec() {
target.DidExec();
}
-addr_t Process::ResolveIndirectFunction(const Address *address, Error &error) {
+addr_t Process::ResolveIndirectFunction(const Address *address, Status &error) {
if (address == nullptr) {
error.SetErrorString("Invalid address argument");
return LLDB_INVALID_ADDRESS;
@@ -6107,10 +6090,10 @@ Process::AdvanceAddressToNextBranchInstruction(Address default_stop_addr,
return retval;
}
-Error Process::GetMemoryRegions(
- std::vector<lldb::MemoryRegionInfoSP> &region_list) {
+Status
+Process::GetMemoryRegions(std::vector<lldb::MemoryRegionInfoSP> &region_list) {
- Error error;
+ Status error;
lldb::addr_t range_end = 0;
@@ -6133,12 +6116,13 @@ Error Process::GetMemoryRegions(
return error;
}
-Error Process::ConfigureStructuredData(
- const ConstString &type_name, const StructuredData::ObjectSP &config_sp) {
+Status
+Process::ConfigureStructuredData(const ConstString &type_name,
+ const StructuredData::ObjectSP &config_sp) {
// If you get this, the Process-derived class needs to implement a method
// to enable an already-reported asynchronous structured data feature.
// See ProcessGDBRemote for an example implementation over gdb-remote.
- return Error("unimplemented");
+ return Status("unimplemented");
}
void Process::MapSupportedStructuredDataPlugins(
@@ -6175,8 +6159,7 @@ void Process::MapSupportedStructuredDataPlugins(
}
const_type_names.insert(ConstString(type_name->GetValue()));
- if (log)
- log->Printf("- %s", type_name->GetValue().c_str());
+ LLDB_LOG(log, "- {0}", type_name->GetValue());
return true;
});
@@ -6245,3 +6228,9 @@ bool Process::RouteAsyncStructuredData(
find_it->second->HandleArrivalOfStructuredData(*this, type_name, object_sp);
return true;
}
+
+Status Process::UpdateAutomaticSignalFiltering() {
+ // Default implementation does nothign.
+ // No automatic signal filtering to speak of.
+ return Status();
+}
OpenPOWER on IntegriCloud