8000 Initial implementation for glibc · python/cpython@0ebdc69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ebdc69

Browse files
committed
Initial implementation for glibc
1 parent 255762c commit 0ebdc69

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Modules/faulthandler.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,43 @@ faulthandler_dump_traceback(int fd, int all_threads,
212212
reentrant = 0;
213213
}
214214

215+
static void
216+
faulthandler_dump_c_stack(int fd, PyInterpreterState *interp)
217+
{
218+
static volatile int reentrant = 0;
219+
220+
if (reentrant)
221+
return;
222+
223+
reentrant = 1;
224+
225+
#include <execinfo.h>
226+
#define SIZE 128
227+
void *callstack[128];
228+
int frames = backtrace(callstack, SIZE);
229+
char **strings = backtrace_symbols(callstack, SIZE);
230+
FILE *fp = fdopen(fd, "w");
231+
if (strings == NULL)
232+
{
233+
fputs("<failed to get current C stack>", fp);
234+
}
235+
else {
236+
fputs("\nCurrent thread's C stack trace:\n", fp);
237+
for (int i = frames; i >= 0; --i)
238+
{
239+
fprintf(fp, " %s\n", strings[i]);
240+
}
241+
242+
if (frames == SIZE)
243+
{
244+
fprintf(fp, "<truncated rest of calls>\n");
245+
}
246+
}
247+
#undef SIZE
248+
249+
reentrant = 0;
250+
}
251+
215252
static PyObject*
216253
faulthandler_dump_traceback_py(PyObject *self,
217254
PyObject *args, PyObject *kwargs)
@@ -322,6 +359,7 @@ faulthandler_fatal_error(int signum)
322359

323360
faulthandler_dump_traceback(fd, fatal_error.all_threads,
324361
fatal_error.interp);
362+
faulthandler_dump_c_stack(fd, fatal_error.interp);
325363

326364
_Py_DumpExtensionModules(fd, fatal_error.interp);
327365

0 commit comments

Comments
 (0)
0