Mobile/Fennec/Android/GDB: Difference between revisions

JimDB is no longer used. So add link to GV debugging document
(JimDB is no longer used. So add link to GV debugging document)
 
(22 intermediate revisions by 12 users not shown)
Line 1: Line 1:
= Deprecated =
This page is the information of deprecated debugging tools.  We recommend to use Android studio (https://mozilla.github.io/geckoview/tutorials/native-debugging.html).
= What JimDB? =
JimDB is a fork of GDB used for simplifying Fennec development. It consists of two parts:
JimDB is a fork of GDB used for simplifying Fennec development. It consists of two parts:


Line 7: Line 12:


= Getting started =
= Getting started =
== Using mach ==
You can use mach to fetch, install, configure, and run JimDB with one simple command. Note that if you are on OS X, mach may install JimDB correctly, but then try to debug using lldb. If that happens, you can still run JimDB manually from your ~/.mozbuild folder (you can find the full path in the output below).
  $ ./mach run --debug
  JimDB (arm) not found: /home/gbrown/.mozbuild/android-device/jimdb-arm does not exist
  Download and setup JimDB (arm)? (Y/n) y
  Installing JimDB (linux64/arm). This may take a while...
  From https://github.com/darchons/android-gdbutils
  * [new branch]      master    -> origin/master
  * [new tag]        gdbutils-2 -> gdbutils-2
  * [new tag]        initial-release -> initial-release
  1:45.57 /home/gbrown/.mozbuild/android-device/jimdb-arm/bin/gdb -q --args
  Fennec GDB utilities
    (see utils/gdbinit and utils/gdbinit.local on how to configure settings)
  1. Debug Fennec (default)
  2. Debug Fennec with env vars and args
  3. Debug using jdb
  4. Debug content Mochitest
  5. Debug compiled-code unit test
  6. Debug Fennec with pid
  Enter option from above: 1
  New ADB device is "emulator-5554"
  Using device emulator-5554
  Using object directory: /home/gbrown/objdirs/droid
  Set sysroot to "/home/gbrown/.mozbuild/android-device/jimdb-arm/lib/emulator-5554".
  Updated solib-search-path.
  Ignoring BHM signal.
  Using package org.mozilla.fennec_gbrown.
  Launching org.mozilla.fennec_gbrown... Done
  Attaching to pid 674... Done
  Setting up remote debugging... Done
  Ready. Use "continue" to resume execution.
  : No such file or directory.
  (gdb)


== Using pre-built binaries ==
== Using pre-built binaries ==
Line 12: Line 53:
=== Instructions ===
=== Instructions ===


# Download the latest pre-built binaries for your platform from [http://people.mozilla.org/~nchen/jimdb this directory]
# Download the latest pre-built jimdb binaries for your host and device platforms from [https://people.mozilla.org/~nchen/jimdb this directory] (use 'jimdb-arm' for ARM devices and 'jimdb-x86' for x86 devices)
# Download the latest pre-built gdbserver binary for your device platform from [https://people.mozilla.org/~nchen/jimdb the same directory]
# Extract to a user-writable directory
# Extract to a user-writable directory
# Replace the gdbserver binary in the jimdb-*/bin/ directory with the one you downloaded separately (it's newer)
# Run 'git pull' from inside the utils/ directory to get the latest scripts
# Run 'git pull' from inside the utils/ directory to get the latest scripts
# Launch bin/gdb to start using JimDB!
# Launch bin/gdb to start using JimDB!
Line 22: Line 65:
For ARM devices on Linux,
For ARM devices on Linux,
  cd $HOME
  cd $HOME
  wget http://people.mozilla.org/~nchen/jimdb/jimdb-arm-linux_x64.tar.bz2 # step 1
  wget https://people.mozilla.org/~nchen/jimdb/jimdb-arm-linux_x64.tar.bz2 # step 1
  tar -xf jimdb-arm-linux_x64.tar.bz2 # step 2
  tar -xf jimdb-arm-linux_x64.tar.bz2 # step 3
  cd jimdb/utils # step 3
  cd jimdb-arm/utils && git pull # step 5
git pull
  ../bin/gdb # step 6
  ../bin/gdb # step 4
  sudo ln -s $HOME/jimdb-arm/bin/gdb /usr/bin/jimdb # step 7
  sudo ln -s $HOME/jimdb/bin/gdb /usr/bin/jimdb # step 5
 
If you download the wrong x86 or x64 build, you might get an error like:
$ ./bin/gdb
./bin/gdb: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory


== Custom-building ==
== Custom-building ==
Line 39: Line 85:
===== GDB =====
===== GDB =====


# Get a zip of the source from [https://github.com/darchons/android-gdb the GitHub repo] (Get the zip because cloning takes a lot longer)
# Clone [https://github.com/darchons/android-gdb the GitHub repo] (do not use the Zip archive, as the build system will try to obtain a git changeset id)
# Extract the zip
# You may need to install additional packages in order to build GDB. For example,<pre>sudo apt-get build-dep gdb</pre>
# You may need to install additional packages in order to build GDB. For example,<pre>sudo apt-get build-dep gdb</pre>
# Run configure inside the source directory<pre># ARM:&#10;./configure --target=arm-linux-android --with-python=yes --prefix=/nonexistent \&#10;  --with-gdb-datadir=/nonexistent/utils --with-system-gdbinit=/nonexistent/utils/gdbinit&#10;# x86:&#10;./configure --target=i686-pc-linux-android --with-python=yes --prefix=/nonexistent \&#10;  --with-gdb-datadir=/nonexistent/utils --with-system-gdbinit=/nonexistent/utils/gdbinit</pre>
# Run configure inside the source directory<pre># ARM:&#10;./configure --target=arm-linux-android --with-python=yes --prefix=/nonexistent \&#10;  --with-gdb-datadir=/nonexistent/utils --with-system-gdbinit=/nonexistent/utils/gdbinit&#10;# x86:&#10;./configure --target=i686-pc-linux-android --with-python=yes --prefix=/nonexistent \&#10;  --with-gdb-datadir=/nonexistent/utils --with-system-gdbinit=/nonexistent/utils/gdbinit</pre>
# Run make <pre>make -j8</pre>
# Run make <pre>make -j8</pre>
# The compiled binary will be at gdb/gdb
# The compiled binary will be at gdb/gdb
If you see an error like:
<pre>
../../../../bfd/doc/bfd.texinfo:325: unknown command `colophon'
../../../../bfd/doc/bfd.texinfo:336: unknown command `cygnus'
Makefile:421: recipe for target 'bfd.info' failed
</pre>
you can fix this by running:
<pre>
sed -i -e 's/@colophon/@@colophon/' -e 's/doc@cygnus.com/doc@@cygnus.com/' bfd/doc/bfd.texinfo
</pre>
or by checking out a more recent branch (this bug is in the 7_5 branch).


===== GDBServer =====
===== GDBServer =====
Line 123: Line 179:
# Debug content Mochitest
# Debug content Mochitest
# Debug compiled-code unit test
# Debug compiled-code unit test
[[File:Jimdb-prompt.png]]


=== Debug Fennec ===
=== Debug Fennec ===
Line 185: Line 243:
* Specify the directory containing the harness itself, i.e. "runtestsremote.py". Not needed normally.
* Specify the directory containing the harness itself, i.e. "runtestsremote.py". Not needed normally.
==== feninit.default.mochi_xre_url ====
==== feninit.default.mochi_xre_url ====
* Specify the directory on [http://ftp.mozilla.org ftp.mozilla.org] to use for downloading XRE. Not used if feninit.default.mochi_xre is specified.
* Specify the directory on [https://ftp.mozilla.org ftp.mozilla.org] to use for downloading XRE. Not used if feninit.default.mochi_xre is specified.
==== feninit.default.mochi_xre_update ====
==== feninit.default.mochi_xre_update ====
* Specify the XRE check for updates interval. Only used if the script is managing the XRE copy, and not used if feninit.default.mochi_xre_update is specified.
* Specify the XRE check for updates interval. Only used if the script is managing the XRE copy, and not used if feninit.default.mochi_xre_update is specified.
Line 195: Line 253:
=== monitor set ignore-ondemand ===
=== monitor set ignore-ondemand ===
  gdb> monitor set ignore-ondemand <0|1>
  gdb> monitor set ignore-ondemand <0|1>
Default setting is 1. Set ignore-ondemand to 0 to not ignore segmentation faults generated by on-demand decompression. This setting may be needed to debug specific segmentation faults that are inadvertently being ignored.
Default setting is 1. Set ignore-ondemand to 0 to not ignore segmentation faults generated by on-demand decompression. This setting may be needed to debug specific segmentation faults that are inadvertently being ignored. This command can only be run after attaching to the target, so it cannot be specified in gdbinit.local.


= FAQ =
= FAQ =
Line 219: Line 277:
* The JimDB Python scripts lack several scripts included in regular GDB packages. To fix that, simply copy your local copy of these scripts to the JimDB utils/python directory. For example, on a typical Linux system, run
* The JimDB Python scripts lack several scripts included in regular GDB packages. To fix that, simply copy your local copy of these scripts to the JimDB utils/python directory. For example, on a typical Linux system, run
  cp -r /usr/share/gdb/python/gdb $jimdb/utils/python/
  cp -r /usr/share/gdb/python/gdb $jimdb/utils/python/
* If you don't have these files, they are available [https://people.mozilla.org/~nchen/jimdb/gdb-python-lib.tar.bz2 here]; just extract it under $jimdb/utils/python/


=== Random segmentation faults when debugging Fennec ===
=== Random segmentation faults when debugging Fennec ===
Line 227: Line 286:
* GDBServer may still be attached to Fennec but is unable to communicate with GDB; try killing GDBServer
* GDBServer may still be attached to Fennec but is unable to communicate with GDB; try killing GDBServer
  adb shell run-as org.mozilla.fennec_$USER kill `adb shell ps | grep gdb | awk '{print $2}'`
  adb shell run-as org.mozilla.fennec_$USER kill `adb shell ps | grep gdb | awk '{print $2}'`
=== "make: `[path]/mochitest-remote' is up to date." while trying to run Mochitests ===
* Delete the mochitest-remote file.
=== "failed to run gdbserver" ===
    "gdbserver" output:
    /system/bin/sh: /data/local/tmp/gdbserver: not executable: magic 7F45
    "run-as" output:
    /data/local/tmp/gdbserver[1]: syntax error: '(' unexpected
    "su -c" output:
    /system/bin/sh: su: not found
    [path]/jimdb-x86/bin/../utils/gdbinit:136: Error in sourced command file:
    failed to run gdbserver
You are probably trying to run the x86 version on an ARM device. Download the ARM version of JimDB instead.
Alternatively, you may just have an out-of-date version of gdbserver. Check for an updated version in the link posted above.
    "gdbserver" output:
    error: only position independent executables (PIE) are supported.
This means your build of gdbserver is too old for the Android version you're debugging on. You may need a newer platform sysroot and/or to add flags to gdb/gdbserver/Makefile to build a position-independent executable.
    CFLAGS += -fvisibility=default -fPIE
    LDFLAGS += -rdynamic -fPIE -pie


=== JimDB sucks! Halp!! ===
=== JimDB sucks! Halp!! ===
Line 234: Line 319:
=== JimDB is awesome now!! Can I buy you a $beverage? ===
=== JimDB is awesome now!! Can I buy you a $beverage? ===
Yes! See also {{bug|800000}}
Yes! See also {{bug|800000}}
=== Using `next` to traverse a function sometimes gets stuck with an error like "Unable to find end of function" ===
Try using the env-var MOZ_LINKER_ONDEMAND=0.
=== Execution pauses often for "Program received signal SIG33, Real-time event 33." ===
This should be caught automatically, but try:
    handle SIG33 pass nostop noprint
=== "Symbol not found: __PyErr_ReplaceException" ===
You should not use python 2.7.11.
See : https://github.com/conda/conda/issues/1367
Confirmed users
14

edits