Xcode equivalent of ' __asm int 3 / DebugBreak() / Halt?

非 Y 不嫁゛ 提交于 2019-11-28 06:52:32

http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeProjectManagement/090_Running_Programs/chapter_11_section_3.html

asm {trap}            ; Halts a program running on PPC32 or PPC64.

__asm {int 3}         ; Halts a program running on IA-32.

You can just insert a call to Debugger() — that will stop your app in the debugger (if it's being run under the debugger), or halt it with an exception if it's not.

Also, do not avoid assert() for "portability reasons" — portability is why it exists! It's part of Standard C, and you'll find it wherever you find a C compiler. What you really want to do is define a new assertion handler that does a debugger break instead of calling abort(); virtually all C compilers offer a mechanism by which you can do this.

Typically this is done by simply implementing a function or macro that follows this prototype:

void __assert(const char *expression, const char *file, int line);

It's called when an assertion expression fails. Usually it, not assert() itself, is what performs "the printf() followed by abort()" that is the default documented behavior. By customizing this function or macro, you can change its behavior.

__builtin_trap();

Since Debugger() is depreciated now this should work instead.

https://developer.apple.com/library/mac/technotes/tn2124/_index.html#//apple_ref/doc/uid/DTS10003391-CH1-SECCONTROLLEDCRASH

For posterity: I have some code for generating halts at the correct stack frame in the debugger and (optionally) pausing the app so you can attach the debugger just-in-time. Works for simulator and device (and possibly desktop, if you should ever need it). Exhaustively detailed post at http://iphone.m20.nl/wp/2010/10/xcode-iphone-debugger-halt-assertions/

I found the following in an Apple Forum:

Xcode doesn't come with any symbolic breaks built in - but they're quick to add. Go to the breakpoints window and add:

-[NSException raise]

kill(getpid(), SIGINT);

Works in the simulator and the device.

There is also the following function that is available as cross platform straight Halt() alternative:

#include <stdlib.h>

void abort(void);

We use it in our cross platform engine for the iPhone implementation in case of fatal asserts. Cross platform across Nintendo DS/Wii/XBOX 360/iOS etc...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!