Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions lldb/source/Target/RegisterContextUnwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ static ConstString GetSymbolOrFunctionName(const SymbolContext &sym_ctx) {
return ConstString();
}

static bool CallFrameAddressIsValid(ABISP abi_sp, lldb::addr_t cfa) {
if (m_cfa == LLDB_INVALID_ADDRESS)
return false;
if (abi_sp)
return abi_sp->CallFrameAddressIsValid(cfa);
return cfa != 0 && cfa != 1;
}

RegisterContextUnwind::RegisterContextUnwind(Thread &thread,
const SharedPtr &next_frame,
SymbolContext &sym_ctx,
Expand Down Expand Up @@ -451,7 +459,7 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
ReadFrameAddress(row_register_kind, row->GetAFAValue(), m_afa);

// A couple of sanity checks..
if (m_cfa == LLDB_INVALID_ADDRESS || m_cfa == 0 || m_cfa == 1) {
if (!CallFrameAddressIsValid(abi_sp, m_cfa)) {
UnwindLogMsg("could not find a valid cfa address");
m_frame_type = eNotAValidFrame;
return;
Expand Down Expand Up @@ -1809,9 +1817,11 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
active_row->GetCFAValue().GetValueType() !=
UnwindPlan::Row::FAValue::unspecified) {
addr_t new_cfa;
ProcessSP process_sp = m_thread.GetProcess();
ABISP abi_sp = process_sp ? process_sp->GetABI() : nullptr;
if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
active_row->GetCFAValue(), new_cfa) ||
new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
active_row->GetCFAValue(), new_cfa) ||
!CallFrameAddressIsValid(abi_sp, new_cfa) {
UnwindLogMsg("failed to get cfa with fallback unwindplan");
m_fallback_unwind_plan_sp.reset();
m_full_unwind_plan_sp = original_full_unwind_plan_sp;
Expand All @@ -1832,10 +1842,8 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
if (ReadRegisterValueFromRegisterLocation(regloc, reg_info,
reg_value)) {
new_caller_pc_value = reg_value.GetAsUInt64();
if (ProcessSP process_sp = m_thread.GetProcess()) {
if (ABISP abi_sp = process_sp->GetABI())
new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
}
if (abi_sp)
new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
}
}
}
Expand Down Expand Up @@ -1894,9 +1902,10 @@ bool RegisterContextUnwind::ForceSwitchToFallbackUnwindPlan() {
active_row->GetCFAValue().GetValueType() !=
UnwindPlan::Row::FAValue::unspecified) {
addr_t new_cfa;
ABISP abi_sp = m_thread.GetProcess()->GetABI();
if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
active_row->GetCFAValue(), new_cfa) ||
new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
active_row->GetCFAValue(), new_cfa) ||
!CallFrameAddressIsValid(abi_sp, new_cfa)) {
UnwindLogMsg("failed to get cfa with fallback unwindplan");
m_fallback_unwind_plan_sp.reset();
return false;
Expand Down Expand Up @@ -2020,8 +2029,7 @@ bool RegisterContextUnwind::ReadFrameAddress(
if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
if (abi_sp)
cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
cfa_reg_contents == 1) {
if (!CallFrameAddressIsValid(abi_sp, cfa_reg_contents)) {
UnwindLogMsg(
"Got an invalid CFA register value - reg %s (%d), value 0x%" PRIx64,
cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),
Expand Down