2

When I run programs with segfaults I get an error message Segmentation fault: 11. For some reason, I'm not getting the (core dumped) message. I tried running the shell command ulimit -c unlimited, but I still get the same error and it doesn't say core dumped. I'm new to GDB so I tried it with a simple program:

/* coredump.c */
#include <stdio.h>
int main (void) {
  int *point = NULL;
  *point = 0;
  return 0;
}

But when I compile using:

gcc coredump.c -g -o coredump

And run it, it still says segfault: 11

Is it still creating a core dump somewhere I don't know about? I want to be able to use gdb coredump core.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
DanMoore
  • 621
  • 1
  • 8
  • 14
  • possible duplicate of [How to enable full coredumps on OS X?](http://stackoverflow.com/questions/2207233/how-to-enable-full-coredumps-on-os-x) – John Carter Aug 18 '12 at 23:42

4 Answers4

2

Look at this link:

Options include:

  • ulimit -c unlimited (default = 0: no core files generated)

  • the directory for the dump must be writable. By default this is the current directory of the process, but that may be changed by setting /proc/sys/kernel/core_pattern.

  • in some conditions, the kernel value in /proc/sys/fs/suid_dumpable may prevent the core to be generated.

  • "man core" for other options

  • find / -name core -print 2> /dev/null to search your filesystem for core files

I presume you're running Linux, and I presume you're executing the .exe in a directory where you have write permissions.

So my top two guesses would be 1) "ulimit -c unlimited" isn't getting set, or is being overridden, or 2) the core files are being generated, but going "somewhere else".

The above suggestions should help. Please post back what you find!

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Thanks for the link! I am using OSX, and when i checked the man page for core, it said that dumps are disabled by default under Darwin/Max OS X to re-enable core dumps, a privelaged user must edit **/etc/launchd.conf**, but I don't see that file under /etc..? – DanMoore Aug 18 '12 at 18:12
  • 2
    @DanMoore - Check out these links: [setting-environment-variables-in-os-x](http://stackoverflow.com/questions/135688/), https://developer.apple.com/library/mac/#technotes/tn2004/tn2124.html, [how-to-enable-full-coredumps-on-os-x](http://stackoverflow.com/questions/2207233/). Note that `/etc/launchd.conf` might not exist. Just create one, per the example in one of the replies the first link. – paulsm4 Aug 18 '12 at 18:49
  • It worked! I checked out the first link you sent me. i created a new config file in /etc, wrote the line **limit core unlimited**, rebooted my mac, and now all my segfault error messages say (core dumped)! The core file itself can be found in /cores. Thanks!! – DanMoore Aug 18 '12 at 19:18
  • @DanMoore - Cool: thank you for the good word! Please mark this reply "accepted" if it worked. – paulsm4 Aug 18 '12 at 21:39
1

If you're running the program that crashes from the shell, then you should follow the guidelines in Apple's Tech Note TN2124, which I found out about in in the answer to SO2207233.

There are a few key points:

  1. You need to set ulimit -c unlimited in bash (same effect, different command in tcsh).
  2. You need to set the permissions on the /cores directory so that you can create files in it. The default permissions are 1775; you need 1777. The 1 indicates the sticky bit is set.
  3. The core dumps are then created in /cores suffixed with a PID (/cores/core.5312, for example).

If you want programs launched graphically to dump core when they crash, then you need to create /etc/launchd.conf if it does not already exist, and add a line limit core unlimited to the file. Again, see the information in the Tech Note for more details.


Watch it; core dumps are huge! Consider this not very complicated or big program:

#include <stdio.h>
int main(void)
{
    int *i = 0;
    int j = 0;
    printf("i = %d, j = %d, i / j = %d\n", *i, j, *i / j);
    return 0;
}

The core dump from this is nearly 360 MB.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0

Sometimes core files are not store in current directory and may follow a different naming rule

sysctl -a | grep kern.core

may give hints to where your core files are stored

philant
  • 34,748
  • 11
  • 69
  • 112
Stephane Rouberol
  • 4,286
  • 19
  • 18
0

Using gcc, if you add the flags:

gcc -g -dH

you should be able to generate a core dump

The -g flag produces some debugging information to use with gdb, and the -dH flag produces a core dump when there is an error

smang
  • 1,187
  • 10
  • 23
  • i compiled using **gcc -g -dH coredump.c**, but when I ran the a.out, no core dump message appeared :( thanks though – DanMoore Aug 18 '12 at 17:46
  • The message may not appear, but was there a file named coredump.dSYM, or something similar – smang Aug 18 '12 at 17:48