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的更多相关文章

  1. 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 ...

  2. ADO.net 更新和插入数据 遇到null 执行不成功

    首先交代下背景,遇到一个问题:SqlCommand新增记录时,参数为null时,运行并不报错,只是返回(0),也就是更新失败. 在用C#往数据库里面插入记录的时候, 可能有的字段我们并不赋值(有可能是 ...

  3. java反编译获取源码

    最近在研究反射,想做一个东西,把运行的java程序饭编译(Decompile)成.java文件.现思路如下: 1.写出程序反编译一个类 2.将所有类反编译 3.java代码注入一个正在运行的java程 ...

  4. 通过接口实现JAVA和.NET互调用-JNInterface

    使用C#编程多年,也十分感激微软在语言架构.语法糖.编辑器等方面给自己带来的便利.但因为最近工作中有接触到JAVA,渐渐地发现的确像大家说的那样,JAVA的生态很好,要找点什么几乎都有现成的,于是自然 ...

  5. C# 反射之调用方法谈

    反射的定义 反射提供了描述程序集.模块和类型的对象(Type 类型). 可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性. 如果代码中使用了特性 ...

  6. 第15章 .NET中的反射

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  7. C#反射基础知识和实战应用

    首先来说一下什么是反射? 反射提供了封装程序集.模块和类型的对象(Type类型) 可以使用反射动态的创建类型的实例,将类型绑定到现有对象,或从现有对象中获取类型,然后,可以调用类型的方法或访问其字段和 ...

  8. C#语法糖之 ReflectionSugar 通用反射类

    用法很简单: ReflectionSugar rs = new ReflectionSugar(100);//缓存100秒 ,可以不填默认不缓存 rs.有嘛点嘛   性能测试: 性能测试类源码: ht ...

  9. OracleHelper(对增删改查分页查询操作进行了面向对象的封装,对批量增删改操作的事务封装)

    公司的一个新项目使用ASP.NET MVC开发,经理让我写个OracleHelper,我从网上找了一个比较全的OracleHelper类,缺点是查询的时候返回DataSet,数据增删改要写很多代码(当 ...

随机推荐

  1. Java串口通信详细解释

    前言 说到开源.恐怕非常少有人不挑大指称赞. 学生通过开源码学到了知识,程序猿通过开源类库获得了别人的成功经验及可以按时完毕手头的project,商家通过开源软件赚到了钱……,总之是皆大欢喜. 然而开 ...

  2. JS function立即调用的几种写法

    //立即执行 (function () { alert(1) })() //立即执行 !function () { alert(1) }() //立即执行 +function () { alert(1 ...

  3. VS2015前端工具:NPM和Web Essentials

    VS2015前端工具:NPM和Web Essentials 1.写作背景 想在5月份前换个工作环境了,“检讨”一下自己混饭的技术水平和处世的人脉关系,觉得很不给力!为人方面,人各有志也就不纠结了,但本 ...

  4. iOS 学习资料汇总

    (适合初学者入门) 本文资料来源于GitHub 一.视频教程(英文) Developing iOS 7 Apps for iPhone and iPad斯坦福开放教程之一, 课程主要讲解了一些 iOS ...

  5. 国籍控件(js源码)

    国籍控件(js源码) 一直苦于没有好的国籍控件可以用,于是抽空写了一个国籍控件,现分享给大家. 主要功能和界面介绍 国籍控件主要支持中文.英文过滤以及键盘上下事件. 源码介绍 国籍控件核心是两个文件, ...

  6. 关于ios的autoLayout的一些简单介绍以及使用方法

    一.autoLayout的用途: 主要用于屏幕适配,尤其是出现了iphone6,plus之后. 二.怎么简单的用autoLayout呢? 点击左一,可以看到: 点击左二: 基本上要想autolayou ...

  7. 访问Google神器,魔高一尺,道高一丈!

    最近谷歌的IP被大范围的禁用了.身处一个连谷歌都用不了的过度的程序员,深感命运多舛.幸好,魔高一尺,道高一丈.下面是几种可以使用谷歌的方法. 方法一 1)在chrome浏览器中输入:chrome:// ...

  8. Backup and Recovery Strategies1

    2.1.Data Recovery Strategy Determines Backup Strategy 在设计备份策略.如若数据恢复需求和数据恢复战略启动.每种类型的数据恢复需要你采取相应的备份类 ...

  9. 【转】NuGet的安装与使用

    学习了一段时间的MVC,今天想自己尝试初步搭建一个MVC框架,结果新建MVC4.0(MVC3.0同样)项目时,弹出一个错误提示框,如下图.上网一搜,说是要安装一个第三方组件NuGet.刚接触MVC,更 ...

  10. jekyll bootstrap搭建github blog

    前提你必须有一个GitHub账号且本机安装有Git 一.创建一个新的仓库 去你的https://github.com主页新建一个仓库 名字为USERNAME.github.com USERNAME为你 ...