objc_msgsend crash

http://lists.apple.com/archives/Cocoa-dev/2006/Mar/msg00058.html 


Aleaxander Cohen wrote:

> Once in a while, my application breaks in the debugger on a

> 'objc_msgsend', is there any way to find out what object is being

> passed to this function so i can understand what is going on in my

> app?


This isn't easy on i386, because the exact location changes depending on how far inside objc_msgSend() you got.


This procedure works well, though it's not fully automatic:

1. Run `x/s $ecx`. This should print the name and address of the selector. If it doesn't, you're too far inside objc_msgSend() to get an easy answer.

3. Run `x/8x $esp`. This is the top 8 words of the stack.

4. Look for the selector address (from step 1) in the stack contents. The word just before the selector address is the receiver object's address. The method's other arguments, if any, start after the selector.


If step #1 doesn't work, check whether you're stopped at the very first instruction of objc_msgSend(). If so, step forward one instruction (`si`) and try again. That first instruction is the one that moves the selector into $ecx.


Example:

0x9ff57eef in objc_msgSend ()

(gdb) x/s $ecx

0x9ffcb230 <_errNotSuper+412640>: "sharedSpellChecker"

// The selector is "sharedSpellChecker", and its address is 0x9ffcb230

(gdb) x/8x $esp

0xbfffee34: 0xbfffee88 0x003539b0 0x93624629 0xa34ab0c0

0xbfffee44: 0x9ffcb230 0xbfffef18 0x9ff57f36 0xa34ac480

// The selector address is the 5th word on the stack, so the receiver is 0xa34ab0c0

(gdb) p (char *)object_getClassName(0xa34ab0c0)

$1 = 0x932aa1750 "NSSpellChecker"

// The receiver is either class NSSpellChecker or one of its instances. This case happens to be the class itself, for + [NSSpellChecker sharedSpellChecker]



Eric Albert wrote:

> Printing arguments on Intel really isn't all that hard.  On

> PowerPC, you'd print $r3, $r4, $r5, etc.  On Intel, it's $ebp + 8,

> $ebp + 12, $ebp + 16, etc.


This doesn't work for objc_msgSend(). Ordinary functions set up $ebp as the frame pointer, but objc_msgSend() usually doesn't do that, for performance reasons.



--

Greg Parker     email@hidden     Runtime Wrangler

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值