src/crashCatcher.cc

Wed, 03 Sep 2014 01:28:58 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 03 Sep 2014 01:28:58 +0300
changeset 875
ce8e9b37d44f
parent 861
83426c5fa732
child 882
2f3cc8e045d5
permissions
-rw-r--r--

- finished line loop mode
- enter and backspace keys may now be used with the draw modes

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
844
11587d419d2f - changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
3 * Copyright (C) 2013, 2014 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QProcess>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QTemporaryFile>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <unistd.h>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <signal.h>
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
23 #include "crashCatcher.h"
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
24 #include "dialogs.h"
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
25
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
26 #ifdef __unix__
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
27 # ifdef Q_OS_LINUX
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
28 # include <sys/prctl.h>
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
29 # endif
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 // Is the crash catcher active now?
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
32 static bool IsCrashCatcherActive = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 // If an assertion failed, what was it?
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
35 static QString AssertionFailureText;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // List of signals to catch and crash on
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
38 static QList<int> SignalsToCatch ({
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 SIGSEGV, // segmentation fault
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 SIGABRT, // abort() calls
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 SIGFPE, // floating point exceptions (e.g. division by zero)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 SIGILL, // illegal instructions
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 });
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
45 // -------------------------------------------------------------------------------------------------
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
46 //
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
47 // Removes the signal handler from SIGABRT and then aborts.
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
48 //
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
49 static void FinalAbort()
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
50 {
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
51 struct sigaction sighandler;
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
52 sighandler.sa_handler = SIG_DFL;
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
53 sighandler.sa_flags = 0;
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
54 sigaction (SIGABRT, &sighandler, 0);
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
55 abort();
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
56 }
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
57
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
58 // -------------------------------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 //
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
60 static void HandleCrash (int sig)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 {
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
62 printf ("!! Caught signal %d, launching gdb\n", sig);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
64 if (IsCrashCatcherActive)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 {
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
66 printf ("Caught signal while crash catcher is active! Execution cannot continue.\n");
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
67 FinalAbort();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
70 pid_t const pid (getpid());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 QProcess proc;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 QTemporaryFile commandsFile;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
74 IsCrashCatcherActive = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 if (commandsFile.open())
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 commandsFile.write (format ("attach %1\n", pid).toLocal8Bit());
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 779
diff changeset
79 commandsFile.write (QString ("backtrace full\n").toLocal8Bit());
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 779
diff changeset
80 commandsFile.write (QString ("detach\n").toLocal8Bit());
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 779
diff changeset
81 commandsFile.write (QString ("quit").toLocal8Bit());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 commandsFile.close();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
85 proc.start ("gdb", {"-x", commandsFile.fileName()});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 // Linux doesn't allow ptrace to be used on anything but direct child processes
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 // so we need to use prctl to register an exception to this to allow GDB attach to us.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 // We need to do this now and no earlier because only now we actually know GDB's PID.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 #ifdef Q_OS_LINUX
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 prctl (PR_SET_PTRACER, proc.pid(), 0, 0, 0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 #endif
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 proc.waitForFinished (1000);
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
95 QString output (proc.readAllStandardOutput());
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
96 QString err (proc.readAllStandardError());
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
97 QFile f (UNIXNAME "-crash.log");
765
6d8ca5219a57 - crashcatcher: hide the main window before doing anything and also write the crashlog into a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
98
6d8ca5219a57 - crashcatcher: hide the main window before doing anything and also write the crashlog into a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
99 if (f.open (QIODevice::WriteOnly))
6d8ca5219a57 - crashcatcher: hide the main window before doing anything and also write the crashlog into a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
100 {
6d8ca5219a57 - crashcatcher: hide the main window before doing anything and also write the crashlog into a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
101 fprint (f, format ("=== Program crashed with signal %1 ===\n\n%2"
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
102 "GDB stdout:\n%3\nGDB stderr:\n%4\n", sig,
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
103 (not AssertionFailureText.isEmpty()) ? AssertionFailureText + "\n\n" : "",
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
104 output, err));
765
6d8ca5219a57 - crashcatcher: hide the main window before doing anything and also write the crashlog into a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
105 f.close();
6d8ca5219a57 - crashcatcher: hide the main window before doing anything and also write the crashlog into a file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
106 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
108 if (not AssertionFailureText.isEmpty())
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
109 printf ("Assertion failed: \"%s\".\n", qPrintable (AssertionFailureText));
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
110
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
111 printf ("Backtrace written to " UNIXNAME "-crash.log. Aborting.\n");
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
112 FinalAbort();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
115 // -------------------------------------------------------------------------------------------------
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
116 //
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
117 // Initializes the crash catcher.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 //
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
119 void InitCrashCatcher()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 struct sigaction sighandler;
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
122 sighandler.sa_handler = &HandleCrash;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 sighandler.sa_flags = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 sigemptyset (&sighandler.sa_mask);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
126 for (int sig : SignalsToCatch)
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
127 {
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
128 if (sigaction (sig, &sighandler, null) == -1)
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
129 {
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
130 fprint (stderr, "Couldn't set signal handler %1: %2", sig, strerror (errno));
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
131 SignalsToCatch.removeOne (sig);
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
132 }
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
133 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
135 print ("Crash catcher hooked to signals: %1\n", SignalsToCatch);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 }
778
0ed96169b8c0 - crashcatcher: don't use the bomb box at all, instead just write the crashlog and then abort for good
Santeri Piippo <crimsondusk64@gmail.com>
parents: 765
diff changeset
137
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 #endif // #ifdef __unix__
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
140 // -------------------------------------------------------------------------------------------------
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 //
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
142 // This function catches an assertion failure. It must be readily available in both Windows and
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
143 // Linux. We display the bomb box straight in Windows while in Linux we let abort() trigger
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
144 // the signal handler, which will cause the usual bomb box with GDB diagnostics. Said prompt will
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
145 // embed the assertion failure information.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 //
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
147 void HandleAssertFailure (const char* file, int line, const char* funcname, const char* expr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 {
779
23130cafe95e - further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents: 778
diff changeset
149 #ifdef __unix__
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 844
diff changeset
150 AssertionFailureText = format ("%1:%2: %3: %4", file, line, funcname, expr);
779
23130cafe95e - further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents: 778
diff changeset
151 #else
23130cafe95e - further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents: 778
diff changeset
152 bombBox (format (
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 "<p><b>File</b>: <tt>%1</tt><br />"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 "<b>Line</b>: <tt>%2</tt><br />"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 "<b>Function:</b> <tt>%3</tt></p>"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 "<p>Assertion <b><tt>`%4'</tt></b> failed.</p>",
779
23130cafe95e - further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents: 778
diff changeset
157 file, line, funcname, expr));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 #endif
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 abort();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 }

mercurial