Switching back to using std::tr1::shared_ptr. We originally switched away
due to RTTI worries since llvm and clang don't use RTTI, but I was able to
switch back with no issues as far as I can tell. Once the RTTI issue wasn't
an issue, we were looking for a way to properly track weak pointers to objects
to solve some of the threading issues we have been running into which naturally
led us back to std::tr1::weak_ptr. We also wanted the ability to make a shared
pointer from just a pointer, which is also easily solved using the
std::tr1::enable_shared_from_this class.
The main reason for this move back is so we can start properly having weak
references to objects. Currently a lldb_private::Thread class has a refrence
to its parent lldb_private::Process. This doesn't work well when we now hand
out a SBThread object that contains a shared pointer to a lldb_private::Thread
as this SBThread can be held onto by external clients and if they end up
using one of these objects we can easily crash.
So the next task is to start adopting std::tr1::weak_ptr where ever it makes
sense which we can do with lldb_private::Debugger, lldb_private::Target,
lldb_private::Process, lldb_private::Thread, lldb_private::StackFrame, and
many more objects now that they are no longer using intrusive ref counted
pointer objects (you can't do std::tr1::weak_ptr functionality with intrusive
pointers).
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@149207 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp b/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
index 199b55c..6e230fb 100644
--- a/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/ProcessKDPLog.cpp
@@ -104,7 +104,7 @@
// Now make a new log with this stream if one was provided
if (log_stream_sp)
{
- log = make_shared<Log>(log_stream_sp);
+ log.reset (new Log(log_stream_sp));
GetLog () = log;
}
diff --git a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
index 3dc2102..3ae19f9 100644
--- a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -126,7 +126,7 @@
{
m_current_offset = frame_sp->GetFrameCodeAddress().GetOffset() - m_start_pc.GetOffset();
}
- else if (frame_sp->GetFrameCodeAddress().GetModule() == m_start_pc.GetModule())
+ else if (frame_sp->GetFrameCodeAddress().GetModulePtr() == m_start_pc.GetModulePtr())
{
// This means that whatever symbol we kicked up isn't really correct
// as no should cross section boundaries... We really should NULL out
@@ -284,7 +284,7 @@
// If we don't have a Module for some reason, we're not going to find symbol/function information - just
// stick in some reasonable defaults and hope we can unwind past this frame.
- if (!m_current_pc.IsValid() || m_current_pc.GetModule() == NULL)
+ if (!m_current_pc.IsValid() || m_current_pc.GetModulePtr() == NULL)
{
if (log)
{
@@ -397,7 +397,7 @@
}
// We require that eSymbolContextSymbol be successfully filled in or this context is of no use to us.
- if ((m_current_pc.GetModule()->ResolveSymbolContextForAddress (m_current_pc, eSymbolContextFunction| eSymbolContextSymbol, m_sym_ctx) & eSymbolContextSymbol) == eSymbolContextSymbol)
+ if ((m_current_pc.GetModulePtr()->ResolveSymbolContextForAddress (m_current_pc, eSymbolContextFunction| eSymbolContextSymbol, m_sym_ctx) & eSymbolContextSymbol) == eSymbolContextSymbol)
{
m_sym_ctx_valid = true;
}
@@ -436,7 +436,7 @@
temporary_pc.SetOffset(m_current_pc.GetOffset() - 1);
m_sym_ctx.Clear();
m_sym_ctx_valid = false;
- if ((m_current_pc.GetModule()->ResolveSymbolContextForAddress (temporary_pc, eSymbolContextFunction| eSymbolContextSymbol, m_sym_ctx) & eSymbolContextSymbol) == eSymbolContextSymbol)
+ if ((m_current_pc.GetModulePtr()->ResolveSymbolContextForAddress (temporary_pc, eSymbolContextFunction| eSymbolContextSymbol, m_sym_ctx) & eSymbolContextSymbol) == eSymbolContextSymbol)
{
m_sym_ctx_valid = true;
}
@@ -619,13 +619,13 @@
RegisterContextLLDB::GetFastUnwindPlanForFrame ()
{
UnwindPlanSP unwind_plan_sp;
- if (!m_current_pc.IsValid() || m_current_pc.GetModule() == NULL || m_current_pc.GetModule()->GetObjectFile() == NULL)
+ if (!m_current_pc.IsValid() || m_current_pc.GetModulePtr() == NULL || m_current_pc.GetModulePtr()->GetObjectFile() == NULL)
return unwind_plan_sp;
if (IsFrameZero ())
return unwind_plan_sp;
- FuncUnwindersSP func_unwinders_sp (m_current_pc.GetModule()->GetObjectFile()->GetUnwindTable().GetFuncUnwindersContainingAddress (m_current_pc, m_sym_ctx));
+ FuncUnwindersSP func_unwinders_sp (m_current_pc.GetModulePtr()->GetObjectFile()->GetUnwindTable().GetFuncUnwindersContainingAddress (m_current_pc, m_sym_ctx));
if (!func_unwinders_sp)
return unwind_plan_sp;
@@ -712,7 +712,7 @@
}
// No Module for the current pc, try using the architecture default unwind.
- if (!m_current_pc.IsValid() || m_current_pc.GetModule() == NULL || m_current_pc.GetModule()->GetObjectFile() == NULL)
+ if (!m_current_pc.IsValid() || m_current_pc.GetModulePtr() == NULL || m_current_pc.GetModulePtr()->GetObjectFile() == NULL)
{
m_frame_type = eNormalFrame;
return arch_default_unwind_plan_sp;
@@ -721,7 +721,7 @@
FuncUnwindersSP func_unwinders_sp;
if (m_sym_ctx_valid)
{
- func_unwinders_sp = m_current_pc.GetModule()->GetObjectFile()->GetUnwindTable().GetFuncUnwindersContainingAddress (m_current_pc, m_sym_ctx);
+ func_unwinders_sp = m_current_pc.GetModulePtr()->GetObjectFile()->GetUnwindTable().GetFuncUnwindersContainingAddress (m_current_pc, m_sym_ctx);
}
// No FuncUnwinders available for this pc, try using architectural default unwind.
diff --git a/source/Plugins/Process/Utility/RegisterContextLLDB.h b/source/Plugins/Process/Utility/RegisterContextLLDB.h
index a578fd7..cdb0ccb 100644
--- a/source/Plugins/Process/Utility/RegisterContextLLDB.h
+++ b/source/Plugins/Process/Utility/RegisterContextLLDB.h
@@ -25,7 +25,7 @@
class RegisterContextLLDB : public lldb_private::RegisterContext
{
public:
- typedef lldb::SharedPtr<RegisterContextLLDB>::Type SharedPtr;
+ typedef SHARED_PTR(RegisterContextLLDB) SharedPtr;
RegisterContextLLDB (lldb_private::Thread &thread,
const SharedPtr& next_frame,
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.cpp b/source/Plugins/Process/Utility/UnwindLLDB.cpp
index 954ad8b..bf71b00 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.cpp
+++ b/source/Plugins/Process/Utility/UnwindLLDB.cpp
@@ -69,10 +69,10 @@
{
// First, set up the 0th (initial) frame
CursorSP first_cursor_sp(new Cursor ());
- RegisterContextLLDBSharedPtr reg_ctx_sp (new RegisterContextLLDB (m_thread,
- RegisterContextLLDBSharedPtr(),
- first_cursor_sp->sctx,
- 0, *this));
+ RegisterContextLLDBSP reg_ctx_sp (new RegisterContextLLDB (m_thread,
+ RegisterContextLLDBSP(),
+ first_cursor_sp->sctx,
+ 0, *this));
if (reg_ctx_sp.get() == NULL)
return false;
@@ -87,7 +87,7 @@
// Everything checks out, so release the auto pointer value and let the
// cursor own it in its shared pointer
- first_cursor_sp->reg_ctx = reg_ctx_sp;
+ first_cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
m_frames.push_back (first_cursor_sp);
return true;
}
@@ -104,10 +104,11 @@
return false;
uint32_t cur_idx = m_frames.size ();
- RegisterContextLLDBSharedPtr reg_ctx_sp(new RegisterContextLLDB (m_thread,
- m_frames[cur_idx - 1]->reg_ctx,
- cursor_sp->sctx,
- cur_idx, *this));
+ RegisterContextLLDBSP reg_ctx_sp(new RegisterContextLLDB (m_thread,
+ m_frames[cur_idx - 1]->reg_ctx_lldb_sp,
+ cursor_sp->sctx,
+ cur_idx,
+ *this));
if (reg_ctx_sp.get() == NULL)
return false;
@@ -171,7 +172,7 @@
}
}
}
- cursor_sp->reg_ctx = reg_ctx_sp;
+ cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
m_frames.push_back (cursor_sp);
return true;
}
@@ -218,21 +219,27 @@
ABI *abi = m_thread.GetProcess().GetABI().get();
- while (idx >= m_frames.size() && AddOneMoreFrame (abi))
- ;
+ while (idx >= m_frames.size())
+ {
+ if (!AddOneMoreFrame (abi))
+ break;
+ }
- if (idx < m_frames.size ())
- reg_ctx_sp = m_frames[idx]->reg_ctx;
+ const uint32_t num_frames = m_frames.size();
+ if (idx < num_frames)
+ {
+ Cursor *frame_cursor = m_frames[idx].get();
+ reg_ctx_sp = frame_cursor->reg_ctx_lldb_sp->shared_from_this();
+ }
return reg_ctx_sp;
}
-UnwindLLDB::RegisterContextLLDBSharedPtr
+UnwindLLDB::RegisterContextLLDBSP
UnwindLLDB::GetRegisterContextForFrameNum (uint32_t frame_num)
{
- RegisterContextLLDBSharedPtr reg_ctx_sp;
- if (frame_num >= m_frames.size())
- return reg_ctx_sp;
- reg_ctx_sp = m_frames[frame_num]->reg_ctx;
+ RegisterContextLLDBSP reg_ctx_sp;
+ if (frame_num < m_frames.size())
+ reg_ctx_sp = m_frames[frame_num]->reg_ctx_lldb_sp;
return reg_ctx_sp;
}
@@ -244,7 +251,7 @@
return false;
while (frame_num >= 0)
{
- if (m_frames[frame_num]->reg_ctx->SavedLocationForRegister (lldb_regnum, regloc, false))
+ if (m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc, false))
return true;
frame_num--;
}
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.h b/source/Plugins/Process/Utility/UnwindLLDB.h
index ec9271b..b9352b6 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.h
+++ b/source/Plugins/Process/Utility/UnwindLLDB.h
@@ -69,11 +69,11 @@
lldb::RegisterContextSP
DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
- typedef lldb::SharedPtr<lldb_private::RegisterContextLLDB>::Type RegisterContextLLDBSharedPtr;
+ typedef SHARED_PTR(RegisterContextLLDB) RegisterContextLLDBSP;
// Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
// The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
- RegisterContextLLDBSharedPtr
+ RegisterContextLLDBSP
GetRegisterContextForFrameNum (uint32_t frame_num);
// Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
@@ -89,14 +89,14 @@
lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
lldb::addr_t cfa; // The canonical frame address for this stack frame
lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
- RegisterContextLLDBSharedPtr reg_ctx; // These are all RegisterContextLLDB's
+ RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
- Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx() { }
+ Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
private:
DISALLOW_COPY_AND_ASSIGN (Cursor);
};
- typedef lldb::SharedPtr<Cursor>::Type CursorSP;
+ typedef SHARED_PTR(Cursor) CursorSP;
std::vector<CursorSP> m_frames;
bool AddOneMoreFrame (ABI *abi);
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
index a605221..7fd5802 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
@@ -104,7 +104,7 @@
// Now make a new log with this stream if one was provided
if (log_stream_sp)
{
- log = make_shared<Log>(log_stream_sp);
+ log.reset (new Log(log_stream_sp));
GetLog () = log;
}