pw_assert_basic: Use full function name when possible
Use the __PRETTY_FUNCTION__ macro, if available, in place of the
__func__ macro. __PRETTY_FUNCTION__ prints the full C++ function name.
Change-Id: Ic0f6c73fe3434116744efaac6ea2c5bd56544bf1
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/107682
Reviewed-by: Keir Mierle <keir@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_assert_basic/public/pw_assert_basic/assert_basic.h b/pw_assert_basic/public/pw_assert_basic/assert_basic.h
index 88405f8..6d8bd6c 100644
--- a/pw_assert_basic/public/pw_assert_basic/assert_basic.h
+++ b/pw_assert_basic/public/pw_assert_basic/assert_basic.h
@@ -18,12 +18,22 @@
#include "pw_preprocessor/compiler.h"
#include "pw_preprocessor/util.h"
+// Use __PRETTY_FUNCTION__, a GNU extension, in place of the __func__ macro when
+// supported. __PRETTY_FUNCTION__ expands to the full C++ function name.
+#ifdef __GNUC__
+#define _PW_ASSERT_BASIC_FUNCTION_NAME __PRETTY_FUNCTION__
+#else
+#define _PW_ASSERT_BASIC_FUNCTION_NAME __func__
+#endif // __GNUC__
+
// Die with a message with many attributes included. This is the crash macro
// frontend that funnels everything into the C handler provided by the user,
// pw_assert_basic_HandleFailure().
#define PW_HANDLE_CRASH(...) \
pw_assert_basic_HandleFailure( \
- __FILE__, __LINE__, __func__ PW_COMMA_ARGS(__VA_ARGS__))
+ __FILE__, \
+ __LINE__, \
+ _PW_ASSERT_BASIC_FUNCTION_NAME PW_COMMA_ARGS(__VA_ARGS__))
// Die with a message with many attributes included. This is the crash macro
// frontend that funnels everything into the C handler provided by the user,
@@ -31,7 +41,7 @@
#define PW_HANDLE_ASSERT_FAILURE(condition_string, message, ...) \
pw_assert_basic_HandleFailure(__FILE__, \
__LINE__, \
- __func__, \
+ _PW_ASSERT_BASIC_FUNCTION_NAME, \
"Check failed: " condition_string \
". " message PW_COMMA_ARGS(__VA_ARGS__))
@@ -51,13 +61,13 @@
type_fmt, \
message, ...) \
pw_assert_basic_HandleFailure( \
- __FILE__, \
- __LINE__, \
- __func__, \
- "Check failed: " \
- arg_a_str " (=" type_fmt ") " \
- comparison_op_str " " \
- arg_b_str " (=" type_fmt ")" \
- ". " message, \
- arg_a_val, arg_b_val PW_COMMA_ARGS(__VA_ARGS__))
+ __FILE__, \
+ __LINE__, \
+ _PW_ASSERT_BASIC_FUNCTION_NAME, \
+ "Check failed: " \
+ arg_a_str " (=" type_fmt ") " \
+ comparison_op_str " " \
+ arg_b_str " (=" type_fmt ")" \
+ ". " message, \
+ arg_a_val, arg_b_val PW_COMMA_ARGS(__VA_ARGS__))
// clang-format on