diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index df85153297..0a72508ebc 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -27,6 +27,9 @@ declare_args() { # Enable -Werror. This can be disabled if using a different compiler # with unfixed or unsupported wanings. treat_warnings_as_errors = true + + # Disable this to allow for overriding built-in defines, such as __FILE__. + warn_builtin_macro_redefined = true } if (current_cpu == "arm" || current_cpu == "arm64") { @@ -209,6 +212,9 @@ config("disabled_warnings") { "-Wno-maybe-uninitialized", ] } + if (!warn_builtin_macro_redefined) { + cflags += [ "-Wno-builtin-macro-redefined" ] + } } config("warnings_common") { diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 83968001c1..0a504a5207 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -78,6 +78,11 @@ if (CONFIG_NRF_802154_RADIO_DRIVER) zephyr_include_directories($) endif() +if (CONFIG_CHIP_LOG_FILE_NAME) + zephyr_compile_definitions(__FILE__=__FILE_NAME__) + zephyr_compile_options(-Wno-builtin-macro-redefined) +endif() + zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C) matter_add_cflags("${ZEPHYR_CFLAGS_C}") zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX) @@ -182,6 +187,10 @@ if (NOT CONFIG_CHIP_DEBUG_SYMBOLS) matter_add_gn_arg_string("symbol_level" "0") endif() +if (CONFIG_CHIP_LOG_FILE_NAME) + matter_add_gn_arg_bool("warn_builtin_macro_redefined" FALSE) +endif() + if (CHIP_COMPILER_LAUNCHER) matter_add_gn_arg_string("pw_command_launcher" ${CHIP_COMPILER_LAUNCHER}) endif() diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig index 9133ba16a0..6333462130 100644 --- a/config/nrfconnect/chip-module/Kconfig +++ b/config/nrfconnect/chip-module/Kconfig @@ -144,6 +144,22 @@ config CHIP_DEBUG_SYMBOLS help Enables building the application with debug symbols. +config CHIP_LOG_VERIFY_OR_DIE + bool "Log source code location on VerifyOrDie failure" + help + Enables the feature to log the file name and line number where the Matter + stack calls the VerifyOrDie macro with the condition evaluating to false. + +config CHIP_LOG_FILE_NAME + bool "Log file name instead of entire file path" + default y + help + Enables using a file name instead of an entire file path whenever the + source code location needs to be logged. This is achieved by overriding + the __FILE__ macro with __FILE_NAME__. + This reduces the code size in debug configurations that enable verbose + assertion macros. + config CHIP_MALLOC_SYS_HEAP default y if !ARCH_POSIX diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index 558e0ee08e..94c2da25aa 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -1024,6 +1024,17 @@ extern const char CHIP_NON_PRODUCTION_MARKER[]; #define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 0 #endif +/** + * @def CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND + * + * @brief If true, VerifyOrDie() built with @c CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE + * generates a short message that includes only the source code location, + * without the condition that fails. + */ +#ifndef CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND +#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND 0 +#endif + /** * @def CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES * diff --git a/src/lib/support/CodeUtils.h b/src/lib/support/CodeUtils.h index 500804bc94..b1dac30b4b 100644 --- a/src/lib/support/CodeUtils.h +++ b/src/lib/support/CodeUtils.h @@ -527,7 +527,10 @@ inline void chipDie(void) * @sa #chipDie * */ -#if CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE +#if CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE && CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND +#define VerifyOrDie(aCondition) \ + nlABORT_ACTION(aCondition, ChipLogError(Support, "VerifyOrDie failure at %s:%d", __FILE__, __LINE__)) +#elif CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE #define VerifyOrDie(aCondition) \ nlABORT_ACTION(aCondition, ChipLogError(Support, "VerifyOrDie failure at %s:%d: %s", __FILE__, __LINE__, #aCondition)) #else // CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE diff --git a/src/platform/nrfconnect/CHIPPlatformConfig.h b/src/platform/nrfconnect/CHIPPlatformConfig.h index d3ee463638..4e0c147b23 100644 --- a/src/platform/nrfconnect/CHIPPlatformConfig.h +++ b/src/platform/nrfconnect/CHIPPlatformConfig.h @@ -163,3 +163,10 @@ #define CHIP_CONFIG_ENABLE_BDX_LOG_TRANSFER CONFIG_CHIP_ENABLE_BDX_LOG_TRANSFER #endif // CONFIG_CHIP_ENABLE_BDX_LOG_TRANSFER #endif // CHIP_CONFIG_ENABLE_BDX_LOG_TRANSFER + +#ifdef CONFIG_CHIP_LOG_VERIFY_OR_DIE +#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 1 +#ifndef CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND +#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND 1 +#endif // CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND +#endif // CONFIG_CHIP_LOG_VERIFY_OR_DIE