Random thoughts shooting out of volatile mind
GDB a GNU debugger
GDB is a free debugger by GNU. Its a command line debugging facility used for debugging C,C++ and few other languages. Most of us are familiar with debugging in a Graphical Interface and feel awkward to use GDB. But GDB is a powerful debugger, once you know how to use it you won't be awkward to use it. Here i'm giving a few tips (which I know about GDB).
  • To debug a C or C++ program using GDB you must specify a switch during compile time i.e tell compiler to produce debugging information file. This can be done as follows
gcc -ggdb filename.c or g++ -ggdb filename.cpp (you can also use cc or c++ and switch can be simply -g)
  • Once you have compiled the program without any errors, its time to launch gdb
gdb a.out (or filename if you renamed the file during compilation)

You will command line of gdb which looks something like this (gdb)_

The commands in gdb are

run command line aruments: If your program doesn't take any command line arguments then simply specify run. This command starts your program.


break place :Creates a breakpoint; the program will halt when it gets there. The most common breakpoints are at the beginnings of functions. You can also specify line numbers in source file where you want to place break point like break 20.

delete N : Deletes break point at line N. Information about the break point can be got by using info break.

step : Executes current line and stops at next line.

next : Similar to step but when current line is function call next command executes the whole function and stops at next line to function call. Step enters the function and stops at first statement in function.

finish : Keeps doing nexts, without stepping, until reaching the end of the current function.

continue : Continues regular execution of the program until a breakpoint is hit or the program stops.

print E : prints the value of E in the current framein the program, where E is a C expression (usually just a
variable). display is similar, except every time you execute a next or step, it will print out the
expression based on the new variable values.

where or bt or backtrace : prints chain of function call that brought the program to current point of execution.

quit : Leaves GDB.

If you want to know further functionality of gdb you should follow this link

http://www.delorie.com/gnu/docs/gdb/gdb_toc.html



Happy Debugging :)

    Posted by: copyninja on Sunday, 21 September 2008

    blog comments powered by Disqus
    Fork me on GitHub