The second part in thread hardening the internals of LLDB where we make
the lldb_private::StackFrame objects hold onto a weak pointer to the thread
object. The lldb_private::StackFrame objects the the most volatile objects
we have as when we are doing single stepping, frames can often get lost or
thrown away, only to be re-created as another object that still refers to the
same frame. We have another bug tracking that. But we need to be able to
have frames no longer be able to get the thread when they are not part of
a thread anymore, and this is the first step (this fix makes that possible
but doesn't implement it yet).
Also changed lldb_private::ExecutionContextScope to return shared pointers to
all objects in the execution context to further thread harden the internals.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@150871 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/ExecutionContext.cpp b/source/Target/ExecutionContext.cpp
index 6cce08a..e284438 100644
--- a/source/Target/ExecutionContext.cpp
+++ b/source/Target/ExecutionContext.cpp
@@ -343,7 +343,7 @@
m_frame_sp = frame_sp;
if (frame_sp)
{
- m_thread_sp = frame_sp->GetThread().shared_from_this();
+ m_thread_sp = frame_sp->CalculateThread();
if (m_thread_sp)
{
m_process_sp = m_thread_sp->GetProcess().shared_from_this();
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index 6f5589b..e959e40 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -3490,6 +3490,12 @@
return false;
}
+lldb::TargetSP
+Process::CalculateTarget ()
+{
+ return m_target.shared_from_this();
+}
+
void
Process::CalculateExecutionContext (ExecutionContext &exe_ctx)
{
diff --git a/source/Target/RegisterContext.cpp b/source/Target/RegisterContext.cpp
index a7856c6..ba1f641 100644
--- a/source/Target/RegisterContext.cpp
+++ b/source/Target/RegisterContext.cpp
@@ -356,32 +356,32 @@
}
-Target *
+TargetSP
RegisterContext::CalculateTarget ()
{
return m_thread.CalculateTarget();
}
-Process *
+ProcessSP
RegisterContext::CalculateProcess ()
{
return m_thread.CalculateProcess ();
}
-Thread *
+ThreadSP
RegisterContext::CalculateThread ()
{
- return &m_thread;
+ return m_thread.shared_from_this();
}
-StackFrame *
+StackFrameSP
RegisterContext::CalculateStackFrame ()
{
// Register contexts might belong to many frames if we have inlined
// functions inside a frame since all inlined functions share the
// same registers, so we can't definitively say which frame we come from...
- return NULL;
+ return StackFrameSP();
}
void
diff --git a/source/Target/StackFrame.cpp b/source/Target/StackFrame.cpp
index 2ce69f8..c1802b4 100644
--- a/source/Target/StackFrame.cpp
+++ b/source/Target/StackFrame.cpp
@@ -39,13 +39,13 @@
#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
-StackFrame::StackFrame (user_id_t frame_idx,
+StackFrame::StackFrame (const ThreadSP &thread_sp,
+ user_id_t frame_idx,
user_id_t unwind_frame_index,
- Thread &thread,
addr_t cfa,
addr_t pc,
const SymbolContext *sc_ptr) :
- m_thread (thread),
+ m_thread_wp (thread_sp),
m_frame_index (frame_idx),
m_concrete_frame_index (unwind_frame_index),
m_reg_context_sp (),
@@ -66,14 +66,14 @@
}
}
-StackFrame::StackFrame (user_id_t frame_idx,
+StackFrame::StackFrame (const ThreadSP &thread_sp,
+ user_id_t frame_idx,
user_id_t unwind_frame_index,
- Thread &thread,
const RegisterContextSP ®_context_sp,
addr_t cfa,
addr_t pc,
const SymbolContext *sc_ptr) :
- m_thread (thread),
+ m_thread_wp (thread_sp),
m_frame_index (frame_idx),
m_concrete_frame_index (unwind_frame_index),
m_reg_context_sp (reg_context_sp),
@@ -95,23 +95,24 @@
if (reg_context_sp && !m_sc.target_sp)
{
- m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().shared_from_this();
- m_flags.Set (eSymbolContextTarget);
+ m_sc.target_sp = reg_context_sp->CalculateTarget();
+ if (m_sc.target_sp)
+ m_flags.Set (eSymbolContextTarget);
}
}
-StackFrame::StackFrame (user_id_t frame_idx,
+StackFrame::StackFrame (const ThreadSP &thread_sp,
+ user_id_t frame_idx,
user_id_t unwind_frame_index,
- Thread &thread,
const RegisterContextSP ®_context_sp,
addr_t cfa,
const Address& pc_addr,
const SymbolContext *sc_ptr) :
- m_thread (thread),
+ m_thread_wp (thread_sp),
m_frame_index (frame_idx),
m_concrete_frame_index (unwind_frame_index),
m_reg_context_sp (reg_context_sp),
- m_id (pc_addr.GetLoadAddress (&thread.GetProcess().GetTarget()), cfa, NULL),
+ m_id (pc_addr.GetLoadAddress (&thread_sp->GetProcess().GetTarget()), cfa, NULL),
m_frame_code_addr (pc_addr),
m_sc (),
m_flags (),
@@ -129,8 +130,9 @@
if (m_sc.target_sp.get() == NULL && reg_context_sp)
{
- m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().shared_from_this();
- m_flags.Set (eSymbolContextTarget);
+ m_sc.target_sp = reg_context_sp->CalculateTarget();
+ if (m_sc.target_sp)
+ m_flags.Set (eSymbolContextTarget);
}
Module *pc_module = pc_addr.GetModulePtr();
@@ -209,18 +211,25 @@
// Resolve the PC into a temporary address because if ResolveLoadAddress
// fails to resolve the address, it will clear the address object...
-
- if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), &m_thread.GetProcess().GetTarget()))
+ ThreadSP thread_sp (GetThread());
+ if (thread_sp)
{
- const Section *section = m_frame_code_addr.GetSection();
- if (section)
+ TargetSP target_sp (thread_sp->CalculateTarget());
+ if (target_sp)
{
- Module *module = section->GetModule();
- if (module)
+ if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
{
- m_sc.module_sp = module->shared_from_this();
- if (m_sc.module_sp)
- m_flags.Set(eSymbolContextModule);
+ const Section *section = m_frame_code_addr.GetSection();
+ if (section)
+ {
+ Module *module = section->GetModule();
+ if (module)
+ {
+ m_sc.module_sp = module->shared_from_this();
+ if (m_sc.module_sp)
+ m_flags.Set(eSymbolContextModule);
+ }
+ }
}
}
}
@@ -235,7 +244,9 @@
m_frame_code_addr.SetSection(NULL);
m_sc.Clear();
m_flags.Reset(0);
- m_thread.ClearStackFrames ();
+ ThreadSP thread_sp (GetThread());
+ if (thread_sp)
+ thread_sp->ClearStackFrames ();
}
const char *
@@ -243,17 +254,19 @@
{
if (m_disassembly.GetSize() == 0)
{
- ExecutionContext exe_ctx;
- CalculateExecutionContext(exe_ctx);
- Target &target = m_thread.GetProcess().GetTarget();
- Disassembler::Disassemble (target.GetDebugger(),
- target.GetArchitecture(),
- NULL,
- exe_ctx,
- 0,
- 0,
- 0,
- m_disassembly);
+ ExecutionContext exe_ctx (shared_from_this());
+ Target *target = exe_ctx.GetTargetPtr();
+ if (target)
+ {
+ Disassembler::Disassemble (target->GetDebugger(),
+ target->GetArchitecture(),
+ NULL,
+ exe_ctx,
+ 0,
+ 0,
+ 0,
+ m_disassembly);
+ }
if (m_disassembly.GetSize() == 0)
return NULL;
}
@@ -411,13 +424,15 @@
// If we don't have a module, then we can't have the compile unit,
// function, block, line entry or symbol, so we can safely call
// ResolveSymbolContextForAddress with our symbol context member m_sc.
- resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
+ TargetSP target_sp (CalculateTarget());
+ if (target_sp)
+ resolved |= target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
}
// If the target was requested add that:
- if (m_sc.target_sp.get() == NULL)
+ if (!m_sc.target_sp)
{
- m_sc.target_sp = CalculateProcess()->GetTarget().shared_from_this();
+ m_sc.target_sp = CalculateTarget();
if (m_sc.target_sp)
resolved |= eSymbolContextTarget;
}
@@ -1019,11 +1034,11 @@
m_frame_base_error.Clear();
m_flags.Set(GOT_FRAME_BASE);
- ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this);
+ ExecutionContext exe_ctx (shared_from_this());
Value expr_value;
addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
if (m_sc.function->GetFrameBaseExpression().IsLocationList())
- loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess().GetTarget());
+ loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
{
@@ -1055,7 +1070,11 @@
StackFrame::GetRegisterContext ()
{
if (!m_reg_context_sp)
- m_reg_context_sp = m_thread.CreateRegisterContextForFrame (this);
+ {
+ ThreadSP thread_sp (GetThread());
+ if (thread_sp)
+ m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
+ }
return m_reg_context_sp;
}
@@ -1130,36 +1149,47 @@
return false;
}
-Target *
+TargetSP
StackFrame::CalculateTarget ()
{
- return m_thread.CalculateTarget();
+ TargetSP target_sp;
+ ThreadSP thread_sp(GetThread());
+ if (thread_sp)
+ {
+ ProcessSP process_sp (thread_sp->CalculateProcess());
+ if (process_sp)
+ target_sp = process_sp->CalculateTarget();
+ }
+ return target_sp;
}
-Process *
+ProcessSP
StackFrame::CalculateProcess ()
{
- return m_thread.CalculateProcess();
+ ProcessSP process_sp;
+ ThreadSP thread_sp(GetThread());
+ if (thread_sp)
+ process_sp = thread_sp->CalculateProcess();
+ return process_sp;
}
-Thread *
+ThreadSP
StackFrame::CalculateThread ()
{
- return &m_thread;
+ return GetThread();
}
-StackFrame *
+StackFrameSP
StackFrame::CalculateStackFrame ()
{
- return this;
+ return shared_from_this();
}
void
StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
{
- m_thread.CalculateExecutionContext (exe_ctx);
- exe_ctx.SetFramePtr(this);
+ exe_ctx.SetContext (shared_from_this());
}
void
@@ -1169,11 +1199,13 @@
return;
GetSymbolContext(eSymbolContextEverything);
- ExecutionContext exe_ctx;
- CalculateExecutionContext(exe_ctx);
+ ExecutionContext exe_ctx (shared_from_this());
const char *end = NULL;
StreamString s;
- const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat();
+ const char *frame_format = NULL;
+ Target *target = exe_ctx.GetTargetPtr();
+ if (target)
+ frame_format = target->GetDebugger().GetFrameFormat();
if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
{
strm->Write(s.GetData(), s.GetSize());
@@ -1193,11 +1225,20 @@
if (show_frame_index)
strm->Printf("frame #%u: ", m_frame_index);
- strm->Printf("0x%0*llx ", m_thread.GetProcess().GetTarget().GetArchitecture().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess().GetTarget()));
+ ExecutionContext exe_ctx (shared_from_this());
+ Target *target = exe_ctx.GetTargetPtr();
+ strm->Printf("0x%0*llx ",
+ target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
+ GetFrameCodeAddress().GetLoadAddress(target));
GetSymbolContext(eSymbolContextEverything);
const bool show_module = true;
const bool show_inline = true;
- m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline);
+ m_sc.DumpStopContext (strm,
+ exe_ctx.GetBestExecutionContextScope(),
+ GetFrameCodeAddress(),
+ show_fullpaths,
+ show_module,
+ show_inline);
}
void
@@ -1216,7 +1257,7 @@
{
assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
- assert (&m_thread == &curr_frame.m_thread);
+ assert (GetThread() == curr_frame.GetThread());
m_frame_index = curr_frame.m_frame_index;
m_concrete_frame_index = curr_frame.m_concrete_frame_index;
m_reg_context_sp = curr_frame.m_reg_context_sp;
@@ -1260,29 +1301,28 @@
if (show_source)
{
- Target &target = GetThread().GetProcess().GetTarget();
- Debugger &debugger = target.GetDebugger();
- const uint32_t source_before = debugger.GetStopSourceLineCount(true);
- const uint32_t source_after = debugger.GetStopSourceLineCount(false);
+ ExecutionContext exe_ctx (shared_from_this());
bool have_source = false;
- if (source_before || source_after)
+ DebuggerInstanceSettings::StopDisassemblyType disasm_display = DebuggerInstanceSettings::eStopDisassemblyTypeNever;
+ Target *target = exe_ctx.GetTargetPtr();
+ if (target && (source_lines_before || source_lines_after))
{
GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
if (m_sc.comp_unit && m_sc.line_entry.IsValid())
{
- if (target.GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
- m_sc.line_entry.line,
- source_before,
- source_after,
- "->",
- &strm))
+ if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
+ m_sc.line_entry.line,
+ source_lines_before,
+ source_lines_after,
+ "->",
+ &strm))
{
have_source = true;
}
}
+ disasm_display = target->GetDebugger().GetStopDisassemblyDisplay ();
}
- DebuggerInstanceSettings::StopDisassemblyType disasm_display = debugger.GetStopDisassemblyDisplay ();
switch (disasm_display)
{
@@ -1294,17 +1334,16 @@
break;
// Fall through to next case
case DebuggerInstanceSettings::eStopDisassemblyTypeAlways:
+ if (target)
{
- const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
+ const uint32_t disasm_lines = target->GetDebugger().GetDisassemblyLineCount();
if (disasm_lines > 0)
{
- const ArchSpec &target_arch = target.GetArchitecture();
+ const ArchSpec &target_arch = target->GetArchitecture();
AddressRange pc_range;
pc_range.GetBaseAddress() = GetFrameCodeAddress();
pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
- ExecutionContext exe_ctx;
- CalculateExecutionContext(exe_ctx);
- Disassembler::Disassemble (debugger,
+ Disassembler::Disassemble (target->GetDebugger(),
target_arch,
NULL,
exe_ctx,
diff --git a/source/Target/StackFrameList.cpp b/source/Target/StackFrameList.cpp
index b69cad2..27383d8 100644
--- a/source/Target/StackFrameList.cpp
+++ b/source/Target/StackFrameList.cpp
@@ -89,9 +89,9 @@
{
cfa = m_thread.m_reg_context_sp->GetSP();
m_thread.GetRegisterContext();
- unwind_frame_sp.reset (new StackFrame (m_frames.size(),
+ unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(),
+ m_frames.size(),
idx,
- m_thread,
m_thread.m_reg_context_sp,
cfa,
m_thread.m_reg_context_sp->GetPC(),
@@ -108,7 +108,7 @@
{
const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
assert (success);
- unwind_frame_sp.reset (new StackFrame (m_frames.size(), idx, m_thread, cfa, pc, NULL));
+ unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), m_frames.size(), idx, cfa, pc, NULL));
m_frames.push_back (unwind_frame_sp);
}
@@ -130,9 +130,9 @@
while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address))
{
- StackFrameSP frame_sp(new StackFrame (m_frames.size(),
+ StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(),
+ m_frames.size(),
idx,
- m_thread,
unwind_frame_sp->GetRegisterContextSP (),
cfa,
next_frame_address,
@@ -264,9 +264,9 @@
// context with the stack frame at index zero.
m_thread.GetRegisterContext();
assert (m_thread.m_reg_context_sp.get());
- frame_sp.reset (new StackFrame (0,
+ frame_sp.reset (new StackFrame (m_thread.shared_from_this(),
0,
- m_thread,
+ 0,
m_thread.m_reg_context_sp,
m_thread.m_reg_context_sp->GetSP(),
m_thread.m_reg_context_sp->GetPC(),
@@ -289,7 +289,7 @@
addr_t pc, cfa;
if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
{
- frame_sp.reset (new StackFrame (idx, idx, m_thread, cfa, pc, NULL));
+ frame_sp.reset (new StackFrame (m_thread.shared_from_this(), idx, idx, cfa, pc, NULL));
Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function;
if (function)
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index c0aa7a5..ce4777f 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -1286,28 +1286,28 @@
}
-Target *
+TargetSP
Target::CalculateTarget ()
{
- return this;
+ return shared_from_this();
}
-Process *
+ProcessSP
Target::CalculateProcess ()
{
- return NULL;
+ return ProcessSP();
}
-Thread *
+ThreadSP
Target::CalculateThread ()
{
- return NULL;
+ return ThreadSP();
}
-StackFrame *
+StackFrameSP
Target::CalculateStackFrame ()
{
- return NULL;
+ return StackFrameSP();
}
void
diff --git a/source/Target/Thread.cpp b/source/Target/Thread.cpp
index 1c13b3d..7423249 100644
--- a/source/Target/Thread.cpp
+++ b/source/Target/Thread.cpp
@@ -1015,28 +1015,28 @@
}
-Target *
+TargetSP
Thread::CalculateTarget ()
{
return m_process.CalculateTarget();
}
-Process *
+ProcessSP
Thread::CalculateProcess ()
{
- return &m_process;
+ return m_process.shared_from_this();
}
-Thread *
+ThreadSP
Thread::CalculateThread ()
{
- return this;
+ return shared_from_this();
}
-StackFrame *
+StackFrameSP
Thread::CalculateStackFrame ()
{
- return NULL;
+ return StackFrameSP();
}
void
diff --git a/source/Target/ThreadPlanStepInRange.cpp b/source/Target/ThreadPlanStepInRange.cpp
index b1c1bbc..3455e90 100644
--- a/source/Target/ThreadPlanStepInRange.cpp
+++ b/source/Target/ThreadPlanStepInRange.cpp
@@ -194,13 +194,13 @@
if (sc.function)
{
func_start_address = sc.function->GetAddressRange().GetBaseAddress();
- if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget()))
+ if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
bytes_to_skip = sc.function->GetPrologueByteSize();
}
else if (sc.symbol)
{
func_start_address = sc.symbol->GetValue();
- if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget()))
+ if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get()))
bytes_to_skip = sc.symbol->GetPrologueByteSize();
}