PDA

View Full Version : GCC and no core dump file?



calibumm
13th July 2004, 05:26 AM
One kind of never wants to see a coredump file when programming, However I came across something a bit odd when using Fedora Core1 and gcc(g++).
When working on a c++ program, the thing faulted, segmentation fault to be precise.
However, it left no core file to debug with.
So, I made a little prog. that would for SURE dump and should have left a file.

ex.
#include<stdio.h>
#include<stdlib.h>

#define BIGNUM 5000

void index_to(int ary[]);

int main(void)
{
int intary[10];

index_to(intary);
exit(EXIT_SUCCESS);
}
void index_to(int ary[])
{
int i;
for(i=1; i<BIGNUM;i++)
ary[i] = i;
}

i compiled the code as gcc -g test.c -o test. It gave nothing, when i executed ./test
I compiled the exact same prog on an AIX machine and it gave me a Segmentation Fault(coredump) and left a core file to play w/.
Whats up w/ my gcc/g++?
I tried to remove the gcc and glibc and all its dependancies but ti wouldnt' let me. rpm -e gcc 2-3.x.x.x right?
Whats even weirder is I ran gdb w/ the prog above and it said it executed correctly.
WHAT??!!

Any suggestions? Before i try another distro... :(

rkl
13th July 2004, 05:44 AM
Looking at your C code, its behaviour once i=10 in the loop is undefined. It runs away into memory, which may or may not cause a program crash. This is very much dependent on where/how the compiler stores the array in memory and whether the loop between 10 and 4999 wipes enough out-of-bounds memory or not to cause a problem.

I'm thinking that something like valgrind here is useful - see http://valgrind.kde.org/ - this might track memory allocations and report on unfreed memory or memory being used that hasn't been allocated.

calibumm
13th July 2004, 07:58 AM
Well suppose BIGNUM was defined to be 10000, wouldn't the compiler in general leave a core file behind if the program crashed then?
My general Q is, does fedora store core dumps somewhere else besides the current directory in which the program was compiled?

Viro
13th July 2004, 09:42 AM
The thing is, the behavior of hte program is undefined. It may not have crashed and so you won't get a core dump.

bretzel
6th August 2004, 03:57 PM
I take this opportunity to ask for : how to enable core dump ? Because I can't recall when and where I read that it is possible to configure something in the system to enable corefile at crash or not. ...But I can't remember how to do it ...


Someone know how to control that ?

bretzel

crackers
7th August 2004, 04:55 AM
If you look in /etc/profile, there's a line like this:


# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

The "-c 0" basically indicates that core-dumps are "0" sized - in other words, no dumps.