Skip to content

Commit 4730801

Browse files
committed
Delegate to ABI plugin to check if call frame addresses are valid
1 parent 51e733d commit 4730801

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lldb/source/Target/RegisterContextUnwind.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ static ConstString GetSymbolOrFunctionName(const SymbolContext &sym_ctx) {
5252
return ConstString();
5353
}
5454

55+
static bool CallFrameAddressIsValid(ABISP abi_sp, lldb::addr_t cfa) {
56+
if (m_cfa == LLDB_INVALID_ADDRESS)
57+
return false;
58+
if (abi_sp)
59+
return abi_sp->CallFrameAddressIsValid(cfa);
60+
return cfa != 0 && cfa != 1;
61+
}
62+
5563
RegisterContextUnwind::RegisterContextUnwind(Thread &thread,
5664
const SharedPtr &next_frame,
5765
SymbolContext &sym_ctx,
@@ -451,7 +459,7 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
451459
ReadFrameAddress(row_register_kind, row->GetAFAValue(), m_afa);
452460

453461
// A couple of sanity checks..
454-
if (m_cfa == LLDB_INVALID_ADDRESS || m_cfa == 0 || m_cfa == 1) {
462+
if (!CallFrameAddressIsValid(abi_sp, m_cfa)) {
455463
UnwindLogMsg("could not find a valid cfa address");
456464
m_frame_type = eNotAValidFrame;
457465
return;
@@ -1809,9 +1817,11 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
18091817
active_row->GetCFAValue().GetValueType() !=
18101818
UnwindPlan::Row::FAValue::unspecified) {
18111819
addr_t new_cfa;
1820+
ProcessSP process_sp = m_thread.GetProcess();
1821+
ABISP abi_sp = process_sp ? process_sp->GetABI() : nullptr;
18121822
if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1813-
active_row->GetCFAValue(), new_cfa) ||
1814-
new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1823+
active_row->GetCFAValue(), new_cfa) ||
1824+
!CallFrameAddressIsValid(abi_sp, new_cfa) {
18151825
UnwindLogMsg("failed to get cfa with fallback unwindplan");
18161826
m_fallback_unwind_plan_sp.reset();
18171827
m_full_unwind_plan_sp = original_full_unwind_plan_sp;
@@ -1832,10 +1842,8 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
18321842
if (ReadRegisterValueFromRegisterLocation(regloc, reg_info,
18331843
reg_value)) {
18341844
new_caller_pc_value = reg_value.GetAsUInt64();
1835-
if (ProcessSP process_sp = m_thread.GetProcess()) {
1836-
if (ABISP abi_sp = process_sp->GetABI())
1837-
new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
1838-
}
1845+
if (abi_sp)
1846+
new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
18391847
}
18401848
}
18411849
}
@@ -1894,9 +1902,10 @@ bool RegisterContextUnwind::ForceSwitchToFallbackUnwindPlan() {
18941902
active_row->GetCFAValue().GetValueType() !=
18951903
UnwindPlan::Row::FAValue::unspecified) {
18961904
addr_t new_cfa;
1905+
ABISP abi_sp = m_thread.GetProcess()->GetABI();
18971906
if (!ReadFrameAddress(m_fallback_unwind_plan_sp->GetRegisterKind(),
1898-
active_row->GetCFAValue(), new_cfa) ||
1899-
new_cfa == 0 || new_cfa == 1 || new_cfa == LLDB_INVALID_ADDRESS) {
1907+
active_row->GetCFAValue(), new_cfa) ||
1908+
!CallFrameAddressIsValid(abi_sp, new_cfa)) {
19001909
UnwindLogMsg("failed to get cfa with fallback unwindplan");
19011910
m_fallback_unwind_plan_sp.reset();
19021911
return false;
@@ -2020,8 +2029,7 @@ bool RegisterContextUnwind::ReadFrameAddress(
20202029
if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
20212030
if (abi_sp)
20222031
cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
2023-
if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
2024-
cfa_reg_contents == 1) {
2032+
if (!CallFrameAddressIsValid(abi_sp, cfa_reg_contents)) {
20252033
UnwindLogMsg(
20262034
"Got an invalid CFA register value - reg %s (%d), value 0x%" PRIx64,
20272035
cfa_reg.GetName(), cfa_reg.GetAsKind(eRegisterKindLLDB),

0 commit comments

Comments
 (0)