Pete Wilson
Pete Wilson

Reputation: 8694

Where is my core file after segfault?

When my program segfaults, I expect a coredump but there is none. I thought just compiling with -g was enough to get a core file. Here are the gcc lines from my makefile:

  gcc -g -c client.c $(incdirs)
  gcc -g -o client client.o $(LIBDIRS) $(LIBS) -lrt -lidn -lssl \
  /home/calls/cgi/libcurl/lib/libcurl.a  -lezxml -lxmlate $(SQLIBS)

All of the libraries are compiled/linked with -g as well.

And here's the gcc version info:

calls/cgi/client>gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-51)

My question: What more do I have to tell gcc (or anybody else) to get a core file?

Upvotes: 12

Views: 15379

Answers (3)

user10736820
user10736820

Reputation: 31

Input it like me:

➜ sysctl kernel.core_pattern
kernel.core_pattern = /var/crash/core-%e-%p-%t

And it will be found in /var/crash

Or maybe you should set it withulimit -c unlimited if you input ulimit -c it says 0

Upvotes: 0

elijah
elijah

Reputation: 2924

it may be that the core size is set to 0. Try

ulimit -a

if it shows

core file size          (blocks, -c) 0

then do

ulimit -c unlimited

(you may need to modify your profile scripts to change this permanently)

Upvotes: 24

You need to enable core dump, in particular by setting the appropriate resource limit. The system call is setrlimit if you wanted to set it in your program. Most often, you need to set it in your shell, e.g. with ulimit -c unlimited

And your question is probably duplicate of this one and many others.

BTW, it is usually not gcc which dumps core, it is your program (compiled by gcc or some other compiler, like clang or tcc).

Don't forget to compile your program with gcc -Wall -g.

And your question has many answers, you'll find thousands or more of them with Google or another search engine.

Upvotes: 2

Related Questions