Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

使用 gdb 及相关工具调试 B2G

gdb 是一个命令行调试器,提供了许多有用的选项,可以用来调试 Firefox OS 应用程序。其他相关的工具也是同样有效的,比如  b2g-ps, 它是对标准 ps 工具的封装,会显示 B2G 实例中运行的每个进程的名称。本文则描述了如何使用这些工具来执行 Fiefox OS 调试工作。

在单进程模式下启动调试器

注意: 在运行调试器前,你可能想要建立一个  .userconfig 文件来自定义一些配置。请查看 Customization with the .userconfig file 获取更多信息。

要重启 Firefox OS 并在 gdb 控制下运行,只需要简单的运行 run-gdb.sh 脚本就可以了:

./run-gdb.sh

注意: 如果你想要在模拟器上调试,请确保并没有连接手机;否则可能会与模拟器上调试 gdb 相冲突。

如果 Firefox OS 已经在运行,你想要在不重启的情况下附加在上面,也可以这样做:

./run-gdb.sh attach

调试 out-of-process 任务

Because of the threaded nature of Firefox OS, 你可能需要掉时除了主 B2G 任务之外的任务。最简单的方式就是使用 b2g-ps 命令来找出你需要调试的进程的 PID:

$ adb shell b2g-ps
b2g              root      106   1     189828 56956 ffffffff 40101330 S /system/b2g/b2g
Browser          app_0     4308  106   52688  16188 ffffffff 400db330 S /system/b2g/plugin-container

此处, Browser 是一个子进程用作 browser 应用的 "content process" 。因此如果在本例中,你想要调试  content process, 可以这么做:

$ ./run-gdb.sh attach 4308

有时候,如果有任何子进程被创建就立刻通知是非常有用的。我们可以在启动  run-gdb.sh  时添加  MOZ_DEBUG_CHILD_PROCESS 环境变量来实现:

MOZ_DEBUG_CHILD_PROCESS=1 ./run-gdb.sh

运行上面命令后,在 Firefox OS 中启动一个 OOP 应用时,就会输出新任务 plugin-container  的 PID。Having done this, launching an OOP application on Firefox OS will output the PID of the plugin-container for the new task, and will sleep for 30 seconds, enough time for you to run the attach command we saw above:

$ ./run-gdb.sh attach 4308

If you are trying to debug something that occurs during boot, you have to launch the debugger instance for the new application fairly quickly. Once the new debugger is launched, you should immediately press "c" to continue running the new task.

支持

What level of functionality to expect

The following debugging features at least should definitely work. If they don't, it's likely that a simple tweak to your setup will make them work:

  • Symbols for all libraries (except perhaps certain drivers on certain Android phones)
  • Backtraces with full debug info (except for optimized-away argument values)
  • Breakpoints: you should be able to break on a symbol, or on a file:line, or on an address. All should work.
  • Single-stepping ('s' and 'n' should both work)

The following debugging features are not supported. Don't try to use them.

  • Watchpoints.

Troubleshooting

Here are a few things to try first whenever GDB is not working as described above.

Ensure that your B2G clone is up-to-date

Always keep in mind to that to update your B2G clone you must run these two commands:

git pull
./repo sync

Forgetting the git pull there is a typical reason why you'd end up with an old run-gdb.sh and not benefit from recent improvements.

确保你已经附着在了正确的进程上

Attaching to the wrong process (e.g. main B2G process versus Browser process) would explain why your breakpoints don't get hit.

Ensure that symbols are correctly read

  1. In gdb, use info shared to check that symbols are correctly read:
    (gdb) info shared
    From        To          Syms Read   Shared Object Library
    0xb0001000  0xb0006928  Yes         out/target/product/otoro/symbols/system/bin/linker
    0x40051100  0x4007ed74  Yes         /hack/b2g/B2G/out/target/product/otoro/symbols/system/lib/libc.so
    0x401ab934  0x401aba2c  Yes         /hack/b2g/B2G/out/target/product/otoro/symbols/system/lib/libstdc++.so
    ...
  2. The Syms Read column should say Yes everywhere. Maybe on some android phone you would see Yes (*) for some system libraries or drivers; that would be OK. You should not see any No.
  3. If you do see a No, that is your first problem and you must solve it before looking at anything else.
  4. Look for any error messages in the terminal output just after you typed your run-gdb.sh command.
  5. Also check in that terminal output that the GDB command is sane. In particular, its last command line argument should be the path to your b2g executable. Here is a sane example:
    prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-gdb -x /tmp/b2g.gdbinit.bjacob /hack/b2g/B2G/objdir-gecko/dist/bin/b2g
  6. Check the value of these GDB variables: solib-search-path and solib-absolute-prefix:
    (gdb) show solib-search-path
    The search path for loading non-absolute shared library symbol files is /hack/b2g/B2G/objdir-gecko/dist/bin:out/target/product/otoro/symbols/system/lib:out/target/product/otoro/symbols/system/lib/hw:out/target/product/otoro/symbols/system/lib/egl:out/target/product/otoro/symbols/system/bin:out/target/product/otoro/system/lib:out/target/product/otoro/system/lib/egl:out/target/product/otoro/system/lib/hw:out/target/product/otoro/system/vendor/lib:out/target/product/otoro/system/vendor/lib/hw:out/target/product/otoro/system/vendor/lib/egl.
    (gdb) show solib-absolute-prefix
    The current system root is "out/target/product/otoro/symbols".

Note: If you need more help, try the #b2g IRC channel. If you think you found a bug, report it on the B2G issue tracker.

 

文档标签和贡献者

标签: 
 此页面的贡献者: chrisdavidmills, ReyCG_sub
 最后编辑者: chrisdavidmills,