tags:

views:

112

answers:

6

Hi,

I just started learning C, and I am looking for a simple tool for debugging in gcc environment. Such tool would print a stack trace, and indicate where a segmentation fault occurs.

+6  A: 

Try gdb; or a frontend like ddd or kdgb.

Compile with the -g flag.

Adrian Panasiuk
gdb being text-based. ddd being a GUI wrapper around gdb.
I'm fairly certain that should read, Compile with -ggdb3 flag.
scvalex
A: 

GDB is what you are looking for. In particular, the backtrace command in GDB will show you a stack trace. http://www.cs.cmu.edu/~gilpin/tutorial/

Edward Amsden
A: 

GDB does it all - you need to compile your program with debug information (use -g switch) and then open it with GDB. To print stack trace use command bt.

To investigate segfaults you need to pass path to core file to GDB as well, like this:

gdb yourprogram core

If your system by default doesn't generate core files in case of segfault, you can switch it on using command:

ulimit -c unlimited
qrdl
A: 

If you use X try "ddd"

Dewfy
A: 

Whether you use the command line gdb, or one of the front-ends such as DDD, you should definitely take a look at the gdb manual, which is also (like many GNU manuals) a very good tutorial.

anon
A: 

I would also advise to look at valgrind.

There's also a nice integration of gdb in kdevelop (the emacs binding is fine too..)

LB