1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2011-2012 Tomas Gavenciak <gavento@ucw.cz> *
20 * Copyright (C) 2012 Cyril Hrubis <metan@ucw.cz> *
22 *****************************************************************************/
26 #include "../config.h"
33 #endif /* HAVE_BACKTRACE */
39 #include "core/GP_Common.h"
41 #define GP_ABORT_INFO_TRACE_LEVELS 20
44 void GP_DebugPrintCStack(void)
47 #if GP_ABORT_INFO_TRACE_LEVELS > 0
48 void * buffer
[GP_ABORT_INFO_TRACE_LEVELS
+ 1];
49 int size
= backtrace(buffer
, GP_ABORT_INFO_TRACE_LEVELS
);
50 fprintf(stderr
, "\nC stack trace (most recent call first):\n");
52 backtrace_symbols_fd(buffer
, size
, fileno(stderr
));
53 #endif /* GP_ABORT_INFO_TRACE_LEVELS > 0 */
54 #endif /* HAVE_BACKTRACE */
57 static void print_python_stack(void)
60 /* Print python stack trace in case python lib is loaded and
61 * a python interpreter is initialized */
62 int (*dl_Py_IsInitialized
)();
63 int (*dl_PyRun_SimpleString
)(const char *);
64 dl_Py_IsInitialized
= dlsym(RTLD_DEFAULT
, "Py_IsInitialized");
65 dl_PyRun_SimpleString
= dlsym(RTLD_DEFAULT
, "PyRun_SimpleString");
66 if (dl_Py_IsInitialized
&& dl_PyRun_SimpleString
&& dl_Py_IsInitialized()) {
67 fprintf(stderr
, "\nPython stack trace (most recent call last; ignore last line):\n");
69 dl_PyRun_SimpleString("import traceback; traceback.print_stack();");
74 void GP_PrintAbortInfo(const char *file
, const char *func
, unsigned int line
,
75 const char *msg
, const char *fmt
, ...)
79 fprintf(stderr
, "*** gfxprim: %s:%d: in %s: %s\n",
80 file
, line
, func
, msg
);
83 vfprintf(stderr
, fmt
, va
);
86 fprintf(stderr
, "\n");
89 GP_DebugPrintCStack();