[Ilugc] .a-tip-a-day. (gdb - debug C programs compiled with gcc -g )

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Mon Nov 2 07:58:39 2009

Dearest Luggies,

I am very sorry for not sending language tip yesterday. I was away
from the computer. I shall send today
evening.

gdb is the canonical C debugger. It is not a graphical tool and there
is a graphical front end called
 ddd developed by Germans. But I did not like it much.

gdb comes built in with many many features like bash. It has
completion features and several aliasing
features. For instance you can type

(gdb) list

or

(gdb) l

or

(gdb) li

with the same result.

And it is a very comprehensive debugging tool. Nowadays I don't rely
on gdb much since I use printf()s to
track what is going on in my code.

But gdb is very essential for program development in C.

The most important commands in gdb are (at least according to me)

o (gdb) where

shows the stack trace and it will tell you which sequence of function
calls crashed your program

o (gdb) list

shows you the next 10 line numbers

o (gdb) b main

sets the breakpoint at main. If you have the same function name
declared in multiple source files as static, then
you can say b foo.c:barfunction to specify that you want to break at
barfunction() in foo.c file

o (gdb) step

or 's' goes into the function. Very useful for stepping into functions
after breakpoint.

o (gdb) next

or 'n' goes to the next function. You can skip loops using 'n'.

o (gdb) continue

or 'c' continues beyond the breakpoint.

Debuggers are a big topic. Hope this gets you started.

-Girish



-- 
Gayatri Hitech
web: http://gayatri-hitech.com

SpamCheetah Spam filter:
http://spam-cheetah.com

Other related posts:

  • » [Ilugc] .a-tip-a-day. (gdb - debug C programs compiled with gcc -g ) - Girish Venkatachalam