5

My C program crashed on CentOS 5.7 with the following log:

kernel: [1030648.130682] myapp[16454]: segfault at 0 ip b765f683 sp bfc3fa0c error 4 in libc-2.5.so[b75ee000+157000]

Seems a call to libc caused the segfault. How can I know in which function in libc the segfault happened?

It's a prod environment and no coredump file was left; and it rarely reproduces. So, what I can do now is to analyze which function in libc (called by my program) caused this segfault, then I can check my code.

It'll be great if there are pointers that explain what these numbers mean: ip b765f683, sp bfc3fa0c, error 4, b75ee000+157000. I googled but didn't find good references.

Thanks.

Wang Tuma
  • 893
  • 5
  • 14
  • 24
  • 2
    Have you tried googling with your title? http://www.unknownroad.com/rtfm/gdbtut/gdbsegfault.html http://stackoverflow.com/questions/13337472/where-is-my-segmentation-fault – RedX Dec 19 '13 at 10:37
  • That's why we compile with the `-g` flag, and [use tools like gdb](http://www.centos.org/docs/3/html/rhel-devtools-en-3/s1-gdb-debugging.html): so we can work it out ourselves, and not use a Q&A site as an interactive debugger – Elias Van Ootegem Dec 19 '13 at 11:40
  • 2
    sorry I didn't mean to use this site as an interactive debugger. My problem is that, the sgefault happened at a prod environment and no coredump file was left; and it rarely reproduces so using gdb to see where it happens doesn't work (since it doesn't crash a lot). So, what I can do now is to analyze which function in libc (called by my program) caused this segfault, then I can check my code. It'll be great if there are pointers that explain what these numbers mean: ip b765f683, sp bfc3fa0c, error 4, b75ee000+157000. I googled but didn't find good references. – Wang Tuma Dec 20 '13 at 03:42
  • Possible duplicate of [Interpreting segfault messages](http://stackoverflow.com/questions/2549214/interpreting-segfault-messages) – Armali Jan 10 '17 at 13:47

2 Answers2

0

Usually, segmentation fault is a sign that your application is trying to access some unauthorized/unintedneded memory region. Compile your code with -g switch, then run the generated binary with some memory debugger like and check what is the output from valgrind. Most of the times, you'll get the erroneous call which caused the error.

Romuald Brunet
  • 5,595
  • 4
  • 38
  • 34
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

Compile using -ggdb switch (using gcc) and use gdb to find out where is the source of the crash ... This tutorial is very helpful.

Algo
  • 841
  • 1
  • 14
  • 26