Re: graceful unwind termination when we'd need unavailable/uncollect memory or registers to unwind further

Pedro Alves
2011-03-18T18:56:24Z

I've checked this one in as well.

On Tuesday 22 February 2011 18:34:42, Pedro Alves wrote:
> This patch applies on top of the "unavailable regs/locals"
> series, starting at:
> <http://sourceware.org/ml/gdb-patches/2011-02/msg00581.html>.
>
> This teaches GDB about terminating unwinding gracefully if
> unwind further we would need registers/memory that haven't
> been collected.
>
> Here's the result:
>
> (gdb) bt
> #0 begin (a=<unavailable>) at ../../../src/gdb/testsuite/gdb.trace/unavailable.cc:182
> #1 0x00000000004008ad in main (argc=1, argv=0x7fff0e22cf28, envp=0x7fff0e22cf38)
> at ../../../src/gdb/testsuite/gdb.trace/unavailable.cc:210
> #2 <unavailable> in ?? ()
> Backtrace stopped: Not enough registers or memory available to unwind further
>
> I think I've implemented this differently in about 10
> different ways. This is the design that I ended up with and
> that I think is best.
>
> - when we sniff unwinders trying to find a matching unwinder,
> we catch NOT_AVAILABLE_ERRORS. If the PC is unavailable,
> it is impossible to determine if a given non-prologue parser unwinder
> would have been the best unwinder or not. By catching
> NOT_AVAILABLE_ERRORS, we don't have too touch many sniffers.
> When sniffing, they just read whatever minimum data they
> require to determine they're the correct unwinder. If
> any of that is unavailable, we'll hit an exception. So what
> this means is that sniffer code does not try to check if a
> given _required_ value is available --- it just goes ahead and
> reads it.
>
> - adds a new frame_unwind method, to make it possible for an unwinder
> to tell the core frame code that it can't unwind further. The
> concept here, is that if we are able to tell a given unwinder
> would be the best unwinder, select it, even if actually trying to
> unwind from it wouldn't work due to unavailable data. E.g., if
> all we have available is the PC, we'll be able to tell that we
> have dwarf unwind info for that frame. But if we then find out
> that we don't have enough registers/memory to compute the CFA, we know
> we aren't going to be able to unwind. We _don't_ fallback to
> prologue parsing in such cases, since if we couldn't unwind with
> the precise unwind info missing, prologue parsing is surely not
> going to be able to unwind correctly.
>
> - this new method incidently allows cleanly reporting to the core
> frame machinery when a frame is the outermost, without resorting
> to hacks in the frame_id, which opens the door to fixing a
> corner case with stepping through the outermost frame when there's
> no debug info. I won't be implementing that, it just paves the way.
>
> - the prologue parsers then need to be made aware that they may trip
> on necessary registers (e.g., PC / SP / FP) unavailable to unwine,
> and that they should return that they can't unwind further in
> the new frame_unwind method in that case. I've taught the x86
> and x64_64 unwinders, but not all others. I did do the mechanical
> work of adjusting all of them to the new interface, so that
> --enable-targets=all still builds, and so that they continue working
> as today. Theaching other prologue unwinders how to terminate
> gracefully with UNWIND_UNAVAILABLE is only interesting when a
> corresponding target supports tracepoints on that architecture, so
> it can be enabled on a case by case basis.

--
Pedro Alves