Break on exception in Xcode

本文介绍了如何在使用Xcode进行开发时,配置其在出现异常时能够打断并准确显示异常发生的代码行,通过设置特定的符号断点来解决在Visual Studio中常见的异常处理问题。

原贴地址 http://blog.emmerinc.be/index.php/2009/03/19/break-on-exception-in-xcode/

One of the issues I encountered switching to Xcode, coming from Visual Studio, was related to exceptions. When an exception occurs in Visual Studio it breaks and shows the exact line that caused the exception, but by default Xcode has a different behaviour. When an exception occurs, some kind of general message is shown like “_objc_error”, “EXC_BAD_ACCESS” or “___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___” and no real indication is given where it happened. Stepping through your code to find the faulty line is time consuming and plain stupid.

Luckily you can configure Xcode to break on exception and here’s how. Let me first give you a little bit of background, when the compiler compiles your application in debug-mode, it adds extra information (called symbols) to the executable enabling Xcode to map the running statements to lines of code. This adds some overhead and is the reason (or one of the) why you shouldn’t deploy your application in debug-mode, but rather in release-mode (without the symbols).

That being said, let’s get to the interesting part, Xcode supports 2 kinds of breakpoints: (normal) breakpoints which are placed on a certain line and symbolic breakpoints. Chances are that you’ve worked with normal breakpoints hundreds of times, without knowing there was another type.

Symbolic breakpoints are breakpoints based on the method name instead of the line number of a file, the advantage of this is that the exact location of the method does not have to be known. Open the breakpoints window (Run – Show – Breakpoints) and add two symbolic breakpoints called “objc_exception_throw” and “[NSException raise]“. If you choose to make them in the Global group, they are available in all your projects while the Project group applies to the current project.

Symbolic Breakpoints

These two methods are used to throw an exception, the first one being the most recent style and the latter being the “old & traditional” style, for simplicity’s sake. If you run your code and a exception is raised your code will stop, just like it used to do without the extra symbolic breakpoints. But if you open the debugger (Run – Debugger) and browse the callstack, you should be able to locate the faulty line, which is displayed with a black font color, while the others are light gray. Click on it and your source code will be shown with the “exception throwing line” highlighted. While it’s not as fast/easy like Visual Studio which shows the baddie immediately, looking it up in the debugger works too, right?

Debugger

Important: while I’ve had great success with this, there have been times when the symbolic breakpoints did not work. The debugger would show the raw statements in the callstack when an exception occured, which is the behaviour without the symbolic breakpoints. I have been able to “fix” this by adding a normal breakpoint (I’ve put it in the method where the exception occured, but I think you can put the breakpoint anywhere) and running the code again, afterward the normal breakpoint could be deleted and the symbolic breakpoints would continue to work. I think it might have something to do with the normal breakpoint causing Xcode to load and/or process all the breakpoints or it’s just me doing something wrong. If anyone knows more about this issue, let me know in the comments.

内容概要:本文围绕“基于最优控制的固定翼飞机着陆控制器设计”展开研究,利用Matlab代码实现相关控制算法的仿真与验证。研究聚焦于飞行器在着陆阶段的动力学建模与最优控制策略设计,通过构建精确的六自由度非线性运动学与动力学模型,结合现代控制理论中的线性二次型调节器(LQR)等最优控制方法,设计出能够有效提升着陆精度、稳定性和抗干扰能力的自动着陆控制器。文中系统阐述了飞行器建模、平衡点分析、小扰动线性化、控制律设计、仿真环境搭建及多工况下的动态响应与性能指标分析全过程,旨在为航空器自动着陆系统的设计与优化提供坚实的理论依据和技术参考。; 适合人群:具备自动控制理论基础、飞行力学背景及Matlab/Simulink仿真能力的高校研究生、科研人员及航空航天领域工程师。; 使用场景及目标:①用于固定翼飞机自动着陆系统的设计与仿真验证;②作为最优控制理论在高阶复杂非线性系统中应用的教学案例;③为飞行控制算法的工程化研究与开发提供完整的技术路线与实现范例。; 阅读建议:建议读者结合Matlab代码与文中理论推导同步阅读,重点关注系统建模的物理假设、线性化条件、控制目标设定及多维度仿真结果的动态响应分析,有条件者可自行复现仿真以深化对最优控制策略设计与系统性能评估的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值