Skip to content

Commit

Permalink
[nrf toup] VerifyOrDie logging for constrained devices
Browse files Browse the repository at this point in the history
1. Add the configuration to enable logging the location of
   a failed VerifyOrDie() without logging the condition to
   reduce the code size impact but still be able to debug
   failing VerifyOrDie() conditions.
2. Allow to override __FILE__ macro with __FILE_NAME__ by
   setting the warn_builtin_macro_redefined GN arg to false
   to further reduce the code size increase.
3. Add Kconfigs for nRF Connect platform for enabling both
   features.

Signed-off-by: Damian Krolik <[email protected]>
  • Loading branch information
Damian-Nordic committed Jul 24, 2024
1 parent 1f60b21 commit bc7fd4c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -209,6 +212,9 @@ config("disabled_warnings") {
"-Wno-maybe-uninitialized",
]
}
if (!warn_builtin_macro_redefined) {
cflags += [ "-Wno-builtin-macro-redefined" ]
}
}

config("warnings_common") {
Expand Down
9 changes: 9 additions & 0 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ if (CONFIG_NRF_802154_RADIO_DRIVER)
zephyr_include_directories($<TARGET_PROPERTY:nrf-802154-driver-interface,INTERFACE_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)
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 @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
*
Expand Down
5 changes: 4 additions & 1 deletion src/lib/support/CodeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/platform/nrfconnect/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc7fd4c

Please sign in to comment.