Commit c981efc6 authored by Ryan V Bissell's avatar Ryan V Bissell
Browse files

Skip ARM.exidx data for unwinding in prologue code

In the absence of debug symbols, one of the strategies that GDB
employs to unwind the stack for ARM is the "ARM.exidx" data section
in an ELF image.  Nominally, this section is used to facilitate
stack unwinding when an exception is thrown in languages that
support exceptions.  However, the exidx data does not cover all
possible ranges of the program counter; and especially it is not
valid for use when the PC currently sits within a function
prologue.

Relying on exception index tables to unwind the stack before a
function's prologue has completed is perilous, as an incorrect
return address may be computed, causing anything from spurious
or missed breakpoints... or even segfaults if the resulting
incorrect return address causes GDB to use a Thumb breakpoint
in ARM code (or vice versa.)

That latter case can happen if the GDB user attempts to step into
(at a source level) a called routine for which no symbols are
available.  GDB will set a breakpoint at the beginning of that
callee, and let the inferior continue.  But once that breakpoint
is reached, GDB will discover that there are no usable symbols,
and then opt to automatically return from whence it came (i.e.,
back to the calling routine.)  To do that, it needs the return
address.  But because at the time of this decision it is sitting
at the beginning of the callee's prologue, using exidx data is
the wrong thing to do.

This change addresses that problem for ARM by attempting to detect
the prologue.  In particular, this change looks for any flavor
of a "PUSH {..., LR}" instruction at the address contained in
the CPU's program counter.  If such an instruction is found,
GDB will now assume (a) that exidx data is not usable at that
critical moment, and (b) continue on to the next unwinding strategy
(which might as well just trust the value in LR as the return
address, since that was what was being pushed to the stack for
preservation, by the prologue code.)

This change also defines a new "set arm exidx-unwinding" command,
that allows the GDB user to disable exidx-based stack unwinding
entirely, in the event that some prologue exists that does not
begin with some "PUSH {..., LR}" instruction.

See https://code.google.com/p/android/issues/detail?id=55826



Change-Id: Iba2010de749483e34a7e1f4b849f8b1669d7b8c6
Signed-off-by: default avatarRyan V Bissell <rbissell@nvidia.com>
parent 9c1ebdf1
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment