Firefox的调试方法

  • 版本网址缩略名: Firefox的调试方法
  • 版本标题: Firefox的调试方法
  • 版本 id: 247043
  • 创建于:
  • 创建者: phenix
  • 是否是当前版本?
  • 评论 no wording changes

修订内容

概述

当我们需要对基于Firefox的插件、组件和扩展等进行调试时,需要首先对firefox进行调试。 获取Firefox的调试信息可以有两种方式:

   1. 下载Firefox的源代码,重新编译,加入debug信息。即在.mozconfig配置文件中加入
ac_add_options --enable-debug
   2.  安装Linux发行版的Firefox调试信息程序包。下面以Fedora 10系统为例介绍第2种方式。

安装需要的程序包

执行以下命令

sudo debuginfo-install firefox

安装时会提示安装了以下软件包

========================================================================================================================================================================
 Package                                               Arch                        Version                                 Repository                           Size
========================================================================================================================================================================
Installing:
 firefox-debuginfo                                     i386                        3.0.11-1.fc10                            updates-debuginfo                   578 k
 GConf2-debuginfo                                      i386                        2.24.0-1.fc10                            fedora-debuginfo                    589 k
 atk-debuginfo                                         i386                        1.24.0-1.fc10                            fedora-debuginfo                    182 k
 cairo-debuginfo                                       i386                        1.8.0-1.fc10                             fedora-debuginfo                    972 k
 fontconfig-debuginfo                                  i386                        2.6.0-3.fc10                             fedora-debuginfo                    326 k
 freetype-debuginfo                                    i386                        2.3.7-3.fc10                             updates-debuginfo                   2.0 M
 gcc-debuginfo                                         i386                        4.3.2-7                                  fedora-debuginfo                    101 M
 glib2-debuginfo                                       i386                        2.18.4-2.fc10                            updates-debuginfo                   2.4 M
 glibc-debuginfo                                       i686                        2.9-3                                    updates-debuginfo                   9.1 M
 gnome-vfs2-debuginfo                                  i386                        2.24.0-3.fc10                            fedora-debuginfo                    1.5 M
 gtk2-debuginfo                                        i386                        2.14.7-8.fc10                            updates-debuginfo                   8.9 M
 nspluginwrapper-debuginfo                             i386                        1.3.0-2.fc10                             updates-debuginfo                   568 k
 nspr-debuginfo                                        i386                        4.7.4-1.fc10                             updates-testing-debuginfo           643 k
 pango-debuginfo                                       i386                        1.22.3-1.fc10                            updates-debuginfo                   1.2 M
 startup-notification-debuginfo                        i386                        0.9-4.fc9                                fedora-debuginfo                    65  k
 xulrunner-debuginfo                                   i386                        1.9.0.11-1.fc10                          updates-debuginfo                   63  M
Installing for dependencies:
 glibc-debuginfo-common                                i386                        2.9-3                                    updates-debuginfo                    13 M

Transaction Summary
========================================================================================================================================================================
Install     17 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total size: 205 M
Is this ok [y/N]:


也可以通过命令

yum --enablerepo=fedora-debuginfo,updates-debuginfo install GConf2-debuginfo ORBit2-debuginfo atk-debuginfo \
 cairo-debuginfo dbus-debuginfo dbus-glib-debuginfo expat-debuginfo fontconfig-debuginfo freetype-debuginfo \
 gcc-debuginfo glib2-debuginfo glibc-debuginfo gnome-vfs2-debuginfo gtk2-debuginfo gtk2-engines-debuginfo \
 hal-debuginfo libX11-debuginfo libXcursor-debuginfo libXext-debuginfo libXfixes-debuginfo libXft-debuginfo \
 libXi-debuginfo libXinerama-debuginfo libXrender-debuginfo libbonobo-debuginfo libgnome-debuginfo \
 libselinux-debuginfo pango-debuginfo popt-debuginfo scim-bridge-debuginfo



这里安装的debuginfo需要很多磁盘空间,下载时大概是205M的内容,安装之后需要大概500M的硬盘空间,安装过程中需要200M左右的临时文件空间,因此至少应该保证900M以上的磁盘空余空间。
使用gdb进行简单调试

使用下面的命令启动firefox。

firefox -g -d gdb

    *
      -g 告诉Firefox以debug的模式启动
    *
      -d 指定采用的调试器,这里我们选择的是gdb

执行了以上命令后,系统将打开一个gdb程序,加在调试信息(debugging symbols),之后进入gdb的调试环境,如:

MOZILLA_FIVE_HOME=/usr/lib/firefox-3.0.11
  LD_LIBRARY_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11/plugins:/usr/lib/firefox-3.0.11
FONTCONFIG_PATH=/etc/fonts:/usr/lib/firefox-3.0.11/res/Xft
DYLD_LIBRARY_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11
     LIBRARY_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11/components:/usr/lib/firefox-3.0.11
       SHLIB_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11
          LIBPATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11
       ADDON_PATH=/usr/lib/firefox-3.0.11
      MOZ_PROGRAM=/usr/lib/firefox-3.0.11/firefox
      MOZ_TOOLKIT=
        moz_debug=1
     moz_debugger=gdb
/usr/bin/gdb /usr/lib/firefox-3.0.11/firefox -x /tmp/mozargs.NMP1yi
GNU gdb Fedora (6.8-32.fc10)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb)

从上面的提示信息可以看出,实际上上面的命令等效于:

/usr/bin/gdb /usr/lib/firefox-3.0.11/firefox -x /tmp/mozargs.NMP1yi

运行firefox

(gdb) run

经过一系列的调用过程,firefox将被最终打开。我们可以在地址栏输入测试的页面,进行调试。

例如如果这个页面造成firefox崩溃,我们可以运行命令

backtrace

查看调用的情况。执行结果例如:

#0  0x07e16d18 in EventObject::GetSurface () from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
#1  0x07e8b945 in PlaylistParser::IsValidPlaylist () from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
#2  0x07e84533 in ASXDemuxerInfo::Supports () from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
#3  0x07e8524c in Media::Open () from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
#4  0x07e85b34 in Media::WorkerLoop () from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
#5  0x07e85bff in Media::WorkerLoop () from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
#6  0x007e251f in start_thread (arg=0xb1cfdb90) at pthread_create.c:297
#7  0x0071804e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

调试插件

插件是以线程方式工作的。

(gdb)info threads
* 9 Thread 0xb2784b90 (LWP 3210)  0x01203d18 in EventObject::GetSurface ()
   from /home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn/plugins/moonlight/libmoon.so
  8 Thread 0xb3186b90 (LWP 3209)  0x00fe0416 in __kernel_vsyscall ()
  7 Thread 0xb3b87b90 (LWP 3208)  0x00fe0416 in __kernel_vsyscall ()
  6 Thread 0xb692bb90 (LWP 3207)  0x00fe0416 in __kernel_vsyscall ()
  5 Thread 0xb5dffb90 (LWP 3206)  0x00fe0416 in __kernel_vsyscall ()
  3 Thread 0xb73e0b90 (LWP 3204)  0x00fe0416 in __kernel_vsyscall ()
  2 Thread 0xb7de1b90 (LWP 3203)  0x00fe0416 in __kernel_vsyscall ()
  1 Thread 0xb7fe26d0 (LWP 3202)  0x00fe0416 in __kernel_vsyscall ()

在使用gdb调试线程的时候,只有一个线程为活动线程,如果希望得到其他的线程的输出结果,必须使用thread命令切换至指定的线程,才能对该线程进行调试或观察输出结果。现在我们的9号线程是活动线程(前面有个星号*)。如果我们想要调试的插件目前不是活动线程,可以通过使用下面的命令进行线程切换。

(gdb)thread 9

也可以配合/proc目录进行调试。下面的例子是查看进程打开的文件

[phenix@huangsl fd]$ ls -la
total 0
dr-x------ 2 phenix phenix  0 2009-07-07 17:25 .
dr-xr-xr-x 5 phenix phenix  0 2009-07-07 17:25 ..
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 0 -> /dev/pts/1
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 1 -> /dev/pts/1
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 10 -> pipe:[85382]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 11 -> pipe:[85383]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 12 -> pipe:[85383]
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 13 -> socket:[85384]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 14 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/.parentlock
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 15 -> pipe:[85391]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 16 -> pipe:[85391]
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 17 -> socket:[85394]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 18 -> pipe:[85396]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 19 -> pipe:[85396]
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 2 -> /dev/pts/1
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 20 -> /dev/urandom
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 22 -> socket:[85399]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 23 -> /usr/lib/firefox-3.0.11/chrome/en-US.jar
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 24 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/permissions.sqlite
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 25 -> /usr/lib/firefox-3.0.11/chrome/browser.jar
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 26 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/places.sqlite
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 27 -> /usr/lib/xulrunner-1.9/chrome/en-US.jar
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 28 -> /usr/lib/xulrunner-1.9/chrome/classic.jar
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 29 -> /usr/lib/xulrunner-1.9/chrome/toolkit.jar
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 3 -> pipe:[85363]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 30 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/XUL.mfasl
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 31 -> socket:[85409]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 32 -> /usr/lib/firefox-3.0.11/chrome/classic.jar
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 33 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/search.sqlite
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 34 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/formhistory.sqlite
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 35 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/places.sqlite-journal
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 36 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/content-prefs.sqlite
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 37 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/cert8.db
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 38 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/key3.db
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 39 -> pipe:[85416]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 4 -> pipe:[85363]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 40 -> pipe:[85416]
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 41 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/urlclassifier3.sqlite
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 42 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/cookies.sqlite
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 43 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/downloads.sqlite
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 44 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_MAP_
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 45 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_001_
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 46 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_002_
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 47 -> /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_003_
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 48 -> /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 49 -> /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 5 -> /usr/lib/firefox-3.0.11/firefox
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 52 -> pipe:[85495]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 53 -> pipe:[85495]
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 54 -> /var/tmp/etilqs_lgJ1KYa7Kf8DH9S (deleted)
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 6 -> socket:[85379]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 7 -> pipe:[85381]
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 8 -> pipe:[85381]
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 9 -> pipe:[85382]

通过

……
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 48 -> /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 49 -> /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)
……

我们就找到了在开发过程中临时文件打开失败的原因。
一个调试过程

$firefox -g -d gdb
(gdb)break main

执行firefox

(gdb)run

中断,主进程,开始调试插件进程

^C

调试插件进程

(gdb)attach 3210

插入断点

(gdb)break media.cpp 100

继续执行

(gdb)continue

参考文件

Debugging Mozilla with gdb https://developer.mozilla.org/En/Debugging_Mozilla_on_Linux_FAQ

Debugging https://developer.mozilla.org/en/Debugging

修订版来源

<h2>概述</h2>
<p>当我们需要对基于Firefox的插件、组件和扩展等进行调试时,需要首先对firefox进行调试。 获取Firefox的调试信息可以有两种方式:<br>
<br>
   1. 下载Firefox的源代码,重新编译,加入debug信息。即在.mozconfig配置文件中加入<br>
<code>ac_add_options --enable-debug</code><br>
   2.  安装Linux发行版的Firefox调试信息程序包。下面以Fedora 10系统为例介绍第2种方式。</p>
<h2>安装需要的程序包</h2>
<p>执行以下命令</p>
<p><code>sudo debuginfo-install firefox</code></p>
<p>安装时会提示安装了以下软件包<br>
<br>
<span style="font-size: small;"><span style="font-family: Verdana;"><code>========================================================================================================================================================================<br>
 Package                                               Arch                        Version                                 Repository                           Size<br>
========================================================================================================================================================================<br>
Installing:<br>
 firefox-debuginfo                                     i386                        3.0.11-1.fc10                            updates-debuginfo                   578 k<br>
 GConf2-debuginfo                                      i386                        2.24.0-1.fc10                            fedora-debuginfo                    589 k<br>
 atk-debuginfo                                         i386                        1.24.0-1.fc10                            fedora-debuginfo                    182 k<br>
 cairo-debuginfo                                       i386                        1.8.0-1.fc10                             fedora-debuginfo                    972 k<br>
 fontconfig-debuginfo                                  i386                        2.6.0-3.fc10                             fedora-debuginfo                    326 k<br>
 freetype-debuginfo                                    i386                        2.3.7-3.fc10                             updates-debuginfo                   2.0 M<br>
 gcc-debuginfo                                         i386                        4.3.2-7                                  fedora-debuginfo                    101 M<br>
 glib2-debuginfo                                       i386                        2.18.4-2.fc10                            updates-debuginfo                   2.4 M<br>
 glibc-debuginfo                                       i686                        2.9-3                                    updates-debuginfo                   9.1 M<br>
 gnome-vfs2-debuginfo                                  i386                        2.24.0-3.fc10                            fedora-debuginfo                    1.5 M<br>
 gtk2-debuginfo                                        i386                        2.14.7-8.fc10                            updates-debuginfo                   8.9 M<br>
 nspluginwrapper-debuginfo                             i386                        1.3.0-2.fc10                             updates-debuginfo                   568 k<br>
 nspr-debuginfo                                        i386                        4.7.4-1.fc10                             updates-testing-debuginfo           643 k<br>
 pango-debuginfo                                       i386                        1.22.3-1.fc10                            updates-debuginfo                   1.2 M<br>
 startup-notification-debuginfo                        i386                        0.9-4.fc9                                fedora-debuginfo                    65  k<br>
 xulrunner-debuginfo                                   i386                        1.9.0.11-1.fc10                          updates-debuginfo                   63  M<br>
Installing for dependencies:<br>
 glibc-debuginfo-common                                i386                        2.9-3                                    updates-debuginfo                    13 M<br>
<br>
Transaction Summary<br>
========================================================================================================================================================================<br>
Install     17 Package(s)         <br>
Update       0 Package(s)         <br>
Remove       0 Package(s)         <br>
<br>
Total size: 205 M<br>
Is this ok [y/N]: </code></span></span><br>
<br>
也可以通过命令<br>
<code><br>
yum --enablerepo=fedora-debuginfo,updates-debuginfo install GConf2-debuginfo ORBit2-debuginfo atk-debuginfo \<br>
 cairo-debuginfo dbus-debuginfo dbus-glib-debuginfo expat-debuginfo fontconfig-debuginfo freetype-debuginfo \<br>
 gcc-debuginfo glib2-debuginfo glibc-debuginfo gnome-vfs2-debuginfo gtk2-debuginfo gtk2-engines-debuginfo \<br>
 hal-debuginfo libX11-debuginfo libXcursor-debuginfo libXext-debuginfo libXfixes-debuginfo libXft-debuginfo \<br>
 libXi-debuginfo libXinerama-debuginfo libXrender-debuginfo libbonobo-debuginfo libgnome-debuginfo \<br>
 libselinux-debuginfo pango-debuginfo popt-debuginfo scim-bridge-debuginfo</code><br>
<br>
<br>
这里安装的debuginfo需要很多磁盘空间,下载时大概是205M的内容,安装之后需要大概500M的硬盘空间,安装过程中需要200M左右的临时文件空间,因此至少应该保证900M以上的磁盘空余空间。<br>
使用gdb进行简单调试<br>
<br>
使用下面的命令启动firefox。<br>
<br>
firefox -g -d gdb<br>
<br>
    *<br>
      -g 告诉Firefox以debug的模式启动<br>
    *<br>
      -d 指定采用的调试器,这里我们选择的是gdb<br>
<br>
执行了以上命令后,系统将打开一个gdb程序,加在调试信息(debugging symbols),之后进入gdb的调试环境,如:<br>
<br>
MOZILLA_FIVE_HOME=/usr/lib/firefox-3.0.11<br>
  LD_LIBRARY_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11/plugins:/usr/lib/firefox-3.0.11<br>
FONTCONFIG_PATH=/etc/fonts:/usr/lib/firefox-3.0.11/res/Xft<br>
DYLD_LIBRARY_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11<br>
     LIBRARY_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11/components:/usr/lib/firefox-3.0.11<br>
       SHLIB_PATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11<br>
          LIBPATH=/usr/lib/firefox-3.0.11:/usr/lib/firefox-3.0.11<br>
       ADDON_PATH=/usr/lib/firefox-3.0.11<br>
      MOZ_PROGRAM=/usr/lib/firefox-3.0.11/firefox<br>
      MOZ_TOOLKIT=<br>
        moz_debug=1<br>
     moz_debugger=gdb<br>
/usr/bin/gdb /usr/lib/firefox-3.0.11/firefox -x /tmp/mozargs.NMP1yi<br>
GNU gdb Fedora (6.8-32.fc10)<br>
Copyright (C) 2008 Free Software Foundation, Inc.<br>
License GPLv3+: GNU GPL version 3 or later &lt;<a class=" external" href="http://gnu.org/licenses/gpl.html" rel="freelink">http://gnu.org/licenses/gpl.html</a>&gt;<br>
This is free software: you are free to change and redistribute it.<br>
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"<br>
and "show warranty" for details.<br>
This GDB was configured as "i386-redhat-linux-gnu"...<br>
(gdb)<br>
<br>
从上面的提示信息可以看出,实际上上面的命令等效于:<br>
<br>
/usr/bin/gdb /usr/lib/firefox-3.0.11/firefox -x /tmp/mozargs.NMP1yi<br>
<br>
运行firefox<br>
<br>
(gdb) run<br>
<br>
经过一系列的调用过程,firefox将被最终打开。我们可以在地址栏输入测试的页面,进行调试。<br>
<br>
例如如果这个页面造成firefox崩溃,我们可以运行命令<br>
<br>
backtrace<br>
<br>
查看调用的情况。执行结果例如:<br>
<br>
#0  0x07e16d18 in EventObject::GetSurface () from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
#1  0x07e8b945 in PlaylistParser::IsValidPlaylist () from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
#2  0x07e84533 in ASXDemuxerInfo::Supports () from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
#3  0x07e8524c in Media::Open () from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
#4  0x07e85b34 in Media::WorkerLoop () from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
#5  0x07e85bff in Media::WorkerLoop () from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
#6  0x007e251f in start_thread (arg=0xb1cfdb90) at pthread_create.c:297<br>
#7  0x0071804e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130<br>
<br>
调试插件<br>
<br>
插件是以线程方式工作的。<br>
<br>
(gdb)info threads<br>
* 9 Thread 0xb2784b90 (LWP 3210)  0x01203d18 in EventObject::GetSurface ()<br>
   from <a class=" link-mailto" href="mailto:/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn" rel="freelink">/home/phenix/.mozilla/firefox/qyvai5...ng@cs2c.com.cn</a>/plugins/moonlight/libmoon.so<br>
  8 Thread 0xb3186b90 (LWP 3209)  0x00fe0416 in __kernel_vsyscall ()<br>
  7 Thread 0xb3b87b90 (LWP 3208)  0x00fe0416 in __kernel_vsyscall ()<br>
  6 Thread 0xb692bb90 (LWP 3207)  0x00fe0416 in __kernel_vsyscall ()<br>
  5 Thread 0xb5dffb90 (LWP 3206)  0x00fe0416 in __kernel_vsyscall ()<br>
  3 Thread 0xb73e0b90 (LWP 3204)  0x00fe0416 in __kernel_vsyscall ()<br>
  2 Thread 0xb7de1b90 (LWP 3203)  0x00fe0416 in __kernel_vsyscall ()<br>
  1 Thread 0xb7fe26d0 (LWP 3202)  0x00fe0416 in __kernel_vsyscall ()<br>
<br>
在使用gdb调试线程的时候,只有一个线程为活动线程,如果希望得到其他的线程的输出结果,必须使用thread命令切换至指定的线程,才能对该线程进行调试或观察输出结果。现在我们的9号线程是活动线程(前面有个星号*)。如果我们想要调试的插件目前不是活动线程,可以通过使用下面的命令进行线程切换。<br>
<br>
(gdb)thread 9<br>
<br>
也可以配合/proc目录进行调试。下面的例子是查看进程打开的文件<br>
<br>
[phenix@huangsl fd]$ ls -la<br>
total 0<br>
dr-x------ 2 phenix phenix  0 2009-07-07 17:25 .<br>
dr-xr-xr-x 5 phenix phenix  0 2009-07-07 17:25 ..<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 0 -&gt; /dev/pts/1<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 1 -&gt; /dev/pts/1<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 10 -&gt; pipe:[85382]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 11 -&gt; pipe:[85383]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 12 -&gt; pipe:[85383]<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 13 -&gt; socket:[85384]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 14 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/.parentlock<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 15 -&gt; pipe:[85391]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 16 -&gt; pipe:[85391]<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 17 -&gt; socket:[85394]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 18 -&gt; pipe:[85396]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 19 -&gt; pipe:[85396]<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 2 -&gt; /dev/pts/1<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 20 -&gt; /dev/urandom<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 22 -&gt; socket:[85399]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 23 -&gt; /usr/lib/firefox-3.0.11/chrome/en-US.jar<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 24 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/permissions.sqlite<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 25 -&gt; /usr/lib/firefox-3.0.11/chrome/browser.jar<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 26 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/places.sqlite<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 27 -&gt; /usr/lib/xulrunner-1.9/chrome/en-US.jar<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 28 -&gt; /usr/lib/xulrunner-1.9/chrome/classic.jar<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 29 -&gt; /usr/lib/xulrunner-1.9/chrome/toolkit.jar<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 3 -&gt; pipe:[85363]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 30 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/XUL.mfasl<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 31 -&gt; socket:[85409]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 32 -&gt; /usr/lib/firefox-3.0.11/chrome/classic.jar<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 33 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/search.sqlite<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 34 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/formhistory.sqlite<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 35 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/places.sqlite-journal<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 36 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/content-prefs.sqlite<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 37 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/cert8.db<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 38 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/key3.db<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 39 -&gt; pipe:[85416]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 4 -&gt; pipe:[85363]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 40 -&gt; pipe:[85416]<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 41 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/urlclassifier3.sqlite<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 42 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/cookies.sqlite<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 43 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/downloads.sqlite<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 44 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_MAP_<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 45 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_001_<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 46 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_002_<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 47 -&gt; /home/phenix/.mozilla/firefox/9ftd6ha2.default/Cache/_CACHE_003_<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 48 -&gt; /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 49 -&gt; /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 5 -&gt; /usr/lib/firefox-3.0.11/firefox<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 52 -&gt; pipe:[85495]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 53 -&gt; pipe:[85495]<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 54 -&gt; /var/tmp/etilqs_lgJ1KYa7Kf8DH9S (deleted)<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 6 -&gt; socket:[85379]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 7 -&gt; pipe:[85381]<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 8 -&gt; pipe:[85381]<br>
lr-x------ 1 phenix phenix 64 2009-07-07 17:25 9 -&gt; pipe:[85382]<br>
<br>
通过<br>
<br>
……<br>
lrwx------ 1 phenix phenix 64 2009-07-07 17:25 48 -&gt; /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)<br>
l-wx------ 1 phenix phenix 64 2009-07-07 17:25 49 -&gt; /tmp/CS2C_MoonlightProgressiveStream.B1MUWU (deleted)<br>
……<br>
<br>
我们就找到了在开发过程中临时文件打开失败的原因。<br>
一个调试过程<br>
<br>
$firefox -g -d gdb<br>
(gdb)break main<br>
<br>
执行firefox<br>
<br>
(gdb)run<br>
<br>
中断,主进程,开始调试插件进程<br>
<br>
^C<br>
<br>
调试插件进程<br>
<br>
(gdb)attach 3210<br>
<br>
插入断点<br>
<br>
(gdb)break media.cpp 100<br>
<br>
继续执行<br>
<br>
(gdb)continue<br>
<br>
参考文件<br>
<br>
Debugging Mozilla with gdb https://developer.mozilla.org/En/Debugging_Mozilla_on_Linux_FAQ<br>
<br>
Debugging https://developer.mozilla.org/en/Debugging</p>
恢复到这个版本