andreasgal/B2G — Issue #153: Add some Makefile helpers for using gdb
Author: cgjones
Created: 2012-02-02 02:12:10+00:00
State: open
Labels: tools

It would be cool if all the hackery needed to run gdb was contained within b2g code.

To do any of this, we need a stock .gdbinit that sets up library search paths correctly. Here's the relevant part of my gdbinit for the emulator

set solib-absolute-prefix /home/cjones/mozilla/b2g/glue/gonk/out/target/product/generic/symbols
set solib-search-path /home/cjones/mozilla/b2g/gecko/objdir-prof-gonk/dist/lib:/home/cjones/mozilla/b2g/glue/gonk/out/target/product/generic/symbols/system/lib:/home/cjones/mozilla/b2g/glue/gonk/out/target/product/generic/symbols/system/lib/hw:/home/cjones/mozilla/b2g/glue/gonk/out/target/product/generic/symbols/system/lib/egl

We should be able to make this relative to the top-level b2g directory, which in my case is "/home/cjones/mozilla/b2g".

We'll need to figure out how to make this work with our multiple targets, emulator/sgs2/maguro. I'm not sure offhand. If the gdb init scripts can interpret environment variables, that would help a lot. At worst, we keep a separate .gdbinit per build target.

With that figured out, we can add a simple target that launches the host-gdb binary with the right .gdbinit. Something like

run-gdb-host:
path/to/host/gdb -x [.gdbinit file] [b2g binary]

That doesn't take care of *all* the hackery needed to get gdb going, but it's a good start. After |make run-gdb-host| works, we can add a more helpful target like

run-gdb: run-gdbserver run-gdb-host
run-gdbserver:
# remount the /system file system as "rw", if it's not already rw
# rename /system/b2g/b2g to /system/b2g/d.b2g or something, to prevent the android process monitor from restarting b2g
# kill any running b2g process
# forward some tcp port over adb, say |adb forward tcp:11111 tcp:11111|
# on device, launch |gdbserver :111111 /system/b2g/d.b2g

It would be cool if we had some magic that would rename "d.b2g" back to "b2g" after gdbserver is done.