-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrashPad.cpp
More file actions
96 lines (80 loc) · 4.63 KB
/
CrashPad.cpp
File metadata and controls
96 lines (80 loc) · 4.63 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
87
88
89
90
91
92
93
94
95
96
//
// Created by joao on 29/08/2021.
//
#include "CrashPad.h"
#include "Core/Tools/Log.h"
#include "Utils/Exception.h"
#include "Utils/STDLibInclude.h"
#include "Core/Controller/CommandLine/CommandLineArgsManager.h"
#include "3rdParty/cxxopts.hpp"
#include <boost/stacktrace.hpp>
// #define WITH_STACK_TRACE
#ifdef NDEBUG
#define RELEASE_COMPILE
#endif
namespace Slab::SafetyNet {
using namespace Core;
void none() {
#ifndef RELEASE_COMPILE
FLog::ErrorFatal() << "Stacktrace:\n" << boost::stacktrace::stacktrace() << FLog::Flush;
#endif
}
void showHelp()
{
if(true) none();
else FCLArgsManager::ShowHelp();
}
Str FORMAT;
#define LogException(description, what, exitFunc) \
{ FLog::ErrorFatal() << description << ": " << FORMAT << " " << what << " " << FLog::ResetFormatting \
<< ". Application will now exit." << FLog::Flush; \
exitFunc(); \
return EXIT_FAILURE; }
int jump(int (*pFunction)(int argc, const char **argv), int argc, const char *argv[]) {
#if defined(RELEASE_COMPILE) || defined(WITH_STACK_TRACE)
try
#endif
{
FORMAT = FLog::BGRed + FLog::BoldFace + FLog::FGBlack;
return pFunction(argc, argv);
}
#if defined(RELEASE_COMPILE) || defined(WITH_STACK_TRACE)
catch (const char *e) LogException("Exception (const char*)", e, none)
catch (Str &e) LogException("Exception (std::string)", e, none)
catch (NotImplementedException &e) LogException("Slab::NotImplementedException", e.what(), none)
catch (Exception &e) LogException("Slab::Exception" , e.what(), none)
catch (cxxopts::exceptions::invalid_option_syntax &e) LogException("Invalid option syntax", e.what(), showHelp)
catch (cxxopts::exceptions::no_such_option &e) LogException("No such option", e.what(), showHelp)
catch (cxxopts::exceptions::option_already_exists &e) LogException("Option already exists", e.what(), showHelp)
catch (cxxopts::exceptions::incorrect_argument_type &e) LogException("Incorrect argument type", e.what(), showHelp)
catch (std::bad_cast &e) LogException("Bad cast", e.what(), none)
catch (cxxopts::exceptions::exception &e) LogException("Parsing exception", e.what(), none)
catch (std::exception &e) LogException("Exception std::exception", e.what(), none)
catch (...) LogException("Unknown exception", "...", none)
#endif
}
int Jump(FApplication& app) {
#if defined(RELEASE_COMPILE) || defined(WITH_STACK_TRACE)
try
#endif
{
app.Create();
FORMAT = FLog::BGRed + FLog::BoldFace + FLog::FGBlack;
return app.Run();
}
#if defined(RELEASE_COMPILE) || defined(WITH_STACK_TRACE)
catch (const char *e) LogException("Exception (const char*)", e, none)
catch (Str &e) LogException("Exception (std::string)", e, none)
catch (NotImplementedException &e) LogException("Slab::NotImplementedException", e.what(), none)
catch (Exception &e) LogException("Slab::Exception" , e.what(), none)
catch (cxxopts::exceptions::invalid_option_syntax &e) LogException("Invalid option syntax", e.what(), showHelp)
catch (cxxopts::exceptions::no_such_option &e) LogException("No such option", e.what(), showHelp)
catch (cxxopts::exceptions::option_already_exists &e) LogException("Option already exists", e.what(), showHelp)
catch (cxxopts::exceptions::incorrect_argument_type &e) LogException("Incorrect argument type", e.what(), showHelp)
catch (std::bad_cast &e) LogException("Bad cast", e.what(), none)
catch (cxxopts::exceptions::exception &e) LogException("Parsing exception", e.what(), none)
catch (std::exception &e) LogException("Exception std::exception", e.what(), none)
catch (...) LogException("Unknown exception", "...", none)
#endif
}
}