Mark
Mark

Reputation: 8688

c++ what is a good debugger for segmentation errors?

Does anyone know a good debugger for C++ segmentation errors on the Linux environment? It would be good enough if the debugger could trace which function is causing the error.

Upvotes: 1

Views: 111

Answers (3)

dimba
dimba

Reputation: 27581

Also consider some techniques that do require from you code changes:

  1. Run your app via valgrind memcheck tool. It's possible to catch error when you access wrong address (e.g. freed pointer, not initialized) - see here.

  2. If you use extensievly stl/boost, consider compiling with -D_GLIBCXX_DEBUG and -D_GLIBCXX_DEBUG_PEDANTIC (see here). This can catch such errors as using invalidated iterator, accessing incorrect index in vector etc.

  3. tcmalloc (from google per tool). When linking with it's debug enabled version, it may find memory related problems

  4. Even more ...

Upvotes: 4

Eelke
Eelke

Reputation: 22013

GDB is indeed about the only choice. There are some GUI's but they are allmost all wrappers for gdb. Finding a segfault is easy. Make sure you compile with -g -O0 then start gdb with your program as argument.

In gdb type run

To start your program running, gdb will stop it is soon as it hits a segfault and report on which line that was. If you need a full backtrace then just type bt. To get out of gdb enter quit.

BTW gdb has a build in help, just type help.

Upvotes: 2

Alok Save
Alok Save

Reputation: 206546

GDB! what else is available on Linux?

Check this out for starting up with GDB, its a nice, concise and easy to understand tutorial.

Upvotes: 3

Related Questions