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.
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.
Try gdb
; or a frontend like ddd
or kdgb
.
Compile with the -g
flag.
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/
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
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.