Skip to content

Commit 4fd4724

Browse files
committed
[nrf toup] VerifyOrDie logging for constrained devices
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 <damian.krolik@nordicsemi.no>
1 parent 1f60b21 commit 4fd4724

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

build/config/compiler/BUILD.gn

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ declare_args() {
2727
# Enable -Werror. This can be disabled if using a different compiler
2828
# with unfixed or unsupported wanings.
2929
treat_warnings_as_errors = true
30+
31+
# Disable this to allow for overriding built-in defines, such as __FILE__.
32+
warn_builtin_macro_redefined = true
3033
}
3134

3235
if (current_cpu == "arm" || current_cpu == "arm64") {
@@ -209,6 +212,9 @@ config("disabled_warnings") {
209212
"-Wno-maybe-uninitialized",
210213
]
211214
}
215+
if (!warn_builtin_macro_redefined) {
216+
cflags += [ "-Wno-builtin-macro-redefined" ]
217+
}
212218
}
213219

214220
config("warnings_common") {

config/nrfconnect/chip-module/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ if (CONFIG_NRF_802154_RADIO_DRIVER)
7878
zephyr_include_directories($<TARGET_PROPERTY:nrf-802154-driver-interface,INTERFACE_INCLUDE_DIRECTORIES>)
7979
endif()
8080

81+
if (CONFIG_CHIP_LOG_FILE_NAME)
82+
zephyr_compile_definitions(__FILE__=__FILE_NAME__)
83+
zephyr_compile_options(-Wno-builtin-macro-redefined)
84+
endif()
85+
8186
zephyr_get_compile_flags(ZEPHYR_CFLAGS_C C)
8287
matter_add_cflags("${ZEPHYR_CFLAGS_C}")
8388
zephyr_get_compile_flags(ZEPHYR_CFLAGS_CC CXX)
@@ -182,6 +187,10 @@ if (NOT CONFIG_CHIP_DEBUG_SYMBOLS)
182187
matter_add_gn_arg_string("symbol_level" "0")
183188
endif()
184189

190+
if (CONFIG_CHIP_LOG_FILE_NAME)
191+
matter_add_gn_arg_bool("warn_builtin_macro_redefined" FALSE)
192+
endif()
193+
185194
if (CHIP_COMPILER_LAUNCHER)
186195
matter_add_gn_arg_string("pw_command_launcher" ${CHIP_COMPILER_LAUNCHER})
187196
endif()

config/nrfconnect/chip-module/Kconfig

+16
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ config CHIP_DEBUG_SYMBOLS
144144
help
145145
Enables building the application with debug symbols.
146146

147+
config CHIP_LOG_VERIFY_OR_DIE
148+
bool "Log source code location on VerifyOrDie failure"
149+
help
150+
Enables the feature to log the file name and line number where the Matter
151+
stack calls the VerifyOrDie macro with the condition evaluating to false.
152+
153+
config CHIP_LOG_FILE_NAME
154+
bool "Log file name instead of entire file path"
155+
default y
156+
help
157+
Enables using a file name instead of an entire file path whenever the
158+
source code location needs to be logged. This is achieved by overriding
159+
the __FILE__ macro with __FILE_NAME__.
160+
This reduces the code size in debug configurations that enable verbose
161+
assertion macros.
162+
147163
config CHIP_MALLOC_SYS_HEAP
148164
default y if !ARCH_POSIX
149165

src/lib/core/CHIPConfig.h

+11
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,17 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
10241024
#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 0
10251025
#endif
10261026

1027+
/**
1028+
* @def CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND
1029+
*
1030+
* @brief If true, VerifyOrDie() built with @c CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
1031+
* generates a short message that includes only the source code location,
1032+
* without the condition that fails.
1033+
*/
1034+
#ifndef CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND
1035+
#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND 0
1036+
#endif
1037+
10271038
/**
10281039
* @def CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES
10291040
*

src/lib/support/CodeUtils.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ inline void chipDie(void)
527527
* @sa #chipDie
528528
*
529529
*/
530-
#if CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
530+
#if CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE && CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND
531+
#define VerifyOrDie(aCondition) \
532+
nlABORT_ACTION(aCondition, ChipLogError(Support, "VerifyOrDie failure at %s:%d", __FILE__, __LINE__))
533+
#elif CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
531534
#define VerifyOrDie(aCondition) \
532535
nlABORT_ACTION(aCondition, ChipLogError(Support, "VerifyOrDie failure at %s:%d: %s", __FILE__, __LINE__, #aCondition))
533536
#else // CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE

src/platform/nrfconnect/CHIPPlatformConfig.h

+7
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,10 @@
163163
#define CHIP_CONFIG_ENABLE_BDX_LOG_TRANSFER CONFIG_CHIP_ENABLE_BDX_LOG_TRANSFER
164164
#endif // CONFIG_CHIP_ENABLE_BDX_LOG_TRANSFER
165165
#endif // CHIP_CONFIG_ENABLE_BDX_LOG_TRANSFER
166+
167+
#ifdef CONFIG_CHIP_LOG_VERIFY_OR_DIE
168+
#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 1
169+
#ifndef CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND
170+
#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND 1
171+
#endif // CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE_NO_COND
172+
#endif // CONFIG_CHIP_LOG_VERIFY_OR_DIE

0 commit comments

Comments
 (0)