assert: Log the assertion expression in case of fail

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2023-01-22 19:31:32 +08:00
committed by Gustavo Henrique Nihei
parent 9b88f8ea5c
commit 43e7b13697
7 changed files with 26 additions and 26 deletions
+2 -4
View File
@@ -237,8 +237,7 @@ static int bt_hci_send(struct bt_driver_s *btdev,
static void sdc_fault_handler(const char *file, const uint32_t line) static void sdc_fault_handler(const char *file, const uint32_t line)
{ {
_alert("SoftDevice Controller Fault\n"); _assert(file, line, "SoftDevice Controller Fault");
_assert(file, line);
} }
/**************************************************************************** /****************************************************************************
@@ -247,8 +246,7 @@ static void sdc_fault_handler(const char *file, const uint32_t line)
static void mpsl_assert_handler(const char *const file, const uint32_t line) static void mpsl_assert_handler(const char *const file, const uint32_t line)
{ {
_alert("MPSL assertion failed\n"); _assert(file, line, "MPSL assertion failed");
_assert(file, line);
} }
/**************************************************************************** /****************************************************************************
+9 -8
View File
@@ -42,14 +42,14 @@
#undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */ #undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
#undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */ #undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
#ifdef CONFIG_HAVE_FILENAME #ifndef CONFIG_HAVE_FILENAME
# define PANIC() __assert(__FILE__, __LINE__) # define __FILE__ "unknown"
#else # define __LINE__ 0
# define PANIC() __assert("unknown", 0)
#endif #endif
#define ASSERT(f) do { if (!(f)) PANIC(); } while (0) #define PANIC() __assert(__FILE__, __LINE__, "panic")
#define VERIFY(f) do { if ((f) < 0) PANIC(); } while (0) #define ASSERT(f) do { if (!(f)) __assert(__FILE__, __LINE__, #f); } while (0)
#define VERIFY(f) do { if ((f) < 0) __assert(__FILE__, __LINE__, #f); } while (0)
#ifdef CONFIG_DEBUG_ASSERTIONS #ifdef CONFIG_DEBUG_ASSERTIONS
# define DEBUGPANIC() PANIC() # define DEBUGPANIC() PANIC()
@@ -115,7 +115,7 @@ extern "C"
* *
****************************************************************************/ ****************************************************************************/
void _assert(FAR const char *filename, int linenum); void _assert(FAR const char *filename, int linenum, FAR const char *msg);
/**************************************************************************** /****************************************************************************
* Name: __assert * Name: __assert
@@ -125,7 +125,8 @@ void _assert(FAR const char *filename, int linenum);
* *
****************************************************************************/ ****************************************************************************/
void __assert(FAR const char *filename, int linenum) noreturn_function; void __assert(FAR const char *filename, int linenum,
FAR const char *msg) noreturn_function;
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus
+1 -1
View File
@@ -25,7 +25,7 @@
*/ */
SYSCALL_LOOKUP1(_exit, 1) SYSCALL_LOOKUP1(_exit, 1)
SYSCALL_LOOKUP(_assert, 2) SYSCALL_LOOKUP(_assert, 3)
SYSCALL_LOOKUP(getpid, 0) SYSCALL_LOOKUP(getpid, 0)
SYSCALL_LOOKUP(gettid, 0) SYSCALL_LOOKUP(gettid, 0)
SYSCALL_LOOKUP(prctl, 2) SYSCALL_LOOKUP(prctl, 2)
+2 -2
View File
@@ -31,8 +31,8 @@
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
void __assert(FAR const char *filename, int linenum) void __assert(FAR const char *filename, int linenum, FAR const char *msg)
{ {
_assert(filename, linenum); _assert(filename, linenum, msg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
+1 -1
View File
@@ -1,7 +1,7 @@
"__errno","errno.h","defined(CONFIG_BUILD_FLAT)","FAR int *" "__errno","errno.h","defined(CONFIG_BUILD_FLAT)","FAR int *"
"__stack_chk_fail","ssp/ssp.h","defined(CONFIG_STACK_CANARIES)","void","void" "__stack_chk_fail","ssp/ssp.h","defined(CONFIG_STACK_CANARIES)","void","void"
"_alert","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..." "_alert","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..."
"_assert","assert.h","","void","FAR const char *","int" "__assert","assert.h","","void","FAR const char *","int","FAR const char *"
"_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..." "_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","void","FAR const char *","..."
"_info","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO)","void","FAR const char *","..." "_info","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO)","void","FAR const char *","..."
"_warn","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN)","void","FAR const char *","..." "_warn","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN)","void","FAR const char *","..."
1 __errno errno.h defined(CONFIG_BUILD_FLAT) FAR int *
2 __stack_chk_fail ssp/ssp.h defined(CONFIG_STACK_CANARIES) void
3 _alert debug.h !defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR) void
4 _assert __assert assert.h void
5 _err debug.h !defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR) void
6 _info debug.h !defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO) void
7 _warn debug.h !defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN) void
+10 -9
View File
@@ -442,7 +442,7 @@ static void show_tasks(void)
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
void _assert(FAR const char *filename, int linenum) void _assert(FAR const char *filename, int linenum, FAR const char *msg)
{ {
FAR struct tcb_s *rtcb = running_task(); FAR struct tcb_s *rtcb = running_task();
struct utsname name; struct utsname name;
@@ -471,19 +471,20 @@ void _assert(FAR const char *filename, int linenum)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
# if CONFIG_TASK_NAME_SIZE > 0 # if CONFIG_TASK_NAME_SIZE > 0
_alert("Assertion failed CPU%d at file: %s:%d task: %s %p\n", _alert("Assertion failed: %s at file: %s:%d task(CPU%d): %s %p\n",
up_cpu_index(), filename, linenum, rtcb->name, rtcb->entry.main); msg, filename, linenum, up_cpu_index(), rtcb->name,
rtcb->entry.main);
# else # else
_alert("Assertion failed CPU%d at file: %s:%d task: %p\n", _alert("Assertion failed: %s at file: %s:%d task(CPU%d): %p\n",
up_cpu_index(), filename, linenum, rtcb->entry.main); msg, filename, linenum, up_cpu_index(), rtcb->entry.main);
# endif # endif
#else #else
# if CONFIG_TASK_NAME_SIZE > 0 # if CONFIG_TASK_NAME_SIZE > 0
_alert("Assertion failed at file: %s:%d task: %s %p\n", _alert("Assertion failed: %s at file: %s:%d task: %s %p\n",
filename, linenum, rtcb->name, rtcb->entry.main); msg, filename, linenum, rtcb->name, rtcb->entry.main);
# else # else
_alert("Assertion failed at file: %s:%d task: %p\n", _alert("Assertion failed: %s at file: %s:%d task: %p\n",
filename, linenum, rtcb->entry.main); msg, filename, linenum, rtcb->entry.main);
# endif # endif
#endif #endif
+1 -1
View File
@@ -1,5 +1,5 @@
"_exit","unistd.h","","noreturn","int" "_exit","unistd.h","","noreturn","int"
"_assert","assert.h","","void","FAR const char *","int" "_assert","assert.h","","void","FAR const char *","int","FAR const char *"
"accept4","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *","int" "accept4","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *","int"
"adjtime","sys/time.h","defined(CONFIG_CLOCK_TIMEKEEPING)","int","FAR const struct timeval *","FAR struct timeval *" "adjtime","sys/time.h","defined(CONFIG_CLOCK_TIMEKEEPING)","int","FAR const struct timeval *","FAR struct timeval *"
"aio_cancel","aio.h","defined(CONFIG_FS_AIO)","int","int","FAR struct aiocb *" "aio_cancel","aio.h","defined(CONFIG_FS_AIO)","int","int","FAR struct aiocb *"
1 _exit unistd.h noreturn int
2 _assert assert.h void FAR const char *
3 accept4 sys/socket.h defined(CONFIG_NET) int int
4 adjtime sys/time.h defined(CONFIG_CLOCK_TIMEKEEPING) int FAR const struct timeval *
5 aio_cancel aio.h defined(CONFIG_FS_AIO) int int