Skip to content

Commit f26f27c

Browse files
[lldb][nfc] Initialize m_initial_sp in ctor for UnwindAssemblyInstEmulation (#167914)
Also rename the "sp" suffix (originally intended to mean "Stack Pointer") to "cfa", as "sp" generally means Shared Pointer.
1 parent 81a73dc commit f26f27c

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,15 @@ bool UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly(
109109
m_range_ptr = ⦥
110110
m_unwind_plan_ptr = &unwind_plan;
111111

112-
const uint32_t addr_byte_size = m_arch.GetAddressByteSize();
113-
114112
m_state.cfa_reg_info = *m_inst_emulator_up->GetRegisterInfo(
115113
unwind_plan.GetRegisterKind(), unwind_plan.GetInitialCFARegister());
116114
m_state.fp_is_cfa = false;
117115
m_state.register_values.clear();
118116

119117
m_pushed_regs.clear();
120118

121-
// Initialize the CFA with a known value. In the 32 bit case it will be
122-
// 0x80000000, and in the 64 bit case 0x8000000000000000. We use the address
123-
// byte size to be safe for any future address sizes
124-
m_initial_sp = (1ull << ((addr_byte_size * 8) - 1));
125119
RegisterValue cfa_reg_value;
126-
cfa_reg_value.SetUInt(m_initial_sp, m_state.cfa_reg_info.byte_size);
120+
cfa_reg_value.SetUInt(m_initial_cfa, m_state.cfa_reg_info.byte_size);
127121
SetRegisterValue(m_state.cfa_reg_info, cfa_reg_value);
128122

129123
const InstructionList &inst_list = disasm_sp->GetInstructionList();
@@ -392,7 +386,7 @@ size_t UnwindAssemblyInstEmulation::WriteMemory(
392386
if (reg_num != LLDB_INVALID_REGNUM &&
393387
generic_regnum != LLDB_REGNUM_GENERIC_SP) {
394388
if (m_pushed_regs.try_emplace(reg_num, addr).second) {
395-
const int32_t offset = addr - m_initial_sp;
389+
const int32_t offset = addr - m_initial_cfa;
396390
m_state.row.SetRegisterLocationToAtCFAPlusOffset(reg_num, offset,
397391
/*can_replace=*/true);
398392
m_curr_row_modified = true;
@@ -559,7 +553,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
559553
sp_reg_info.kinds[m_unwind_plan_ptr->GetRegisterKind()];
560554
assert(cfa_reg_num != LLDB_INVALID_REGNUM);
561555
m_state.row.GetCFAValue().SetIsRegisterPlusOffset(
562-
cfa_reg_num, m_initial_sp - sp_reg_val.GetAsUInt64());
556+
cfa_reg_num, m_initial_cfa - sp_reg_val.GetAsUInt64());
563557
}
564558
}
565559
}
@@ -590,7 +584,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
590584
reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()];
591585
assert(cfa_reg_num != LLDB_INVALID_REGNUM);
592586
m_state.row.GetCFAValue().SetIsRegisterPlusOffset(
593-
cfa_reg_num, m_initial_sp - reg_value.GetAsUInt64());
587+
cfa_reg_num, m_initial_cfa - reg_value.GetAsUInt64());
594588
m_curr_row_modified = true;
595589
}
596590
break;
@@ -603,7 +597,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
603597
reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()];
604598
assert(cfa_reg_num != LLDB_INVALID_REGNUM);
605599
m_state.row.GetCFAValue().SetIsRegisterPlusOffset(
606-
cfa_reg_num, m_initial_sp - reg_value.GetAsUInt64());
600+
cfa_reg_num, m_initial_cfa - reg_value.GetAsUInt64());
607601
m_curr_row_modified = true;
608602
}
609603
break;
@@ -614,7 +608,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
614608
if (!m_state.fp_is_cfa) {
615609
m_state.row.GetCFAValue().SetIsRegisterPlusOffset(
616610
m_state.row.GetCFAValue().GetRegisterNumber(),
617-
m_initial_sp - reg_value.GetAsUInt64());
611+
m_initial_cfa - reg_value.GetAsUInt64());
618612
m_curr_row_modified = true;
619613
}
620614
break;

lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly {
6363
UnwindAssemblyInstEmulation(const lldb_private::ArchSpec &arch,
6464
lldb_private::EmulateInstruction *inst_emulator)
6565
: UnwindAssembly(arch), m_inst_emulator_up(inst_emulator),
66-
m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr), m_initial_sp(0),
66+
m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr),
6767
m_curr_row_modified(false), m_forward_branch_offset(0) {
6868
if (m_inst_emulator_up) {
6969
m_inst_emulator_up->SetBaton(this);
7070
m_inst_emulator_up->SetCallbacks(ReadMemory, WriteMemory, ReadRegister,
7171
WriteRegister);
7272
}
73+
// Initialize the CFA with a known value. In the 32 bit case it will be
74+
// 0x80000000, and in the 64 bit case 0x8000000000000000. We use the address
75+
// byte size to be safe for any future address sizes
76+
m_initial_cfa = (1ull << ((m_arch.GetAddressByteSize() * 8) - 1));
7377
}
7478

7579
static size_t
@@ -134,8 +138,8 @@ class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly {
134138
lldb_private::AddressRange *m_range_ptr;
135139
lldb_private::UnwindPlan *m_unwind_plan_ptr;
136140
UnwindState m_state;
141+
uint64_t m_initial_cfa;
137142
typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap;
138-
uint64_t m_initial_sp;
139143
PushedRegisterToAddrMap m_pushed_regs;
140144

141145
// While processing the instruction stream, we need to communicate some state

0 commit comments

Comments
 (0)