Skip to content

Commit e06fabc

Browse files
[lldb][nfc] Simplify instruction iteration in UnwindAssemblyInstEmulation (#167914)
1 parent f26f27c commit e06fabc

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lldb/include/lldb/Core/Disassembler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ class InstructionList {
297297

298298
lldb::InstructionSP GetInstructionAtIndex(size_t idx) const;
299299

300+
llvm::ArrayRef<lldb::InstructionSP> Instructions() const {
301+
return m_instructions;
302+
}
303+
300304
/// Get the instruction at the given address.
301305
///
302306
/// \return

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,14 @@ bool UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly(
120120
cfa_reg_value.SetUInt(m_initial_cfa, m_state.cfa_reg_info.byte_size);
121121
SetRegisterValue(m_state.cfa_reg_info, cfa_reg_value);
122122

123-
const InstructionList &inst_list = disasm_sp->GetInstructionList();
124-
const size_t num_instructions = inst_list.GetSize();
123+
InstructionList inst_list = disasm_sp->GetInstructionList();
125124

126-
if (num_instructions == 0) {
125+
if (inst_list.GetSize() == 0) {
127126
DumpUnwindRowsToLog(log, range, unwind_plan);
128127
return unwind_plan.GetRowCount() > 0;
129128
}
130129

131-
Instruction &first_inst = *inst_list.GetInstructionAtIndex(0).get();
130+
Instruction &first_inst = *inst_list.GetInstructionAtIndex(0);
132131
const lldb::addr_t base_addr = first_inst.GetAddress().GetFileAddress();
133132

134133
// Map for storing the unwind state at a given offset. When we see a forward
@@ -151,15 +150,14 @@ bool UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly(
151150
EmulateInstruction::InstructionCondition last_condition =
152151
EmulateInstruction::UnconditionalCondition;
153152

154-
for (size_t idx = 0; idx < num_instructions; ++idx) {
155-
m_curr_row_modified = false;
156-
m_forward_branch_offset = 0;
157-
158-
Instruction *inst = inst_list.GetInstructionAtIndex(idx).get();
153+
for (const InstructionSP &inst : inst_list.Instructions()) {
159154
if (!inst)
160155
continue;
161156
DumpInstToLog(log, *inst, inst_list);
162157

158+
m_curr_row_modified = false;
159+
m_forward_branch_offset = 0;
160+
163161
lldb::addr_t current_offset =
164162
inst->GetAddress().GetFileAddress() - base_addr;
165163
auto it = saved_unwind_states.upper_bound(current_offset);

0 commit comments

Comments
 (0)