[Lldb-commits] [lldb] r110899 - in /lldb/trunk: include/lldb/Target/Thread.h source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp source/Plugins/Process/gdb-remote/ThreadGDBRemote.h source/Target/Thread.cpp
Jim Ingham
jingham at apple.com
Wed Aug 11 19:14:28 PDT 2010
Author: jingham
Date: Wed Aug 11 21:14:28 2010
New Revision: 110899
URL: http://llvm.org/viewvc/llvm-project?rev=110899&view=rev
Log:
Now that we are using the Unwinder (or Jason's new unwinder when that comes about) all the plugin-specific details of getting stack frames
should be hidden behind that, and the "GetStackFrameAtIndex" and "GetStackFrameCount" algorithms become generic. So I moved them to Thread.cpp.
Modified:
lldb/trunk/include/lldb/Target/Thread.h
lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp
lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h
lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
lldb/trunk/source/Target/Thread.cpp
Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=110899&r1=110898&r2=110899&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Wed Aug 11 21:14:28 2010
@@ -15,6 +15,7 @@
#include "lldb/Core/UserID.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/StackFrameList.h"
+#include "libunwind/include/libunwind.h"
#define LLDB_THREAD_MAX_STOP_EXC_DATA 8
@@ -298,10 +299,10 @@
}
virtual uint32_t
- GetStackFrameCount() = 0;
+ GetStackFrameCount();
virtual lldb::StackFrameSP
- GetStackFrameAtIndex (uint32_t idx) = 0;
+ GetStackFrameAtIndex (uint32_t idx);
lldb::StackFrameSP
GetCurrentFrame ();
@@ -661,6 +662,9 @@
typedef std::vector<lldb::ThreadPlanSP> plan_stack;
+ virtual lldb_private::Unwind *
+ GetUnwinder () = 0;
+
//------------------------------------------------------------------
// Classes that inherit from Process can see and modify these
//------------------------------------------------------------------
@@ -679,6 +683,7 @@
uint32_t m_current_frame_idx;///< The current frame for this thread
int m_resume_signal; ///< The signal that should be used when continuing this thread.
lldb::StateType m_resume_state; ///< The state that indicates what this thread should do when the process is resumed.
+ std::auto_ptr<lldb_private::Unwind> m_unwinder_ap;
private:
//------------------------------------------------------------------
// For Thread only
Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp?rev=110899&r1=110898&r2=110899&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.cpp Wed Aug 11 21:14:28 2010
@@ -22,6 +22,10 @@
#include "lldb/Target/RegisterContext.h"
#include "lldb/Breakpoint/WatchpointLocation.h"
#include "lldb/Core/StreamString.h"
+#include "lldb/Target/Unwind.h"
+#include "LibUnwindRegisterContext.h"
+#include "UnwindLibUnwind.h"
+#include "UnwindMacOSXFrameBackchain.h"
using namespace lldb;
using namespace lldb_private;
@@ -203,54 +207,28 @@
m_basic_info_string.clear();
}
-uint32_t
-ThreadMacOSX::GetStackFrameCount()
-{
- if (m_fp_pc_pairs.empty())
- GetStackFrameData(m_fp_pc_pairs);
- return m_fp_pc_pairs.size();
-}
-
-// Make sure that GetStackFrameAtIndex() does NOT call GetStackFrameCount() when
-// getting the stack frame at index zero! This way GetStackFrameCount() (via
-// GetStackFRameData()) can call this function to get the first frame in order
-// to provide the first frame to a lower call for efficiency sake (avoid
-// redundant lookups in the frame symbol context).
-lldb::StackFrameSP
-ThreadMacOSX::GetStackFrameAtIndex (uint32_t idx)
+Unwind *
+ThreadMacOSX::GetUnwinder ()
{
- StackFrameSP frame_sp(m_frames.GetFrameAtIndex(idx));
-
- if (frame_sp)
- return frame_sp;
-
- // Don't try and fetch a frame while process is running
- // Calling IsRunning isn't right here, because IsRunning reads the Public
- // state but we need to be able to read the stack frames in the ShouldStop
- // methods, which happen before the Public state has been updated.
-// if (m_process.IsRunning())
-// return frame_sp;
-
- // Special case the first frame (idx == 0) so that we don't need to
- // know how many stack frames there are to get it. If we need any other
- // frames, then we do need to know if "idx" is a valid index.
- if (idx == 0)
- {
- // If this is the first frame, we want to share the thread register
- // context with the stack frame at index zero.
- GetRegisterContext();
- assert (m_reg_context_sp.get());
- frame_sp.reset (new StackFrame (idx, *this, m_reg_context_sp, m_reg_context_sp->GetFP(), m_reg_context_sp->GetPC()));
- }
- else if (idx < GetStackFrameCount())
+ if (m_unwinder_ap.get() == NULL)
{
- assert (idx < m_fp_pc_pairs.size());
- frame_sp.reset (new StackFrame (idx, *this, m_fp_pc_pairs[idx].first, m_fp_pc_pairs[idx].second));
+ const ArchSpec target_arch (GetProcess().GetTarget().GetArchitecture ());
+#if 0 // Not sure this is the right thing to do for native, but this will all go away with Jason's new
+ // unwinder anyway...
+ if (target_arch == ArchSpec("x86_64") || target_arch == ArchSpec("i386"))
+ {
+ m_unwinder_ap.reset (new UnwindLibUnwind (*this, GetGDBProcess().GetLibUnwindAddressSpace()));
+ }
+ else
+#endif
+ {
+ m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
+ }
}
- m_frames.SetFrameAtIndex(idx, frame_sp);
- return frame_sp;
+ return m_unwinder_ap.get();
}
+
void
ThreadMacOSX::ClearStackFrames ()
{
Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h?rev=110899&r1=110898&r2=110899&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h Wed Aug 11 21:14:28 2010
@@ -51,12 +51,6 @@
virtual bool
RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint);
- virtual uint32_t
- GetStackFrameCount();
-
- virtual lldb::StackFrameSP
- GetStackFrameAtIndex (uint32_t idx);
-
virtual void
ClearStackFrames ();
@@ -139,6 +133,9 @@
static bool
GetBasicInfo (lldb::tid_t threadID, struct thread_basic_info *basic_info);
+ virtual lldb_private::Unwind *
+ GetUnwinder ();
+
//------------------------------------------------------------------
// Member variables.
//------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp?rev=110899&r1=110898&r2=110899&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp Wed Aug 11 21:14:28 2010
@@ -38,8 +38,7 @@
Thread(process, tid),
m_thread_name (),
m_dispatch_queue_name (),
- m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS),
- m_unwinder_ap ()
+ m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS)
{
// ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD | GDBR_LOG_VERBOSE, "ThreadGDBRemote::ThreadGDBRemote ( pid = %i, tid = 0x%4.4x, )", m_process.GetID(), GetID());
ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID());
@@ -136,61 +135,6 @@
return m_unwinder_ap.get();
}
-uint32_t
-ThreadGDBRemote::GetStackFrameCount()
-{
- Unwind *unwinder = GetUnwinder ();
- if (unwinder)
- return unwinder->GetFrameCount();
- return 0;
-}
-
-// Make sure that GetStackFrameAtIndex() does NOT call GetStackFrameCount() when
-// getting the stack frame at index zero! This way GetStackFrameCount() (via
-// GetStackFRameData()) can call this function to get the first frame in order
-// to provide the first frame to a lower call for efficiency sake (avoid
-// redundant lookups in the frame symbol context).
-lldb::StackFrameSP
-ThreadGDBRemote::GetStackFrameAtIndex (uint32_t idx)
-{
-
- StackFrameSP frame_sp (m_frames.GetFrameAtIndex(idx));
-
- if (frame_sp.get())
- return frame_sp;
-
- // Don't try and fetch a frame while process is running
-// FIXME: This check isn't right because IsRunning checks the Public state, but this
-// is work you need to do - for instance in ShouldStop & friends - before the public
-// state has been changed.
-// if (m_process.IsRunning())
-// return frame_sp;
-
- // Special case the first frame (idx == 0) so that we don't need to
- // know how many stack frames there are to get it. If we need any other
- // frames, then we do need to know if "idx" is a valid index.
- if (idx == 0)
- {
- // If this is the first frame, we want to share the thread register
- // context with the stack frame at index zero.
- GetRegisterContext();
- assert (m_reg_context_sp.get());
- frame_sp.reset (new StackFrame (idx, *this, m_reg_context_sp, m_reg_context_sp->GetSP(), m_reg_context_sp->GetPC()));
- }
- else if (idx < GetStackFrameCount())
- {
- Unwind *unwinder = GetUnwinder ();
- if (unwinder)
- {
- addr_t pc, cfa;
- if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
- frame_sp.reset (new StackFrame (idx, *this, cfa, pc));
- }
- }
- m_frames.SetFrameAtIndex(idx, frame_sp);
- return frame_sp;
-}
-
void
ThreadGDBRemote::ClearStackFrames ()
{
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h?rev=110899&r1=110898&r2=110899&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h Wed Aug 11 21:14:28 2010
@@ -54,12 +54,6 @@
virtual bool
RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint);
- virtual uint32_t
- GetStackFrameCount();
-
- virtual lldb::StackFrameSP
- GetStackFrameAtIndex (uint32_t idx);
-
virtual void
ClearStackFrames ();
@@ -121,12 +115,11 @@
std::string m_thread_name;
std::string m_dispatch_queue_name;
lldb::addr_t m_thread_dispatch_qaddr;
- std::auto_ptr<lldb_private::Unwind> m_unwinder_ap;
//------------------------------------------------------------------
// Member variables.
//------------------------------------------------------------------
- lldb_private::Unwind *
+ virtual lldb_private::Unwind *
GetUnwinder ();
void
Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=110899&r1=110898&r2=110899&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Wed Aug 11 21:14:28 2010
@@ -32,6 +32,7 @@
#include "lldb/Target/ThreadPlanRunToAddress.h"
#include "lldb/Target/ThreadPlanStepUntil.h"
#include "lldb/Target/ThreadSpec.h"
+#include "lldb/Target/Unwind.h"
using namespace lldb;
using namespace lldb_private;
@@ -51,7 +52,9 @@
m_frames (),
m_current_frame_idx (0),
m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
- m_resume_state (eStateRunning)
+ m_resume_state (eStateRunning),
+ m_unwinder_ap ()
+
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT);
if (log)
@@ -790,6 +793,56 @@
exe_ctx.frame = NULL;
}
+uint32_t
+Thread::GetStackFrameCount()
+{
+ Unwind *unwinder = GetUnwinder ();
+ if (unwinder)
+ return unwinder->GetFrameCount();
+ return 0;
+}
+
+lldb::StackFrameSP
+Thread::GetStackFrameAtIndex (uint32_t idx)
+{
+
+ StackFrameSP frame_sp (m_frames.GetFrameAtIndex(idx));
+
+ if (frame_sp.get())
+ return frame_sp;
+
+ // Don't try and fetch a frame while process is running
+// FIXME: This check isn't right because IsRunning checks the Public state, but this
+// is work you need to do - for instance in ShouldStop & friends - before the public
+// state has been changed.
+// if (m_process.IsRunning())
+// return frame_sp;
+
+ // Special case the first frame (idx == 0) so that we don't need to
+ // know how many stack frames there are to get it. If we need any other
+ // frames, then we do need to know if "idx" is a valid index.
+ if (idx == 0)
+ {
+ // If this is the first frame, we want to share the thread register
+ // context with the stack frame at index zero.
+ GetRegisterContext();
+ assert (m_reg_context_sp.get());
+ frame_sp.reset (new StackFrame (idx, *this, m_reg_context_sp, m_reg_context_sp->GetSP(), m_reg_context_sp->GetPC()));
+ }
+ else if (idx < GetStackFrameCount())
+ {
+ Unwind *unwinder = GetUnwinder ();
+ if (unwinder)
+ {
+ addr_t pc, cfa;
+ if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
+ frame_sp.reset (new StackFrame (idx, *this, cfa, pc));
+ }
+ }
+ m_frames.SetFrameAtIndex(idx, frame_sp);
+ return frame_sp;
+}
+
lldb::StackFrameSP
Thread::GetCurrentFrame ()
{
More information about the lldb-commits
mailing list