Install termination handler to collect additional information for C++ exceptions

This commit is contained in:
Asher Baker 2019-07-20 00:51:47 +00:00
parent 853ba22b0d
commit 8e42daada7
2 changed files with 36 additions and 14 deletions

View File

@ -88,7 +88,6 @@ class SM:
self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
self.compiler.AddToListVar('POSTLINKFLAGS', '-Wl,-z,defs') self.compiler.AddToListVar('POSTLINKFLAGS', '-Wl,-z,defs')
self.compiler.AddToListVar('CXXFLAGS', '-std=c++11') self.compiler.AddToListVar('CXXFLAGS', '-std=c++11')
self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual') self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')

View File

@ -56,23 +56,23 @@ public:
// Taken from https://hg.mozilla.org/mozilla-central/file/3eb7623b5e63b37823d5e9c562d56e586604c823/build/unix/stdc%2B%2Bcompat/stdc%2B%2Bcompat.cpp // Taken from https://hg.mozilla.org/mozilla-central/file/3eb7623b5e63b37823d5e9c562d56e586604c823/build/unix/stdc%2B%2Bcompat/stdc%2B%2Bcompat.cpp
extern "C" void __attribute__((weak)) __cxa_throw_bad_array_new_length() { extern "C" void __attribute__((weak)) __cxa_throw_bad_array_new_length() {
abort(); abort();
} }
namespace std { namespace std {
/* We shouldn't be throwing exceptions at all, but it sadly turns out /* We shouldn't be throwing exceptions at all, but it sadly turns out
we call STL (inline) functions that do. */ we call STL (inline) functions that do. */
void __attribute__((weak)) __throw_out_of_range_fmt(char const* fmt, ...) { void __attribute__((weak)) __throw_out_of_range_fmt(char const* fmt, ...) {
va_list ap; va_list ap;
char buf[1024]; // That should be big enough. char buf[1024]; // That should be big enough.
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap); vsnprintf(buf, sizeof(buf), fmt, ap);
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
va_end(ap); va_end(ap);
__throw_range_error(buf); __throw_range_error(buf);
} }
} // namespace std } // namespace std
// Updated versions of the SM ones for C++14 // Updated versions of the SM ones for C++14
@ -146,6 +146,27 @@ PluginInfo plugins[256];
#endif #endif
#if defined _LINUX #if defined _LINUX
void terminateHandler()
{
const char *msg = "missing exception";
std::exception_ptr pEx = std::current_exception();
if (pEx) {
try {
std::rethrow_exception(pEx);
} catch(const std::exception &e) {
msg = strdup(e.what());
} catch(...) {
msg = "unknown exception";
}
}
size_t msgLength = strlen(msg) + 2;
volatile char * volatile msgForCrashDumps = (char *)alloca(msgLength);
strcpy((char *)msgForCrashDumps + 1, msg);
abort();
}
void (*SignalHandler)(int, siginfo_t *, void *); void (*SignalHandler)(int, siginfo_t *, void *);
const int kExceptionSignals[] = { const int kExceptionSignals[] = {
@ -253,6 +274,8 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void OnGameFrame(bool simulating) void OnGameFrame(bool simulating)
{ {
std::set_terminate(terminateHandler);
bool weHaveBeenFuckedOver = false; bool weHaveBeenFuckedOver = false;
struct sigaction oact; struct sigaction oact;