[转]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,数据增删改要写很多代码(当 ...
随机推荐
- AJAX 怎样在一个UpDatePanel中刷新另一个updatePanel
原文:AJAX 怎样在一个UpDatePanel中刷新另一个updatePanel 在页面上(.aspx)<asp:UpdatePanel ID="MyID1" runat= ...
- BIEE在creating domain步骤停止的解决的方法
1.错误现象: biee11g creating domain csf entries will not be parsed since the adminserver is unreachable ...
- ABP模块系统
ABP模块系统 基于DDD的现代ASP.NET开发框架--ABP系列之4.ABP模块系统 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ABP ...
- opencv2对于读书笔记——二值化——thresholded功能
opencv二进制图象值功能threshold功能 其结构 double cv::threshold( //二值化函数 const CvArr* src, //原始图像 CvArr* dst, //输 ...
- mac_Alfred_快捷设置
1.安装(不说了去 Google 吧) 2.基础快捷键:option+space 3.打开应用程序:Alfred 几乎是一切程序的入口,你再也不需要找妈妈要开始菜单了.用快捷键呼出Alfred,输入任 ...
- 进程切换switch_to宏第三个参数分析
进程切换一般都涉及三个进程,如进程a切换成进程b,b开始执行,但是当a恢复执行的时候往往是通过一个进程c,而不是进程b. 注意switch_to的调用: switch_to(prev,next,pre ...
- webkit的几个属性
-webkit-text-size-adjust 1.当样式表里font-size<12px时,中文版chrome浏览器里字体显示仍为12px,这时可以用 html{-webkit-text-s ...
- Oracle SqlPlus 方向键的方法和解决的退格键失效
SqlPlus中退格键和方向键的设置 在刚装好的Oracle中,我们使用SqlPlus会发现很的蹩脚,不仅退格键不好用,方向键也不行调出history.以下有几种解决方法. 1.能够使用ctrl+Ba ...
- ViewPaper实现轮播广告条
使用V4包中的viewPaper组件自己定义轮播广告条效果. 实现viewpaper的滑动切换和定时自己主动切换效果. 上效果图 布局文件 <RelativeLayout xmlns:andro ...
- Visual Studio 中的单元测试 UNIT TEST
原文:Visual Studio 中的单元测试 UNIT TEST 注:本文系作者原创,可随意转载,但请注明出处.如实在不愿注明可留空,强烈反对更改原创出处.TDD(Test-Driven Devel ...