[Lldb-commits] [lldb] 0d7401c - [lldb/api] Add checks for StackFrame::GetRegisterContext calls (NFC)
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 7 14:30:51 PDT 2020
Author: Med Ismail Bennani
Date: 2020-07-07T23:30:24+02:00
New Revision: 0d7401cf9d5cc0db3de9a8ddb8ea2362d5412d2f
URL: https://github.com/llvm/llvm-project/commit/0d7401cf9d5cc0db3de9a8ddb8ea2362d5412d2f
DIFF: https://github.com/llvm/llvm-project/commit/0d7401cf9d5cc0db3de9a8ddb8ea2362d5412d2f.diff
LOG: [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 at gmail.com>
Added:
Modified:
lldb/source/API/SBFrame.cpp
Removed:
################################################################################
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 5ecf1c537536..81782dbf838f 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -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();
+ }
+ }
}
}
More information about the lldb-commits
mailing list