Skip to content

Commit 86bf7d9

Browse files
anchaoxiaoxiang781216
authored andcommitted
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>
1 parent e0f4a76 commit 86bf7d9

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

boards/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,30 @@ config BOARD_CRASHDUMP
40344034
"machine state" in a place where on the next reset can write it
40354035
to more sophisticated storage in a sane operating environment.
40364036

4037+
config BOARD_COREDUMP
4038+
bool "Enable Core Dump after assert"
4039+
default n
4040+
depends on ELF_COREDUMP
4041+
---help---
4042+
Enable to support for the dump core information after assert.
4043+
4044+
if BOARD_COREDUMP
4045+
4046+
config BOARD_COREDUMP_FULL
4047+
bool "Core Dump all thread registers and stacks"
4048+
default y
4049+
---help---
4050+
Enable to support for the dump all task registers and stacks.
4051+
4052+
config BOARD_COREDUMP_COMPRESSION
4053+
bool "Enable Core Dump compression"
4054+
default y
4055+
select LIBC_LZF
4056+
---help---
4057+
Enable LZF compression algorithm for core dump content
4058+
4059+
endif # BOARD_COREDUMP
4060+
40374061
config BOARD_ENTROPY_POOL
40384062
bool "Enable Board level storing of entropy pool structure"
40394063
default n

sched/misc/assert.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <nuttx/config.h>
2626

2727
#include <nuttx/arch.h>
28+
#include <nuttx/binfmt/binfmt.h>
2829
#include <nuttx/board.h>
2930
#include <nuttx/irq.h>
3031
#include <nuttx/tls.h>
@@ -71,6 +72,14 @@
7172

7273
static uint8_t g_last_regs[XCPTCONTEXT_SIZE];
7374

75+
#ifdef CONFIG_BOARD_COREDUMP
76+
static struct lib_syslogstream_s g_syslogstream;
77+
static struct lib_hexdumpstream_s g_hexstream;
78+
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
79+
static struct lib_lzfoutstream_s g_lzfstream;
80+
# endif
81+
#endif
82+
7483
static FAR const char *g_policy[4] =
7584
{
7685
"FIFO", "RR", "SPORADIC"
@@ -459,6 +468,53 @@ static void show_tasks(void)
459468
#endif
460469
}
461470

471+
/****************************************************************************
472+
* Name: dump_core
473+
****************************************************************************/
474+
475+
#ifdef CONFIG_BOARD_COREDUMP
476+
static void dump_core(pid_t pid)
477+
{
478+
FAR void *stream;
479+
int logmask;
480+
481+
logmask = setlogmask(LOG_ALERT);
482+
483+
_alert("Start coredump:\n");
484+
485+
/* Initialize hex output stream */
486+
487+
lib_syslogstream(&g_syslogstream, LOG_EMERG);
488+
489+
stream = &g_syslogstream;
490+
491+
lib_hexdumpstream(&g_hexstream, stream);
492+
493+
stream = &g_hexstream;
494+
495+
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
496+
497+
/* Initialize LZF compression stream */
498+
499+
lib_lzfoutstream(&g_lzfstream, stream);
500+
stream = &g_lzfstream;
501+
502+
# endif
503+
504+
/* Do core dump */
505+
506+
core_dump(NULL, stream, pid);
507+
508+
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
509+
_alert("Finish coredump (Compression Enabled).\n");
510+
# else
511+
_alert("Finish coredump.\n");
512+
# endif
513+
514+
setlogmask(logmask);
515+
}
516+
#endif
517+
462518
/****************************************************************************
463519
* Public Functions
464520
****************************************************************************/
@@ -550,6 +606,16 @@ void _assert(FAR const char *filename, int linenum,
550606

551607
#ifdef CONFIG_BOARD_CRASHDUMP
552608
board_crashdump(up_getsp(), rtcb, filename, linenum, msg);
609+
610+
#elif defined(CONFIG_BOARD_COREDUMP)
611+
/* Dump core information */
612+
613+
# ifdef CONFIG_BOARD_COREDUMP_FULL
614+
dump_core(INVALID_PROCESS_ID);
615+
# else
616+
dump_core(rtcb->pid);
617+
# endif
618+
553619
#endif
554620

555621
/* Flush any buffered SYSLOG data */

0 commit comments

Comments
 (0)