tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
debug_trap.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4
#
ifndef
TETL_CONFIG_DEBUG_TRAP_HPP
5
#
define
TETL_CONFIG_DEBUG_TRAP_HPP
6
7
#
include
<
etl
/
_config
/
attributes
.
hpp
>
8
#
include
<
etl
/
_config
/
preprocessor
.
hpp
>
9
10
#
if
!
defined
(
TETL_NDEBUG
)
&&
defined
(
NDEBUG
)
&&
!
defined
(
TETL_DEBUG
)
11
#
define
TETL_NDEBUG
1
12
#
else
13
#
define
TETL_DEBUG
1
14
#
endif
15
16
#
if
defined
(
_MSC_VER
)
17
#
define
TETL_DEBUG_TRAP
__debugbreak
18
#
else
19
20
#
define
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
1
21
#
define
TETL_DEBUG_TRAP_IMPL_BULTIN_TRAP
2
22
#
define
TETL_DEBUG_TRAP_IMPL_BULTIN_DEBUGTRAP
3
23
#
define
TETL_DEBUG_TRAP_IMPL_SIGTRAP
4
24
25
#
if
defined
(
__i386__
)
||
defined
(
__x86_64__
)
26
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
27
28
inline
auto
trap_inst() ->
void
29
{
30
__asm__
volatile
(
"int $0x03"
);
31
}
32
#
elif
defined
(
__thumb__
)
33
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
34
35
inline
auto
trap_inst() ->
void
36
{
37
__asm__
volatile
(
".inst 0xde01"
);
38
}
39
#
elif
defined
(
__arm__
)
&&
!
defined
(
__thumb__
)
40
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
41
42
inline
auto
trap_inst() ->
void
43
{
44
__asm__
volatile
(
".inst 0xe7f001f0"
);
45
}
46
#
elif
defined
(
__aarch64__
)
&&
defined
(
__APPLE__
)
47
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_BULTIN_DEBUGTRAP
48
#
elif
defined
(
__aarch64__
)
49
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
50
51
inline
auto
trap_inst() ->
void
52
{
53
__asm__
volatile
(
".inst 0xd4200000"
);
54
}
55
#
elif
defined
(
__powerpc__
)
56
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
57
58
inline
auto
trap_inst() ->
void
59
{
60
__asm__
volatile
(
".4byte 0x7d821008"
);
61
}
62
#
elif
defined
(
__riscv
)
63
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
64
65
inline
auto
trap_inst() ->
void
66
{
67
__asm__
volatile
(
".4byte 0x00100073"
);
68
}
69
#
elif
defined
(
__AVR__
)
70
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
71
72
inline
auto
trap_inst() ->
void
{ }
73
#
elif
defined
(
__STDC_HOSTED__
)
// hosted builds
74
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_SIGTRAP
75
#
else
76
// TETL_DEBUG_TRAP is not supported on this target
77
#
define
TETL_DEBUG_TRAP_IMPL
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
78
79
inline
auto
trap_inst() ->
void
{ }
80
#
endif
81
82
#
if
!
defined
(
TETL_DEBUG_TRAP_IMPL
)
83
inline
auto
TETL_DEBUG_TRAP() ->
void
{ }
84
#
elif
TETL_DEBUG_TRAP_IMPL
==
TETL_DEBUG_TRAP_IMPL_TRAP_INSTRUCTION
85
inline
auto
TETL_DEBUG_TRAP
() ->
void
86
{
87
trap_inst();
88
}
89
#
elif
TETL_DEBUG_TRAP_IMPL
==
TETL_DEBUG_TRAP_IMPL_BULTIN_DEBUGTRAP
90
inline
auto
TETL_DEBUG_TRAP() ->
void
91
{
92
__builtin_debugtrap();
93
}
94
#
elif
TETL_DEBUG_TRAP_IMPL
==
TETL_DEBUG_TRAP_IMPL_BULTIN_TRAP
95
inline
auto
TETL_DEBUG_TRAP() ->
void
96
{
97
__builtin_trap();
98
}
99
#
elif
TETL_DEBUG_TRAP_IMPL
==
TETL_DEBUG_TRAP_IMPL_SIGTRAP
100
#
include
<
signal
.
h
>
101
102
inline
auto
TETL_DEBUG_TRAP() ->
void
103
{
104
::raise(SIGTRAP);
105
}
106
#
else
107
#
error
"invalid TETL_DEBUG_TRAP_IMPL value"
108
#
endif
109
110
#
endif
111
112
#
endif
// TETL_CONFIG_DEBUG_TRAP_HPP
TETL_DEBUG_TRAP
auto TETL_DEBUG_TRAP() -> void
Definition
debug_trap.hpp:85
include
etl
_config
debug_trap.hpp
Generated on Sun Sep 7 2025 19:14:53 for tetl by
1.9.8