diff options
Diffstat (limited to 'source/Target/Process.cpp')
-rw-r--r-- | source/Target/Process.cpp | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp index c72662e4e343..0bc58f073bf1 100644 --- a/source/Target/Process.cpp +++ b/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" @@ -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( @@ -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; @@ -2798,7 +2776,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 @@ -2862,7 +2845,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. @@ -3046,7 +3031,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 +3190,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()); @@ -3276,6 +3262,10 @@ Error Process::PrivateResume() { m_mod_id.GetStopID(), StateAsCString(m_public_state.GetValue()), StateAsCString(m_private_state.GetValue())); + // If signals handing status changed we might want to update + // our signal filters before resuming. + UpdateAutomaticSignalFiltering(); + Error error(WillResume()); // Tell the process it is about to resume before the thread list if (error.Success()) { @@ -3754,8 +3744,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) @@ -5248,15 +5238,9 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, 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) { + ThreadPlanSP plan = thread->GetCompletedPlan(); + if (plan == thread_plan_sp && plan->PlanSucceeded()) { + if (log) log->PutCString("Process::RunThreadPlan(): execution " "completed successfully."); @@ -5267,9 +5251,11 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx, return_value = eExpressionCompleted; } else { + StopInfoSP stop_info_sp = thread_sp->GetStopInfo(); // Something restarted the target, so just wait for it to // stop for real. - if (stop_reason == eStopReasonBreakpoint) { + if (stop_info_sp && + stop_info_sp->GetStopReason() == eStopReasonBreakpoint) { if (log) log->Printf("Process::RunThreadPlan() stopped for " "breakpoint: %s.", @@ -5348,19 +5334,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 @@ -6245,3 +6228,9 @@ bool Process::RouteAsyncStructuredData( find_it->second->HandleArrivalOfStructuredData(*this, type_name, object_sp); return true; } + +Error Process::UpdateAutomaticSignalFiltering() { + // Default implementation does nothign. + // No automatic signal filtering to speak of. + return Error(); +} |