[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Segmentation faults and Core Dump

Shridhar Daithankar forced the electrons to say:
>  The only answer to core dump is pointer(barring divide by zero but I think 
> that's trapped)

Actually, divide by zero will also generate a core dump, I think - but it
won't be SIGSEGV - it will be SIGFPE that generates the dump.

man 7 signal will give you a list of all signals that causes a program to dump

>  Either you try to use a function pointer that's invalid or access data by 
> reference of a pointer, that's invalid.

It is not due to referencing a pointer - but dereferencing it ;-)

char *p = malloc (1); p += 1000000; will not dump core - but if you try
to access data at p, with things like *p = 0x42, it most likely will.

To OP: Compile your program with debugging support turned on (gcc -g), run it
to generate the core dump, and then invoke gdb <exe file> core. From within
gdb, give the bt command to get a full backtrace to the point of core dump.
Run your program under gdb's control, examine all variables at the point of
the dump - and usually you will find the cause of the dump (most likely buffer