Using cgdb with ndk-debug (and cgdb tutorial)

Android ndk (http://developer.android.com/sdk/ndk/index.html) comes with ndk-gdb command that starts gdb debugger and connects it to Android application.

cgdb (http://cgdb.sourceforge.net/) is superior console front-end to gdb so it seems logical to use it for debugging of Android applications. Following modification of ndk-gdb script will cause that cgdb will be invoked instead of gdb.

Original ndk-gdb (Android NDK, r5):

# Now launch the appropriate gdb client with the right init commands
#
GDBCLIENT=${TOOLCHAIN_PREFIX}gdb
GDBSETUP=$APP_OUT/gdb.setup


Modified ndk-gdb (originally from Android NDK, r5) which uses cgdb instead of gdb:

# Now launch the appropriate gdb client with the right init commands
#
GDBCLIENT="cgdb -d ${TOOLCHAIN_PREFIX}gdb --"
GDBSETUP=$APP_OUT/gdb.setup


Now if you run ndk-gdb you will get cgdb front-end.

Small cgdb tutorial

In cgdb you can have focus either on source window (part with the source text) or gdb window.
To switch from source window to gdb press i.
To switch from gdb window to source press esc.

Commands you can use in source window:
arrows — scroll the text
space — set or delete breakpoint
o — open source file
i — switch focus to gdb window
- — make source window 1 line smaller
= — make source window 1 line bigger

Commands you can use in gdb window:
n — next instruction. Will not dive into subfunctions
s — step. Will dive into subfunctions
c — continue
b — set breakpoint
bt — show call stack (backtrace)
info threads — show information about running threads
info breakpoints — show information about breakpoints
pgup, pgdown — scroll the content of gdb window
esc — switch focus to source windows

Full cgdb documentation is at http://cgdb.sourceforge.net/docs/cgdb-no-split.html
Full gdb documentation is at http://www.gnu.org/software/gdb/documentation/

Have fun!

About these ads
This entry was posted in Android and tagged , , , , . Bookmark the permalink.

5 Responses to Using cgdb with ndk-debug (and cgdb tutorial)

  1. Pingback: Debug NDK by Eclipse « SunCopy

  2. Pingback: E-sitesweb » Using Eclipse for Android C/C++ Debugging

  3. Giora says:

    Using DDD instead of cgdb.

    Hi

    Thanks Marting for your articles. They where very helpful.

    I prefer using ddd which is full graphic interface for gdb.
    in order to work with ddd, when modifying the ndk-gdb file
    replace #GDBCLIENT=${TOOLCHAIN_PREFIX}gdb
    with GDBCLIENT=”ddd –debugger ${TOOLCHAIN_PREFIX}gdb”
    instead of #GDBCLIENT=”cgdb -d ${TOOLCHAIN_PREFIX}gdb –” as in Martin example.

    The debug procedure is: (I think it is also needed for cgdb)
    Insert a breakpoint after calling loadLibrary in java.
    Run the application in eclipse.
    Activate the ndk-dbg
    Mark a breakpoint (double click with the mouse);
    Press continue in the ddd.
    Press go in the eclipse.

    I checked it only on a real device not on emulator.

    Giora

  4. What’s up to every body, it’s my first pay a visit of
    this weblog; this website carries remarkable and genuinely good stuff designed for readers.

  5. Emanuel says:

    Heya! I realize this is somewhat off-topic however I had to ask.
    Does operating a well-established blog such as yours take a large amount of work?

    I’m brand new to writing a blog however I do write in my journal everyday. I’d like to start a blog
    so I can easily share my own experience and views online.
    Please let me know if you have any ideas or tips for new aspiring blog owners.
    Thankyou!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s