原文:http://www.russbishop.net/xcode-exception-breakpoints

Many people are not aware of Xcode's powerful features for managing breakpoints during debugging. One such feature is the Exception breakpoint. Go to the Breakpoint navigator pane, click +, then click Add Exception Breakpoint. Cool, now you'll break right at any exception, instead of in main() long after the context has been lost.

However if you happen to use CoreData, you'll discover that it throws and catches exceptions internally as a form of stack unwinding and control flow which makes debugging such an application highly annoying. You can fix that by excluding all CoreData exceptions. First remove the All Exceptions breakpoint, then and add a new Symbolic breakpoint on objc_exception_throw, then set a condition on the Breakpoint for (BOOL)(! (BOOL)[[(NSException *)$eax className] hasPrefix:@"_NSCoreData"]).

That works just fine... on the 32-bit simulator or a 32-bit Mac application. Unfortunately the register names are quite different on 64-bit Intel and both 32-bit and 64-bit ARM:

Architecture Exception Register
x86 $eax
x86-64 $rdi
ARM $r0
ARM-64 $x0

We could create an lldb Python script to help us figure out the proper register and setup exception exclusions, but fortunately poster chendo over on StackOverflow has done the work for us.

Just create the script as shown in the answer and hook it up in your ~/.lldbinit. Then you can create the vanilla All Exceptions breakpoint, but make the first action your ignore script with the proper parameters. During execution the breakpoint will be hit, but Xcode will run the command causing it to immediately resume execution. This delay would be intolerable in a tight loop, but exceptions should be exceptional events so the performance should be perfectly acceptable.

This also highlights some awesome power debugging features many people don't take advantage of; if you can script it in Python, you can make Xcode do it for you automatically. Just setup your breakpoint conditions and have Xcode launch one or more scripts in response. You dump network responses, log all initializer parameters for a certain class, and many other things without having to include that code explicitly in every project and gate it behind preprocessor flags.

[1] Who clicks on these kinds of advertisements!? My pet theory is they're designed to weed out those with intelligence and common sense to ensure only the most gullible people become sales leads.

 

 

[转]http://www.russbishop.net/xcode-exception-breakpoints的更多相关文章

  1. IOS调试技巧:当程序崩溃的时候怎么办 xcode调试

    转自:http://www.ityran.com/archives/1143 ------------------------------------------------ 欢迎回到当程序崩溃的时候 ...

  2. Xcode 的正确打开方式——Debugging

    程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不可避免地需要使用 Xcode.这篇博客就主要介绍了 Xcode 中几种能够大幅提升代码调试效率的方式. “If debuggi ...

  3. 【转】 当程序崩溃的时候怎么办 Part-2

    转自:http://www.tairan.com/archives/1143 欢迎回到当程序崩溃的时候怎么办 教程! 在这个教程的第一部分,我们介绍了SIGABRT和EXC_BAD_ACCESS错误, ...

  4. [ios-必看] IOS调试技巧:当程序崩溃的时候怎么办 iphone IOS

    from:http://article.ityran.com/archives/1143 有这样一种情形:当我们正在快乐的致力于我们的app时,并且什么看都是无比顺利,但是突然,坑爹啊,它崩溃了.(悲 ...

  5. 【转】你所不知道的Android Studio调试技巧

    这篇写Android studio debug技巧个人觉得写得不错,转自:http://www.jianshu.com/p/011eb88f4e0d# Android Studio目前已经成为开发An ...

  6. Eclipse Debug

    [IT168 专稿]调试的方法虽然千千万万,但归根结底,就是找到引发错误的代码.Eclipse调试器的目标是让程序员能对本地或远程程序进行错误侦测与诊断.该调试器提供所有标准调试功能,包括进行单步执行 ...

  7. 你所不知道的Android Studio调试技巧

    转载:http://www.jianshu.com/p/011eb88f4e0d Android Studio目前已经成为开发Android的主要工具,用熟了可谓相当顺手.作为开发者,调试并发现bug ...

  8. 在Intellij IDEA中使用Debug

    Debug用来追踪代码的运行流程,通常在程序运行过程中出现异常,启用Debug模式可以分析定位异常发生的位置,以及在运行过程中参数的变化.通常我们也可以启用Debug模式来跟踪代码的运行流程去学习三方 ...

  9. idea之debug

    [转载]原文地址:https://www.cnblogs.com/nihaorz/p/7613967.html 在Intellij IDEA中使用Debug Debug用来追踪代码的运行流程,通常在程 ...

  10. debug2

    调试常用功能介绍 日常java开发中实际写代码的时间并不会很多,花在整理思路,代码重构,调试bug会占用很大部分时间. 熟练掌握调试工具,了解调试相关技巧,是java开发中减少调试时间,提高效率不可或 ...

随机推荐

  1. python_random随机

    在数据清洗,评估 ,抽验等等过程中,经常有这样的应用场景 : 需要在一个大的数据集合中随机出来样本,进行人工评估.为了保证足够随机,借助脚本来实现. 下面一个脚本  ,用于应对这种应用场景. 使用方法 ...

  2. <七>阅读<<大话设计模式>>该模板模型

    哈哈,没想到.在不知不觉中拥有第七书面文章,看来我仍然非常有毅力. 上坚持一件事非常easy,仅仅要你每天不断的朝着自己的目标出发,不论什么事情都不会挡着你.好了大道理不多说,谁都懂.那看看这个模板模 ...

  3. 将图片转为ASCII字符画

    原文:将图片转为ASCII字符画 Copyright 2012 Conmajia 源代码下载:点击这里 什么是字符画?就是用ASCII字符来近似组成图像,就像这样: ╭╮ ╭╮ ││ ││ ╭┴┴—— ...

  4. 【百度地图API】如何制作班级地理通讯录?LBS通讯录

    原文:[百度地图API]如何制作班级地理通讯录?LBS通讯录 摘要:班级通讯录必备的功能,比如人员列表,人员地理位置标注,展示复杂信息窗口,公交和驾车等.一般班级人员都不会超过300个,因为可以高效地 ...

  5. linq 分组求和

    static void Main()         {             DataTable dt = new DataTable();             dt.Columns.Add( ...

  6. What is HHVM?

    What is HHVM? HHVM is an open-source virtual machine designed for executing programs written in Hack ...

  7. addEventListener 与attachEvent

    第一:简单的通用方法(IE && FF) window.onload = function(){ var oDiv = document.getElementById("J_ ...

  8. navicat连接oracle一个错误:ORA-12737 Instant Client Light:unsupported server character set ZHS16GBK

    今天使用Navicat连接Oracle数据库.它报告了以下错误:"ORA-12737 Instant Client Light:unsupported server character se ...

  9. SQL点滴29—错误无处不在

    原文:SQL点滴29-错误无处不在 我只想说以下是很基础的sql知识,但是很容易犯错.所以睁大我们的眼睛,屏住我们的呼吸,小心的检查吧! 案例1if not exists (select OrderI ...

  10. Mysql插入内容过长(Packet for query is too large)

    原文:Mysql插入内容过长(Packet for query is too large) 这个以前一直没有碰到过,一次性向Mysql数据库插入内容过长的话会出现这个问题,解决办法就是在Mysql配置 ...