debug: coredump: allow for coredump backends to be defined outside of tree
Move coredump_backend_api struct to public header so that custom backends for coredump can be defined out of tree. Create simple backend in test directory for verification. Signed-off-by: Mark Holden <mholden@fb.com>
This commit is contained in:
parent
1fd29fb131
commit
7b2b283677
|
@ -128,6 +128,31 @@ struct coredump_mem_hdr_t {
|
|||
uintptr_t end;
|
||||
} __packed;
|
||||
|
||||
typedef void (*coredump_backend_start_t)(void);
|
||||
typedef void (*coredump_backend_end_t)(void);
|
||||
typedef void (*coredump_backend_buffer_output_t)(uint8_t *buf, size_t buflen);
|
||||
typedef int (*coredump_backend_query_t)(enum coredump_query_id query_id,
|
||||
void *arg);
|
||||
typedef int (*coredump_backend_cmd_t)(enum coredump_cmd_id cmd_id,
|
||||
void *arg);
|
||||
|
||||
struct coredump_backend_api {
|
||||
/* Signal to backend of the start of coredump. */
|
||||
coredump_backend_start_t start;
|
||||
|
||||
/* Signal to backend of the end of coredump. */
|
||||
coredump_backend_end_t end;
|
||||
|
||||
/* Raw buffer output */
|
||||
coredump_backend_buffer_output_t buffer_output;
|
||||
|
||||
/* Perform query on backend */
|
||||
coredump_backend_query_t query;
|
||||
|
||||
/* Perform command on backend */
|
||||
coredump_backend_cmd_t cmd;
|
||||
};
|
||||
|
||||
void coredump(unsigned int reason, const z_arch_esf_t *esf,
|
||||
struct k_thread *thread);
|
||||
void coredump_memory_dump(uintptr_t start_addr, uintptr_t end_addr);
|
||||
|
|
|
@ -28,6 +28,11 @@ config DEBUG_COREDUMP_BACKEND_FLASH_PARTITION
|
|||
Core dump is saved to a flash partition with DTS alias
|
||||
"coredump-partition".
|
||||
|
||||
config DEBUG_COREDUMP_BACKEND_OTHER
|
||||
bool "Backend subsystem for coredump defined out of tree"
|
||||
help
|
||||
Core dump is done via custom mechanism defined out of tree
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
|
|
|
@ -498,7 +498,7 @@ static int coredump_flash_backend_cmd(enum coredump_cmd_id cmd_id,
|
|||
}
|
||||
|
||||
|
||||
struct z_coredump_backend_api z_coredump_backend_flash_partition = {
|
||||
struct coredump_backend_api coredump_backend_flash_partition = {
|
||||
.start = coredump_flash_backend_start,
|
||||
.end = coredump_flash_backend_end,
|
||||
.buffer_output = coredump_flash_backend_buffer_output,
|
||||
|
|
|
@ -117,7 +117,7 @@ static int coredump_logging_backend_cmd(enum coredump_cmd_id cmd_id,
|
|||
}
|
||||
|
||||
|
||||
struct z_coredump_backend_api z_coredump_backend_logging = {
|
||||
struct coredump_backend_api coredump_backend_logging = {
|
||||
.start = coredump_logging_backend_start,
|
||||
.end = coredump_logging_backend_end,
|
||||
.buffer_output = coredump_logging_backend_buffer_output,
|
||||
|
|
|
@ -14,13 +14,17 @@
|
|||
#include "coredump_internal.h"
|
||||
|
||||
#if defined(CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING)
|
||||
extern struct z_coredump_backend_api z_coredump_backend_logging;
|
||||
static struct z_coredump_backend_api
|
||||
*backend_api = &z_coredump_backend_logging;
|
||||
extern struct coredump_backend_api coredump_backend_logging;
|
||||
static struct coredump_backend_api
|
||||
*backend_api = &coredump_backend_logging;
|
||||
#elif defined(CONFIG_DEBUG_COREDUMP_BACKEND_FLASH_PARTITION)
|
||||
extern struct z_coredump_backend_api z_coredump_backend_flash_partition;
|
||||
static struct z_coredump_backend_api
|
||||
*backend_api = &z_coredump_backend_flash_partition;
|
||||
extern struct coredump_backend_api coredump_backend_flash_partition;
|
||||
static struct coredump_backend_api
|
||||
*backend_api = &coredump_backend_flash_partition;
|
||||
#elif defined(CONFIG_DEBUG_COREDUMP_BACKEND_OTHER)
|
||||
extern struct coredump_backend_api coredump_backend_other;
|
||||
static struct coredump_backend_api
|
||||
*backend_api = &coredump_backend_other;
|
||||
#else
|
||||
#error "Need to select a coredump backend"
|
||||
#endif
|
||||
|
|
|
@ -53,31 +53,6 @@ void z_coredump_start(void);
|
|||
*/
|
||||
void z_coredump_end(void);
|
||||
|
||||
typedef void (*z_coredump_backend_start_t)(void);
|
||||
typedef void (*z_coredump_backend_end_t)(void);
|
||||
typedef void (*z_coredump_backend_buffer_output_t)(uint8_t *buf, size_t buflen);
|
||||
typedef int (*coredump_backend_query_t)(enum coredump_query_id query_id,
|
||||
void *arg);
|
||||
typedef int (*coredump_backend_cmd_t)(enum coredump_cmd_id cmd_id,
|
||||
void *arg);
|
||||
|
||||
struct z_coredump_backend_api {
|
||||
/* Signal to backend of the start of coredump. */
|
||||
z_coredump_backend_start_t start;
|
||||
|
||||
/* Signal to backend of the end of coredump. */
|
||||
z_coredump_backend_end_t end;
|
||||
|
||||
/* Raw buffer output */
|
||||
z_coredump_backend_buffer_output_t buffer_output;
|
||||
|
||||
/* Perform query on backend */
|
||||
coredump_backend_query_t query;
|
||||
|
||||
/* Perform command on backend */
|
||||
coredump_backend_cmd_t cmd;
|
||||
};
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
|
|
@ -6,3 +6,8 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|||
project(hello_world)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
|
||||
zephyr_library_sources_ifdef(
|
||||
CONFIG_DEBUG_COREDUMP_BACKEND_OTHER
|
||||
src/coredump_backend_empty.c
|
||||
)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_DEBUG_COREDUMP=y
|
||||
CONFIG_DEBUG_COREDUMP_BACKEND_OTHER=y
|
||||
CONFIG_MP_NUM_CPUS=1
|
||||
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
|
||||
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM=n
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright Meta Platforms, Inc. and its affiliates.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug/coredump.h>
|
||||
|
||||
static int error;
|
||||
static bool is_valid;
|
||||
|
||||
static void coredump_empty_backend_start(void)
|
||||
{
|
||||
/* Reset error, is_valid */
|
||||
error = 0;
|
||||
is_valid = false;
|
||||
}
|
||||
|
||||
static void coredump_empty_backend_end(void)
|
||||
{
|
||||
is_valid = true;
|
||||
}
|
||||
|
||||
static void coredump_empty_backend_buffer_output(uint8_t *buf, size_t buflen)
|
||||
{
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
static int coredump_empty_backend_query(enum coredump_query_id query_id,
|
||||
void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
switch (query_id) {
|
||||
case COREDUMP_QUERY_GET_ERROR:
|
||||
ret = error;
|
||||
break;
|
||||
case COREDUMP_QUERY_HAS_STORED_DUMP:
|
||||
ret = 0;
|
||||
if (is_valid) {
|
||||
ret = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coredump_empty_backend_cmd(enum coredump_cmd_id cmd_id,
|
||||
void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
switch (cmd_id) {
|
||||
case COREDUMP_CMD_CLEAR_ERROR:
|
||||
error = 0;
|
||||
ret = 0;
|
||||
break;
|
||||
case COREDUMP_CMD_VERIFY_STORED_DUMP:
|
||||
ret = 0;
|
||||
if (is_valid) {
|
||||
ret = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct coredump_backend_api coredump_backend_other = {
|
||||
.start = coredump_empty_backend_start,
|
||||
.end = coredump_empty_backend_end,
|
||||
.buffer_output = coredump_empty_backend_buffer_output,
|
||||
.query = coredump_empty_backend_query,
|
||||
.cmd = coredump_empty_backend_cmd,
|
||||
};
|
|
@ -15,3 +15,8 @@ tests:
|
|||
filter: CONFIG_ARCH_SUPPORTS_COREDUMP
|
||||
extra_args: CONF_FILE=prj_flash_partition.conf
|
||||
platform_allow: qemu_x86
|
||||
coredump.backends.other:
|
||||
tags: ignore_faults ignore_qemu_crash
|
||||
filter: CONFIG_ARCH_SUPPORTS_COREDUMP
|
||||
extra_args: CONF_FILE=prj_backend_other.conf
|
||||
platform_exclude: acrn_ehl_crb
|
||||
|
|
Loading…
Reference in a new issue