Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot reproduce segfault in gdb

Tags:

c

gdb

I'm getting segfaults when I run my project. Every time I run the program in gdb, the segfaults disappear. This behavior is not random: each time I run it in my shell it segfaults, each time I run it in gdb, the segfaults disappear. (I did recompile using -g).

So before I start adding printfs frantically everywhere in my code, I would like to know a few things:

  • Is this behavior common?
  • What's the best way to approach the issue?

I don't know if tests can be scripted since my application is interactive and crashes on a particular user input.

I didn't paste my code here because it'd be way too long. But if anyone is interested in helping out, here it is: https://github.com/rahmu/Agros

like image 252
rahmu Avatar asked Aug 14 '11 15:08

rahmu


1 Answers

The easiest way to figure it out is to capture core dumps:

$ ulimit -c unlimited

Then run your program. It will generate a core file

Then use gdb:

$ gdb ./program core

And gdb will load and you can run a backtrace to see exactly what operation elicited the segfault.

like image 80
Foo Bah Avatar answered Sep 28 '22 11:09

Foo Bah