Re: [PATCH 1/4] Teach arm unwinders to terminate gracefully

Yao Qi
2016-04-06T15:54:39Z

Pedro Alves <palves@redhat.com> writes:

Hi Pedro,

> I think it'd work to have an ultimate-fallback unwinder that
> frame_unwind_find_by_frame returns instead of the internal error at
> the end. This would return UNWIND_UNAVAILABLE or UNWIND_MEMORY_ERROR
> in the unwinder->stop_reason method, depending on the error the last registered
> unwinder thrown. (That last unwinder will always be the arch's heuristic unwinder.)
> And it would return frame_id_build_unavailable_stack(PC) in the unwinder->this_id
> method if the last error was UNWIND_UNAVAILABLE, outer_frame_id otherwise
> (or we add a new frame_id_build_stackless function, to go along with
> frame_id_build_unavailable_stack).

I write some code to implement your suggestion here, and it looks OK
except that I can't get PC to pass to frame_id_build_unavailable_stack,
since PC is extracted from frame cache which varies on different archs
and unwinders.

I tried to define a super class frame_cache for various frame cache
(nowadays, it is defined as void *), frame_cache has one field PC, and
various frame caches are the sub class of frame_cache. Many frame
unwinding APIs need update, and many places need update too, as a
result. I stop here as I am not sure it is a right approach.

However, I think we can still do the change you suggested, but in a
smaller scope, so the change is less aggressive, and some progress can
be made, like this,

- Add an unavailable frame unwinder for gdbarch A which supports
tracepoint, as the ultimate-fallback.

- For the unwinders in gdbarch A, move the code creating frame cache to
the sniffer. If the sniffer accepts the frame, creates the frame cache.

- Exceptions are allowed to be thrown out in frame cache creation.
The exception is caught in the caller of sniffer
(frame_unwind_try_unwinder) today, so if exception is thrown, GDB
will try the next unwinder,

- In this way, only 'sniffer' in 'frame_unwind' may throw exception, so
we don't have to worry about other 'frame_unwind' methods. IOW, all
unwinders in gdbarch A except unavailable frame unwinder don't worry
about the unavailable memory/register.

- the unavailable frame unwinder is the last unwinder for gdbarch A, it
knows how/where to get PC, if PC is available, return
frame_id_build_unavailable_stack (PC), otherwise return outer_frame_id.

In this way, the change will be smaller, and we can apply this change to
each gdbarch one by one, and in the future, it is possible to have a
single gdbarch-independent unavailable frame unwinder once we figure out
how to get PC from various frame caches.

--
Yao (齐尧)