system/coredump: add coredump tool to capture system status
Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
parent
97a38b2b1f
commit
6f4546f597
25
system/coredump/Kconfig
Normal file
25
system/coredump/Kconfig
Normal file
@ -0,0 +1,25 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
menuconfig SYSTEM_COREDUMP
|
||||
tristate "Coredump tool capture system status"
|
||||
default n
|
||||
depends on ELF_COREDUMP
|
||||
|
||||
if SYSTEM_COREDUMP
|
||||
|
||||
config SYSTEM_COREDUMP_STACKSIZE
|
||||
int "coredump stack size"
|
||||
default DEFAULT_TASK_STACKSIZE
|
||||
---help---
|
||||
This is the stack size that will be used when starting the coredump.
|
||||
|
||||
config SYSTEM_COREDUMP_PRIORITY
|
||||
int "coredump priority"
|
||||
default 100
|
||||
---help---
|
||||
This is the task priority that will be used when starting the coredump.
|
||||
|
||||
endif # SYSTEM_COREDUMP
|
23
system/coredump/Make.defs
Normal file
23
system/coredump/Make.defs
Normal file
@ -0,0 +1,23 @@
|
||||
############################################################################
|
||||
# apps/system/coredump/Make.defs
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_SYSTEM_COREDUMP),)
|
||||
CONFIGURED_APPS += $(APPDIR)/system/coredump
|
||||
endif
|
30
system/coredump/Makefile
Normal file
30
system/coredump/Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
############################################################################
|
||||
# apps/system/coredump/Makefile
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
MAINSRC = coredump.c
|
||||
|
||||
PROGNAME = coredump
|
||||
PRIORITY = $(CONFIG_SYSTEM_COREDUMP_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_SYSTEM_COREDUMP_STACKSIZE)
|
||||
MODULE = $(CONFIG_SYSTEM_COREDUMP)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
149
system/coredump/coredump.c
Normal file
149
system/coredump/coredump.c
Normal file
@ -0,0 +1,149 @@
|
||||
/****************************************************************************
|
||||
* apps/system/coredump/coredump.c
|
||||
*
|
||||
* 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/streams.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <execinfo.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* coredump_main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
FAR struct lib_stdoutstream_s *outstream;
|
||||
FAR struct lib_hexdumpstream_s *hstream;
|
||||
FAR struct lib_lzfoutstream_s *lstream;
|
||||
char *name = NULL;
|
||||
FAR void *stream;
|
||||
int logmask;
|
||||
int pid = 0;
|
||||
FILE *file;
|
||||
|
||||
if (argc >= 2)
|
||||
{
|
||||
pid = atoi(argv[1]);
|
||||
if (pid == 0)
|
||||
{
|
||||
name = argv[1];
|
||||
}
|
||||
|
||||
if (argc >= 3)
|
||||
{
|
||||
if (name == NULL)
|
||||
{
|
||||
name = argv[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
pid = atoi(argv[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
pid = INVALID_PROCESS_ID;
|
||||
}
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
file = fopen(name, "w");
|
||||
if (file == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
file = stdout;
|
||||
}
|
||||
|
||||
hstream = malloc(sizeof(*hstream) + sizeof(*lstream) + sizeof(*outstream));
|
||||
if (hstream == NULL)
|
||||
{
|
||||
if (name != NULL)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
lstream = (FAR void *)(hstream + 1);
|
||||
outstream = (FAR void *)(lstream + 1);
|
||||
|
||||
logmask = setlogmask(LOG_ALERT);
|
||||
|
||||
printf("Start coredump:\n");
|
||||
|
||||
/* Initialize hex output stream */
|
||||
|
||||
lib_stdoutstream(outstream, file);
|
||||
lib_hexdumpstream(hstream, (FAR void *)outstream);
|
||||
|
||||
stream = hstream;
|
||||
|
||||
#ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
|
||||
|
||||
/* Initialize LZF compression stream */
|
||||
|
||||
lib_lzfoutstream(lstream, stream);
|
||||
stream = lstream;
|
||||
|
||||
#endif
|
||||
|
||||
/* Do core dump */
|
||||
|
||||
core_dump(NULL, stream, pid);
|
||||
|
||||
#ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
|
||||
printf("Finish coredump (Compression Enabled).\n");
|
||||
#else
|
||||
printf("Finish coredump.\n");
|
||||
#endif
|
||||
|
||||
setlogmask(logmask);
|
||||
|
||||
free(hstream);
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user