debug/assert: split out trace and common sections
This commit is contained in:
parent
2c7eb400c3
commit
6f8197c0e2
@ -302,6 +302,8 @@ list (
|
|||||||
cpuid.hpp
|
cpuid.hpp
|
||||||
debug/assert.cpp
|
debug/assert.cpp
|
||||||
debug/assert.hpp
|
debug/assert.hpp
|
||||||
|
debug/common.cpp
|
||||||
|
debug/common.hpp
|
||||||
debug/compiler.cpp
|
debug/compiler.cpp
|
||||||
debug/compiler.hpp
|
debug/compiler.hpp
|
||||||
debug/crash.hpp
|
debug/crash.hpp
|
||||||
@ -313,6 +315,8 @@ list (
|
|||||||
debug/panic.hpp
|
debug/panic.hpp
|
||||||
debug/system.cpp
|
debug/system.cpp
|
||||||
debug/system.hpp
|
debug/system.hpp
|
||||||
|
debug/trace.cpp
|
||||||
|
debug/trace.hpp
|
||||||
debug/validate.cpp
|
debug/validate.cpp
|
||||||
debug/validate.hpp
|
debug/validate.hpp
|
||||||
debug/warn.cpp
|
debug/warn.cpp
|
||||||
|
@ -8,63 +8,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "./common.hpp"
|
||||||
#include "./panic.hpp"
|
#include "./panic.hpp"
|
||||||
|
#include "./debugger.hpp"
|
||||||
|
|
||||||
#include "../platform.hpp"
|
#include "../platform.hpp"
|
||||||
#include "../maths.hpp"
|
#include "../maths.hpp"
|
||||||
|
|
||||||
#include "debugger.hpp"
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// it is fractionally easier to define a constexpr variable which can be used
|
|
||||||
// in constexpr-if to enable/disable some codepaths rather than deal with
|
|
||||||
// macros in some scenarios. eg, templates are complicated enough without
|
|
||||||
// (more) macros.
|
|
||||||
#if !defined(NDEBUG)
|
|
||||||
constexpr bool debug_enabled = true;
|
|
||||||
constexpr bool assertions_enabled = true;
|
|
||||||
#else
|
|
||||||
constexpr bool debug_enabled = false;
|
|
||||||
constexpr bool assertions_enabled = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
///----------------------------------------------------------------------------
|
|
||||||
/// enable some code only if assertions are enabled
|
|
||||||
///
|
|
||||||
/// explicitly does not use constexpr if to remove the code as some paths may
|
|
||||||
/// refer to variables which do not always exist, and current compiler
|
|
||||||
/// implementations are a little picky here.
|
|
||||||
#ifndef NDEBUG
|
|
||||||
#include <iostream>
|
|
||||||
#define DEBUG_ONLY(X) do { X; } while (0)
|
|
||||||
#else
|
|
||||||
#define DEBUG_ONLY(X) do { ; } while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#define DEBUG_ONLY(X) do { if constexpr (debug_enabled) { X } } while (0)
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
#define EXIT_XSUCCESS 0
|
|
||||||
#define EXIT_XSKIP 77
|
|
||||||
#define EXIT_XHARD_ERROR 99
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
#define TRACE { \
|
|
||||||
DEBUG_ONLY ( \
|
|
||||||
std::cerr << "tid: " << std::this_thread::get_id () \
|
|
||||||
<< "; " << __FILE__ \
|
|
||||||
<< ":" << __func__ \
|
|
||||||
<< ":" << __LINE__ \
|
|
||||||
<< '\n'; \
|
|
||||||
); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#ifdef COMPILER_GCC
|
#ifdef COMPILER_GCC
|
||||||
#define CHECK(C) do { \
|
#define CHECK(C) do { \
|
||||||
|
1
debug/common.cpp
Normal file
1
debug/common.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "./common.hpp"
|
42
debug/common.hpp
Normal file
42
debug/common.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2019 Danny Robson <danny@nerdcruft.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// it is fractionally easier to define a constexpr variable which can be used
|
||||||
|
// in constexpr-if to enable/disable some codepaths rather than deal with
|
||||||
|
// macros in some scenarios. eg, templates are complicated enough without
|
||||||
|
// (more) macros.
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
constexpr bool debug_enabled = true;
|
||||||
|
constexpr bool assertions_enabled = true;
|
||||||
|
#else
|
||||||
|
constexpr bool debug_enabled = false;
|
||||||
|
constexpr bool assertions_enabled = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
///----------------------------------------------------------------------------
|
||||||
|
/// enable some code only if assertions are enabled
|
||||||
|
///
|
||||||
|
/// explicitly does not use constexpr if to remove the code as some paths may
|
||||||
|
/// refer to variables which do not always exist, and current compiler
|
||||||
|
/// implementations are a little picky here.
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#include <iostream>
|
||||||
|
#define DEBUG_ONLY(X) do { X; } while (0)
|
||||||
|
#else
|
||||||
|
#define DEBUG_ONLY(X) do { ; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define EXIT_XSUCCESS 0
|
||||||
|
#define EXIT_XSKIP 77
|
||||||
|
#define EXIT_XHARD_ERROR 99
|
9
debug/trace.cpp
Normal file
9
debug/trace.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* Copyright 2021, Danny Robson <danny@nerdcruft.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "./trace.hpp"
|
25
debug/trace.hpp
Normal file
25
debug/trace.hpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
* Copyright 2010-2019 Danny Robson <danny@nerdcruft.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "./common.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define TRACE { \
|
||||||
|
DEBUG_ONLY ( \
|
||||||
|
std::cerr << "tid: " << std::this_thread::get_id () \
|
||||||
|
<< "; " << __FILE__ \
|
||||||
|
<< ":" << __func__ \
|
||||||
|
<< ":" << __LINE__ \
|
||||||
|
<< '\n'; \
|
||||||
|
); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user