4

I have an NPAPI plug in running on OS X 10.6.8 that I'd like to debug. When I load it using FireFox 3.6.19, I can set the active executable to FF, start FF, attach using XCode, and the breakpoint will fire at the expected time.

When using Safari 5.1, I see that the plug in runs out of process, so I created and activated a customer executable for /System/Library/PrivateFrameworks/WebKit2.framework/PluginProcess.app. I then start Safari, navigate to the page hosting the plug in, attach to the plug in process, and then use the UI such the breakpoint should fire, but it doesn't. I can tell by the UI that the plug in definately loaded. If the pause the process, I see:

(gdb) i b
Num Type           Disp Enb Address    What
1   breakpoint     keep y   <PENDING>  "ADP_NPAPI_Interface.m":34
2   breakpoint     keep y   <PENDING>  "ADP_NPAPI_Interface.m":34
3   breakpoint     keep y   <PENDING>  "ADP_NPAPI_Interface.m":34
4   breakpoint     keep y   <PENDING>  "plugin.cpp":244
5   breakpoint     keep y   <PENDING>  "plugin.cpp":358
6   breakpoint     keep y   <PENDING>  objc_exception_throw
(gdb) show directories
Source directories searched: $cdir:$cwd
(gdb) info sources
No symbol table is loaded.  Use the "file" command.
(gdb) file sources
sources: No such file or directory
(gdb) info file
No registers.
No registers.
(gdb) show paths
Executable and object file path: /Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin

DEBUG_INFORMATION_FORMAT = dwarf-with-dsym. My understanding is that the symbols will be in the plug in, so, I believe that gdb can't find my source files.

Thanks in advance for your help, Dave

3 Answers3

3

One method that I have used occasionally with FireBreath plugins 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;
}
#endif

Then in one of the entrypoints (such as NP_Initialize) you do:

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

A friend of mine came up with this, and it seems to work pretty well. However, you should know that in Safari 5.1 the browser will kill the plugin (send a SIG_KILL) after a (fairly brief) time of not getting a response from it. Because of this, it's nearly impossible to debug with Safari 5.1; I highly recommend you debug in either Firefox or Chrome because of this.

This will cause the plugin to wait for your debugger to attach. Note that in Safari 5.1 the name of the plugin process has changed; I forget what it is now exactly, but it's definitely out of process and it's not Safari =]

One of these days I'll get around to adding this to the default FireBreath np_mainmain.cpp file....

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • This isn't really answering the question; your instructions are for attaching, whereas the OP is successfully attached but missing symbol information. (Also, this kind of hack is really only needed if you need to debug initialization, otherwise there's no need to pause and wait for attaching.) – smorgan Sep 04 '11 at 18:51
  • 1
    Ahh, he has added additional information since I answered; I believed that he hadn't attached to the correct process. Well, this is useful information for someone anyway, so the time wasn't wasted. – taxilian Sep 04 '11 at 20:55
2

Xcode has an option to Run ->Attach to process. Use this to attach to plugin process and not the browser. From here you can start debugging plugin running in 64 bit browser

Vishvesh
  • 512
  • 8
  • 21
0

The "with-dsym" part of dwarf-with-dsym means that the symbols are in a separate symbol file, not in the binary.

Your options are: - sWitch to plain dwarf - copy the .dsym bundle from your build directory to next to the installed plugin - manually load the dsym in gdb (at least, I believe this is possible; I haven't actually done it though)

smorgan
  • 20,228
  • 3
  • 47
  • 55