Quick tips on changing ndk-gdb interface

Quick tips on changing ndk-gdb interface

 
 
 
 
 
 
2 Votes


When doing Android debugging we usually use ndk-gdb. ndk-gdb is a script that can automatically start an Android app and automatically setup the debugger to connect to a gdbserver running on the device so we can debug native code. But ndk-gdb uses the plain text gdb. If you’re not used to it or if you want something else you’re kind of stuck. I know my way around GDB but I always want the source window, to always keep my eyes on the source code. This is probably because the first debugger that I’ve used, was the Turbo Pascal debugger from Borland.

Well there are a number of interfaces over GDB and this post gives three quick methods on how to use them with ndk-gdb.

1. GDB text GUI

GDB has an integrated text GUI that can be enabled by passing -tui option to it. Because ndk-gdb is just a script over GDB, we can modify it to make it run GDB in this mode.

1
2
3
$ which ndk-gdb
/home/cristi/Programe/android-ndk-r6b/ndk-gdb
$ sed -i 's/$GDBCLIENT/$GDBCLIENT -tui/g' /home/cristi/Programe/android-ndk-r6b/ndk-gdb

You can use the commands above to pass the -tui option to GDB or you can just edit the file and change it manually.

2. CGDB

A similar method can be used for cgdb. Just edit the ndk-gdb script and find whre GDBCLIENT variable is set.

1
$ sed -i 's/GDBCLIENT=${TOOLCHAIN_PREFIX}gdb/GDBCLIENT="cgdb -d ${TOOLCHAIN_PREFIX}gdb --"/g' $(which ndk-gdb)

… so now the variable will read:

1
GDBCLIENT="cgdb -d ${TOOLCHAIN_PREFIX}gdb --"

3. DDD

And now if we want a “more visual” debugger we can setup DDD. We have to replace the following line (in ndk-gdb):

1
$GDBCLIENT -x `native_path $GDBSETUP`

with this:

1
ddd --debugger "$GDBCLIENT -x `native_path $GDBSETUP`"

Now after enabling one of the three options, after running ndk-gdb your favourite debugger interface should start instead of the plain text GDB.


注意之前先安装ddd,步骤如下

macosx:

需要先安装xquartz(x11),再安装brew


Shell代码   收藏代码
  1. curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1  

再安装ddd

brew install libtool

brew install ddd



你可能感兴趣的:(Quick tips on changing ndk-gdb interface)