[lldb/api] Add checks for StackFrame::GetRegisterContext calls (NFC)

This patch fixes a crash that is happening because of a null pointer
dereference in SBFrame.

StackFrame::GetRegisterContext says explicitly that you might not get
a valid RegisterContext back but the pointer wasn't tested before,
resulting in crashes. This should solve the issue.

rdar://54462095

Differential Revision: https://reviews.llvm.org/D83343

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
This commit is contained in:
Med Ismail Bennani 2020-07-07 22:08:20 +02:00
parent b6a20a4970
commit 0d7401cf9d
No known key found for this signature in database
GPG Key ID: 9040401522D38F4E

View File

@ -354,15 +354,15 @@ bool SBFrame::SetPC(addr_t new_pc) {
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
StackFrame *frame = nullptr;
Target *target = exe_ctx.GetTargetPtr();
Process *process = exe_ctx.GetProcessPtr();
if (target && process) {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame) {
ret_val = frame->GetRegisterContext()->SetPC(new_pc);
if (StackFrame *frame = exe_ctx.GetFramePtr()) {
if (RegisterContextSP reg_ctx_sp = frame->GetRegisterContext()) {
ret_val = reg_ctx_sp->SetPC(new_pc);
}
}
}
}
@ -377,15 +377,15 @@ addr_t SBFrame::GetSP() const {
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
StackFrame *frame = nullptr;
Target *target = exe_ctx.GetTargetPtr();
Process *process = exe_ctx.GetProcessPtr();
if (target && process) {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame) {
addr = frame->GetRegisterContext()->GetSP();
if (StackFrame *frame = exe_ctx.GetFramePtr()) {
if (RegisterContextSP reg_ctx_sp = frame->GetRegisterContext()) {
addr = reg_ctx_sp->GetSP();
}
}
}
}
@ -400,15 +400,16 @@ addr_t SBFrame::GetFP() const {
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
StackFrame *frame = nullptr;
Target *target = exe_ctx.GetTargetPtr();
Process *process = exe_ctx.GetProcessPtr();
if (target && process) {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame)
addr = frame->GetRegisterContext()->GetFP();
if (StackFrame *frame = exe_ctx.GetFramePtr()) {
if (RegisterContextSP reg_ctx_sp = frame->GetRegisterContext()) {
addr = reg_ctx_sp->GetFP();
}
}
}
}