Re: Fun GDB tricks
Re: Fun GDB tricks
- Subject: Re: Fun GDB tricks
- From: Alastair Houghton <email@hidden>
- Date: Mon, 5 Jan 2004 15:00:49 +0000
On 1 Jan 2004, at 21:47, Daniel Jalkut wrote:
>
If anybody else spends any time in GDB looking at other people's
>
disassembly, you might find this hack interesting, either as is or as
>
a basis for tweaking.
>
>
I got tired of performing a tedious, yet common pattern in my gdb
>
sessions: look ahead for the next subroutine call, set a breakpoint on
>
it, and continue. I wrote a (probably clunkier than necessary) gdb
>
macro that does this for me, and I thought I'd share it, if only
>
because I couldn't find any examples that (ab)use gdb macros in this
>
way. This gdb pattern is especially useful when you're scoping out
>
somebody else's Objective C calls. It could probably be a lot
>
prettier if I took time to learn more about gdb's expression syntax :)
>
>
The gist of what it's doing is this:
>
>
Starting at the current PC, look at every instruction in order.
>
>
If it looks like a bl (branch and link) instruction, then set a
>
temporary breakpoint and continue.
You probably also want to look for bctrl instructions, which are used
for indirect subroutine calls, as well as calls into shared libraries
and under other circumstances where the displacement might be >26 bits.
>
>
If it looks like a blr (branch to link register) instruction, then
>
give up, because we're probably not interested in stuff beyond the end
>
of the routine.
You also need to be a bit careful about conditional branches; you've
assumed straight-line code, which may not always be the case.
Functions can, for example, have any number of "blr"s, and it's quite
possible that your breakpoint will get set on a bl that is not actually
executed, in which case you'll enter "nl" and your program won't come
back :-)
Still, quite an interesting macro.
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.