note: add noteram crash dump
Dump all content when a crash occurs Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
parent
2740f377eb
commit
1e164b7f75
@ -59,6 +59,11 @@ The following configurations are configurable parameters for trace.
|
||||
- If enabled, stop overwriting old notes in the circular buffer when the buffer is full by default.
|
||||
This is useful to keep instrumentation data of the beginning of a system boot.
|
||||
|
||||
- ``CONFIG_DRIVERS_NOTERAM_CRASH_DUMP``
|
||||
|
||||
- If enabled, it will dump the data in the noteram buffer after a system crash.
|
||||
This function can help to view the behavior of the system before the crash
|
||||
|
||||
After the configuration, rebuild the NuttX kernel and application.
|
||||
|
||||
If the trace function is enabled, "``trace``" :doc:`../applications/nsh/builtin` will be available.
|
||||
|
@ -79,6 +79,12 @@ config DRIVERS_NOTERAM_DEFAULT_NOOVERWRITE
|
||||
is full by default. This is useful to keep instrumentation data of the
|
||||
beginning of a system boot.
|
||||
|
||||
config DRIVERS_NOTERAM_CRASH_DUMP
|
||||
bool "Dump noteram buffer on panic"
|
||||
default n
|
||||
---help---
|
||||
If this option is enabled, dump all contents when a crash occurs.
|
||||
|
||||
endif # DRIVERS_NOTERAM
|
||||
|
||||
config DRIVERS_NOTELOG
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/note/note_driver.h>
|
||||
#include <nuttx/note/noteram_driver.h>
|
||||
#include <nuttx/panic_notifier.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/streams.h>
|
||||
|
||||
@ -1007,6 +1008,60 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DRIVERS_NOTERAM_CRASH_DUMP
|
||||
|
||||
/****************************************************************************
|
||||
* Name: noteram_dump
|
||||
****************************************************************************/
|
||||
|
||||
static void noteram_dump(FAR struct noteram_driver_s *drv)
|
||||
{
|
||||
struct noteram_dump_context_s ctx;
|
||||
struct lib_syslograwstream_s stream;
|
||||
uint8_t note[64];
|
||||
|
||||
lib_syslograwstream_open(&stream);
|
||||
lib_sprintf(&stream.public, "# tracer:nop\n#\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = noteram_get(drv, note, sizeof(note));
|
||||
if (ret <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
noteram_dump_one(note, &stream.public, &ctx);
|
||||
}
|
||||
|
||||
lib_syslograwstream_close(&stream);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: noteram_crash_dump
|
||||
****************************************************************************/
|
||||
|
||||
static int noteram_crash_dump(FAR struct notifier_block *nb,
|
||||
unsigned long action, FAR void *data)
|
||||
{
|
||||
if (action == PANIC_KERNEL)
|
||||
{
|
||||
noteram_dump(&g_noteram_driver);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void noteram_crash_dump_register(void)
|
||||
{
|
||||
static struct notifier_block nb;
|
||||
nb.notifier_call = noteram_crash_dump;
|
||||
panic_notifier_chain_register(&nb);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -1028,6 +1083,9 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s,
|
||||
|
||||
int noteram_register(void)
|
||||
{
|
||||
#ifdef CONFIG_DRIVERS_NOTERAM_CRASH_DUMP
|
||||
noteram_crash_dump_register();
|
||||
#endif
|
||||
return register_driver("/dev/note/ram", &g_noteram_fops, 0666,
|
||||
&g_noteram_driver);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user