<p>What's the instruction to cause a hard-break in Xcode? For example under Visual Studio I could do '_asm int 3' or 'DebugBreak()'. Under some GCC implementations it's asm("break 0") or asm("trap").</p>

<p>I've tried various combos under Xcode without any luck. (inline assembler works fine so it's not a syntax issue).</p>

<p>For reference this is for an assert macro. I don't want to use the definitions in assert.h both for portability, and because they appear to do an abort() in the version XCode provides.</p>

<hr>

<p>John - Super, cheers. For reference the int 3 syntax is the one required for Intel Macs and iPhone.</p>

<hr>

<p>Chris - Thanks for your comment but there are many reasons to avoid the standard assert() function for codebases ported to different platforms. If you've gone to the trouble of rolling your own assert it's usually because you have additional functionality (logging, stack unwinding, user-interaction) that you wish to retain.</p>

<p>Your suggestion of attempting to replace the hander via an implementation of '__assert" or similar is not going to be portable. The standard 'assert' is usually a macro and while it may map to __assert on the Mac it doesn't on other platforms.</p>

[{'answer_id': 37303, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 2, 'selected': False, 'text': '<p>I found the following in an <a href="http://lists.apple.com/archives/Cocoa-dev/2003/Nov/msg00166.html" rel="nofollow noreferrer">Apple Forum</a>:</p>\n\n<blockquote>\n  <p>Xcode doesn\'t come with any symbolic breaks built in - but they\'re\n  quick to add. Go to the breakpoints window and add:</p>\n  \n  <p>-[NSException raise]</p>\n</blockquote>\n'}, {'answer_id': 37304, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 6, 'selected': True, 'text': '<p><a href="http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeProjectManagement/090_Running_Programs/chapter_11_section_3.html" rel="noreferrer">http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeProjectManagement/090_Running_Programs/chapter_11_section_3.html</a></p>\n\n<pre><code>asm {trap}            ; Halts a program running on PPC32 or PPC64.\n\n__asm {int 3}         ; Halts a program running on IA-32.\n</code></pre>\n'}, {'answer_id': 38546, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 4, 'selected': False, 'text': '<p>You can just insert a call to <code>Debugger()</code> — 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.</p>\n\n<p>Also, <strong>do not avoid <code>assert()</code> for "portability reasons"</strong> — 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 <em>assertion handler</em> that does a debugger break instead of calling <code>abort()</code>; virtually all C compilers offer a mechanism by which you can do this.</p>\n\n<p>Typically this is done by simply implementing a function or macro that follows this prototype:</p>\n\n<pre><code>void __assert(const char *expression, const char *file, int line);\n</code></pre>\n\n<p>It\'s called when an assertion expression fails.  Usually it, not <code>assert()</code> itself, is what performs "the <code>printf()</code> followed by <code>abort()</code>" that is the default documented behavior.  By customizing this function or macro, you can change its behavior.</p>\n'}, {'answer_id': 720381, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>There is also the following function that is available as cross platform straight Halt() alternative:</p>\n\n<pre><code>#include &lt;stdlib.h&gt;\n\nvoid abort(void);\n</code></pre>\n\n<p>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...</p>\n'}, {'answer_id': 5800922, 'author': 'Steven Kramer', 'author_id': 473067, 'author_profile': 'https://Stackoverflow.com/users/473067', 'pm_score': 2, 'selected': False, 'text': '<p>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 <a href="http://iphone.m20.nl/wp/2010/10/xcode-iphone-debugger-halt-assertions/" rel="nofollow">http://iphone.m20.nl/wp/2010/10/xcode-iphone-debugger-halt-assertions/</a></p>\n'}, {'answer_id': 6205564, 'author': 'Sonny Saluja', 'author_id': 539115, 'author_profile': 'https://Stackoverflow.com/users/539115', 'pm_score': 2, 'selected': False, 'text': '<pre><code>kill(getpid(), SIGINT);\n</code></pre>\n\n<p>Works in the simulator and the device.</p>\n'}, {'answer_id': 12321843, 'author': 'Tod', 'author_id': 16679, 'author_profile': 'https://Stackoverflow.com/users/16679', 'pm_score': 3, 'selected': False, 'text': '<pre><code>__builtin_trap();\n</code></pre>\n\n<p>Since Debugger() is depreciated now this should work instead.</p>\n\n<p><a href="https://developer.apple.com/library/mac/technotes/tn2124/_index.html#//apple_ref/doc/uid/DTS10003391-CH1-SECCONTROLLEDCRASH" rel="noreferrer">https://developer.apple.com/library/mac/technotes/tn2124/_index.html#//apple_ref/doc/uid/DTS10003391-CH1-SECCONTROLLEDCRASH</a></p>\n'}]
['https://Stackoverflow.com/questions/37299', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1043/']