diff options
author | Greg Clayton <gclayton@apple.com> | 2012-02-21 00:09:25 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-02-21 00:09:25 +0000 |
commit | 1ac04c308832f7a9b2e07e360f07c82f7cb2a02c (patch) | |
tree | bb908a56f1d08a946f4f25aa7b4b762066e1ec57 /lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp | |
parent | 3508a0054301ef24b8d8619351788698bcd97620 (diff) | |
download | bcm5719-llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.tar.gz bcm5719-llvm-1ac04c308832f7a9b2e07e360f07c82f7cb2a02c.zip |
Thread hardening part 3. Now lldb_private::Thread objects have std::weak_ptr
objects for the backlink to the lldb_private::Process. The issues we were
running into before was someone was holding onto a shared pointer to a
lldb_private::Thread for too long, and the lldb_private::Process parent object
would get destroyed and the lldb_private::Thread had a "Process &m_process"
member which would just treat whatever memory that used to be a Process as a
valid Process. This was mostly happening for lldb_private::StackFrame objects
that had a member like "Thread &m_thread". So this completes the internal
strong/weak changes.
Documented the ExecutionContext and ExecutionContextRef classes so that our
LLDB developers can understand when and where to use ExecutionContext and
ExecutionContextRef objects.
llvm-svn: 151009
Diffstat (limited to 'lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp b/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp index 5706c6d2381..f1cb91535eb 100644 --- a/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp +++ b/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp @@ -12,9 +12,10 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/ArchSpec.h" -#include "lldb/Target/Thread.h" +#include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" +#include "lldb/Target/Thread.h" #include "RegisterContextMacOSXFrameBackchain.h" @@ -32,14 +33,19 @@ UnwindMacOSXFrameBackchain::DoGetFrameCount() { if (m_cursors.empty()) { - const ArchSpec& target_arch = m_thread.GetProcess().GetTarget().GetArchitecture (); - // Frame zero should always be supplied by the thread... - StackFrameSP frame_sp (m_thread.GetStackFrameAtIndex (0)); - - if (target_arch.GetAddressByteSize() == 8) - GetStackFrameData_x86_64 (frame_sp.get()); - else - GetStackFrameData_i386 (frame_sp.get()); + ExecutionContext exe_ctx (m_thread.shared_from_this()); + Target *target = exe_ctx.GetTargetPtr(); + if (target) + { + const ArchSpec& target_arch = target->GetArchitecture (); + // Frame zero should always be supplied by the thread... + exe_ctx.SetFrameSP (m_thread.GetStackFrameAtIndex (0)); + + if (target_arch.GetAddressByteSize() == 8) + GetStackFrameData_x86_64 (exe_ctx); + else + GetStackFrameData_i386 (exe_ctx); + } } return m_cursors.size(); } @@ -75,10 +81,16 @@ UnwindMacOSXFrameBackchain::DoCreateRegisterContextForFrame (StackFrame *frame) } size_t -UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (StackFrame *first_frame) +UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (const ExecutionContext &exe_ctx) { m_cursors.clear(); + + StackFrame *first_frame = exe_ctx.GetFramePtr(); + Process *process = exe_ctx.GetProcessPtr(); + if (process == NULL) + return 0; + std::pair<lldb::addr_t, lldb::addr_t> fp_pc_pair; struct Frame_i386 @@ -103,7 +115,7 @@ UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (StackFrame *first_frame) while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0)) { // Read both the FP and PC (8 bytes) - if (m_thread.GetProcess().ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size) + if (process->ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size) break; if (frame.pc >= 0x1000) { @@ -137,7 +149,7 @@ UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (StackFrame *first_frame) // previous PC by dereferencing the SP lldb::addr_t first_frame_sp = reg_ctx->GetSP (0); // Read the real second frame return address into frame.pc - if (first_frame_sp && m_thread.GetProcess().ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc)) + if (first_frame_sp && process->ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc)) { cursor.fp = m_cursors.front().fp; cursor.pc = frame.pc; // Set the new second frame PC @@ -163,10 +175,16 @@ UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (StackFrame *first_frame) size_t -UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (StackFrame *first_frame) +UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (const ExecutionContext &exe_ctx) { m_cursors.clear(); + Process *process = exe_ctx.GetProcessPtr(); + if (process == NULL) + return 0; + + StackFrame *first_frame = exe_ctx.GetFramePtr(); + std::pair<lldb::addr_t, lldb::addr_t> fp_pc_pair; struct Frame_x86_64 @@ -190,7 +208,7 @@ UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (StackFrame *first_frame) while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0)) { // Read both the FP and PC (16 bytes) - if (m_thread.GetProcess().ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size) + if (process->ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size) break; if (frame.pc >= 0x1000) @@ -225,7 +243,7 @@ UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (StackFrame *first_frame) // previous PC by dereferencing the SP lldb::addr_t first_frame_sp = reg_ctx->GetSP (0); // Read the real second frame return address into frame.pc - if (m_thread.GetProcess().ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc)) + if (process->ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc)) { cursor.fp = m_cursors.front().fp; cursor.pc = frame.pc; // Set the new second frame PC |