B2G icon indicating copy to clipboard operation
B2G copied to clipboard

Add some Makefile helpers for using gdb

Open joneschrisg opened this issue 13 years ago • 5 comments

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.

joneschrisg avatar Feb 02 '12 02:02 joneschrisg

It goes an inconsistent state to rename b2g as d.b2g and fail to back. In latest version of gdb, it supports follow-exec-mode. We can attach on a running b2g, and invoke exec to execute itself in the process.

ThinkerYzu avatar Feb 02 '12 06:02 ThinkerYzu

Note that the search paths in the first comment are for the emulator, where all libs have symbols. On the sgs2, these paths allow gdb to find all libs

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

joneschrisg avatar Feb 08 '12 05:02 joneschrisg

I am working on this issue. I think we can do this completely in Makefile and don't need have a .gdbinit file for each target platform. This provides us "scripting" .gdbinit to some extent.

The current progress is run-gdb-server and run-gdb-host Makefile targets. run-gdb-host will attach to the running b2g process. I am working on re-exec the executable so we may debug from main().

cervantesyu avatar Feb 09 '12 03:02 cervantesyu

I added a attach-gdb target to the makefile to attach to the currently running b2g process

https://github.com/andreasgal/B2G/commit/181e7a09ddd62b27ef79f9a0ec28940fb363fbed

andreasgal avatar Feb 11 '12 23:02 andreasgal

update the gdb targets

https://github.com/CervantesYu/B2G/commit/c1b04b873c7000093aa75e83acc5fef531562062

cervantesyu avatar Feb 13 '12 09:02 cervantesyu