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)
 
(36 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:
* Binaries - the GDB/GDBServer binaries that include Android-specific patches (https://github.com/darchons/android-gdb)
* Binaries - the GDB/GDBServer binaries that include Android-specific patches (https://github.com/darchons/android-gdb)
* Scripts - the Python scripts that run under GDB to simplify common tasks (https://github.com/darchons/android-gdbutils)
* Scripts - the Python scripts that run under GDB to simplify common tasks (https://github.com/darchons/android-gdbutils)
Use #mobile on IRC for support.
Use #mobile on IRC for support.


= 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 10: 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!
# OPTIONAL: For easier access, you can create a symlink to jimdb under, e.g., /usr/bin


=== Example ===
=== Example ===


For Linux,
For ARM devices on Linux,
  cd $HOME
  cd $HOME
  wget http://people.mozilla.org/~nchen/jimdb/jimdb-linux-x64.tar.bz2 # step 1
  wget https://people.mozilla.org/~nchen/jimdb/jimdb-arm-linux_x64.tar.bz2 # step 1
  tar -xf jimdb-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
 
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 35: 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>./configure --target=arm-elf-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 47: Line 107:
# Use the source directory from above
# Use the source directory from above
# Make sure you have a copy of the Android NDK
# Make sure you have a copy of the Android NDK
# Run configure inside the ''gdb/gdbserver directory'' (following is for NDK r8d)<pre>export NDK=/PATH/TO/NDK&#10;export PATH=$PATH:$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin&#10;./configure --host=arm-linux-androideabi --with-sysroot=$NDK/platforms/android-9/arch-arm</pre>
# Run configure inside the ''gdb/gdbserver directory'' (following is for NDK r8d)<pre>export NDK=/PATH/TO/NDK&#10;# ARM:&#10;export PATH=$PATH:$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin&#10;./configure --host=arm-linux-androideabi --with-sysroot=$NDK/platforms/android-9/arch-arm&#10;# x86:&#10;export PATH=$PATH:$NDK/toolchains/x86-4.6/prebuilt/linux-x86/bin&#10;./configure --host=i686-linux-android --with-sysroot=$NDK/platforms/android-9/arch-x86</pre>
# Run make <pre>make -j8</pre>
# Run make <pre>make -j8</pre>
# The compiled binary will be at gdbserver
# The compiled binary will be at gdbserver
Line 58: Line 118:
# Extract the zip
# Extract the zip
# You may need to install additional packages in order to build GDB. For example,<pre>port install bison flex ncurses texinfo python27</pre>
# You may need to install additional packages in order to build GDB. For example,<pre>port install bison flex ncurses texinfo python27</pre>
# Run configure inside the source directory<pre>./configure --target=arm-elf-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
Line 67: Line 127:
# Use the source directory from above
# Use the source directory from above
# Make sure you have a copy of the Android NDK
# Make sure you have a copy of the Android NDK
# Run configure inside the ''gdb/gdbserver directory'' (following is for NDK r8d)<pre>export NDK=/PATH/TO/NDK&#10;export PATH=$PATH:$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin&#10;./configure --host=arm-linux-androideabi --with-sysroot=$NDK/platforms/android-9/arch-arm</pre>
# Run configure inside the ''gdb/gdbserver directory'' (following is for NDK r8d)<pre>export NDK=/PATH/TO/NDK&#10;# ARM:&#10;export PATH=$PATH:$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin&#10;./configure --host=arm-linux-androideabi --with-sysroot=$NDK/platforms/android-9/arch-arm&#10;# x86:&#10;export PATH=$PATH:$NDK/toolchains/x86-4.6/prebuilt/darwin-x86/bin&#10;./configure --host=i686-linux-android --with-sysroot=$NDK/platforms/android-9/arch-x86</pre>
# Run make <pre>make -j8</pre>
# Run make <pre>make -j8</pre>
# The compiled binary will be at gdb/gdbserver/gdbserver
# The compiled binary will be at gdb/gdbserver/gdbserver
Line 103: Line 163:
== Configuring JimDB ==
== Configuring JimDB ==


utils/gdbinit is the GDB command file that JimDB runs at launch. It contains the launch commands as well as settings for JimDB.
utils/gdbinit is the GDB command file that JimDB runs at launch. Open it in your favorite text editor to see configurable settings for JimDB.


utils/gdbinit also loads utils/gdbinit.local. Because utils/gdbinit can change frequently across updates, it's recommended to copy your custom settings to utils/gdbinit.local, so that updates do not override your settings.
utils/gdbinit also loads utils/gdbinit.local. Because utils/gdbinit can change frequently across updates, it's recommended to copy your custom settings to utils/gdbinit.local, so that updates do not override your settings.


For example, to configure the feninit.default.objdir option, paste the following line inside utils/gdbinit.local,
For example, to configure the feninit.default.objdir option, paste the following line anywhere inside utils/gdbinit.local,
  python feninit.default.objdir = '/home/user/mozilla/central/objdir-android'
  python feninit.default.objdir = '/home/user/mozilla/central/objdir-android'


Line 119: 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 149: Line 211:
* Alternatively, if your object directories are called 'obj*' under your source directory, you can set feninit.default.objdir to the source directory itself. The script will scan the source directory and list all the object directories that it found.
* Alternatively, if your object directories are called 'obj*' under your source directory, you can set feninit.default.objdir to the source directory itself. The script will scan the source directory and list all the object directories that it found.
* Note that there have been problems in the past with using ~ and $HOME in the setting, so use absolute path for best results.
* Note that there have been problems in the past with using ~ and $HOME in the setting, so use absolute path for best results.
* PRO-TIP: Put the following code block inside gdbinit.local to always use the current directory as the object directory,
python
import os
feninit.default.objdir = os.getcwd()
end
==== feninit.default.srcroot ====
==== feninit.default.srcroot ====
* Unlike the previous setting, feninit.default.srcroot specifies the directory containing all the source directories. This is convenient if you have 'src/mozilla-central', 'src/mozilla-inbound', 'src/mozilla-aurora', etc. In that case, you can set feninit.default.srcroot to 'src' and all the source directories will be scanned for object directories.
* Unlike the previous setting, feninit.default.srcroot specifies the directory containing all the source directories. This is convenient if you have 'src/mozilla-central', 'src/mozilla-inbound', 'src/mozilla-aurora', etc. In that case, you can set feninit.default.srcroot to 'src' and all the source directories will be scanned for object directories.
Line 175: 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.
== GDB commands specific to JimDB ==
=== set delay-add-remote-solibs ===
gdb> set delay-add-remote-solibs <0|1>
Default setting is 0. Set delay-add-remote-solibs to 1 to delay loading symbols when shared libraries are loaded. This may improve the set up time. However, you may need to use the "sharedlibrary" command to manually load symbols before using breakpoints.
=== monitor set ignore-ondemand ===
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. This command can only be run after attaching to the target, so it cannot be specified in gdbinit.local.


= FAQ =
= FAQ =
Line 190: Line 266:
* You may need to create a libtinfo.so.5 symlink to libncurses.so.5. For example,
* You may need to create a libtinfo.so.5 symlink to libncurses.so.5. For example,
  sudo ln -s libncurses.so.5 /usr/lib/libtinfo.so.5
  sudo ln -s libncurses.so.5 /usr/lib/libtinfo.so.5
=== "Segmentation fault: 11" or "Illegal instruction: 4" on Mac OS X ===
* This may be due to incompatible OS X SDK versions. You should build your own JimDB binary to avoid the issue.


=== "cannot locate symbol "__exidx_end"" when starting to debug ===
=== "cannot locate symbol "__exidx_end"" when starting to debug ===
* If you're using pre-built binaries, you need to update to a newer version of JimDB
* If you're using pre-built binaries, you need to update to a newer version of JimDB
* If you're using custom-built binaries, you need to recompile gdbserver using a newer version of the NDK
* If you're using custom-built binaries, you need to recompile gdbserver using a newer version of the NDK
=== "No module named printing" when debugging Fennec with JimDB ===
* 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/
* 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 ===
* GDB can catch segmentation faults generated by on-demand decompression; just use "continue" to continue execution.
* Alternatively, specify the "MOZ_LINKER_ONDEMAND=0" environment variable when launching Fennec using Option 2. You can also put the option inside jimdb/utils/gdbinit.local.


=== GDB crashed and Fennec is stuck. Halp!! ===
=== GDB crashed and Fennec is stuck. Halp!! ===
* 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 205: 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