Display runtime error message on a specific line in Xcode

I would like to display a custom runtime error message in Xcode in C / C ++ code. This can be used, for example, for the user-defined function assert ().

I would like to display an inline message like SenTestingKit:

SenTestingKit

Currently, the only thing I can do is use __builtin_trap to stop on the correct line. But an individual error message is not displayed.

__builtin_trap

+6
source share
1 answer

I am not familiar with xcode, but here is how it is done almost everywhere. Your user statement will look like this:

 #define MY_ASSERT(a1, a2, desc, ...) {\ PrintAssertMessage(...); \ DebugBreak(); \ } 

The windows already have the DebugBreak function in the win32 API. On Linux and most other systems that run IA32 / X64, you can simply call int 3, which is an interrupt trap.

 asm ("int 3"); 

I read that in xcode this is:

 __asm {int 3} 

or

 __asm__("int $3") 

or

 __asm__("trap") 

In any case, this should be surrounded by a macro that also disables the statement in debug builds, as well as a macro that defines how to call a breakpoint.

0
source

Source: https://habr.com/ru/post/957207/


All Articles