3

Attempting to debug an NPAPI plugin by attaching to the plugin process does not appear to work in 10.11.

Attaching with lldb reveals:

sudo lldb -p 39337
(lldb) process attach --pid 39337
error: attach failed: unable to attach

This seems to affect both 'legacy' webkit used for embedded Webkit (with plugin host named WebKitPluginHost) and 'modern' webkit used in safari (with plugin host named com.apple.WebKit.Plugin.64)

I have disabled the "Debugging Restrictions" using csrutil in recovery mode, but that does not appear to help in this case.

harningt
  • 709
  • 7
  • 19
  • I have the same problem trying to debug Perl extensions. Running the system `perl` under `lldb` returns `error: process exited with status -1 (unable to attach)` even after disabling debugging restrictions. – nwellnhof Jun 14 '16 at 08:52
  • A workaround for perl is to copy the perl binary out of /usr/bin an run using that. Many applications can be attached to in this fashion (just not mine because the browser directly launches it). – harningt Jun 15 '16 at 15:43

1 Answers1

0

I haven't tried it specifically in 10.11, but I find the easiest way is to add a blocking section to wait for your plugin to be debugged in the startup code:

#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;
}
#endif

then in startup code somewhere:

#if WAIT_FOR_DEBUGGER
    #warning "WILL BLOCK ON P_TRACED"
    while (!beingDebugged())
        sleep(1);
#endif

If you have trouble finding the right process to connect to you could have this also output the PID to a file so you can read and find it.

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • That is a useful item, however debugging protections in the system prevent anything from attaching to the determined plugin processes. – harningt Jun 13 '16 at 16:41
  • Interesting; that must be new. I haven't tried it recently in Safari since all of my plugins are still working correctly so far =] – taxilian Jun 13 '16 at 22:08