jasonmolenda wrote:

> Testing this is in theory possible, tricky bit is guaranteeing a frameless 
> function. There is the naked attribute but it's not portable 
> https://godbolt.org/z/s9117Gr7a. Or you could write the function in an 
> assembly file, or define and call it inside an inline assembly block, inside 
> a normal C function. That function would branch to self waiting for SIGALRM 
> for example.
> 
> Maybe that has its own problems, I haven't tried it. Maybe it wouldn't 
> generate enough debug info for us to know that the assembly function was 
> there?

There's (I'd argue) three parts to the unwind system.  First is converting the 
different unwind info formats (eh_frame, debug_frame, compact unwind, arm idx, 
assembly instruciton scanning) into the intermediate representation of 
UnwindPlans.  Second is the unwind engine itself, which encodes rules about 
which type of unwind plan to use for a given stack frame, which registers can 
be passed up the stack, and rules about behavior on the 0th frame or above a 
fault handler/sigtramp.  And third are correctly fetching the register value 
for a row in an UnwindPlan (often, dereferencing memory offset from the 
Canonical Frame Address which is set in terms of another register most often) 
-- these often end up being dwarf expressions.

That middle bit, the unwind engine logic, is hard to test today without making 
hand-written assembly programs that set up specific unwind scenarios with 
metadata (.cfi directives) about what they've done.  Source level tests are at 
the mercy of compiler codegen and not stable, or requires capturing a corefile 
and object binary when the necessary conditions are achieved.

But here's the idea I had the other day.  With a scripted process, an 
ObjectFileJSON to create a fake binary with function start addresses, and a way 
to specify UnwindPlans for those functions, where all of the register rules 
would be "and the value of fp is <x>" instead of "read stack memory to get the 
value of fp", I bet there's a way we could write unwind engine tests entirely 
in these terms.   And honest, the unwind engine method has a lot of very tricky 
corner cases and because it's not directly tested, it's easy to make mistakes - 
I am genuinely not thrilled about the state of it.  And without strong test 
infrastructure, it's going to be very intimidating to try to rewrite if anyone 
wanted to do that some day.

This is only "shower thoughts" level detail, but it's the first time I can see 
a testing strategy that I actually think could work well.

https://github.com/llvm/llvm-project/pull/98566
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to