Sun, 22 Jun 2014 14:23:35 +0000
README.md edited online with Bitbucket
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 |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
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 | #ifdef __unix__ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QProcess> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QTemporaryFile> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <unistd.h> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #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
|
25 | #include "crashCatcher.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #ifdef Q_OS_LINUX |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | # include <sys/prctl.h> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #endif |
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? |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | static bool g_crashCatcherActive = false; |
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? |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
779
diff
changeset
|
35 | static QString g_assertionFailure; |
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 |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | static QList<int> g_signalsToCatch ({ |
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 | |
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
|
45 | // |
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 | // 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
|
47 | // |
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 | static void finalAbort() |
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
|
49 | { |
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 | 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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | 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
|
55 | } |
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 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | static void handleCrash (int sig) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | { |
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
|
61 | printf ("!! Caught signal %d, launching gdb\n", sig); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | if (g_crashCatcherActive) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | { |
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
|
65 | printf ("Caught signal while crash catcher is active! Execution cannot continue.\n"); |
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 | finalAbort(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | } |
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 | const pid_t pid = getpid(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | QProcess proc; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | QTemporaryFile commandsFile; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | g_crashCatcherActive = true; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | if (commandsFile.open()) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | commandsFile.write (format ("attach %1\n", pid).toLocal8Bit()); |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
779
diff
changeset
|
78 | commandsFile.write (QString ("backtrace full\n").toLocal8Bit()); |
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
779
diff
changeset
|
79 | commandsFile.write (QString ("detach\n").toLocal8Bit()); |
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
779
diff
changeset
|
80 | commandsFile.write (QString ("quit").toLocal8Bit()); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | commandsFile.close(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | |
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
|
84 | proc.start ("gdb", {"-x", commandsFile.fileName()}); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | // 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
|
87 | // 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
|
88 | // 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
|
89 | #ifdef Q_OS_LINUX |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | prctl (PR_SET_PTRACER, proc.pid(), 0, 0, 0); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | #endif |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | proc.waitForFinished (1000); |
789
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
779
diff
changeset
|
94 | QString output = QString (proc.readAllStandardOutput()); |
4b7306f52bb5
- String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents:
779
diff
changeset
|
95 | QString err = QString (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
|
96 | 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
|
97 | |
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 | 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
|
99 | { |
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 | fprint (f, format ("=== Program crashed with signal %1 ===\n\n%2" |
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 | "GDB stdout:\n%3\n" |
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
|
102 | "GDB stderr:\n%4\n", |
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
|
103 | sig, (not g_assertionFailure.isEmpty()) ? g_assertionFailure + "\n\n" : "", output, err)); |
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
|
104 | 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
|
105 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
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
|
107 | if (g_assertionFailure.isEmpty()) |
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
|
108 | { |
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
|
109 | printf ("Crashlog written to " UNIXNAME "-crash.log. Aborting.\n"); |
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 | } |
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
|
111 | else |
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
|
112 | { |
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
|
113 | printf ("Assertion failed: \"%s\". Backtrace written to " UNIXNAME "-crash.log.\n", |
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
|
114 | qPrintable (g_assertionFailure)); |
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
|
115 | } |
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 | finalAbort(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
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
|
120 | // |
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
|
121 | // Initializes the crash catcher. |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | void initCrashCatcher() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | struct sigaction sighandler; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | sighandler.sa_handler = &handleCrash; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | sighandler.sa_flags = 0; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | sigemptyset (&sighandler.sa_mask); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | for (int sig : g_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
|
131 | { |
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 | 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
|
133 | { |
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
|
134 | fprint (stderr, "Couldn't set signal handler %1: %2", sig, strerror (errno)); |
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
|
135 | g_signalsToCatch.removeOne (sig); |
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
|
136 | } |
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 | |
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
|
139 | print ("Crash catcher hooked to signals: %1\n", g_signalsToCatch); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | } |
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
|
141 | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | #endif // #ifdef __unix__ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // ============================================================================= |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | // This function must be readily available in both Windows and Linux. We display |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | // the bomb box straight in Windows while in Linux we let abort() trigger the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | // signal handler, which will cause the usual bomb box with GDB diagnostics. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | // Said prompt will embed the assertion failure information. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | // |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | void assertionFailure (const char* file, int line, const char* funcname, const char* expr) |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | { |
779
23130cafe95e
- further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents:
778
diff
changeset
|
153 | #ifdef __unix__ |
23130cafe95e
- further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents:
778
diff
changeset
|
154 | g_assertionFailure = format ("%1:%2: %3: %4", file, line, funcname, expr); |
23130cafe95e
- further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents:
778
diff
changeset
|
155 | #else |
23130cafe95e
- further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents:
778
diff
changeset
|
156 | bombBox (format ( |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | "<p><b>File</b>: <tt>%1</tt><br />" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | "<b>Line</b>: <tt>%2</tt><br />" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | "<b>Function:</b> <tt>%3</tt></p>" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | "<p>Assertion <b><tt>`%4'</tt></b> failed.</p>", |
779
23130cafe95e
- further edits to crashcatcher
Santeri Piippo <crimsondusk64@gmail.com>
parents:
778
diff
changeset
|
161 | file, line, funcname, expr)); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | #endif |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | abort(); |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | } |