[Lldb-commits] [lldb] [lldb][RISCV] Implement trap handler unwind plan (PR #166531)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 17 01:37:24 PST 2025
================
@@ -302,12 +304,56 @@ static lldb::UnwindPlanSP GetAArch64TrapHandlerUnwindPlan(ConstString name) {
return unwind_plan_sp;
}
+static lldb::UnwindPlanSP GetRISCVTrapHandlerUnwindPlan(ConstString name) {
+ if (name != "__vdso_rt_sigreturn")
+ return UnwindPlanSP{};
+
+ UnwindPlan::Row row;
+
+ // In the signal trampoline frame, sp points to an rt_sigframe[1], which is:
+ // - 128-byte siginfo struct
+ // - ucontext struct:
+ // - 8-byte long (uc_flags)
+ // - 8-byte pointer (*uc_link)
+ // - 24-byte struct (uc_stack)
+ // - 8-byte struct (uc_sigmask)
+ // - 120-byte of padding to allow sigset_t to be expanded in the future
+ // - 8 bytes of padding because sigcontext has 16-byte alignment
+ // - struct sigcontext uc_mcontext
+ // [1]
+ // https://github.com/torvalds/linux/blob/master/arch/riscv/kernel/signal.c
+
+ constexpr size_t siginfo_size = 128;
+ constexpr size_t uc_flags_size = 8;
+ constexpr size_t uc_link_ptr_size = 8;
+ constexpr size_t uc_stack_size = 24;
+ constexpr size_t uc_sigmask_size = 8;
+ constexpr size_t padding_size = 128;
+
+ constexpr size_t offset = siginfo_size + uc_flags_size + uc_link_ptr_size +
+ uc_stack_size + uc_sigmask_size + padding_size;
+
+ row.GetCFAValue().SetIsRegisterPlusOffset(gpr_sp_riscv, offset);
+ for (uint32_t reg_num = 0; reg_num <= 31; ++reg_num)
+ row.SetRegisterLocationToAtCFAPlusOffset(reg_num, reg_num * 8, false);
+
+ UnwindPlanSP unwind_plan_sp = std::make_shared<UnwindPlan>(eRegisterKindLLDB);
+ unwind_plan_sp->AppendRow(std::move(row));
+ unwind_plan_sp->SetSourceName("RISC-V Linux sigcontext");
+ unwind_plan_sp->SetSourcedFromCompiler(eLazyBoolYes);
----------------
DavidSpickett wrote:
Yeah you'd like to think that but I don't know why I set it that way (https://reviews.llvm.org/D112069). Possibly because the code that would try to use the unwind plan just wouldn't unless it was set.
So that's one way to justify it here, if you change it, does it still get used?
@jasonmolenda added this back in https://github.com/llvm/llvm-project/commit/60f0bd4944ab958894005ddc1f0016bfe67c505a. Maybe he remembers what it means.
I see things setting it to no even when they are plans built inside LLDB. Perhaps the reason we set it to yes in a trap handler unwind plan is because the plan is *representing* a compiler generated thing?
Whereas ABI plugins do not represent compiler decisions. Beyond "I should follow the ABI" of course.
(IIRC the AArch64 trap handler actually has CFI directives commented out due to some crash somewhere else if they were actually used)
https://github.com/llvm/llvm-project/pull/166531
More information about the lldb-commits
mailing list