This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Get backtrace at PLT and stepi into PLT


Hi all,

I have a patch that makes GDB can properly stepi into PLT for ARM Thumb
instruction.  The patch also allow GDB to perform backtrace at PLT.

If you have a caller function, compiled with Thumb
instruction set with GCC, calls another callee function in another
file and you link the object containing caller to a ELF shared object,
GNU ld will generate a special trampoline in PLT section for the
callee function which is not in the same shared boject.  If you
try to stepi on bl instruction of caller and expect that GDB would
stop at first instruction of the trampoline, you would be
disappointed.

LD generates a trampoline that starts with 4 bytes
of Thumb instruction (2 instructions) followed by 14 bytes of
ARM instructins (3 instructions).  The Thumb instructions
are braches that branch to first instruction of the ARM
instructions and clear T flags.  It means switching processor to
ARM instruction set from Thumb instruction set.

It means GDB should put a invalid instruction of Thumb version at
base address of the trampoline.  But, it actually puts
ARM version one.  I have checked GDB source code for this issue.
GDB check flags in symbol that contain memory space that breakpoint
was setted at.  If the symbol is flaged as Thumb, it uses
Thumb version invalid instruction code, or it would use
ARM version.  It is reasonable.  But, the trampoline in PLT contains
both types of instructions.  And, the result of checking is
the block where the trampoline is in is not Thumb.

The solution is to check bl instructions in Thumb caller function.
If the bl instruction will not transit processor to ARM from Thumb
instruction set, we should still use Thumb version despite what
is got from the symbol.

If you try to backtrace stack when GDB stop at PLT, you would
get nothing.  It is because no any unwinder can handle code in PLT.
I add and register a tramp_frame for ARM Linux architecture, and
add a new frame type "GHOST_FRAME".  The tramp_frame can handle
PLT trampoline for ARM Thumb.  And, I can get backtrace when GDB
stop an inferior at PLT.


Following is changelog of the patch and patch itself.

2009-07-16  Thinker @ 0xlab <thinker@branda.to>

	* arm-linux-tdep.c (arm_eabi_linux_plt_tramp_frame): Add a new
	tramp_frame for ARM Linux PLT code with GHOST_FRAME type.
	* frame.h (enum frame_type): Add new frame_type GHOST_FRAME.
	* frame.c (get_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