From 1d42c7bc3214818781b232428f09d679d4906342 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Sat, 14 Jul 2012 04:52:53 +0000 Subject: Switch nearly all of the use of the UnwindPlan::Row's to go through a shared pointer to ease some memory management issues with a patch I'm working on. The main complication with using SPs for these objects is that most methods that build up an UnwindPlan will construct a Row to a given instruction point in a function, then add additional regsaves in the next instruction point to that row and push it again. A little care is needed to not mutate the previous instruction point's Row once these are switched to being held behing shared pointers. llvm-svn: 160214 --- .../InstEmulation/UnwindAssemblyInstEmulation.cpp | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp') diff --git a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp index 6d2b0a54b6a..6dc75adaa02 100644 --- a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp +++ b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp @@ -86,23 +86,29 @@ UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly (AddressRange& RegisterValue cfa_reg_value; cfa_reg_value.SetUInt (m_initial_sp, m_cfa_reg_info.byte_size); SetRegisterValue (m_cfa_reg_info, cfa_reg_value); - + const InstructionList &inst_list = disasm_sp->GetInstructionList (); const size_t num_instructions = inst_list.GetSize(); + + UnwindPlan::RowSP prologue_completed_row; + if (num_instructions > 0) { Instruction *inst = inst_list.GetInstructionAtIndex (0).get(); const addr_t base_addr = inst->GetAddress().GetFileAddress(); // Initialize the current row with the one row that was created // from the CreateFunctionEntryUnwind call above... - m_curr_row = unwind_plan.GetLastRow(); + UnwindPlan::RowSP last_row = unwind_plan.GetLastRow(); + UnwindPlan::Row *newrow = new UnwindPlan::Row; + if (last_row.get()) + *newrow = *last_row.get(); + m_curr_row.reset(newrow); for (size_t idx=0; idxGetVerbose ()) { StreamString strm; @@ -120,9 +126,13 @@ UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly (AddressRange& { // Be sure to not edit the offset unless our row has changed // so that the "!=" call above doesn't trigger every time - m_curr_row.SetOffset (inst->GetAddress().GetFileAddress() + inst->GetOpcode().GetByteSize() - base_addr); + m_curr_row->SetOffset (inst->GetAddress().GetFileAddress() + inst->GetOpcode().GetByteSize() - base_addr); // Append the new row unwind_plan.AppendRow (m_curr_row); + + UnwindPlan::Row *newrow = new UnwindPlan::Row; + *newrow = *m_curr_row.get(); + m_curr_row.reset(newrow); } } } @@ -362,7 +372,7 @@ UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction, { m_pushed_regs[reg_num] = addr; const int32_t offset = addr - m_initial_sp; - m_curr_row.SetRegisterLocationToAtCFAPlusOffset (reg_num, offset, cant_replace); + m_curr_row->SetRegisterLocationToAtCFAPlusOffset (reg_num, offset, cant_replace); if (is_return_address_reg) { // This push was pushing the return address register, @@ -372,7 +382,7 @@ UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction, { uint32_t pc_reg_num = pc_reg_info.kinds[unwind_reg_kind]; if (pc_reg_num != LLDB_INVALID_REGNUM) - m_curr_row.SetRegisterLocationToAtCFAPlusOffset (pc_reg_num, offset, can_replace); + m_curr_row->SetRegisterLocationToAtCFAPlusOffset (pc_reg_num, offset, can_replace); } } } @@ -488,7 +498,7 @@ UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction, const uint32_t reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()]; if (reg_num != LLDB_INVALID_REGNUM) { - m_curr_row.SetRegisterLocationToSame (reg_num, must_replace); + m_curr_row->SetRegisterLocationToSame (reg_num, must_replace); } } break; @@ -500,8 +510,8 @@ UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction, m_cfa_reg_info = *reg_info; const uint32_t cfa_reg_num = reg_info->kinds[m_unwind_plan_ptr->GetRegisterKind()]; assert (cfa_reg_num != LLDB_INVALID_REGNUM); - m_curr_row.SetCFARegister(cfa_reg_num); - m_curr_row.SetCFAOffset(m_initial_sp - reg_value.GetAsUInt64()); + m_curr_row->SetCFARegister(cfa_reg_num); + m_curr_row->SetCFAOffset(m_initial_sp - reg_value.GetAsUInt64()); } break; @@ -510,7 +520,7 @@ UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction, // subsequent adjustments to the stack pointer. if (!m_fp_is_cfa) { - m_curr_row.SetCFAOffset (m_initial_sp - reg_value.GetAsUInt64()); + m_curr_row->SetCFAOffset (m_initial_sp - reg_value.GetAsUInt64()); } break; } -- cgit v1.2.3