From: User Thinker <thinker@branda.to>
To: gdb-patches@sourceware.org
Cc: mokoko-group@googlegroups.com
Subject: Get backtrace at PLT and stepi into PLT
Date: Thu, 16 Jul 2009 19:07:00 -0000 [thread overview]
Message-ID: <19038.65134.58926.218902@bibi.branda.to> (raw)
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_prev_frame):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(<5)DI![#M6.I:O)O6]<QYMAA?*PMJ$P6PHH,?WV
MK3QLY2ZD1A]5R^#-&5Q]N[O[N[A?(?5JM_XQ9`]X$?F(T2IQ\UOB=F>JWO%>
M/P,LQ2&@N,^4I3:-:FL2#TK\%`Q*L<_PBF9/8JQ@>1B6D4,HV)GPPWAB5-0:
ML*]4%-$@%?N8/;\`Y/0%(*>_"\CI3H!\_U[B$5^627C<N`2_,G%BKHW0'IP$
M0L""58X,67$;EG?_X@?$KD"P9JNY`BMFSK+"I3ZG&RQ03Y.81<BSE,?IGRN&
MHAP@#)?CS1(4ZRMRU,&S2>T2'@A[=0HN;]'`'DFD3]=6TH8SHS<CHE+M48$T
M+%N>$U'1RC,DI^NUE).IFWG&YSRDDAQCZ2W\4)JNRGD%A\7\7%9W1"'B@/(T
E0<EB2HW,D)=HRKP9:EC$A;(3\'*\X6/ZXF"F_0>O0T$Q]Q$`````
`
end
next reply other threads:[~2009-07-16 10:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-16 19:07 User Thinker [this message]
2009-07-16 19:11 ` Daniel Jacobowitz
[not found] ` <19040.7376.886250.727782@bibi.branda.to>
[not found] ` <bc7444e5-0719-4ee1-acbb-4495ded392a6@a37g2000prf.googlegroups.com>
2009-07-17 8:47 ` Fwd: " Thinker Li
2009-07-17 8:48 Thinker Li
2009-07-17 14:26 ` Daniel Jacobowitz
[not found] ` <19040.34533.656545.753721@bibi.branda.to>
2009-07-17 15:07 ` Daniel Jacobowitz
[not found] ` <19044.7794.607077.330791@bibi.branda.to>
2009-07-20 13:15 ` Daniel Jacobowitz
2009-07-21 15:12 ` Thinker Li
2009-07-21 18:15 ` Daniel Jacobowitz
2009-07-22 12:12 ` Thinker Li
2009-07-22 15:49 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19038.65134.58926.218902@bibi.branda.to \
--to=thinker@branda.to \
--cc=gdb-patches@sourceware.org \
--cc=mokoko-group@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox