# How can I make core dump manualy?



## milo (Nov 9, 2009)

Hello everybody. How can I make core dump of my program manualy? I mean syscall like do_coredump() in linux. Handler of SIGSEGV is defined (so there are no default behavior) and do something and I want it to make core dump too. thanks.


----------



## anemos (Nov 9, 2009)

I think that 
	
	



```
kill(getpid(), SIGSEGV);
```
will do that.


----------



## milo (Nov 9, 2009)

anemos said:
			
		

> I think that
> 
> 
> 
> ...



no. SIGSEGV handler will catch signal and handle it without core dump. I need to do core dump inside of SIGSEGV handler.


----------



## TerryP (Nov 9, 2009)

Last time I required a core file, I think it was a matter of enabling core dumps with ulimit, and sysctl kern.core=1.


----------



## milo (Nov 10, 2009)

no, the OS has capability to make core files. again, i need to make core dump of my program by myself from inside of the propgram (via syscall or so). i cannot find the name of such function, that's i want. in linux it calls do_coredump() and what about FreeBSD?


----------



## aragon (Nov 10, 2009)

Possibly not what you're after, but in the signal handler maybe you can reset the SEGV action back to default, and then send a SEGV signal to yourself.


----------



## milo (Nov 10, 2009)

i don't think it's beautiful solution...


----------



## anemos (Nov 10, 2009)

Why? What do you mean beautiful?
From a quick "scan" I did in src/sys/kern/syscalls.master I concluded that there is not such a system call in FreeBSD. 

coredump() is the kernel routine which dumps a process but there is not a system call so you can reach this function.
So, as far as I can tell, you have two options:
either you write your own system call as a dynamically loadable kernel module, or you follow aragon's suggestion.

I would be interested though to see what you'll end up with.

Regards


----------



## whoppix (Nov 14, 2009)

I don't know what language you are using, but I think there should be a syscall to do that. F.ex. in perl:

```
perl -e 'dump'
```


----------



## TerryP (Nov 15, 2009)

Other then CORE::dump is obsoleted, I always thought the core dump it was based on perl opcodes rather then the perl binary.


----------



## bigearsbilly (Nov 16, 2009)

simples!


```
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>


int main(int argc, char ** argv) {


    kill(getpid(), SIGQUIT);
}
```


----------



## MorgothV8 (Nov 24, 2009)

also:
kill(getpid(), SIGABRT);

SIGABRT, SIGABORT, abort();

It worked for me.


----------



## melkov (Nov 27, 2009)

ok, one more suggestion 

```
char cmd[50];
sprintf(cmd, "gcore -s %u", getpid());
system(cmd);
```


----------



## knarf (Nov 27, 2009)

bigearsbilly said:
			
		

> simples!
> 
> 
> ```
> ...



What about hitting ^\ on the keyboard?


----------

