HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
debugger.hpp
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
6#pragma once
7
8#include "architecture.hpp"
9#include "console.hpp"
10#include "dialog.hpp"
11#include <format>
12
13namespace tt {
14
15#if TT_OPERATING_SYSTEM == TT_OS_WINDOWS
16void _debugger_break();
17#define tt_debugger_break() _debugger_break()
18
19#elif TT_COMPILER == TT_CC_GCC || TT_COMPILER == TT_CC_CLANG
20#define tt_debugger_break() __builtin_trap()
21
22#else
23#error "Not implemented"
24#endif
25
26
29bool debugger_is_present() noexcept;
30
31
38template<typename... Args>
39[[noreturn]] tt_no_inline void debugger_abort(char const *source_file, int source_line, std::string_view fmt, Args &&... args)
40{
41 std::string message;
42
43 if constexpr (sizeof...(Args) == 0) {
44 message = fmt;
45 } else {
46 message = std::format(fmt, std::forward<Args>(args)...);
47 }
48
49 if (debugger_is_present()) {
50 print("{}:{} {}\n", source_file, source_line, message);
51 tt_debugger_break();
52 } else {
53 dialog_ok("Aborting", "{}:{} {}", source_file, source_line, message);
54 }
55
56 std::abort();
57}
58
59[[noreturn]] tt_no_inline inline void debugger_abort(char const *source_file, int source_line)
60{
61 debugger_abort(source_file, source_line, "<unknown>");
62}
63
64#define tt_debugger_abort(...) ::tt::debugger_abort(__FILE__, __LINE__ __VA_OPT__(,) __VA_ARGS__)
65
66}
STL namespace.
T abort(T... args)