forked from Tracktion/pluginval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrashHandler.cpp
More file actions
86 lines (66 loc) · 2.59 KB
/
CrashHandler.cpp
File metadata and controls
86 lines (66 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*==============================================================================
Copyright 2018 by Tracktion Corporation.
For more information visit www.tracktion.com
You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
pluginval IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================*/
#include "CrashHandler.h"
#if JUCE_MAC
#include <dlfcn.h>
#endif
namespace
{
String getExtraPlatformSpecificInfo()
{
#if JUCE_MAC
StringArray imagesDone;
StringArray output;
for (auto& l : StringArray::fromLines (SystemStats::getStackBacktrace()))
{
const String imageName = l.upToFirstOccurrenceOf ("0x", false, false).fromFirstOccurrenceOf (" ", false, false).trim();
const String addressString = l.fromFirstOccurrenceOf ("0x", true, false).upToFirstOccurrenceOf (" ", false, false).trim();
if (imagesDone.contains (imageName))
continue;
imagesDone.add (imageName);
Dl_info info;
const size_t address = static_cast<size_t> (addressString.getHexValue64());
if (dladdr (reinterpret_cast<void*> (address), &info) != 0)
output.add (String ("0x") + String::toHexString (static_cast<pointer_sized_int> (reinterpret_cast<size_t> (info.dli_fbase))) + " " + imageName);
}
return "Binary Images:\n" + output.joinIntoString ("\n");
#else
return {};
#endif
}
String getCrashLogContents()
{
return "\n" + SystemStats::getStackBacktrace() + "\n" + getExtraPlatformSpecificInfo();
}
static File getCrashTraceFile()
{
return File::getSpecialLocation (File::tempDirectory).getChildFile ("pluginval_crash.txt");
}
static void handleCrash (void*)
{
const auto log = getCrashLogContents();
std::cout << "\n*** FAILED: VALIDATION CRASHED\n" << log << std::endl;
getCrashTraceFile().replaceWithText (log);
}
}
//==============================================================================
void initialiseCrashHandler()
{
// Delete the crash file, this will be created if possible
getCrashTraceFile().deleteFile();
SystemStats::setApplicationCrashHandler (handleCrash);
}
String getCrashLog()
{
const auto f = getCrashTraceFile();
if (f.existsAsFile())
return f.loadFileAsString();
return getCrashLogContents();
}