<rdar://problem/13516463>
Don't crash when there is no register context for a thread with kernel debugging. The kernel debugging uses the OperatingSystemPlugin that may behave badly when trying to get thread state, so be prepared to have invalid register contexts in threads.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@178574 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index 339c83a..226f590 100644
--- a/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -386,13 +386,35 @@
break;
case eStateStepping:
- kernel_thread_sp->GetRegisterContext()->HardwareSingleStep (true);
- resume = true;
+ {
+ lldb::RegisterContextSP reg_ctx_sp (kernel_thread_sp->GetRegisterContext());
+
+ if (reg_ctx_sp)
+ {
+ reg_ctx_sp->HardwareSingleStep (true);
+ resume = true;
+ }
+ else
+ {
+ error.SetErrorStringWithFormat("KDP thread 0x%llx has no register context", kernel_thread_sp->GetID());
+ }
+ }
break;
case eStateRunning:
- kernel_thread_sp->GetRegisterContext()->HardwareSingleStep (false);
- resume = true;
+ {
+ lldb::RegisterContextSP reg_ctx_sp (kernel_thread_sp->GetRegisterContext());
+
+ if (reg_ctx_sp)
+ {
+ reg_ctx_sp->HardwareSingleStep (false);
+ resume = true;
+ }
+ else
+ {
+ error.SetErrorStringWithFormat("KDP thread 0x%llx has no register context", kernel_thread_sp->GetID());
+ }
+ }
break;
default:
@@ -774,8 +796,13 @@
if (process->m_comm.WaitForPacketWithTimeoutMicroSeconds (exc_reply_packet, 1 * USEC_PER_SEC))
{
ThreadSP thread_sp (process->GetKernelThread(process->GetThreadList(), process->GetThreadList()));
- thread_sp->GetRegisterContext()->InvalidateAllRegisters();
- static_cast<ThreadKDP *>(thread_sp.get())->SetStopInfoFrom_KDP_EXCEPTION (exc_reply_packet);
+ if (thread_sp)
+ {
+ lldb::RegisterContextSP reg_ctx_sp (thread_sp->GetRegisterContext());
+ if (reg_ctx_sp)
+ reg_ctx_sp->InvalidateAllRegisters();
+ static_cast<ThreadKDP *>(thread_sp.get())->SetStopInfoFrom_KDP_EXCEPTION (exc_reply_packet);
+ }
// TODO: parse the stop reply packet
is_running = false;
diff --git a/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp b/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
index 8ce90e5..2961643 100644
--- a/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
+++ b/source/Plugins/Process/MacOSX-Kernel/ThreadKDP.cpp
@@ -95,7 +95,9 @@
// register supply functions where they check the process stop ID and do
// the right thing.
const bool force = false;
- GetRegisterContext()->InvalidateIfNeeded (force);
+ lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext());
+ if (reg_ctx_sp)
+ reg_ctx_sp->InvalidateIfNeeded (force);
}
void