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

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)
{
_alert("SoftDevice Controller Fault\n");
_assert(file, line);
_assert(file, line, "SoftDevice Controller Fault");
}
/****************************************************************************
@ -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)
{
_alert("MPSL assertion failed\n");
_assert(file, line);
_assert(file, line, "MPSL assertion failed");
}
/****************************************************************************

View File

@ -42,14 +42,14 @@
#undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
#undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
#ifdef CONFIG_HAVE_FILENAME
# define PANIC() __assert(__FILE__, __LINE__)
#else
# define PANIC() __assert("unknown", 0)
#ifndef CONFIG_HAVE_FILENAME
# define __FILE__ "unknown"
# define __LINE__ 0
#endif
#define ASSERT(f) do { if (!(f)) PANIC(); } while (0)
#define VERIFY(f) do { if ((f) < 0) PANIC(); } while (0)
#define PANIC() __assert(__FILE__, __LINE__, "panic")
#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
# 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
@ -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
#ifdef __cplusplus

View File

@ -25,7 +25,7 @@
*/
SYSCALL_LOOKUP1(_exit, 1)
SYSCALL_LOOKUP(_assert, 2)
SYSCALL_LOOKUP(_assert, 3)
SYSCALL_LOOKUP(getpid, 0)
SYSCALL_LOOKUP(gettid, 0)
SYSCALL_LOOKUP(prctl, 2)

View File

@ -31,8 +31,8 @@
* 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);
}

View File

@ -1,7 +1,7 @@
"__errno","errno.h","defined(CONFIG_BUILD_FLAT)","FAR int *"
"__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 *","..."
"_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 *","..."
"_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 *","..."

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -442,7 +442,7 @@ static void show_tasks(void)
* 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();
struct utsname name;
@ -471,19 +471,20 @@ void _assert(FAR const char *filename, int linenum)
#ifdef CONFIG_SMP
# if CONFIG_TASK_NAME_SIZE > 0
_alert("Assertion failed CPU%d at file: %s:%d task: %s %p\n",
up_cpu_index(), filename, linenum, rtcb->name, rtcb->entry.main);
_alert("Assertion failed: %s at file: %s:%d task(CPU%d): %s %p\n",
msg, filename, linenum, up_cpu_index(), rtcb->name,
rtcb->entry.main);
# else
_alert("Assertion failed CPU%d at file: %s:%d task: %p\n",
up_cpu_index(), filename, linenum, rtcb->entry.main);
_alert("Assertion failed: %s at file: %s:%d task(CPU%d): %p\n",
msg, filename, linenum, up_cpu_index(), rtcb->entry.main);
# endif
#else
# if CONFIG_TASK_NAME_SIZE > 0
_alert("Assertion failed at file: %s:%d task: %s %p\n",
filename, linenum, rtcb->name, rtcb->entry.main);
_alert("Assertion failed: %s at file: %s:%d task: %s %p\n",
msg, filename, linenum, rtcb->name, rtcb->entry.main);
# else
_alert("Assertion failed at file: %s:%d task: %p\n",
filename, linenum, rtcb->entry.main);
_alert("Assertion failed: %s at file: %s:%d task: %p\n",
msg, filename, linenum, rtcb->entry.main);
# endif
#endif

View File

@ -1,5 +1,5 @@
"_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"
"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 *"

Can't render this file because it has a wrong number of fields in line 2.