summaryrefslogtreecommitdiffstats
path: root/lldb/source/Target/StopInfo.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2010-08-04 01:40:35 +0000
committerGreg Clayton <gclayton@apple.com>2010-08-04 01:40:35 +0000
commitf4b47e15799f16cef4baef4c3ee2519878b0f37a (patch)
tree44271b117f0b87f44f903c5eb471448dd17f5e93 /lldb/source/Target/StopInfo.cpp
parent5cae10339208cdf484d67df5d65995a5338f097d (diff)
downloadbcm5719-llvm-f4b47e15799f16cef4baef4c3ee2519878b0f37a.tar.gz
bcm5719-llvm-f4b47e15799f16cef4baef4c3ee2519878b0f37a.zip
Abtracted the old "lldb_private::Thread::StopInfo" into an abtract class.
This will allow debugger plug-ins to make any instance of "lldb_private::StopInfo" that can completely describe any stop reason. It also provides a framework for doing intelligent things with the stop info at important times in the lifetime of the inferior. Examples include the signal stop info in StopInfoUnixSignal. It will check with the process to see that the current action is for the signal. These actions include wether to stop for the signal, wether the notify that the signal was hit, and wether to pass the signal along to the inferior process. The StopInfoUnixSignal class overrides the "ShouldStop()" method of StopInfo and this allows the stop info to determine if it should stop at the signal or continue the process. StopInfo subclasses must override the following functions: virtual lldb::StopReason GetStopReason () const = 0; virtual const char * GetDescription () = 0; StopInfo subclasses can override the following functions: // If the subclass returns "false", the inferior will resume. The default // version of this function returns "true" which means the default stop // info will stop the process. The breakpoint subclass will check if // the breakpoint wants us to stop by calling any installed callback on // the breakpoint, and also checking if the breakpoint is for the current // thread. Signals will check if they should stop based off of the // UnixSignal settings in the process. virtual bool ShouldStop (Event *event_ptr); // Sublasses can state if they want to notify the debugger when "ShouldStop" // returns false. This would be handy for breakpoints where you want to // log information and continue and is also used by the signal stop info // to notify that a signal was received (after it checks with the process // signal settings). virtual bool ShouldNotify (Event *event_ptr) { return false; } // Allow subclasses to do something intelligent right before we resume. // The signal class will figure out if the signal should be propagated // to the inferior process and pass that along to the debugger plug-ins. virtual void WillResume (lldb::StateType resume_state) { // By default, don't do anything } The support the Mach exceptions was moved into the lldb/source/Plugins/Process/Utility folder and now doesn't polute the lldb_private::Thread class with platform specific code. llvm-svn: 110184
Diffstat (limited to 'lldb/source/Target/StopInfo.cpp')
-rw-r--r--lldb/source/Target/StopInfo.cpp351
1 files changed, 351 insertions, 0 deletions
diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
new file mode 100644
index 00000000000..9d48e8188d4
--- /dev/null
+++ b/lldb/source/Target/StopInfo.cpp
@@ -0,0 +1,351 @@
+//===-- StopInfo.cpp ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/StopInfo.h"
+
+// C Includes
+// C++ Includes
+#include <string>
+
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Log.h"
+#include "lldb/Breakpoint/BreakpointLocation.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/UnixSignals.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+StopInfo::StopInfo (Thread &thread, uint64_t value) :
+ m_thread (thread),
+ m_stop_id (thread.GetProcess().GetStopID()),
+ m_value (value)
+{
+}
+
+bool
+StopInfo::IsValid () const
+{
+ return m_thread.GetProcess().GetStopID() == m_stop_id;
+}
+
+//----------------------------------------------------------------------
+// StopInfoBreakpoint
+//----------------------------------------------------------------------
+
+class StopInfoBreakpoint : public StopInfo
+{
+public:
+
+ StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
+ StopInfo (thread, break_id),
+ m_description(),
+ m_should_stop (false),
+ m_should_stop_is_valid (false)
+ {
+ }
+
+ virtual ~StopInfoBreakpoint ()
+ {
+ }
+
+ virtual StopReason
+ GetStopReason () const
+ {
+ return eStopReasonBreakpoint;
+ }
+
+ virtual bool
+ ShouldStop (Event *event_ptr)
+ {
+ if (!m_should_stop_is_valid)
+ {
+ // Only check once if we should stop at a breakpoint
+ BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
+ if (bp_site_sp)
+ {
+ StoppointCallbackContext context (event_ptr,
+ &m_thread.GetProcess(),
+ &m_thread,
+ m_thread.GetStackFrameAtIndex(0).get(),
+ false);
+
+ m_should_stop = bp_site_sp->ShouldStop (&context);
+ }
+ else
+ {
+ Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
+
+ if (log)
+ log->Printf ("Process::%s could not find breakpoint site id: %lld...", __FUNCTION__, m_value);
+
+ m_should_stop = true;
+ }
+ m_should_stop_is_valid = true;
+ }
+ return m_should_stop;
+ }
+
+ virtual bool
+ ShouldNotify (Event *event_ptr)
+ {
+ BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
+ if (bp_site_sp)
+ {
+ bool all_internal = true;
+
+ for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
+ {
+ if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
+ {
+ all_internal = false;
+ break;
+ }
+ }
+ return all_internal == false;
+ }
+ return true;
+ }
+
+ virtual const char *
+ GetDescription ()
+ {
+ if (m_description.empty())
+ {
+ StreamString strm;
+ strm.Printf("breakpoint %lli", m_value);
+ m_description.swap (strm.GetString());
+ }
+ return m_description.c_str();
+ }
+
+private:
+ std::string m_description;
+ bool m_should_stop;
+ bool m_should_stop_is_valid;
+};
+
+
+//----------------------------------------------------------------------
+// StopInfoWatchpoint
+//----------------------------------------------------------------------
+
+class StopInfoWatchpoint : public StopInfo
+{
+public:
+
+ StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
+ StopInfo (thread, watch_id),
+ m_description()
+ {
+ }
+
+ virtual ~StopInfoWatchpoint ()
+ {
+ }
+
+ virtual StopReason
+ GetStopReason () const
+ {
+ return eStopReasonWatchpoint;
+ }
+
+ virtual const char *
+ GetDescription ()
+ {
+ if (m_description.empty())
+ {
+ StreamString strm;
+ strm.Printf("watchpoint %lli", m_value);
+ m_description.swap (strm.GetString());
+ }
+ return m_description.c_str();
+ }
+
+
+
+private:
+ std::string m_description;
+};
+
+
+
+//----------------------------------------------------------------------
+// StopInfoUnixSignal
+//----------------------------------------------------------------------
+
+class StopInfoUnixSignal : public StopInfo
+{
+public:
+
+ StopInfoUnixSignal (Thread &thread, int signo) :
+ StopInfo (thread, signo),
+ m_description()
+ {
+ }
+
+ virtual ~StopInfoUnixSignal ()
+ {
+ }
+
+
+ virtual StopReason
+ GetStopReason () const
+ {
+ return eStopReasonSignal;
+ }
+
+ virtual bool
+ ShouldStop (Event *event_ptr)
+ {
+ return m_thread.GetProcess().GetUnixSignals().GetShouldStop (m_value);
+ }
+
+
+ // If should stop returns false, check if we should notify of this event
+ virtual bool
+ ShouldNotify (Event *event_ptr)
+ {
+ return m_thread.GetProcess().GetUnixSignals().GetShouldNotify (m_value);
+ }
+
+
+ virtual void
+ WillResume (lldb::StateType resume_state)
+ {
+ if (m_thread.GetProcess().GetUnixSignals().GetShouldSuppress(m_value) == false)
+ m_thread.SetResumeSignal(m_value);
+ }
+
+ virtual const char *
+ GetDescription ()
+ {
+ if (m_description.empty())
+ {
+ StreamString strm;
+ const char *signal_name = m_thread.GetProcess().GetUnixSignals().GetSignalAsCString (m_value);
+ if (signal_name)
+ strm.Printf("signal = %s", signal_name);
+ else
+ strm.Printf("signal = %lli", m_value);
+ m_description.swap (strm.GetString());
+ }
+ return m_description.c_str();
+ }
+
+private:
+ std::string m_description;
+};
+
+//----------------------------------------------------------------------
+// StopInfoTrace
+//----------------------------------------------------------------------
+
+class StopInfoTrace : public StopInfo
+{
+public:
+
+ StopInfoTrace (Thread &thread) :
+ StopInfo (thread, LLDB_INVALID_UID)
+ {
+ }
+
+ virtual ~StopInfoTrace ()
+ {
+ }
+
+ virtual StopReason
+ GetStopReason () const
+ {
+ return eStopReasonTrace;
+ }
+
+ virtual const char *
+ GetDescription ()
+ {
+ return "trace";
+ }
+};
+
+
+//----------------------------------------------------------------------
+// StopInfoThreadPlan
+//----------------------------------------------------------------------
+
+class StopInfoThreadPlan : public StopInfo
+{
+public:
+
+ StopInfoThreadPlan (ThreadPlanSP &plan_sp) :
+ StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
+ m_plan_sp (plan_sp)
+ {
+ }
+
+ virtual ~StopInfoThreadPlan ()
+ {
+ }
+
+ virtual StopReason
+ GetStopReason () const
+ {
+ return eStopReasonPlanComplete;
+ }
+
+ virtual const char *
+ GetDescription ()
+ {
+ if (m_description.empty())
+ {
+ StreamString strm;
+ m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
+ m_description.swap (strm.GetString());
+ }
+ return m_description.c_str();
+ }
+
+private:
+ ThreadPlanSP m_plan_sp;
+ std::string m_description;
+};
+
+StopInfoSP
+StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
+{
+ return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
+}
+
+StopInfoSP
+StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
+{
+ return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
+}
+
+StopInfoSP
+StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
+{
+ return StopInfoSP (new StopInfoUnixSignal (thread, signo));
+}
+
+StopInfoSP
+StopInfo::CreateStopReasonToTrace (Thread &thread)
+{
+ return StopInfoSP (new StopInfoTrace (thread));
+}
+
+StopInfoSP
+StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp)
+{
+ return StopInfoSP (new StopInfoThreadPlan (plan_sp));
+}
OpenPOWER on IntegriCloud