• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fun GDB tricks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fun GDB tricks


  • Subject: Fun GDB tricks
  • From: Daniel Jalkut <email@hidden>
  • Date: Thu, 1 Jan 2004 13:47:03 -0800

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.

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.

If it's been a while (1000 bytes), then give, we're probably looking at garbage.

You can put this in your .gdbinit file and invoke it by typing "nl" while debugging:

define nl
set $peek=$pc
set $found=0
set $bignum = $peek+1000
while (($found==0) && ($peek < $bignum))
if ((*$peek & 0xf8000000) == 0x48000000)
if ((*$peek & 0x00000003) == 1)
set $found=1
end
end
if (*$peek == 0x4e800020)
echo Found end of routine, stopped searching.\n
set $peek=$bignum
end
if ($found == 0)
set $peek=$peek+4
end
end
if ($found == 1)
tb *$peek
c
end
if ($found == 0)
echo bl not found.\n
end
end

document nl
Searches memory for a "bl" instruction starting at the current PC.
If found, a temporary breakpoint is set at the bl call point, and
execution is continued.
end
_______________________________________________
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.

  • Follow-Ups:
    • Re: Fun GDB tricks
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: Encryption
  • Next by Date: Re: Encryption
  • Previous by thread: Re: handling of huge bitmaps, incremental saving?
  • Next by thread: Re: Fun GDB tricks
  • Index(es):
    • Date
    • Thread