Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is my core file after segfault?

Tags:

gcc

coredump

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?

like image 777
Pete Wilson Avatar asked Jan 03 '12 20:01

Pete Wilson


People also ask

Where do core files go?

By default, all core dumps are stored in /var/lib/systemd/coredump (due to Storage=external ) and they are compressed with zstd (due to Compress=yes ). Additionally, various size limits for the storage can be configured. Note: The default value for kernel.

What is Segfault core dump?

Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.” When a piece of code tries to do read and write operation in a read only location in memory or freed block of memory, it is known as core dump.

Where does apport store core dumps?

If apport is enabled, it stores core dumps in the /var/crash directory by default, and you should ensure that sufficient space is maintained in the file system with that directory.


2 Answers

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)

like image 158
elijah Avatar answered Sep 25 '22 14:09

elijah


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.

like image 30
Basile Starynkevitch Avatar answered Sep 23 '22 14:09

Basile Starynkevitch