2017-07-06 22:28:42 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 21/08/2014
|
|
|
|
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
|
|
|
|
|
|
|
#include "catch_platform.h"
|
|
|
|
#include "catch_compiler_capabilities.h"
|
|
|
|
|
2021-03-27 17:54:22 +01:00
|
|
|
#include <cassert>
|
2017-07-06 22:28:42 +02:00
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
2021-04-04 13:35:38 +02:00
|
|
|
// Wrapper for platform-specific fatal error (signals/SEH) handlers
|
|
|
|
//
|
|
|
|
// Tries to be cooperative with other handlers, and not step over
|
|
|
|
// other handlers. This means that unknown structured exceptions
|
|
|
|
// are passed on, previous signal handlers are called, and so on.
|
|
|
|
//
|
|
|
|
// Can only be instantiated once, and assumes that once a signal
|
|
|
|
// is caught, the binary will end up terminating. Thus, there
|
2021-03-27 17:54:22 +01:00
|
|
|
class FatalConditionHandler {
|
|
|
|
bool m_started = false;
|
|
|
|
|
|
|
|
// Install/disengage implementation for specific platform.
|
|
|
|
// Should be if-defed to work on current platform, can assume
|
|
|
|
// engage-disengage 1:1 pairing.
|
|
|
|
void engage_platform();
|
|
|
|
void disengage_platform();
|
|
|
|
public:
|
|
|
|
// Should also have platform-specific implementations as needed
|
2017-07-06 22:28:42 +02:00
|
|
|
FatalConditionHandler();
|
|
|
|
~FatalConditionHandler();
|
|
|
|
|
2021-03-27 17:54:22 +01:00
|
|
|
void engage() {
|
|
|
|
assert(!m_started && "Handler cannot be installed twice.");
|
|
|
|
m_started = true;
|
|
|
|
engage_platform();
|
|
|
|
}
|
|
|
|
|
|
|
|
void disengage() {
|
|
|
|
assert(m_started && "Handler cannot be uninstalled without being installed first");
|
|
|
|
m_started = false;
|
|
|
|
disengage_platform();
|
|
|
|
}
|
2017-07-06 22:28:42 +02:00
|
|
|
};
|
|
|
|
|
2021-03-27 17:54:22 +01:00
|
|
|
//! Simple RAII guard for (dis)engaging the FatalConditionHandler
|
|
|
|
class FatalConditionHandlerGuard {
|
|
|
|
FatalConditionHandler* m_handler;
|
|
|
|
public:
|
|
|
|
FatalConditionHandlerGuard(FatalConditionHandler* handler):
|
|
|
|
m_handler(handler) {
|
|
|
|
m_handler->engage();
|
|
|
|
}
|
|
|
|
~FatalConditionHandlerGuard() {
|
|
|
|
m_handler->disengage();
|
|
|
|
}
|
2018-02-23 14:56:07 +01:00
|
|
|
};
|
|
|
|
|
2021-03-27 17:54:22 +01:00
|
|
|
} // end namespace Catch
|
2017-07-06 22:28:42 +02:00
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|