xref: /aosp_15_r20/external/pigweed/pw_assert_trap/public/pw_assert_trap/check_trap.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include "pw_assert_trap/handler.h"
17 #include "pw_preprocessor/arguments.h"
18 
19 #define PW_HANDLE_CRASH(...)                                    \
20   pw_assert_trap_interrupt_lock();                              \
21   pw_assert_trap_HandleCheckFailure(                            \
22       __FILE__, __LINE__, __func__ PW_COMMA_ARGS(__VA_ARGS__)); \
23   _PW_ASSERT_TRAP_EPILOG()
24 
25 #define PW_HANDLE_ASSERT_FAILURE(condition_string, ...)         \
26   pw_assert_trap_interrupt_lock();                              \
27   pw_assert_trap_HandleCheckFailure(                            \
28       __FILE__, __LINE__, __func__ PW_COMMA_ARGS(__VA_ARGS__)); \
29   _PW_ASSERT_TRAP_EPILOG()
30 
31 #define PW_HANDLE_ASSERT_BINARY_COMPARE_FAILURE(arg_a_str,                    \
32                                                 arg_a_val,                    \
33                                                 comparison_op_str,            \
34                                                 arg_b_str,                    \
35                                                 arg_b_val,                    \
36                                                 type_fmt,                     \
37                                                 message,                      \
38                                                 ...)                          \
39   pw_assert_trap_interrupt_lock();                                            \
40   pw_assert_trap_HandleCheckFailure(__FILE__,                                 \
41                                     __LINE__,                                 \
42                                     __func__,                                 \
43                                     "Check failed: " arg_a_str " (=" type_fmt \
44                                     ") " comparison_op_str " " arg_b_str      \
45                                     " (=" type_fmt                            \
46                                     ")"                                       \
47                                     ". " message,                             \
48                                     arg_a_val,                                \
49                                     arg_b_val PW_COMMA_ARGS(__VA_ARGS__));    \
50   _PW_ASSERT_TRAP_EPILOG()
51