[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53721] trunk/blender/source: include a stacktrace in the crashlog text written by the segfault handler.

Campbell Barton ideasman42 at gmail.com
Fri Jan 11 02:30:44 CET 2013


Revision: 53721
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53721
Author:   campbellbarton
Date:     2013-01-11 01:30:44 +0000 (Fri, 11 Jan 2013)
Log Message:
-----------
include a stacktrace in the crashlog text written by the segfault handler.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_report.h
    trunk/blender/source/blender/blenkernel/intern/report.c
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/source/blender/blenkernel/BKE_report.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_report.h	2013-01-11 01:08:06 UTC (rev 53720)
+++ trunk/blender/source/blender/blenkernel/BKE_report.h	2013-01-11 01:30:44 UTC (rev 53721)
@@ -74,7 +74,7 @@
 
 int BKE_reports_contain(ReportList *reports, ReportType level);
 
-// int BKE_report_write_file_fp(struct FILE *fp, ReportList *reports, const char *header);
+bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char *header);
 bool BKE_report_write_file(const char *filepath, ReportList *reports, const char *header);
 
 #ifdef __cplusplus

Modified: trunk/blender/source/blender/blenkernel/intern/report.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/report.c	2013-01-11 01:08:06 UTC (rev 53720)
+++ trunk/blender/source/blender/blenkernel/intern/report.c	2013-01-11 01:30:44 UTC (rev 53721)
@@ -302,7 +302,7 @@
 	return FALSE;
 }
 
-static bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char *header)
+bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char *header)
 {
 	Report *report;
 
@@ -321,8 +321,6 @@
 {
 	FILE *fp;
 
-	/* first try create the file, if it exists call without 'O_CREAT',
-	 * to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
 	errno = 0;
 	fp = BLI_fopen(filepath, "wb");
 	if (fp == NULL) {

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2013-01-11 01:08:06 UTC (rev 53720)
+++ trunk/blender/source/creator/creator.c	2013-01-11 01:30:44 UTC (rev 53721)
@@ -40,11 +40,16 @@
 #  include <xmmintrin.h>
 #endif
 
+/* crash handler */
 #ifdef WIN32
 #  include <process.h> /* getpid */
 #else
 #  include <unistd.h> /* getpid */
 #endif
+/* for backtrace */
+#ifndef WIN32
+#  include <execinfo.h>
+#endif
 
 #ifdef WIN32
 #  include <Windows.h>
@@ -54,6 +59,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
+#include <errno.h>
 
 /* This little block needed for linking to Blender... */
 
@@ -438,6 +444,32 @@
 	return 0;
 }
 
+static void blender_crash_handler_backtrace(FILE *fp)
+{
+#ifndef WIN32
+#define SIZE 100
+	void *buffer[SIZE];
+	int nptrs;
+	char **strings;
+	int i;
+
+	fputs("\n# backtrace\n", fp);
+
+	/* include a backtrace for good measure */
+	nptrs = backtrace(buffer, SIZE);
+	strings = backtrace_symbols(buffer, nptrs);
+	for (i = 0; i < nptrs; i++) {
+		fputs(strings[i], fp);
+		fputc('\n', fp);
+	}
+
+	free(strings);
+#undef SIZE
+#else  /* WIN32 */
+	/* TODO */
+	(void)fp;
+#endif
+}
 static void blender_crash_handler(int signum)
 {
 
@@ -460,28 +492,41 @@
 	}
 #endif
 
-	{
-		char header[512];
-		wmWindowManager *wm = G.main->wm.first;
+	FILE *fp;
+	char header[512];
+	wmWindowManager *wm = G.main->wm.first;
 
-		char fname[FILE_MAX];
+	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");
-		}
+	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);
+	printf("Writing: %s\n", fname);
+	fflush(stdout);
 
-		BLI_snprintf(header, sizeof(header), "# " BLEND_VERSION_STRING_FMT);
+	BLI_snprintf(header, sizeof(header), "# " BLEND_VERSION_STRING_FMT);
 
-		BKE_report_write_file(fname, &wm->reports, header);
+	/* open the crash log */
+	errno = 0;
+	fp = BLI_fopen(fname, "wb");
+	if (fp == NULL) {
+		fprintf(stderr, "Unable to save '%s': %s\n",
+				fname, errno ? strerror(errno) : "Unknown error opening file");
 	}
+	else {
+		BKE_report_write_file_fp(fp, &wm->reports, header);
 
+		blender_crash_handler_backtrace(fp);
+
+		fclose(fp);
+	}
+
+
 	/* really crash */
 	signal(signum, SIG_DFL);
 	kill(getpid(), signum);




More information about the Bf-blender-cvs mailing list