http://blog.csdn.net/chenyong05314/article/details/42121001

2014-12-24 10:49 878人阅读 评论(0) 收藏 举报

转载自:  http://iloss.me/post/kai-fa/2014-12-09-objc_msgsend

之前一直用objc_msgSend,但是没注意apple的文档提示,所以突然objc_msgSend crash了。

之前32位的时候没问题,然后转换为64位之后就会发生EXC_BAD_ACCESS问题。

当然apple再文档(64-Bit Transition Guide for Cocoa Touch中有)中也有提到:

  1. Dispatch Objective-C Messages Using the Method Functions Prototype
  2. An exception to the casting rule described above is when you are calling the objc_msgSend function or any other similar functions in the Objective-C runtime that send messages. Although the prototype for the message functions has a variadic form, the method function that is called by the Objective-C runtime does not share the same prototype. The Objective-C runtime directly dispatches to the function that implements the method, so the calling conventions are mismatched, as described previously. Therefore you must cast the objc_msgSend function to a prototype that matches the method function being called.
  3. Listing 2-14 shows the proper form for dispatching a message to an object using the low-level message functions. In this example, the doSomething: method takes a single parameter and does not have a variadic form. It casts the objc_msgSend function using the prototype of the method function. Note that a method function always takes an id variable and a selector as its first two parameters. After the objc_msgSend function is cast to a function pointer, the call is dispatched through that same function pointer

你必须先定义原型才可以使用,这样才不会发生崩溃

  1. id Fun(int x,id y,...);
  2. id (*action)(int,id) = (id (*)(int,id)) Fun;
  3. action(1,@"s");

如果没有返回值id改为void

原来我们这么写:

  1. objc_msgSend(self,@selector(doSomething:), 0);

按照apple的规范:

  1. - (int) doSomething:(int) x { ... }
  2. - (void) doSomethingElse {
  3. int (*action)(id, SEL, int) = (int (*)(id, SEL, int)) objc_msgSend;
  4. action(self, @selector(doSomething:), 0);
  5. }

最终简化之后64位调用:

  1. ((void(*)(id, SEL,int))objc_msgSend)(self, @selector(doSomething:), 0);

objc_msgSend arm64 崩溃问题的更多相关文章

  1. 漫谈iOS Crash收集框架

    漫谈iOS Crash收集框架   Crash日志收集 为了能够第一时间发现程序问题,应用程序需要实现自己的崩溃日志收集服务,成熟的开源项目很多,如 KSCrash,plcrashreporter,C ...

  2. 如何看iOS崩溃日志

    重点:Triggered by Thread这句话后边的线程号,快速定位问题出现在那个线程,是否是你的锅:Triggered by Thread所指的线程表示导致异常.崩溃的线程 下边内容转自简书 简 ...

  3. iOS----- Crash 分析(文三)- 符号化崩溃日志

    未符号化的崩溃日志就象一本天书,看不懂,更别谈分析崩溃原因了.所以我们在分析日志之前,要把日志翻译成我们可以看得懂的文字.这一步我们称之为符号化. 在iOS Crash分析(文一)中已经提到过符号化的 ...

  4. iOS 崩溃日志 Backtrace的符号化

    iOS的崩溃日志配合dsym文件可以找到崩溃时的backtrace,这是解决崩溃的最重要的信息. 如果是在同一台mac上打包, 导入crash log时候会自动将backtrace符号化,可以看到方法 ...

  5. 使用dSYM分析App崩溃日志

    前言 我们在开发App过程中,因为连接到控制台,所以遇到问题会很容易找到问题代码.但是对于线上的App出现Crash的时候,我们不可能通过这种方式,也不现实,所以我们只能通过收集Crash信息,来解决 ...

  6. iOS崩溃日志分析

    Incident Identifier: 55864905-937C-4172-B435-2ACA13D3070ECrashReporter Key: b85cab13431711060a5fab55 ...

  7. iOS崩溃日志分析-b

    1名词解释 1.1. UUID 一个字符串,在iOS上每个可执行文件或库文件都包含至少一个UUID,目的是为了唯一识别这个文件. 1.2. dwarfdump 苹果提供的命令行工具,其中一些功能就是查 ...

  8. iOS应用崩溃日志分析-备用

    作为一名应用开发者,你是否有过如下经历?   为确保你的应用正确无误,在将其提交到应用商店之前,你必定进行了大量的测试工作.它在你的设备上也运行得很好,但是,上了应用商店后,还是有用户抱怨会闪退 ! ...

  9. 友盟崩溃日志分析工具 - dSYMTools

    公司的项目中集成了UM的统计功能,UM统计可以统计app的用户新增,版本分布,日志崩溃等信息,打开错误分析按钮,则可能会看到很多崩溃的日志信息 选择编辑可以选择更多的版本号 点击列表中的一个崩溃日志, ...

随机推荐

  1. git部署详解

    1.1 关于版本控制 1.1.1 本地版本控制 本地版本控制系统 许多人习惯用复制整个项目目录的方式来保存不同的版本,或许还会改名加上备份时间以示区别.这么做唯一的 好处就是简单,但是特别容易犯错.有 ...

  2. [模板]BZOJ4756线段树合并

    题面 Solution: 板子不解释 #include <iostream> #include <algorithm> #include <cstdio> #inc ...

  3. Ubuntu16.04 + CUDA9.0 + cuDNN7.3 + Tensorflow-gpu-1.12 + Jupyter Notebook 深度学习环境配置

    目录 一.Ubuntu16.04 LTS系统的安装 二.设置软件源的国内镜像 1. 设置方法 2.关于ubuntu镜像的小知识 三.Nvidia显卡驱动的安装 1. 首先查看显卡型号和推荐的显卡驱动 ...

  4. 装机、UEFI双系统安装

    装机设置 设置默认中图标显示查看-选项-查看-应用到文件夹 控制面板-语言-管理输入法 word-选项-取消输入法设置处于活动状态word-字体-设置默认值 高DPI的显示屏,需要使用125%的缩放, ...

  5. 传输控制层协议TCP概述---抄书

    1.TCP的主要特点 TCP是TCP/IP体系中非常复杂的一个协议.下面介绍TCP的最主要的特点. (1)TCP是面向连接的运输层协议.也就是说,应用程序在使用TCP协议之前,必须先建立TCP连接.在 ...

  6. redis的认识

    <?php /* Redis优势: 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s . 丰富的数据类型 – Redis支持二进制案例的 String, Lis ...

  7. 走进Android系统

    一.Android背景 [Android定义] Android是Google公司在2007年11月5日公布的基于Linux平台的开源手机操作系统. [发展历程] 2005年,Google收购企业And ...

  8. PAT 1086 就不告诉你

    https://pintia.cn/problem-sets/994805260223102976/problems/1038429065476579328 做作业的时候,邻座的小盆友问你:“五乘以七 ...

  9. shit element ui & form password validation

    shit element ui & form password validation shit docs https://github.com/yiminghe/async-validator ...

  10. react router路由传参

    今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...