I’m using Ubuntu and gcc. My application crashes I only have Segmentation fault
message in console. (previously Segmentation fault (core dumped)
was reported but now it changed to just Segmentation fault
).
There are no hints where the problem is so I do not understand how should I fix the problem. I need some hints to find what caused this – ideally complete stack trace or at least object type/method or something like this.
What would be the correct way of troubleshooting such type of problem? (may be compile with some extra flags, run some tools, collect core dump and analyze it somehow?)
Advertisement
Answer
You might well need to enable core dumps with
ulimit -c unlimited
Once you have a core dump, you can look at the program state with GDB:
gdb my_prog core
You should then have the same view that you would have had if you’d run the program under GDB until it crashed – you could just do that, rather than collecting the core dump. In particular, it will show you which line caused the segfault, and the state of the call stack at that point.
To get the best debugging view, you should tell the compiler to include debugging symbols (-g
) and disable optimisation (-O0
).