From 72abd300e6347e9d5304c48ee291d57db90c8ea6 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Thu, 29 Jul 2021 16:55:17 +0800 Subject: [PATCH] system/dumpstack: add dump stack tool support Signed-off-by: chao.an --- system/dumpstack/Kconfig | 26 ++++++++++++++ system/dumpstack/Make.defs | 23 ++++++++++++ system/dumpstack/Makefile | 30 ++++++++++++++++ system/dumpstack/dumpstack.c | 70 ++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 system/dumpstack/Kconfig create mode 100644 system/dumpstack/Make.defs create mode 100644 system/dumpstack/Makefile create mode 100644 system/dumpstack/dumpstack.c diff --git a/system/dumpstack/Kconfig b/system/dumpstack/Kconfig new file mode 100644 index 000000000..ad7f0a9c2 --- /dev/null +++ b/system/dumpstack/Kconfig @@ -0,0 +1,26 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig SYSTEM_DUMPSTACK + tristate "dumpstack tool for show the task backtrace" + default n + depends on SCHED_BACKTRACE + ---help--- + +if SYSTEM_DUMPSTACK + +config SYSTEM_DUMPSTACK_STACKSIZE + int "dumpstack stack size" + default DEFAULT_TASK_STACKSIZE + ---help--- + This is the stack size that will be used when starting the dumpstack. + +config SYSTEM_DUMPSTACK_PRIORITY + int "dumpstack priority" + default 100 + ---help--- + This is the task priority that will be used when starting the dumpstack. + +endif # SYSTEM_DUMPSTACK diff --git a/system/dumpstack/Make.defs b/system/dumpstack/Make.defs new file mode 100644 index 000000000..e44ed9013 --- /dev/null +++ b/system/dumpstack/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# system/dumpstack/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_DUMPSTACK),) +CONFIGURED_APPS += $(APPDIR)/system/dumpstack +endif diff --git a/system/dumpstack/Makefile b/system/dumpstack/Makefile new file mode 100644 index 000000000..38069689d --- /dev/null +++ b/system/dumpstack/Makefile @@ -0,0 +1,30 @@ +############################################################################ +# system/dumpstack/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 = dumpstack.c + +PROGNAME = dumpstack +PRIORITY = $(CONFIG_SYSTEM_DUMPSTACK_PRIORITY) +STACKSIZE = $(CONFIG_SYSTEM_DUMPSTACK_STACKSIZE) +MODULE = $(CONFIG_SYSTEM_DUMPSTACK) + +include $(APPDIR)/Application.mk diff --git a/system/dumpstack/dumpstack.c b/system/dumpstack/dumpstack.c new file mode 100644 index 000000000..94af6483a --- /dev/null +++ b/system/dumpstack/dumpstack.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * apps/system/dumpstack/dumpstack.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 + +#include + +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * hello_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + int spid = -1; + int epid = -1; + + if (argc == 2) + { + spid = epid = atoi(argv[1]); + } + else if (argc >= 3) + { + spid = atoi(argv[1]); + epid = atoi(argv[2]); + } + + if (spid < 0 || epid < 0) + { + spid = epid = gettid(); + } + + do + { + sched_dumpstack(spid); + } + while (spid++ != epid); + + return 0; +}