sched/misc: Add support for coredump in assert

Add coredump support to collect the stacks and registers of all threads when asserting

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2023-05-24 19:51:12 +08:00 committed by Xiang Xiao
parent e0f4a76d6c
commit 86bf7d9bec
2 changed files with 90 additions and 0 deletions

View File

@ -4034,6 +4034,30 @@ config BOARD_CRASHDUMP
"machine state" in a place where on the next reset can write it
to more sophisticated storage in a sane operating environment.
config BOARD_COREDUMP
bool "Enable Core Dump after assert"
default n
depends on ELF_COREDUMP
---help---
Enable to support for the dump core information after assert.
if BOARD_COREDUMP
config BOARD_COREDUMP_FULL
bool "Core Dump all thread registers and stacks"
default y
---help---
Enable to support for the dump all task registers and stacks.
config BOARD_COREDUMP_COMPRESSION
bool "Enable Core Dump compression"
default y
select LIBC_LZF
---help---
Enable LZF compression algorithm for core dump content
endif # BOARD_COREDUMP
config BOARD_ENTROPY_POOL
bool "Enable Board level storing of entropy pool structure"
default n

View File

@ -25,6 +25,7 @@
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/board.h>
#include <nuttx/irq.h>
#include <nuttx/tls.h>
@ -71,6 +72,14 @@
static uint8_t g_last_regs[XCPTCONTEXT_SIZE];
#ifdef CONFIG_BOARD_COREDUMP
static struct lib_syslogstream_s g_syslogstream;
static struct lib_hexdumpstream_s g_hexstream;
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
static struct lib_lzfoutstream_s g_lzfstream;
# endif
#endif
static FAR const char *g_policy[4] =
{
"FIFO", "RR", "SPORADIC"
@ -459,6 +468,53 @@ static void show_tasks(void)
#endif
}
/****************************************************************************
* Name: dump_core
****************************************************************************/
#ifdef CONFIG_BOARD_COREDUMP
static void dump_core(pid_t pid)
{
FAR void *stream;
int logmask;
logmask = setlogmask(LOG_ALERT);
_alert("Start coredump:\n");
/* Initialize hex output stream */
lib_syslogstream(&g_syslogstream, LOG_EMERG);
stream = &g_syslogstream;
lib_hexdumpstream(&g_hexstream, stream);
stream = &g_hexstream;
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
/* Initialize LZF compression stream */
lib_lzfoutstream(&g_lzfstream, stream);
stream = &g_lzfstream;
# endif
/* Do core dump */
core_dump(NULL, stream, pid);
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
_alert("Finish coredump (Compression Enabled).\n");
# else
_alert("Finish coredump.\n");
# endif
setlogmask(logmask);
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -550,6 +606,16 @@ void _assert(FAR const char *filename, int linenum,
#ifdef CONFIG_BOARD_CRASHDUMP
board_crashdump(up_getsp(), rtcb, filename, linenum, msg);
#elif defined(CONFIG_BOARD_COREDUMP)
/* Dump core information */
# ifdef CONFIG_BOARD_COREDUMP_FULL
dump_core(INVALID_PROCESS_ID);
# else
dump_core(rtcb->pid);
# endif
#endif
/* Flush any buffered SYSLOG data */