-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbacktrace.c
More file actions
39 lines (33 loc) · 762 Bytes
/
Copy pathcbacktrace.c
File metadata and controls
39 lines (33 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* author: tomasz.grel@gmail.com
* date 2017-04-08
*/
#include <Python.h>
#include <stdio.h>
#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
static PyMethodDef Methods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};
/*
* handler for the SEGFAULT signal
*/
void handler(int sig) {
const int frames = 100;
void* buffer[frames];
size_t size = backtrace(buffer, frames);
fprintf(stderr, "Received signal %d:\n", sig);
backtrace_symbols_fd(buffer, size, STDERR_FILENO);
exit(1);
}
/*
* initialization function installing the handler
*/
PyMODINIT_FUNC
initcbacktrace(void) {
(void) Py_InitModule("cbacktrace", Methods);
signal(SIGSEGV, handler); // install our handler
}