One of the methods I used sometimes with FireBreath is this:
#if WAIT_FOR_DEBUGGER static bool beingDebugged() { int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; size_t mib_size = 4; struct kinfo_proc kp; size_t kp_size = sizeof(kp); int result = sysctl(mib, mib_size, &kp, &kp_size, NULL, 0); return (0 == result) ? (P_TRACED & kp.kp_proc.p_flag) : false; }
Then at one of the entry points (for example, NP_Initialize) you will do:
#if WAIT_FOR_DEBUGGER #warning "WILL BLOCK ON P_TRACED" while (!beingDebugged()) sleep(1); #endif
My friend came up with this and it seems to work very well. However, you should be aware that in Safari 5.1 the browser will kill the plugin (send SIG_KILL) after a (rather short) time so as not to get a response from it. Because of this, it is almost impossible to debug with Safari 5.1; Because of this, I highly recommend that you debug Firefox or Chrome.
This will make the plugin wait for your debugger to connect. Note that in Safari 5.1 the name of the plugin process has changed; I forgot that itβs accurate now, but itβs definitely not in order, and itβs not Safari =]
The other day Iβll talk about this in the default Firebreath file np_mainmain.cpp ....
source share