forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
terminate_handler.cc
42 lines (34 loc) · 1.2 KB
/
terminate_handler.cc
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
#include "source/exe/terminate_handler.h"
#include <cstdlib>
#include "envoy/common/exception.h"
#include "source/common/common/logger.h"
#include "source/common/common/thread.h"
#include "source/server/backtrace.h"
#include "absl/strings/str_format.h"
namespace Envoy {
std::terminate_handler TerminateHandler::logOnTerminate() const {
// Pre-populate the address mapping so it doesn't require signal-unsafe file
// actions during stack trace.
BackwardsTrace::addrMapping(/*setup=*/true);
return std::set_terminate([]() {
logException(std::current_exception());
BACKTRACE_LOG();
std::abort();
});
}
void TerminateHandler::logException(const std::exception_ptr current_exception) {
if (current_exception != nullptr) {
TRY_NEEDS_AUDIT { std::rethrow_exception(current_exception); }
END_TRY
MULTI_CATCH(
const EnvoyException& e,
{
ENVOY_LOG(critical, "std::terminate called! Uncaught EnvoyException '{}', see trace.",
e.what());
},
{ ENVOY_LOG(critical, "std::terminate called! Uncaught unknown exception, see trace."); });
} else {
ENVOY_LOG(critical, "std::terminate called! See trace.");
}
}
} // namespace Envoy