Monday, June 3, 2013

GDB Findings

Enable non-stop debugging mode in GDB:

set target-async 1

 # If using the CLI, pagination breaks non-stop.
set pagination off

# Finally, turn it on!
set non-stop on

Enable logging in GDB:

* set remotelogfile [FILE_PATH]

List of targets in GDB:

* There is no command to get list of targets but GDB matches target against configure.tgt target list. Easiest way to check supported targets is to view gdb/configure.tgt file.

Removing noisy signals while debugging with GDB:
I faced this problem while debugging  QEMU with GDB. I built QEMU with debug info and tried debugging it with GDB. On giving 'run' command, I noticed that GDB was suspending on every user signal. I gave following command on GDB console to ignore USR1 signals

* handle SIGUSR1 noprint nostop

Similar command can be use to ignore other signals e.g.
* handle SIGINT  nostop noprint
* handle SIGQUIT nostop noprint
* handle SIGUSR2 nostop noprint

Increasing remote connection timeout:

I initially thought set remotetimeout is used for initial connection timeout but after spending some time, I noticed that GDB has separate timeout for initial connection and it is set by following command:

* set tcp connect-timeout num

Enable/Disable Inferior debug information:

I found this command very useful to understand run-control commands behavior in GDB. It is used to switch on/off debug information of running inferior. It helped me a lot to understand how stepping works in GDB. infrun.c contains GDB's runtime state machine used for implementing operations such as single-stepping the inferior.
* set debug infrun 1
You can also check state of debugging inferior using following command:
* show debug infrun

Multi-Target GDB:

GDB now allows to build multi-target GDB using --enable-targets option in configure. Below is example of configuring GDB for ARM EABI and Linux:

*  ./configure --target=arm-none-eabi --enable-targets=arm-linux
* make

Now if you look at gdb/init.c, you can see linux target calls.

 Debugging running GDB using GDB:

GDB can be debugged using GDB. It often happens that one need to debug running instance of GDB by attaching to it. A problem that comes in this case is that gdb is set up to let the non-erroneous signals like SIGALRM be silently passed to your program (so as not to interfere with their role in the program's functioning) but to stop your program immediately whenever an error signal happens.

To change this use following command in debugger GDB:
              handle SIGINT nostop pass