I would like to display custom error message during runtime in Xcode in C/C++ code. This could be used for example for custom assert() function.
I would like to display message inline, like SenTestingKit does:
Right now the only thing I can do is use __builtin_trap
to stop at the correct line. But no custom error message is displayed.
I'm not familiar with xcode but here's how it's done almost everywhere else. Your custom assert will look like this:
#define MY_ASSERT(a1, a2, desc, ...) {\
PrintAssertMessage(...); \
DebugBreak(); \
}
In windows there's already a DebugBreak function in win32 API. In Linux and most other systems that run IA32/X64 you can simply call int 3 which is the breakpoint trap.
asm ("int 3");
I read that in xcode it's:
__asm {int 3}
or
__asm__("int $3")
or
__asm__("trap")
In any case this should be surrounded by a macro that disables the assert in debug builds as well macro that defines how to cause a break point.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.