Jack Jacobsen
Jack Jacobsen

Reputation: 93

GDB creating a core file

For testing purposes I want to create a core file of a test program I made. It's not corrupted and it doesn't screw up, but I want to generate a core file of it. Here's the code:

#include <stdio.h>
int main(){
printf("TEST");
}

How can I create a core dump of it? BTW I'm on Ubuntu 10.04

Upvotes: 6

Views: 14081

Answers (4)

CB Bailey
CB Bailey

Reputation: 792129

If you can change the program adding a call to abort() will generate a core dump in many unix environments.

You need to make sure that you have core files enabled. The most common reason for core files not being generated is a zero size core ulimit. Check with the command ulimit -c and reset if zero with ulimit -c unlimited.

If you don't want to change the program you can send an abort signal with the kill command: kill -SIGABRT <pid> but with such a short program you are probably going to have to used a script and even then you may not be able to get the signal in before the process exits.

With bash you can try something like this (assuming that your program is called a.out and is in the current directory):

./a.out & kill -SIGABRT $!

& says run this in the background and $! is the PID of the most recently executed background command.

Upvotes: 6

dev
dev

Reputation: 829

Another option is to use - gcore command.

Upvotes: 0

jcopenha
jcopenha

Reputation: 3975

Load your program in gdb, set a breakpoint, run to the break point and then

(gdb) generate-core-file

Upvotes: 6

Karl Bielefeldt
Karl Bielefeldt

Reputation: 49088

From the gdb command prompt with your executable loaded, issue the generate-core-file command.

Upvotes: 12

Related Questions