如何让 XCode / GDB 融入 Safari 5.1 NPAPI 插件?

发布于 2024-12-03 02:55:36 字数 1255 浏览 1 评论 0原文

我有一个在 OS X 10.6.8 上运行的 NPAPI 插件,我想对其进行调试。当我使用 FireFox 3.6.19 加载它时,我可以将活动可执行文件设置为 FF,启动 FF,使用 XCode 附加,并且断点将在预期时间触发。

使用 Safari 5.1 时,我发现插件在进程中运行,因此我为 /System/Library/PrivateFrameworks/WebKit2.framework/PluginProcess.app 创建并激活了客户可执行文件。然后,我启动 Safari,导航到托管插件的页面,附加到插件进程,然后使用 UI,这样断点应该触发,但它没有。我可以通过 UI 判断该插件已加载。如果暂停进程,我会看到:

(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。我的理解是符号将在插件中,所以,我相信gdb找不到我的源文件。

预先感谢您的帮助, 戴夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大姐,你呐 2024-12-10 02:55:36

我偶尔使用 FireBreath 插件的一种方法是:

#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

然后在入口点之一(例如 NP_Initialize)中,您do:

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

我的一个朋友想出了这个,看起来效果不错。但是,您应该知道,在 Safari 5.1 中,浏览器将在(相当短暂的)一段时间没有收到插件响应后杀死该插件(发送 SIG_KILL)。因此,使用 Safari 5.1 进行调试几乎是不可能的;因此,我强烈建议您在 Firefox 或 Chrome 中进行调试。

这将导致插件等待调试器附加。请注意,在 Safari 5.1 中,插件进程的名称已更改;我忘记了它现在到底是什么,但它肯定不在进程中,而且不是 Safari =]

有一天我会抽出时间将其添加到默认的 FireBreath np_mainmain.cpp 文件....

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....

天涯沦落人 2024-12-10 02:55:36

Xcode 有一个选项 Run -> Attach to process。使用它附加到插件进程而不是浏览器。从这里您可以开始调试在 64 位浏览器中运行的插件

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

眉目亦如画i 2024-12-10 02:55:36

dwarf-with-dsym 的“with-dsym”部分意味着符号位于单独的符号文件中,而不是二进制文件中。

您的选择是:
- 切换到普通矮星
- 将 .dsym 包从构建目录复制到已安装插件旁边
- 在 gdb 中手动加载 dsym (至少,我相信这是可能的;但我实际上还没有这样做)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文