[转]Inspecting Obj-C parameters in gdb
Since the addition of i386 and x86_64 to the Mac OS’s repertoire several years back, remembering which registers are used for what has become difficult, and this can complicate the debugging of code for which you have no symbols. So here is my cheat-sheet (posted here, mostly so that I can find it again without google-ing for old mailing list posts; but, I figure someone else may find it useful as well):
arm (before prolog)
$r0➡ arg0 (self)$r1➡ arg1 (_cmd)$r2➡ arg2$r3➡ arg3*($sp)➡ arg4*($sp+4)➡ arg5*($sp+8)➡ arg6
ppc/ppc64
$r3➡ arg0 (self)$r4➡ arg1 (_cmd)$r5➡ arg2$r6➡ arg3$r7➡ arg4$r8➡ arg5
i386 (before prolog)
*($esp+4n)➡ arg(n)*($esp)➡ arg0 (self)*($esp+4)➡ arg1 (_cmd)*($esp+8)➡ arg2*($esp+12)➡ arg3*($esp+16)➡ arg4*($esp+20)➡ arg5
i386 (after prolog)
*($ebp+8+4n)➡ arg(n)*($ebp+4)➡ Return addr*($ebp+8)➡ arg0 (self)*($ebp+12)➡ arg1 (_cmd)*($ebp+16)➡ arg2*($ebp+20)➡ arg3*($ebp+24)➡ arg4*($ebp+28)➡ arg5*($ebp)➡ Previous $ebp
x86_64
$rdi➡ arg0 (self)$rsi➡ arg1 (_cmd)$rdx➡ arg2$rcx➡ arg3$r8➡ arg4$r9➡ arg5
So, if you have a method defined as:-(id)method:(id)foo bar:(id)bar baz:(id)baz
you can print each of the parameters with:
| arm | ppc/ppc64 | x86_64 | i386 (before prolog) | i386 (after prolog) | |
|---|---|---|---|---|---|
| self | po $r0 |
po $r3 |
po $rdi |
po *(id*)($esp) |
po *(id*)($ebp+8) |
| _cmd | p (SEL)$r1 |
p (SEL)$r4 |
p (SEL)$rsi |
p *(SEL*)($esp+4) |
p *(SEL*)($ebp+12) |
| foo | po $r2 |
po $r5 |
po $rdx |
po *(id*)($esp+8) |
po *(id*)($ebp+16) |
| bar | po $r3 |
po $r6 |
po $rcx |
po *(id*)($esp+12) |
po *(id*)($ebp+20) |
| baz | po *(id*)($sp) |
po $r7 |
po $r8 |
po *(id*)($esp+16) |
po *(id*)($ebp+24) |
As Blake mentioned in his comment, on i386, if you’re at the beginning of a function or method, before the prolog has executed (i.e. the bit of code responsible for saving registers, adjusting the stack pointer, etc.), then ebp won’t have been set up for you yet.
So, I’ve amended the above table.
That complexity is another reason I long for the simplicity of PowerPC asm, not to mention M68k asm; at least x86_64 has made the step towards using registers for parameters where possible.
Edited to add: In case it isn’t obvious, these particular stack offsets and registers assignments only make sense when dealing with pointer and integer parameters and return values. When structures and floating point values come into the mix, things can get more complicated.
Edited to add: I’ve added registers/stack offsets for arm. But note that these are for before the prolog has executed. Arm code seems much looser about what happens in its function prologs, so there really isn’t a standard layout post-prolog
[转]Inspecting Obj-C parameters in gdb的更多相关文章
- Can't bind multiple parameters ('header' and 'parameters') to the request's content.
2019-01-23 15:46:29.012+08:00 ERROR [6]: System.InvalidOperationException: Can't bind multiple param ...
- ADO.net 更新和插入数据 遇到null 执行不成功
首先交代下背景,遇到一个问题:SqlCommand新增记录时,参数为null时,运行并不报错,只是返回(0),也就是更新失败. 在用C#往数据库里面插入记录的时候, 可能有的字段我们并不赋值(有可能是 ...
- java反编译获取源码
最近在研究反射,想做一个东西,把运行的java程序饭编译(Decompile)成.java文件.现思路如下: 1.写出程序反编译一个类 2.将所有类反编译 3.java代码注入一个正在运行的java程 ...
- 通过接口实现JAVA和.NET互调用-JNInterface
使用C#编程多年,也十分感激微软在语言架构.语法糖.编辑器等方面给自己带来的便利.但因为最近工作中有接触到JAVA,渐渐地发现的确像大家说的那样,JAVA的生态很好,要找点什么几乎都有现成的,于是自然 ...
- C# 反射之调用方法谈
反射的定义 反射提供了描述程序集.模块和类型的对象(Type 类型). 可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性. 如果代码中使用了特性 ...
- 第15章 .NET中的反射
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- C#反射基础知识和实战应用
首先来说一下什么是反射? 反射提供了封装程序集.模块和类型的对象(Type类型) 可以使用反射动态的创建类型的实例,将类型绑定到现有对象,或从现有对象中获取类型,然后,可以调用类型的方法或访问其字段和 ...
- C#语法糖之 ReflectionSugar 通用反射类
用法很简单: ReflectionSugar rs = new ReflectionSugar(100);//缓存100秒 ,可以不填默认不缓存 rs.有嘛点嘛 性能测试: 性能测试类源码: ht ...
- OracleHelper(对增删改查分页查询操作进行了面向对象的封装,对批量增删改操作的事务封装)
公司的一个新项目使用ASP.NET MVC开发,经理让我写个OracleHelper,我从网上找了一个比较全的OracleHelper类,缺点是查询的时候返回DataSet,数据增删改要写很多代码(当 ...
随机推荐
- JavaScript中的try...catch和异常处理
在JavaScript可以使用try...catch来进行异常处理.例如: try { foo.bar();} catch (e) { alert(e.name + ": " + ...
- [WPF]程序全屏
原文:[WPF]程序全屏 代码: 使用:
- Java判断当前用户数及当前登录用户数工具类-session原理
JavaWeb开发中,有时会遇到统计或管理用户登录数或者当前在线多少用户,分别都是谁的情况.当然,实现途径多种多样.下面列举一下通过session实现的一种统计. public class MySes ...
- 小结php中几种网页跳转
1.使用网页中<a href=.....></a>实现跳转: 2.<form action="php_request2.php" method=&qu ...
- CSS3可按进度变色的进度条
原文:CSS3可按进度变色的进度条 今天是周末,看到一款利用CSS3实现的进度条应用,觉得非常棒,就将它分享给大家,并且将这款CSS3进度条的实现过程大致整理了一下,实现的关键是根据当前的进度需要能改 ...
- oracle中导入导出数据备份数据库
原文:oracle中导入导出数据备份数据库 数据库所在位置 将数据导出到的文件名 用户名 备份数据库 :exp c ...
- ORA-00265: instance recovery required, cannot set ARCHIVELOG mode
症状: 我打开后归档命令报告运行错误ORA-00265 SQL> alter database archivelog; alter database archivelog * ERROR at ...
- DOM2级事件对象、添加事件、阻止默认事件、阻止冒泡事件、获取事件对象目标的兼容处理
事件对象——兼容处理 /* * 功能: 事件对象兼容 * 参数: 表示常规浏览器的事件对象e */ function getEvent(e) { // 如果存在e存在,直接返回,否则返回window. ...
- 为Pythonic论坛添加一个“专题”功能
代码还没读完就踏上了修改功能的深坑.还好思路清晰,通过修改模板和视图,实现了专题模块 原论坛的模式是用户点击节点发帖,然后就归到节点的分类里面了.我需要一个功能,就是右侧需要一个专题区,管理员发帖的话 ...
- ios 8 地图定位
在xcode6在 苹果公司定位方法改变地图,谁也无法使用 错误说明:Trying to start MapKit location updates without prompting for loca ...