diff --git a/boards/Kconfig b/boards/Kconfig index 1f1bde8acf..c7b66681f1 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -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 diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 7a3e056e54..180ccfc5ee 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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 */