Debugging Firefox OS using gdb is easy. This article will help make it even more so.
Starting the debugger in single-process mode
Note: Before running the debugger, you may want to set up a
.userconfig file to customize things. See Customization with the .userconfig file for details.
To restart Firefox OS and run it under gdb control, simply use the
Note: If you want to debug on the emulator, be sure there are no phones attached; this may conflict with gdb's ability to connect to the emulator.
If Firefox OS is already running and you want to attach to it without restarting it, you can do so like this:
Debugging out-of-process tasks
Because of the threaded nature of Firefox OS, you often need to be able to debug tasks other than the main B2G task. To do this, the simplest way is to use the b2g-ps command to find out the PID of the process that you need to debug:
$ 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
Here, Browser is the child process used as the "content process" for the browser application. So if you want to debug the content process, in this example, do:
$ ./run-gdb attach 4308
Sometimes, it is useful to be notified immediately of any child process creation. This can be achieved by starting run-gdb.sh with the MOZ_DEBUG_CHILD_PROCESS environment variable:
Having done this, launching an OOP application on Firefox OS will cause gdb to output the PID of the plugin-container for the new task. You can then do
$ ./run-gdb attach <pid>
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.