gdba

Just wanted to share a quick hint for GDB users. When you want to debug a program that takes command-line arguments, the “traditional” way looks something like this:

% gdb a.out
GNU gdb 6.3.50-20050815...

(gdb) set args x y z
(gdb) run

But you can do even better. GDB itself has the command-line flag --args, which means that the rest of the arguments go to the program you’re debugging!

% gdb --args a.out x y z

I found this so useful that I made gdba an alias for gdb --args.

% alias gdba='gdb --args'

Bonus tip: if your project uses make, you can remake your executable from inside GDB and re-run, without even using the shell command.

(gdb) make
(gdb) run

Haven’t tried LLDB yet, but hoping it gets there. GDB still locks up whenever I accidentally use tab-completion on a big project. I should just disable that.

blog comments powered by Disqus