int AmIBeingDebugged(void) { int mib[4]; struct kinfo_proc info; size_t size; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = getpid(); size = sizeof(info); info.kp_proc.p_flag = 0; sysctl(mib,4,&info,&size,NULL,0); return ((info.kp_proc.p_flag & P_TRACED) == P_TRACED); } #define StopIfInDebugger() __asm__ volatile ("twnei %0,0" : : "r" (AmIBeingDebugged()))(courtesy of arwyn on #macdev. Useful uses: controlling voluminous console output when running in gdb, or if running non-debugged, an assert routine that generates stack trace and logs it when not-being debugged, but just traps into the debugger at the point of failure when being debugged)
gdb
There are two ways to enable core files:
% limit coredumpsize unlimited
.cshrc
. I don't know what to do for bash
)
struct rlimit corelimit = { RLIM_INFINITY, RLIM_INFINITY };
setrlimit (RLIMIT_CORE, &corelimit);
You may need to also add#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
Core files seem to be getting dumped into /cores
, rather than the directory the program was run from.
/System/Library/Frameworks/Foundation.framework/Headers/NSDebug.h
. Lots of low-level unsupported APIs for mucking around with gory technical details.Put this somewhere convenient to trigger - in a timer, under a button, or something. Obviously, you don't want to ship with it.
[[UIApplication sharedApplication] performSelector:@selector(_receivedMemoryNotification)];
% defaults write com.apple.CrashReporter DialogType none
Turn turn it back on, replace none
with prompt
to get the original behavior. See for details.
fprintf
% gdb build/Debug/Snorkfizzle.app/Contents/MacOS/Snorkfizzle (gdb) set env NSZombieEnabled=YES (gdb) fb -[_NSZombie methodSignatureForSelector:] (gdb) runThen exercise your app and trip the error.
(gdb) thread apply all where
(gdb) fb -[NSTextView drawRect:]
b objc_msgSend comm silent printf "%c[%s %s]\n", $r3&&((id)$r3)->isa->info&2?'+':'-', $r3?((id)$r3)->isa->name:"nil", $r4 cont end b objc_msgSend_rtp comm silent printf "%c[%s %s]\n", $r3&&((id)$r3)->isa->info&2?'+':'-', $r3?((id)$r3)->isa->name:"nil", $r4 cont endAnd you'll get some output like this:
-[NSTableColumn _bindingAdaptor] +[NSBinder binderClassesForObject:] +[NSBinder _allBinderClasses] +[NSDisplayPatternTitleBinder isUsableWithObject:] +[NSBox self](courtesy of Rob Mayoff)