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. 词组缩写(isalpha()的应用)

    Problem Description 定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写.比如,C语言里常用的EOF就是end of file的缩写.   Input 输入的第一行是一个整数 ...

  2. oracle_常用命令(表空间查询)

    ---查询表空间 对应的物理文件,名称 ,大小 ,已用的,利用率 SELECT B.FILE_NAME "FILE_NAME", B.TABLESPACE_NAME "T ...

  3. 无废话WCF入门教程四[WCF的配置文件]

    一.概述 配置也是WCF编程中的主要组成部分.在以往的.net应用程序中,我们会把DBConn和一些动态加载类及变量写在配置文件里.但WCF有所不同.他指定向客户端公开的服务,包括服务的地址.服务用于 ...

  4. Redhat Enterprise server 6.3 构造VPN

    一.软体 dkms.kernel_ppp_mppe.pptpd 二.下载软件 wget http://sourceforge.net/projects/poptop/files/mppe%20modu ...

  5. 关于webbrowser控件自动登陆的问题

    原文:关于webbrowser控件自动登陆的问题 楼主dtb(陈少)2004-03-04 22:16:55 在 VB / 网络编程 提问 请问怎么用webbrowser自动登陆www.jp168.co ...

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

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

  7. 第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介(原创)

    天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文“寻求合作伙伴编写<深入理解 MonkeyRunner>书籍“.但因为诸多原因,没有如愿.所以这里把草稿分享出来,所以错误在 ...

  8. checkbox 选择功能和反选

    使用jQuery实现checkbox全补选和反选功能.什么时候checkbox选择禁用时,不涉及功能 <!DOCTYPE html> <html> <head> & ...

  9. PHP开发API接口及使用

    服务端 <?php require 'conn.php'; header('Content-Type:text/html;charset=utf-8'); $action = $_GET['ac ...

  10. 新手可以学习cocos2dx 3.0 组态(两)

    这主要是关于cocos3.0 组态,鉴于互联网已经有很多这样的文章.所以我简单谈一下: 1.python2.7 因为cocos目新建是用python脚本做的,至于为什么不用python3.x  那么请 ...