|
25 | 25 | #include <nuttx/config.h>
|
26 | 26 |
|
27 | 27 | #include <nuttx/arch.h>
|
| 28 | +#include <nuttx/binfmt/binfmt.h> |
28 | 29 | #include <nuttx/board.h>
|
29 | 30 | #include <nuttx/irq.h>
|
30 | 31 | #include <nuttx/tls.h>
|
|
71 | 72 |
|
72 | 73 | static uint8_t g_last_regs[XCPTCONTEXT_SIZE];
|
73 | 74 |
|
| 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 | + |
74 | 83 | static FAR const char *g_policy[4] =
|
75 | 84 | {
|
76 | 85 | "FIFO", "RR", "SPORADIC"
|
@@ -459,6 +468,53 @@ static void show_tasks(void)
|
459 | 468 | #endif
|
460 | 469 | }
|
461 | 470 |
|
| 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 | + |
462 | 518 | /****************************************************************************
|
463 | 519 | * Public Functions
|
464 | 520 | ****************************************************************************/
|
@@ -550,6 +606,16 @@ void _assert(FAR const char *filename, int linenum,
|
550 | 606 |
|
551 | 607 | #ifdef CONFIG_BOARD_CRASHDUMP
|
552 | 608 | 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 | + |
553 | 619 | #endif
|
554 | 620 |
|
555 | 621 | /* Flush any buffered SYSLOG data */
|
|
0 commit comments