coredump:Move coredump to sched/misc

1. move coredump form libelf to sched/misc
2. rename core_dump to coredump

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao
2024-07-06 15:22:51 +08:00
committed by Xiang Xiao
parent 9e868cadfb
commit 52126aede1
20 changed files with 697 additions and 879 deletions
+1 -3
View File
@@ -16,9 +16,7 @@ Enable Kconfig
.. code-block:: console
CONFIG_ELF=y /* Enable ELF */
CONFIG_ELF_COREDUMP=y /* Enable ELF Coredump */
CONFIG_COREDUMP=y /* Enable Coredump */
CONFIG_BOARD_COREDUMP_SYSLOG=y /* Enable Board Coredump, if exceptions and assertions occur, */
+1 -2
View File
@@ -39,8 +39,7 @@ list(
binfmt_exec.c
binfmt_copyargv.c
binfmt_copyactions.c
binfmt_dumpmodule.c
binfmt_coredump.c)
binfmt_dumpmodule.c)
if(CONFIG_BINFMT_LOADABLE)
list(APPEND SRCS binfmt_exit.c)
-1
View File
@@ -27,7 +27,6 @@ include $(TOPDIR)/Make.defs
CSRCS = binfmt_globals.c binfmt_initialize.c binfmt_register.c binfmt_unregister.c
CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
CSRCS += binfmt_exec.c binfmt_copyargv.c binfmt_copyactions.c binfmt_dumpmodule.c
CSRCS += binfmt_coredump.c
ifeq ($(CONFIG_BINFMT_LOADABLE),y)
CSRCS += binfmt_exit.c
-72
View File
@@ -1,72 +0,0 @@
/****************************************************************************
* binfmt/binfmt_coredump.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/binfmt/binfmt.h>
#include <errno.h>
#include "binfmt.h"
#ifndef CONFIG_BINFMT_DISABLE
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: core_dump
*
* Description:
* This function for generating core dump stream.
*
****************************************************************************/
int core_dump(FAR const struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,
pid_t pid)
{
FAR struct binfmt_s *binfmt;
int ret = -ENOENT;
for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
{
/* Use this handler to try to load the format */
if (binfmt->coredump)
{
ret = binfmt->coredump(regions, stream, pid);
if (ret == OK)
{
break;
}
}
}
return ret;
}
#endif /* CONFIG_BINFMT_DISABLE */
-34
View File
@@ -69,11 +69,6 @@ static int elf_loadbinary(FAR struct binary_s *binp,
FAR const char *filename,
FAR const struct symtab_s *exports,
int nexports);
#ifdef CONFIG_ELF_COREDUMP
static int elf_dumpbinary(FAR const struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,
pid_t pid);
#endif
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_DEBUG_BINFMT)
static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo);
#endif
@@ -87,9 +82,6 @@ static struct binfmt_s g_elfbinfmt =
NULL, /* next */
elf_loadbinary, /* load */
NULL, /* unload */
#ifdef CONFIG_ELF_COREDUMP
elf_dumpbinary, /* coredump */
#endif
};
/****************************************************************************
@@ -370,32 +362,6 @@ errout_with_init:
return ret;
}
/****************************************************************************
* Name: elf_dumpbinary
*
* Description:
* Generat the core dump stream as ELF structure.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ELF_COREDUMP
static int elf_dumpbinary(FAR const struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,
pid_t pid)
{
struct elf_dumpinfo_s dumpinfo;
dumpinfo.regions = regions;
dumpinfo.stream = stream;
dumpinfo.pid = pid;
return elf_coredump(&dumpinfo);
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
-5
View File
@@ -40,11 +40,6 @@ if(CONFIG_ELF)
libelf_unload.c
libelf_verify.c)
if(CONFIG_ELF_COREDUMP)
list(APPEND SRCS libelf_coredump.c)
target_include_directories(binfmt PRIVATE ${NUTTX_DIR}/sched)
endif()
if(CONFIG_BINFMT_CONSTRUCTORS)
list(APPEND SRCS libelf_ctors.c libelf_dtors.c)
endif()
-11
View File
@@ -63,17 +63,6 @@ config ELF_SYMBOL_CACHECOUNT
This is a cache that is used to store elf symbol table to
reduce access fs. Default: 256
config ELF_COREDUMP
bool "ELF Coredump"
depends on ARCH_HAVE_TCBINFO
default n
---help---
Generate ELF core dump to provide information about the CPU state and the
memory state of program.
The memory state embeds a snapshot of all segments mapped in the
memory space of the program. The CPU state contains register values
when the core dump has been generated.
config ELF_LOADTO_LMA
bool "ELF load sections to LMA"
default n
-6
View File
@@ -28,12 +28,6 @@ CSRCS += libelf_bind.c libelf_init.c libelf_addrenv.c libelf_iobuffer.c
CSRCS += libelf_load.c libelf_read.c libelf_sections.c libelf_symbols.c
CSRCS += libelf_uninit.c libelf_unload.c libelf_verify.c
ifeq ($(CONFIG_ELF_COREDUMP),y)
CSRCS += libelf_coredump.c
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)sched
endif
ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y)
CSRCS += libelf_ctors.c libelf_dtors.c
endif
File diff suppressed because it is too large Load Diff
-1
View File
@@ -81,7 +81,6 @@ static struct binfmt_s g_nxflatbinfmt =
NULL, /* next */
nxflat_loadbinary, /* load */
nxflat_unloadbinary, /* unload */
NULL, /* coredump */
};
/****************************************************************************
+2 -2
View File
@@ -4634,14 +4634,14 @@ config BOARD_CRASHDUMP
config BOARD_COREDUMP_SYSLOG
bool "Enable Core dump to syslog"
default n
depends on ELF_COREDUMP
depends on COREDUMP
---help---
Enable put coredump to syslog when crash.
config BOARD_COREDUMP_BLKDEV
bool "Enable Core Dump to block device"
default n
depends on ELF_COREDUMP
depends on COREDUMP
---help---
Enable save coredump at block device when crash.
@@ -21,13 +21,12 @@ CONFIG_BOARD_COREDUMP_SYSLOG=y
CONFIG_BOARD_LOOPSPERMSEC=99369
CONFIG_BOOT_RUNFROMSDRAM=y
CONFIG_BUILTIN=y
CONFIG_COREDUMP=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y
CONFIG_ELF=y
CONFIG_ELF_COREDUMP=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXPERIMENTAL=y
CONFIG_FS_PROCFS=y
-37
View File
@@ -31,18 +31,14 @@
#include <spawn.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <nuttx/sched.h>
#include <nuttx/streams.h>
#include <nuttx/memoryregion.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define BINFMT_NALLOC 4
#define COREDUMP_MAGIC 0x434f5245
/****************************************************************************
* Public Types
@@ -138,22 +134,6 @@ struct binfmt_s
/* Unload module callback */
CODE int (*unload)(FAR struct binary_s *bin);
/* Coredump callback */
CODE int (*coredump)(FAR const struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,
pid_t pid);
};
/* Coredump information for block header */
struct coredump_info_s
{
uint32_t magic;
struct utsname name;
time_t time;
size_t size;
};
/****************************************************************************
@@ -209,23 +189,6 @@ int register_binfmt(FAR struct binfmt_s *binfmt);
int unregister_binfmt(FAR struct binfmt_s *binfmt);
/****************************************************************************
* Name: core_dump
*
* Description:
* This function for generating core dump stream.
*
* Returned Value:
* This is a NuttX internal function so it follows the convention that
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
****************************************************************************/
int core_dump(FAR const struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,
pid_t pid);
/****************************************************************************
* Name: load_module
*
-31
View File
@@ -129,19 +129,6 @@ struct elf_loadinfo_s
struct file file; /* Descriptor for the file being loaded */
};
/* This struct provides a description of the dump information of
* memory regions.
*/
#ifdef CONFIG_ELF_COREDUMP
struct elf_dumpinfo_s
{
FAR const struct memory_region_s *regions;
FAR struct lib_outstream_s *stream;
pid_t pid;
};
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -233,24 +220,6 @@ int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
int elf_unload(FAR struct elf_loadinfo_s *loadinfo);
/****************************************************************************
* Name: elf_coredump
*
* Description:
* Generat the core dump stream as ELF structure.
*
* Input Parameters:
* dumpinfo - elf coredump informations
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ELF_COREDUMP
int elf_coredump(FAR struct elf_dumpinfo_s *dumpinfo);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
+36 -1
View File
@@ -27,9 +27,32 @@
* Included Files
****************************************************************************/
#include <nuttx/memoryregion.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <nuttx/streams.h>
#include <nuttx/memoryregion.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define COREDUMP_MAGIC 0x434f5245
/****************************************************************************
* Public Types
****************************************************************************/
/* Coredump information for block header */
struct coredump_info_s
{
uint32_t magic;
struct utsname name;
time_t time;
size_t size;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -54,4 +77,16 @@ int coredump_set_memory_region(FAR const struct memory_region_s *region);
int coredump_add_memory_region(FAR const void *ptr, size_t size);
/****************************************************************************
* Name: coredump
*
* Description:
* This function for generating core dump stream.
*
****************************************************************************/
int coredump(FAR const struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,
pid_t pid);
#endif /* __INCLUDE_NUTTX_COREDUMP_H */
+1 -1
View File
@@ -40,7 +40,7 @@
* Public Types
****************************************************************************/
#ifdef CONFIG_ELF_COREDUMP
#ifdef CONFIG_COREDUMP
typedef struct elf_prpsinfo_s
{
char pr_state; /* Numeric process state */
+12
View File
@@ -2047,3 +2047,15 @@ config ASSERT_PAUSE_CPU_TIMEOUT
---help---
Timeout in milisecond to pause another CPU when assert. Only available
when SMP is enabled.
Enable to support perf events.
config COREDUMP
bool "Coredump support"
depends on ARCH_HAVE_TCBINFO
default n
---help---
Generate ELF core dump to provide information about the CPU state and the
memory state of program.
The memory state embeds a snapshot of all segments mapped in the
memory space of the program. The CPU state contains register values
when the core dump has been generated.
+1 -1
View File
@@ -26,7 +26,7 @@ if(CONFIG_ARCH_DEADLOCKDUMP)
list(APPEND SRCS deadlock.c)
endif()
if(CONFIG_BOARD_COREDUMP_SYSLOG OR CONFIG_BOARD_COREDUMP_BLKDEV)
if(CONFIG_COREDUMP)
list(APPEND SRCS coredump.c)
endif()
+1 -1
View File
@@ -26,7 +26,7 @@ ifeq ($(CONFIG_ARCH_DEADLOCKDUMP),y)
CSRCS += deadlock.c
endif
ifneq ($(CONFIG_BOARD_COREDUMP_SYSLOG)$(CONFIG_BOARD_COREDUMP_BLKDEV),)
ifeq ($(CONFIG_COREDUMP),y)
CSRCS += coredump.c
endif
+641 -2
View File
File diff suppressed because it is too large Load Diff