https://github.com/labath updated https://github.com/llvm/llvm-project/pull/127661
>From 40a29a7ba10caeae2a02355abddb9469246cdd3e Mon Sep 17 00:00:00 2001 From: Pavel Labath <pa...@labath.sk> Date: Tue, 18 Feb 2025 16:14:30 +0100 Subject: [PATCH] [lldb] Prepare UnwindPlans for discontinuous functions The main changes are: - changing the internal row representation from vector to a map. This wasn't strictly necessary, but I'm doing it because due the functions not starting at the lowest address, the Row for the function entry point (offset zero) may no longer be the first (zeroth) entry in the vector, so we will need to (binary) search for it. This would have been possible with a (sorted) vector representation as well, but that's somewhat tricky because the unwind plans are constructed in place, so there isn't a good place to insert a sort operations (the plans are currently implicitly sorted due to the sequential nature of their construction, but that will be harder to ensure when jumping between multiple regions. - changing the valid address range from singular to plural The changes to other files are due to the address range pluralization and due to the removal of `AppendRow` (as there isn't really an "append" operation in a map). --- lldb/include/lldb/Symbol/UnwindPlan.h | 32 +++--- .../Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp | 4 +- .../Plugins/ABI/AArch64/ABISysV_arm64.cpp | 4 +- lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp | 2 +- lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp | 4 +- lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp | 4 +- .../Plugins/ABI/Hexagon/ABISysV_hexagon.cpp | 4 +- .../ABI/LoongArch/ABISysV_loongarch.cpp | 4 +- .../Plugins/ABI/MSP430/ABISysV_msp430.cpp | 4 +- lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp | 4 +- .../Plugins/ABI/Mips/ABISysV_mips64.cpp | 4 +- .../Plugins/ABI/PowerPC/ABISysV_ppc.cpp | 4 +- .../Plugins/ABI/PowerPC/ABISysV_ppc64.cpp | 4 +- .../Plugins/ABI/RISCV/ABISysV_riscv.cpp | 4 +- .../Plugins/ABI/SystemZ/ABISysV_s390x.cpp | 2 +- .../source/Plugins/ABI/X86/ABIMacOSX_i386.cpp | 4 +- lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp | 4 +- .../source/Plugins/ABI/X86/ABISysV_x86_64.cpp | 4 +- .../Plugins/ABI/X86/ABIWindows_x86_64.cpp | 4 +- .../Instruction/ARM/EmulateInstructionARM.cpp | 2 +- .../ARM64/EmulateInstructionARM64.cpp | 2 +- .../MIPS/EmulateInstructionMIPS.cpp | 2 +- .../MIPS64/EmulateInstructionMIPS64.cpp | 2 +- .../PPC64/EmulateInstructionPPC64.cpp | 2 +- .../ObjectFile/PECOFF/PECallFrameInfo.cpp | 6 +- .../Plugins/Platform/Linux/PlatformLinux.cpp | 2 +- .../Breakpad/SymbolFileBreakpad.cpp | 18 ++-- .../x86/x86AssemblyInspectionEngine.cpp | 10 +- lldb/source/Symbol/ArmUnwindInfo.cpp | 2 +- lldb/source/Symbol/CompactUnwindInfo.cpp | 16 +-- lldb/source/Symbol/DWARFCallFrameInfo.cpp | 14 +-- lldb/source/Symbol/UnwindPlan.cpp | 98 +++++++------------ lldb/unittests/Symbol/CMakeLists.txt | 1 + lldb/unittests/Symbol/UnwindPlanTest.cpp | 76 ++++++++++++++ .../x86/Testx86AssemblyInspectionEngine.cpp | 24 ++--- 35 files changed, 209 insertions(+), 168 deletions(-) create mode 100644 lldb/unittests/Symbol/UnwindPlanTest.cpp diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h b/lldb/include/lldb/Symbol/UnwindPlan.h index 462c1a52b01db..e8846cf111c9b 100644 --- a/lldb/include/lldb/Symbol/UnwindPlan.h +++ b/lldb/include/lldb/Symbol/UnwindPlan.h @@ -438,7 +438,7 @@ class UnwindPlan { // Performs a deep copy of the plan, including all the rows (expensive). UnwindPlan(const UnwindPlan &rhs) - : m_plan_valid_address_range(rhs.m_plan_valid_address_range), + : m_plan_valid_ranges(rhs.m_plan_valid_ranges), m_register_kind(rhs.m_register_kind), m_return_addr_register(rhs.m_return_addr_register), m_source_name(rhs.m_source_name), @@ -448,9 +448,8 @@ class UnwindPlan { m_plan_is_for_signal_trap(rhs.m_plan_is_for_signal_trap), m_lsda_address(rhs.m_lsda_address), m_personality_func_addr(rhs.m_personality_func_addr) { - m_row_list.reserve(rhs.m_row_list.size()); - for (const RowSP &row_sp : rhs.m_row_list) - m_row_list.emplace_back(new Row(*row_sp)); + for (const auto &[offset, row_sp] : rhs.m_rows) + m_rows.emplace(offset, std::make_shared<Row>(*row_sp)); } UnwindPlan(UnwindPlan &&rhs) = default; UnwindPlan &operator=(const UnwindPlan &rhs) { @@ -462,9 +461,7 @@ class UnwindPlan { void Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const; - void AppendRow(const RowSP &row_sp); - - void InsertRow(const RowSP &row_sp, bool replace_existing = false); + void InsertRow(const RowSP &row_sp, bool replace_existing = true); // Returns a pointer to the best row for the given offset into the function's // instructions. If offset is -1 it indicates that the function start is @@ -484,19 +481,15 @@ class UnwindPlan { uint32_t GetReturnAddressRegister() { return m_return_addr_register; } uint32_t GetInitialCFARegister() const { - if (m_row_list.empty()) - return LLDB_INVALID_REGNUM; - return m_row_list.front()->GetCFAValue().GetRegisterNumber(); + if (auto it = m_rows.find(0); it != m_rows.end()) + return it->second->GetCFAValue().GetRegisterNumber(); + return LLDB_INVALID_REGNUM; } // This UnwindPlan may not be valid at every address of the function span. // For instance, a FastUnwindPlan will not be valid at the prologue setup // instructions - only in the body of the function. - void SetPlanValidAddressRange(const AddressRange &range); - - const AddressRange &GetAddressRange() const { - return m_plan_valid_address_range; - } + void SetPlanValidAddressRanges(std::vector<AddressRange> ranges); bool PlanValidAtAddress(Address addr); @@ -547,8 +540,8 @@ class UnwindPlan { int GetRowCount() const; void Clear() { - m_row_list.clear(); - m_plan_valid_address_range.Clear(); + m_rows.clear(); + m_plan_valid_ranges.clear(); m_register_kind = lldb::eRegisterKindDWARF; m_source_name.Clear(); m_plan_is_sourced_from_compiler = eLazyBoolCalculate; @@ -571,9 +564,8 @@ class UnwindPlan { } private: - typedef std::vector<RowSP> collection; - collection m_row_list; - AddressRange m_plan_valid_address_range; + std::map<lldb::addr_t, RowSP> m_rows; + std::vector<AddressRange> m_plan_valid_ranges; lldb::RegisterKind m_register_kind; // The RegisterKind these register numbers // are in terms of - will need to be // translated to lldb native reg nums at unwind time diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp index d208c6f874692..31ad602a4c3a7 100644 --- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp +++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp @@ -357,7 +357,7 @@ UnwindPlanSP ABIMacOSX_arm64::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm64 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -378,7 +378,7 @@ UnwindPlanSP ABIMacOSX_arm64::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm64-apple-darwin default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp index 280ec5ba37100..61a8d85f4e37a 100644 --- a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp +++ b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp @@ -402,7 +402,7 @@ UnwindPlanSP ABISysV_arm64::CreateFunctionEntryUnwindPlan() { row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetReturnAddressRegister(lr_reg_num); plan_sp->SetSourceName("arm64 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); @@ -426,7 +426,7 @@ UnwindPlanSP ABISysV_arm64::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm64 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp index a38396dc14635..20bd8c32cd1ad 100644 --- a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp +++ b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp @@ -565,7 +565,7 @@ UnwindPlanSP ABISysV_arc::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(dwarf::pc, dwarf::blink, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arc at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; diff --git a/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp index d85f4a5943acf..068954c92c7a2 100644 --- a/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp +++ b/lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp @@ -1795,7 +1795,7 @@ UnwindPlanSP ABIMacOSX_arm::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -1817,7 +1817,7 @@ UnwindPlanSP ABIMacOSX_arm::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm-apple-ios default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp index 38f4413bb263b..a18e4f110896b 100644 --- a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp +++ b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp @@ -1909,7 +1909,7 @@ UnwindPlanSP ABISysV_arm::CreateFunctionEntryUnwindPlan() { // The previous PC is in the LR, all other registers are the same. row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -1931,7 +1931,7 @@ UnwindPlanSP ABISysV_arm::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("arm default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/Hexagon/ABISysV_hexagon.cpp b/lldb/source/Plugins/ABI/Hexagon/ABISysV_hexagon.cpp index 4af9bcb8644f5..c8d0142f756e1 100644 --- a/lldb/source/Plugins/ABI/Hexagon/ABISysV_hexagon.cpp +++ b/lldb/source/Plugins/ABI/Hexagon/ABISysV_hexagon.cpp @@ -1207,7 +1207,7 @@ UnwindPlanSP ABISysV_hexagon::CreateFunctionEntryUnwindPlan() { LLDB_REGNUM_GENERIC_RA, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindGeneric); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetReturnAddressRegister(LLDB_REGNUM_GENERIC_RA); plan_sp->SetSourceName("hexagon at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); @@ -1229,7 +1229,7 @@ UnwindPlanSP ABISysV_hexagon::CreateDefaultUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindGeneric); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("hexagon default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp b/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp index 1dd6070ec29c5..6f5239be34c71 100644 --- a/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp +++ b/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp @@ -547,7 +547,7 @@ UnwindPlanSP ABISysV_loongarch::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(pc_reg_num, ra_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("loongarch function-entry unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -573,7 +573,7 @@ UnwindPlanSP ABISysV_loongarch::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, reg_size * -1, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindGeneric); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("loongarch default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp b/lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp index 2cc1bbbcef11b..dd258bfc1db92 100644 --- a/lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp +++ b/lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp @@ -315,7 +315,7 @@ UnwindPlanSP ABISysV_msp430::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("msp430 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -333,7 +333,7 @@ UnwindPlanSP ABISysV_msp430::CreateDefaultUnwindPlan() { row->SetRegisterLocationToUnspecified(fp_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("msp430 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp index d7ebe22c90261..3f6ed22f84a9a 100644 --- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp +++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp @@ -964,7 +964,7 @@ UnwindPlanSP ABISysV_mips::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("mips at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetReturnAddressRegister(dwarf_r31); @@ -980,7 +980,7 @@ UnwindPlanSP ABISysV_mips::CreateDefaultUnwindPlan() { row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("mips default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp index dcaef20b1a036..4641b0f40d725 100644 --- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp +++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp @@ -1137,7 +1137,7 @@ UnwindPlanSP ABISysV_mips64::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("mips64 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetReturnAddressRegister(dwarf_r31); @@ -1153,7 +1153,7 @@ UnwindPlanSP ABISysV_mips64::CreateDefaultUnwindPlan() { row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("mips64 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp index 405ba57deba83..da84dc1e9fdfa 100644 --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp @@ -871,7 +871,7 @@ UnwindPlanSP ABISysV_ppc::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("ppc at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -892,7 +892,7 @@ UnwindPlanSP ABISysV_ppc::CreateDefaultUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("ppc default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp index 0392dab3f118b..67ccae5932bbf 100644 --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp @@ -979,7 +979,7 @@ UnwindPlanSP ABISysV_ppc64::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("ppc64 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -1010,7 +1010,7 @@ UnwindPlanSP ABISysV_ppc64::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(cr_reg_num, ptr_size, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("ppc64 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp b/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp index 06415a6e7f52c..cd7ff94038c8d 100644 --- a/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp +++ b/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp @@ -732,7 +732,7 @@ UnwindPlanSP ABISysV_riscv::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToRegister(pc_reg_num, ra_reg_num, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("riscv function-entry unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -758,7 +758,7 @@ UnwindPlanSP ABISysV_riscv::CreateDefaultUnwindPlan() { row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, reg_size * -1, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindGeneric); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("riscv default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp index a88a3b0e0825d..43ae76ba52a3a 100644 --- a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp +++ b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp @@ -628,7 +628,7 @@ UnwindPlanSP ABISysV_s390x::CreateFunctionEntryUnwindPlan() { // All other registers are the same. auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("s390x at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; diff --git a/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp b/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp index d484b781a5136..dceca1c99c037 100644 --- a/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp +++ b/lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp @@ -366,7 +366,7 @@ UnwindPlanSP ABIMacOSX_i386::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("i386 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -394,7 +394,7 @@ UnwindPlanSP ABIMacOSX_i386::CreateDefaultUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("i386 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp index f6b3666632728..41c09c2667b0b 100644 --- a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp +++ b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp @@ -633,7 +633,7 @@ UnwindPlanSP ABISysV_i386::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("i386 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -661,7 +661,7 @@ UnwindPlanSP ABISysV_i386::CreateDefaultUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("i386 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp index a224b3b9d4c23..004bf2ea53de3 100644 --- a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp +++ b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp @@ -868,7 +868,7 @@ UnwindPlanSP ABISysV_x86_64::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("x86_64 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -896,7 +896,7 @@ UnwindPlanSP ABISysV_x86_64::CreateDefaultUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("x86_64 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp index 8c6cea679fbd2..dc55e09840d3c 100644 --- a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp +++ b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp @@ -748,7 +748,7 @@ UnwindPlanSP ABIWindows_x86_64::CreateFunctionEntryUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("x86_64 at-func-entry default"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); return plan_sp; @@ -774,7 +774,7 @@ UnwindPlanSP ABIWindows_x86_64::CreateDefaultUnwindPlan() { row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true); auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - plan_sp->AppendRow(row); + plan_sp->InsertRow(row); plan_sp->SetSourceName("x86_64 default unwind plan"); plan_sp->SetSourcedFromCompiler(eLazyBoolNo); plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp index 147c00e51b40d..634bffab5b7a2 100644 --- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp +++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp @@ -14463,7 +14463,7 @@ bool EmulateInstructionARM::CreateFunctionEntryUnwind(UnwindPlan &unwind_plan) { // Our previous Call Frame Address is the stack pointer row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_sp, 0); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); unwind_plan.SetSourceName("EmulateInstructionARM"); unwind_plan.SetSourcedFromCompiler(eLazyBoolNo); unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolYes); diff --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp index 62ecac3e0831d..ed2ce4a68c2a4 100644 --- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp +++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp @@ -447,7 +447,7 @@ bool EmulateInstructionARM64::CreateFunctionEntryUnwind( row->SetRegisterLocationToSame(gpr_lr_arm64, /*must_replace=*/false); row->SetRegisterLocationToSame(gpr_fp_arm64, /*must_replace=*/false); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); unwind_plan.SetSourceName("EmulateInstructionARM64"); unwind_plan.SetSourcedFromCompiler(eLazyBoolNo); unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolYes); diff --git a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp index 76d7a8272f3fc..7353d42b9ba24 100644 --- a/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp +++ b/lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp @@ -1137,7 +1137,7 @@ bool EmulateInstructionMIPS::CreateFunctionEntryUnwind( // Our previous PC is in the RA row->SetRegisterLocationToRegister(dwarf_pc_mips, dwarf_ra_mips, can_replace); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); // All other registers are the same. unwind_plan.SetSourceName("EmulateInstructionMIPS"); diff --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp index e33ca95b523be..e7e9cbb9ad1a3 100644 --- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp +++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp @@ -1027,7 +1027,7 @@ bool EmulateInstructionMIPS64::CreateFunctionEntryUnwind( row->SetRegisterLocationToRegister(dwarf_pc_mips64, dwarf_ra_mips64, can_replace); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); // All other registers are the same. unwind_plan.SetSourceName("EmulateInstructionMIPS64"); diff --git a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp index 3035c51341778..94a9c2f342192 100644 --- a/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp +++ b/lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp @@ -123,7 +123,7 @@ bool EmulateInstructionPPC64::CreateFunctionEntryUnwind( // Our previous Call Frame Address is the stack pointer row->GetCFAValue().SetIsRegisterPlusOffset(gpr_r1_ppc64le, 0); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); unwind_plan.SetSourceName("EmulateInstructionPPC64"); unwind_plan.SetSourcedFromCompiler(eLazyBoolNo); unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolYes); diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp index 9bd48f2b9f60f..cdc4f85c3f8bf 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp @@ -493,11 +493,11 @@ bool PECallFrameInfo::GetUnwindPlan(const AddressRange &range, } for (auto it = rows.rbegin(); it != rows.rend(); ++it) - unwind_plan.AppendRow(*it); + unwind_plan.InsertRow(*it); - unwind_plan.SetPlanValidAddressRange(AddressRange( + unwind_plan.SetPlanValidAddressRanges({AddressRange( m_object_file.GetAddress(runtime_function->StartAddress), - runtime_function->EndAddress - runtime_function->StartAddress)); + runtime_function->EndAddress - runtime_function->StartAddress)}); unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); return true; diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp index 13465986f49c5..3c727ebc14d58 100644 --- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp +++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -276,7 +276,7 @@ static lldb::UnwindPlanSP GetAArch64TrapHandlerUnwindPlan(ConstString name) { // here. unwind_plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF); - unwind_plan_sp->AppendRow(row); + unwind_plan_sp->InsertRow(row); unwind_plan_sp->SetSourceName("AArch64 Linux sigcontext"); unwind_plan_sp->SetSourcedFromCompiler(eLazyBoolYes); // Because sp is the same throughout the function diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp index dee5a7ce2876d..b3280fa73a63f 100644 --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp @@ -656,15 +656,15 @@ SymbolFileBreakpad::ParseCFIUnwindPlan(const Bookmark &bookmark, plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); plan_sp->SetUnwindPlanForSignalTrap(eLazyBoolNo); plan_sp->SetSourcedFromCompiler(eLazyBoolYes); - plan_sp->SetPlanValidAddressRange( - AddressRange(base + init_record->Address, *init_record->Size, - m_objfile_sp->GetModule()->GetSectionList())); + plan_sp->SetPlanValidAddressRanges( + {AddressRange(base + init_record->Address, *init_record->Size, + m_objfile_sp->GetModule()->GetSectionList())}); auto row_sp = std::make_shared<UnwindPlan::Row>(); row_sp->SetOffset(0); if (!ParseCFIUnwindRow(init_record->UnwindRules, resolver, *row_sp)) return nullptr; - plan_sp->AppendRow(row_sp); + plan_sp->InsertRow(row_sp); for (++It; It != End; ++It) { std::optional<StackCFIRecord> record = StackCFIRecord::parse(*It); if (!record) @@ -676,7 +676,7 @@ SymbolFileBreakpad::ParseCFIUnwindPlan(const Bookmark &bookmark, row_sp->SetOffset(record->Address - init_record->Address); if (!ParseCFIUnwindRow(record->UnwindRules, resolver, *row_sp)) return nullptr; - plan_sp->AppendRow(row_sp); + plan_sp->InsertRow(row_sp); } return plan_sp; } @@ -698,9 +698,9 @@ SymbolFileBreakpad::ParseWinUnwindPlan(const Bookmark &bookmark, plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); plan_sp->SetUnwindPlanForSignalTrap(eLazyBoolNo); plan_sp->SetSourcedFromCompiler(eLazyBoolYes); - plan_sp->SetPlanValidAddressRange( - AddressRange(base + record->RVA, record->CodeSize, - m_objfile_sp->GetModule()->GetSectionList())); + plan_sp->SetPlanValidAddressRanges( + {AddressRange(base + record->RVA, record->CodeSize, + m_objfile_sp->GetModule()->GetSectionList())}); auto row_sp = std::make_shared<UnwindPlan::Row>(); row_sp->SetOffset(0); @@ -769,7 +769,7 @@ SymbolFileBreakpad::ParseWinUnwindPlan(const Bookmark &bookmark, row_sp->SetRegisterInfo(info->kinds[eRegisterKindLLDB], loc); } - plan_sp->AppendRow(row_sp); + plan_sp->InsertRow(row_sp); return plan_sp; } diff --git a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp index 84f37ebe52492..04105c1f6c141 100644 --- a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp +++ b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp @@ -918,7 +918,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly( UnwindPlan::Row::AbstractRegisterLocation initial_regloc; UnwindPlan::RowSP row(new UnwindPlan::Row); - unwind_plan.SetPlanValidAddressRange(func_range); + unwind_plan.SetPlanValidAddressRanges({func_range}); unwind_plan.SetRegisterKind(eRegisterKindLLDB); // At the start of the function, find the CFA by adding wordsize to the SP @@ -935,7 +935,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly( initial_regloc.SetAtCFAPlusOffset(-current_sp_bytes_offset_from_fa); row->SetRegisterInfo(m_lldb_ip_regnum, initial_regloc); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); // Allocate a new Row, populate it with the existing Row contents. UnwindPlan::Row *newrow = new UnwindPlan::Row; @@ -1299,7 +1299,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly( if (row_updated) { if (current_func_text_offset + insn_len < size) { row->SetOffset(current_func_text_offset + insn_len); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); // Allocate a new Row, populate it with the existing Row contents. newrow = new UnwindPlan::Row; *newrow = *row.get(); @@ -1404,7 +1404,7 @@ bool x86AssemblyInspectionEngine::AugmentUnwindPlanFromCallSite( UnwindPlan::RowSP new_row(new UnwindPlan::Row()); *new_row = *original_last_row; new_row->SetOffset(offset); - unwind_plan.AppendRow(new_row); + unwind_plan.InsertRow(new_row); row = std::make_shared<UnwindPlan::Row>(); *row = *new_row; reinstate_unwind_state = false; @@ -1573,7 +1573,7 @@ bool x86AssemblyInspectionEngine::AugmentUnwindPlanFromCallSite( } } - unwind_plan.SetPlanValidAddressRange(func_range); + unwind_plan.SetPlanValidAddressRanges({func_range}); if (unwind_plan_updated) { std::string unwind_plan_source(unwind_plan.GetSourceName().AsCString()); unwind_plan_source += " plus augmentation from assembly parsing"; diff --git a/lldb/source/Symbol/ArmUnwindInfo.cpp b/lldb/source/Symbol/ArmUnwindInfo.cpp index 569e0f591cbaf..f7ff4c0210706 100644 --- a/lldb/source/Symbol/ArmUnwindInfo.cpp +++ b/lldb/source/Symbol/ArmUnwindInfo.cpp @@ -340,7 +340,7 @@ bool ArmUnwindInfo::GetUnwindPlan(Target &target, const Address &addr, row->SetRegisterLocationToRegister(dwarf_pc, dwarf_lr, false); } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); unwind_plan.SetSourceName("ARM.exidx unwind info"); unwind_plan.SetSourcedFromCompiler(eLazyBoolYes); unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); diff --git a/lldb/source/Symbol/CompactUnwindInfo.cpp b/lldb/source/Symbol/CompactUnwindInfo.cpp index c9039ea51ff70..d9c0627cbb84c 100644 --- a/lldb/source/Symbol/CompactUnwindInfo.cpp +++ b/lldb/source/Symbol/CompactUnwindInfo.cpp @@ -206,7 +206,7 @@ bool CompactUnwindInfo::GetUnwindPlan(Target &target, Address addr, function_info.valid_range_offset_end - function_info.valid_range_offset_start, sl); - unwind_plan.SetPlanValidAddressRange(func_range); + unwind_plan.SetPlanValidAddressRanges({func_range}); } } @@ -786,7 +786,7 @@ bool CompactUnwindInfo::CreateUnwindPlan_x86_64(Target &target, saved_registers_offset--; saved_registers_locations >>= 3; } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } break; @@ -954,7 +954,7 @@ bool CompactUnwindInfo::CreateUnwindPlan_x86_64(Target &target, } } } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } break; @@ -1057,7 +1057,7 @@ bool CompactUnwindInfo::CreateUnwindPlan_i386(Target &target, saved_registers_offset--; saved_registers_locations >>= 3; } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } break; @@ -1218,7 +1218,7 @@ bool CompactUnwindInfo::CreateUnwindPlan_i386(Target &target, } } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } break; @@ -1336,7 +1336,7 @@ bool CompactUnwindInfo::CreateUnwindPlan_arm64(Target &target, row->SetRegisterLocationToRegister(arm64_eh_regnum::pc, arm64_eh_regnum::ra, true); - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } @@ -1430,7 +1430,7 @@ bool CompactUnwindInfo::CreateUnwindPlan_arm64(Target &target, reg_pairs_saved_count++; } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } @@ -1606,6 +1606,6 @@ bool CompactUnwindInfo::CreateUnwindPlan_armv7(Target &target, } } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } diff --git a/lldb/source/Symbol/DWARFCallFrameInfo.cpp b/lldb/source/Symbol/DWARFCallFrameInfo.cpp index a743de596b8d8..d968fbe7fc78a 100644 --- a/lldb/source/Symbol/DWARFCallFrameInfo.cpp +++ b/lldb/source/Symbol/DWARFCallFrameInfo.cpp @@ -623,7 +623,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, uint32_t code_align = cie->code_align; int32_t data_align = cie->data_align; - unwind_plan.SetPlanValidAddressRange(range); + unwind_plan.SetPlanValidAddressRanges({range}); UnwindPlan::Row *cie_initial_row = new UnwindPlan::Row; *cie_initial_row = cie->initial_row; UnwindPlan::RowSP row(cie_initial_row); @@ -650,7 +650,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, // that is computed by taking the current entry's location value and // adding (delta * code_align). All other values in the new row are // initially identical to the current row. - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); UnwindPlan::Row *newrow = new UnwindPlan::Row; *newrow = *row.get(); row.reset(newrow); @@ -690,7 +690,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, // specified address as the location. All other values in the new row // are initially identical to the current row. The new location value // should always be greater than the current one. - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); UnwindPlan::Row *newrow = new UnwindPlan::Row; *newrow = *row.get(); row.reset(newrow); @@ -704,7 +704,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, // takes a single uword argument that represents a constant delta. // This instruction is identical to DW_CFA_advance_loc except for the // encoding and size of the delta argument. - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); UnwindPlan::Row *newrow = new UnwindPlan::Row; *newrow = *row.get(); row.reset(newrow); @@ -717,7 +717,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, // takes a single uword argument that represents a constant delta. // This instruction is identical to DW_CFA_advance_loc except for the // encoding and size of the delta argument. - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); UnwindPlan::Row *newrow = new UnwindPlan::Row; *newrow = *row.get(); row.reset(newrow); @@ -730,7 +730,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, // takes a single uword argument that represents a constant delta. // This instruction is identical to DW_CFA_advance_loc except for the // encoding and size of the delta argument. - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); UnwindPlan::Row *newrow = new UnwindPlan::Row; *newrow = *row.get(); row.reset(newrow); @@ -812,7 +812,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset, } } } - unwind_plan.AppendRow(row); + unwind_plan.InsertRow(row); return true; } diff --git a/lldb/source/Symbol/UnwindPlan.cpp b/lldb/source/Symbol/UnwindPlan.cpp index a3df927cddae8..f65fceffa7e9e 100644 --- a/lldb/source/Symbol/UnwindPlan.cpp +++ b/lldb/source/Symbol/UnwindPlan.cpp @@ -389,74 +389,51 @@ bool UnwindPlan::Row::operator==(const UnwindPlan::Row &rhs) const { m_register_locations == rhs.m_register_locations; } -void UnwindPlan::AppendRow(const UnwindPlan::RowSP &row_sp) { - if (m_row_list.empty() || - m_row_list.back()->GetOffset() != row_sp->GetOffset()) - m_row_list.push_back(row_sp); - else - m_row_list.back() = row_sp; -} - void UnwindPlan::InsertRow(const UnwindPlan::RowSP &row_sp, bool replace_existing) { - collection::iterator it = m_row_list.begin(); - while (it != m_row_list.end()) { - RowSP row = *it; - if (row->GetOffset() >= row_sp->GetOffset()) - break; - it++; - } - if (it == m_row_list.end() || (*it)->GetOffset() != row_sp->GetOffset()) - m_row_list.insert(it, row_sp); - else if (replace_existing) - *it = row_sp; + if (replace_existing) + m_rows.insert_or_assign(row_sp->GetOffset(), row_sp); + else + m_rows.emplace(row_sp->GetOffset(), row_sp); } const UnwindPlan::Row *UnwindPlan::GetRowForFunctionOffset(int offset) const { - if (m_row_list.empty()) + auto it = offset == -1 ? m_rows.end() : m_rows.upper_bound(offset); + if (it == m_rows.begin()) return nullptr; - if (offset == -1) - return m_row_list.back().get(); - - RowSP row; - collection::const_iterator pos, end = m_row_list.end(); - for (pos = m_row_list.begin(); pos != end; ++pos) { - if ((*pos)->GetOffset() <= static_cast<lldb::offset_t>(offset)) - row = *pos; - else - break; - } - return row.get(); + // upper_bound returns the row strictly greater than our desired offset, which + // means that the row before it is a match. + return std::prev(it)->second.get(); } bool UnwindPlan::IsValidRowIndex(uint32_t idx) const { - return idx < m_row_list.size(); + return idx < m_rows.size(); } const UnwindPlan::Row *UnwindPlan::GetRowAtIndex(uint32_t idx) const { - if (idx < m_row_list.size()) - return m_row_list[idx].get(); + if (idx < m_rows.size()) + return std::next(m_rows.begin(), idx)->second.get(); + LLDB_LOG(GetLog(LLDBLog::Unwind), "error: UnwindPlan::GetRowAtIndex(idx = {0}) invalid index " "(number rows is {1})", - idx, m_row_list.size()); + idx, m_rows.size()); return nullptr; } const UnwindPlan::Row *UnwindPlan::GetLastRow() const { - if (m_row_list.empty()) { - Log *log = GetLog(LLDBLog::Unwind); - LLDB_LOGF(log, "UnwindPlan::GetLastRow() when rows are empty"); + if (m_rows.empty()) { + LLDB_LOG(GetLog(LLDBLog::Unwind), + "UnwindPlan::GetLastRow() when rows are empty"); return nullptr; } - return m_row_list.back().get(); + return m_rows.rbegin()->second.get(); } -int UnwindPlan::GetRowCount() const { return m_row_list.size(); } +int UnwindPlan::GetRowCount() const { return m_rows.size(); } -void UnwindPlan::SetPlanValidAddressRange(const AddressRange &range) { - if (range.GetBaseAddress().IsValid() && range.GetByteSize() != 0) - m_plan_valid_address_range = range; +void UnwindPlan::SetPlanValidAddressRanges(std::vector<AddressRange> ranges) { + m_plan_valid_ranges = std::move(ranges); } bool UnwindPlan::PlanValidAtAddress(Address addr) { @@ -482,9 +459,9 @@ bool UnwindPlan::PlanValidAtAddress(Address addr) { // If the 0th Row of unwind instructions is missing, or if it doesn't provide // a register to use to find the Canonical Frame Address, this is not a valid // UnwindPlan. - if (GetRowAtIndex(0) == nullptr || - GetRowAtIndex(0)->GetCFAValue().GetValueType() == - Row::FAValue::unspecified) { + const Row *row0 = GetRowForFunctionOffset(0); + if (!row0 || + row0->GetCFAValue().GetValueType() == Row::FAValue::unspecified) { Log *log = GetLog(LLDBLog::Unwind); if (log) { StreamString s; @@ -503,17 +480,15 @@ bool UnwindPlan::PlanValidAtAddress(Address addr) { return false; } - if (!m_plan_valid_address_range.GetBaseAddress().IsValid() || - m_plan_valid_address_range.GetByteSize() == 0) + if (m_plan_valid_ranges.empty()) return true; if (!addr.IsValid()) return true; - if (m_plan_valid_address_range.ContainsFileAddress(addr)) - return true; - - return false; + return llvm::any_of(m_plan_valid_ranges, [&](const AddressRange &range) { + return range.ContainsFileAddress(addr); + }); } void UnwindPlan::Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const { @@ -570,20 +545,17 @@ void UnwindPlan::Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const { s.Printf("not specified.\n"); break; } - if (m_plan_valid_address_range.GetBaseAddress().IsValid() && - m_plan_valid_address_range.GetByteSize() > 0) { + if (!m_plan_valid_ranges.empty()) { s.PutCString("Address range of this UnwindPlan: "); TargetSP target_sp(thread->CalculateTarget()); - m_plan_valid_address_range.Dump(&s, target_sp.get(), - Address::DumpStyleSectionNameOffset); + for (const AddressRange &range : m_plan_valid_ranges) + range.Dump(&s, target_sp.get(), Address::DumpStyleSectionNameOffset); s.EOL(); } - collection::const_iterator pos, begin = m_row_list.begin(), - end = m_row_list.end(); - for (pos = begin; pos != end; ++pos) { - s.Printf("row[%u]: ", (uint32_t)std::distance(begin, pos)); - (*pos)->Dump(s, this, thread, base_addr); - s.Printf("\n"); + for (const auto &[index, kv] : llvm::enumerate(m_rows)) { + s.Format("row[{0}]: ", index); + kv.second->Dump(s, this, thread, base_addr); + s << "\n"; } } diff --git a/lldb/unittests/Symbol/CMakeLists.txt b/lldb/unittests/Symbol/CMakeLists.txt index ab5cecd101833..5664c21adbe3f 100644 --- a/lldb/unittests/Symbol/CMakeLists.txt +++ b/lldb/unittests/Symbol/CMakeLists.txt @@ -12,6 +12,7 @@ add_lldb_unittest(SymbolTests TestDWARFCallFrameInfo.cpp TestType.cpp TestLineEntry.cpp + UnwindPlanTest.cpp LINK_LIBS lldbCore diff --git a/lldb/unittests/Symbol/UnwindPlanTest.cpp b/lldb/unittests/Symbol/UnwindPlanTest.cpp new file mode 100644 index 0000000000000..afbd9ab6ac38d --- /dev/null +++ b/lldb/unittests/Symbol/UnwindPlanTest.cpp @@ -0,0 +1,76 @@ +//===-- UnwindPlanTest.cpp ------------------------------------------------===// +// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Symbol/UnwindPlan.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using namespace lldb_private; +using namespace lldb; + +static UnwindPlan::RowSP make_simple_row(addr_t offset, uint64_t cfa_value) { + UnwindPlan::RowSP row_sp = std::make_shared<UnwindPlan::Row>(); + row_sp->SetOffset(offset); + row_sp->GetCFAValue().SetIsConstant(cfa_value); + return row_sp; +} + +TEST(UnwindPlan, InsertRow) { + UnwindPlan::RowSP row1_sp = make_simple_row(0, 42); + UnwindPlan::RowSP row2_sp = make_simple_row(0, 47); + + UnwindPlan plan(eRegisterKindGeneric); + plan.InsertRow(row1_sp); + EXPECT_THAT(plan.GetRowForFunctionOffset(0), testing::Pointee(*row1_sp)); + + plan.InsertRow(row2_sp, /*replace_existing=*/false); + EXPECT_THAT(plan.GetRowForFunctionOffset(0), testing::Pointee(*row1_sp)); + + plan.InsertRow(row2_sp, /*replace_existing=*/true); + EXPECT_THAT(plan.GetRowForFunctionOffset(0), testing::Pointee(*row2_sp)); +} + +TEST(UnwindPlan, GetRowForFunctionOffset) { + UnwindPlan::RowSP row1_sp = make_simple_row(10, 42); + UnwindPlan::RowSP row2_sp = make_simple_row(20, 47); + + UnwindPlan plan(eRegisterKindGeneric); + plan.InsertRow(row1_sp); + plan.InsertRow(row2_sp); + + EXPECT_THAT(plan.GetRowForFunctionOffset(0), nullptr); + EXPECT_THAT(plan.GetRowForFunctionOffset(9), nullptr); + EXPECT_THAT(plan.GetRowForFunctionOffset(10), testing::Pointee(*row1_sp)); + EXPECT_THAT(plan.GetRowForFunctionOffset(19), testing::Pointee(*row1_sp)); + EXPECT_THAT(plan.GetRowForFunctionOffset(20), testing::Pointee(*row2_sp)); + EXPECT_THAT(plan.GetRowForFunctionOffset(99), testing::Pointee(*row2_sp)); +} + +TEST(UnwindPlan, PlanValidAtAddress) { + UnwindPlan::RowSP row1_sp = make_simple_row(0, 42); + UnwindPlan::RowSP row2_sp = make_simple_row(10, 47); + + UnwindPlan plan(eRegisterKindGeneric); + EXPECT_FALSE(plan.PlanValidAtAddress(Address(0))); + + plan.InsertRow(row2_sp); + EXPECT_FALSE(plan.PlanValidAtAddress(Address(0))); + + plan.InsertRow(row1_sp); + EXPECT_TRUE(plan.PlanValidAtAddress(Address(0))); + EXPECT_TRUE(plan.PlanValidAtAddress(Address(10))); + + plan.SetPlanValidAddressRanges({AddressRange(0, 5), AddressRange(15, 5)}); + EXPECT_TRUE(plan.PlanValidAtAddress(Address(0))); + EXPECT_FALSE(plan.PlanValidAtAddress(Address(5))); + EXPECT_FALSE(plan.PlanValidAtAddress(Address(10))); + EXPECT_TRUE(plan.PlanValidAtAddress(Address(15))); + EXPECT_FALSE(plan.PlanValidAtAddress(Address(20))); + EXPECT_FALSE(plan.PlanValidAtAddress(Address(25))); +} diff --git a/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp b/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp index 3600360fad229..4fb1985f1a319 100644 --- a/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp +++ b/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp @@ -2248,7 +2248,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSpArithx86_64Augmented) { sample_range = AddressRange(0x1000, sizeof(data)); unwind_plan.SetSourceName("unit testing hand-created unwind plan"); - unwind_plan.SetPlanValidAddressRange(sample_range); + unwind_plan.SetPlanValidAddressRanges({sample_range}); unwind_plan.SetRegisterKind(eRegisterKindLLDB); row_sp = std::make_shared<UnwindPlan::Row>(); @@ -2260,7 +2260,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSpArithx86_64Augmented) { regloc.SetAtCFAPlusOffset(-8); row_sp->SetRegisterInfo(k_rip, regloc); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); // Allocate a new Row, populate it with the existing Row contents. UnwindPlan::Row *new_row = new UnwindPlan::Row; @@ -2272,7 +2272,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSpArithx86_64Augmented) { row_sp->GetCFAValue().SetIsRegisterPlusOffset(k_rsp, 16); regloc.SetAtCFAPlusOffset(-16); row_sp->SetRegisterInfo(k_rbp, regloc); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); // Allocate a new Row, populate it with the existing Row contents. new_row = new UnwindPlan::Row; @@ -2282,7 +2282,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSpArithx86_64Augmented) { // Describe offset 4 row_sp->SetOffset(4); row_sp->GetCFAValue().SetIsRegisterPlusOffset(k_rsp, 16); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); RegisterContextSP reg_ctx_sp; EXPECT_TRUE(engine64->AugmentUnwindPlanFromCallSite( @@ -2335,7 +2335,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplex86_64Augmented) { sample_range = AddressRange(0x1000, sizeof(data)); unwind_plan.SetSourceName("unit testing hand-created unwind plan"); - unwind_plan.SetPlanValidAddressRange(sample_range); + unwind_plan.SetPlanValidAddressRanges({sample_range}); unwind_plan.SetRegisterKind(eRegisterKindLLDB); row_sp = std::make_shared<UnwindPlan::Row>(); @@ -2347,7 +2347,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplex86_64Augmented) { regloc.SetAtCFAPlusOffset(-8); row_sp->SetRegisterInfo(k_rip, regloc); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); // Allocate a new Row, populate it with the existing Row contents. UnwindPlan::Row *new_row = new UnwindPlan::Row; @@ -2359,7 +2359,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplex86_64Augmented) { row_sp->GetCFAValue().SetIsRegisterPlusOffset(k_rsp, 16); regloc.SetAtCFAPlusOffset(-16); row_sp->SetRegisterInfo(k_rbp, regloc); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); // Allocate a new Row, populate it with the existing Row contents. new_row = new UnwindPlan::Row; @@ -2369,7 +2369,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplex86_64Augmented) { // Describe offset 4 row_sp->SetOffset(4); row_sp->GetCFAValue().SetIsRegisterPlusOffset(k_rbp, 16); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); RegisterContextSP reg_ctx_sp; EXPECT_TRUE(engine64->AugmentUnwindPlanFromCallSite( @@ -2413,7 +2413,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplei386ugmented) { sample_range = AddressRange(0x1000, sizeof(data)); unwind_plan.SetSourceName("unit testing hand-created unwind plan"); - unwind_plan.SetPlanValidAddressRange(sample_range); + unwind_plan.SetPlanValidAddressRanges({sample_range}); unwind_plan.SetRegisterKind(eRegisterKindLLDB); row_sp = std::make_shared<UnwindPlan::Row>(); @@ -2425,7 +2425,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplei386ugmented) { regloc.SetAtCFAPlusOffset(-4); row_sp->SetRegisterInfo(k_eip, regloc); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); // Allocate a new Row, populate it with the existing Row contents. UnwindPlan::Row *new_row = new UnwindPlan::Row; @@ -2437,7 +2437,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplei386ugmented) { row_sp->GetCFAValue().SetIsRegisterPlusOffset(k_esp, 8); regloc.SetAtCFAPlusOffset(-8); row_sp->SetRegisterInfo(k_ebp, regloc); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); // Allocate a new Row, populate it with the existing Row contents. new_row = new UnwindPlan::Row; @@ -2447,7 +2447,7 @@ TEST_F(Testx86AssemblyInspectionEngine, TestSimplei386ugmented) { // Describe offset 3 row_sp->SetOffset(3); row_sp->GetCFAValue().SetIsRegisterPlusOffset(k_ebp, 8); - unwind_plan.AppendRow(row_sp); + unwind_plan.InsertRow(row_sp); RegisterContextSP reg_ctx_sp; EXPECT_TRUE(engine32->AugmentUnwindPlanFromCallSite( _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits