Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-01-10 20:37:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-01-10 20:37:48 +0400
commit18536e201f26f20bde6379afa996153433404c65 (patch)
tree092fee45425217006de6d36ba26c110831c0cabe /source/creator
parentf6f33515ac62fb603ceba0eeaf79047b4451f754 (diff)
add a segfault handler that writes out the info log into a crash file alongside the blend file.
Diffstat (limited to 'source/creator')
-rw-r--r--source/creator/creator.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 158ce8f2eeb..7dd43840c91 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -41,6 +41,12 @@
#endif
#ifdef WIN32
+# include <process.h> /* getpid */
+#else
+# include <unistd.h> /* getpid */
+#endif
+
+#ifdef WIN32
# include <Windows.h>
# include "utfconv.h"
#endif
@@ -157,6 +163,8 @@ static int print_version(int argc, const char **argv, void *data);
/* Initialize callbacks for the modules that need them */
static void setCallbacks(void);
+static bool use_crash_handler = true;
+
#ifndef WITH_PYTHON_MODULE
/* set breakpoints here when running in debug mode, useful to catch floating point errors */
@@ -246,6 +254,7 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
printf("Misc Options:\n");
BLI_argsPrintArgDoc(ba, "--debug");
BLI_argsPrintArgDoc(ba, "--debug-fpe");
+ BLI_argsPrintArgDoc(ba, "--disable-crash-handler");
#ifdef WITH_FFMPEG
BLI_argsPrintArgDoc(ba, "--debug-ffmpeg");
@@ -350,6 +359,12 @@ static int disable_python(int UNUSED(argc), const char **UNUSED(argv), void *UNU
return 0;
}
+static int disable_crash_handler(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+ use_crash_handler = false;
+ return 0;
+}
+
static int background_mode(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
{
G.background = 1;
@@ -423,6 +438,56 @@ static int set_fpe(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(dat
return 0;
}
+static void blender_crash_handler(int signum)
+{
+
+#if 0
+ {
+ char fname[FILE_MAX];
+
+ if (!G.main->name[0]) {
+ BLI_make_file_string("/", fname, BLI_temporary_dir(), "crash.blend");
+ }
+ else {
+ BLI_strncpy(fname, G.main->name, sizeof(fname));
+ BLI_replace_extension(fname, sizeof(fname), ".crash.blend");
+ }
+
+ printf("Writing: %s\n", fname);
+ fflush(stdout);
+
+ BKE_undo_save_file(fname);
+ }
+#endif
+
+ {
+ char header[512];
+ wmWindowManager *wm = G.main->wm.first;
+
+ char fname[FILE_MAX];
+
+ if (!G.main->name[0]) {
+ BLI_make_file_string("/", fname, BLI_temporary_dir(), "blender.crash.txt");
+ }
+ else {
+ BLI_strncpy(fname, G.main->name, sizeof(fname));
+ BLI_replace_extension(fname, sizeof(fname), ".crash.txt");
+ }
+
+ printf("Writing: %s\n", fname);
+ fflush(stdout);
+
+ BLI_snprintf(header, sizeof(header), "# " BLEND_VERSION_STRING_FMT);
+
+ BKE_report_write_file(fname, &wm->reports, header);
+ }
+
+ /* really crash */
+ signal(signum, SIG_DFL);
+ kill(getpid(), signum);
+}
+
+
static int set_factory_startup(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
{
G.factory_startup = 1;
@@ -1122,6 +1187,8 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
BLI_argsAdd(ba, 1, "-y", "--enable-autoexec", "\n\tEnable automatic python script execution" PY_ENABLE_AUTO, enable_python, NULL);
BLI_argsAdd(ba, 1, "-Y", "--disable-autoexec", "\n\tDisable automatic python script execution (pydrivers & startup scripts)" PY_DISABLE_AUTO, disable_python, NULL);
+ BLI_argsAdd(ba, 1, NULL, "--disable-crash-handler", "\n\tDisable the crash handler", disable_crash_handler, NULL);
+
#undef PY_ENABLE_AUTO
#undef PY_DISABLE_AUTO
@@ -1301,6 +1368,10 @@ int main(int argc, const char **argv)
BLI_argsParse(ba, 1, NULL, NULL);
#endif
+ if (use_crash_handler) {
+ /* after parsing args */
+ signal(SIGSEGV, blender_crash_handler);
+ }
/* after level 1 args, this is so playanim skips RNA init */
RNA_init();