Skip to content

Commit 701030c

Browse files
committed
In InitializeZerothFrame check for a CFA/AFA or error out
There is a failure where we somehow get an invalid register number being used to calculate the canonical frame address, and this ends up with lldb crashing with a null deref because it assumes that it is always able to find information about that register. This patch adds a check for a failure to get a register, and declares the frame invalid in that case, with some additional logging or an assert for debug builds. Differential Revision: https://reviews.llvm.org/D143232 rdar://104428038
1 parent 96bd364 commit 701030c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lldb/source/Target/RegisterContextUnwind.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "lldb/Utility/RegisterValue.h"
3838
#include "lldb/Utility/VASPrintf.h"
3939
#include "lldb/lldb-private.h"
40+
41+
#include <cassert>
4042
#include <memory>
4143

4244
using namespace lldb;
@@ -289,6 +291,13 @@ void RegisterContextUnwind::InitializeZerothFrame() {
289291
} else
290292
ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
291293

294+
if (m_cfa == LLDB_INVALID_ADDRESS && m_afa == LLDB_INVALID_ADDRESS) {
295+
UnwindLogMsg(
296+
"could not read CFA or AFA values for first frame, not valid.");
297+
m_frame_type = eNotAValidFrame;
298+
return;
299+
}
300+
292301
UnwindLogMsg("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64
293302
" afa is 0x%" PRIx64 " using %s UnwindPlan",
294303
(uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
@@ -2116,6 +2125,14 @@ bool RegisterContextUnwind::ReadGPRValue(lldb::RegisterKind register_kind,
21162125
}
21172126

21182127
const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum);
2128+
assert(reg_info);
2129+
if (!reg_info) {
2130+
UnwindLogMsg(
2131+
"Could not find RegisterInfo definition for lldb register number %d",
2132+
lldb_regnum);
2133+
return false;
2134+
}
2135+
21192136
RegisterValue reg_value;
21202137
// if this is frame 0 (currently executing frame), get the requested reg
21212138
// contents from the actual thread registers

0 commit comments

Comments
 (0)