mozilla

Revision 315027 of Debugging B2G using gdb and related tools

  • Revision slug: Mozilla/Boot_to_Gecko/Debugging_on_Boot_to_Gecko/Debugging_B2G_using_gdb
  • Revision title: Debugging B2G using gdb
  • Revision id: 315027
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment

Revision Content

{{draft()}}

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 run-gdb.sh script:

./run-gdb.sh

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:

./run-gdb.sh attach

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:

MOZ_DEBUG_CHILD_PROCESS=1 ./run-gdb.sh

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>

as above.

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.

Revision Source

<p>{{draft()}}</p>
<p>Debugging Firefox OS using gdb is easy. This article will help make it even more so.</p>
<h2 id="Starting_the_debugger_in_single-process_mode">Starting the debugger in single-process mode</h2>
<div class="note">
  <p><strong>Note:</strong> Before running the debugger, you may want to set up a <code>.userconfig</code> file to customize things. See <a href="/en-US/docs/Mozilla/Boot_to_Gecko/Customization_with_the_.userconfig_file" title="/en-US/docs/Mozilla/Boot_to_Gecko/Customization_with_the_.userconfig_file">Customization with the .userconfig file</a> for details.</p>
</div>
<p>To restart Firefox OS and run it under gdb control, simply use the <code>run-gdb.sh</code> script:</p>
<pre>
./run-gdb.sh
</pre>
<div class="note">
  <p><strong>Note:</strong> 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.</p>
</div>
<p>If Firefox OS is already running and you want to attach to it without restarting it, you can do so like this:</p>
<pre>
./run-gdb.sh attach
</pre>
<h2 id="Debugging_out-of-process_tasks">Debugging out-of-process tasks</h2>
<p>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:</p>
<pre>
$ 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
</pre>
<p>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:</p>
<pre>
$ ./run-gdb attach 4308</pre>
<p>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:</p>
<pre>
MOZ_DEBUG_CHILD_PROCESS=1 ./run-gdb.sh</pre>
<p>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</p>
<pre>
$ ./run-gdb attach &lt;pid&gt;</pre>
<p>as above.</p>
<p>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.</p>
Revert to this revision