how to get a core dump in darwin?

pfons

Registered
In a large fortran program I would like to get the system to do a core dump so I can poke around the symbol table at my leisure. I have attempted to do so with a small test c program (compiled using Apple's developer tools).

ulimit coredumpsize

cat dumpcore.c

#include <stdio.h>
#include <signal.h>
int dumpcore();
int main()
{
return dumpcore();
}
int dumpcore(void)
{
int dog[50],i;
for(i=0;i<50;i++) {
dog = i*i;
}
return raise(SIGABRT); // dump core
}

galatica% ./dumpcore
Abort (core dumped)

... but there is no core file! What gives?

 
Is there a "nocoredump" or "coredump=0" or similar line somewhere in the environemnt variables? It is entirely likely that this might be a "feature" of one of the generic user startup scripts that your shell reads. I don't have PB any more, but I know that at my school on the UNIX boxes the generic startup script (etc/tcsh.rc or something...) has a command to suppress coredumps. I had to manually override it with my .tcshrc file before I could get anything out.

Hope this helps,

Zach
 
If it *says* "core dumped", then it probably did dump one in /cores/core.&lt;pid&gt;

Core dumps are off by default I'm pretty sure, but when they are I don't think it actually says "core dumped" when aborting.

If the corefiles aren't showing up, then I vaguely recollect there being an environment variable to change the setting, but I have no idea where to look for it.

You could change the limit in your code explicitly with setrlimit():

#include &lt;sys/types.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;sys/resource.h&gt;

void set_core_max(int max)
{
struct rlimit limit;

limit.rlim_cur = limit.rlim_max = max;
setrlimit(RLIMIT_CORE, &amp;limit);
}

and call it with INT_MAX or RLIM_INFINITY or whatever.
I did manage to force a coredump that way.


[Edited by lindberg on 02-19-2001 at 01:27 AM]
 
Here is the offending line from the generic cshrc that prevented me from seing core dumps on the solaris machines at school... I don't know how similar the BSD/darwin commands will be, though.
limit coredumpsize 0 # don't write core dumps


Zach
 
Unlike other unix systems I have used, core dumps don't occur in the current folder, but are dumped in /core. This is a feature of the operating system. I didn't find any mention of it in the man pages. Go figure. In any case it does work.
 
Back
Top