Objective-C - 使用GDB打印方法参数 [英] Objective-C - print method parameters with GDB

查看:157
本文介绍了Objective-C - 使用GDB打印方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正努力用GDB来调试我的Objective-C程序。我有一个函数 - (NSString *)reverse:(NSString *)someString ,我想调试它。



以下是我设置断点的方式:

 (gdb)break  -  [MyClass reverse:] 
self <的值, / code>和方法参数?我做了一些Google搜索,发现了诸如 po $ rdx 之类的建议,但没有发现任何作品。

我怎么能解决这个问题?

解决方案

克拉克考克斯写了我见过的最好的解释。我一直提到这个页面,并且已经做了一个本地副本,以防万一它消失。



http://www.clarkcox.com/blog/2009/02/04/inspecting-obj-c-parameters-in -gdb /



x86_64和非浮点参数的快速版本是:

  first ObjC arg => $ rdx 
秒ObjC arg => $ rcx
第三个ObjC arg => $ r8
第四个ObjC arg => $ r9

请记住,传递给方法的前两件事情(在$ rdi和$ rsi中)是 self _cmd 。如果你通过浮点,结构或超过四个参数,事情会变得更加复杂,你应该阅读调用 AMD64 ABI 部分中的约定3.2.3。如果您正在处理i386,PPC或ARM,请参阅Clark的帖子,该帖子涵盖了那些常见案例。


I'm struggling to debug my Objective-C program with GDB. I have a function - (NSString *)reverse:(NSString *)someString which I want to debug.

Here's how I set the breakpoint:

(gdb) break -[MyClass reverse:]

Now, when the code gets to the breakpoint, how do I print the addresses or even better the values of self and the method argument? I've done some googling and found suggestions like po $rdx but nothing I found works.

How can I solve this?

解决方案

Clark Cox has written the best explanation of this I've ever found. I refer to this page all the time and have made a local copy in case it ever goes away.

http://www.clarkcox.com/blog/2009/02/04/inspecting-obj-c-parameters-in-gdb/

The quick version for x86_64 and non-floating-point parameters is:

first ObjC arg => $rdx
second ObjC arg => $rcx
third ObjC arg => $r8
fourth ObjC arg => $r9

Remember, the first two things passed to a method (in $rdi and $rsi) are self and _cmd. I'm not counting those here.

If you're passing floating points, structs, or more than four arguments, things get more complicated, and you should read the calling conventions in the AMD64 ABI section 3.2.3. If you're dealing with i386, PPC, or ARM, see Clark's post, which covers those cases well for the common cases.

这篇关于Objective-C - 使用GDB打印方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆