You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2021/12/29 03:03:18 UTC
[incubator-nuttx] branch master updated: arch/sim: Implement up_backtrace
This is an automated email from the ASF dual-hosted git repository.
archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new f302e8f arch/sim: Implement up_backtrace
f302e8f is described below
commit f302e8fd401d9ff987aab96a91821cb24c250ed8
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Dec 25 23:28:16 2021 +0800
arch/sim: Implement up_backtrace
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
arch/sim/src/Makefile | 6 +++-
arch/sim/src/nuttx-names.in | 1 +
arch/sim/src/sim/up_assert.c | 16 ++++++---
.../src/sim/{up_host_abort.c => up_backtrace.c} | 38 +++++++++++++---------
.../sim/src/sim/{up_host_abort.c => up_hostmisc.c} | 9 ++++-
arch/sim/src/sim/up_internal.h | 3 +-
6 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile
index f24045c..67d2ae1 100644
--- a/arch/sim/src/Makefile
+++ b/arch/sim/src/Makefile
@@ -61,6 +61,10 @@ CSRCS += up_heap.c up_uart.c up_assert.c up_puts.c
CSRCS += up_copyfullstate.c
CSRCS += up_sigdeliver.c
+ifeq ($(CONFIG_SCHED_BACKTRACE),y)
+CSRCS += up_backtrace.c
+endif
+
ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
ifeq ($(CONFIG_SCHED_WAITPID),y)
CSRCS += up_vfork.c
@@ -75,7 +79,7 @@ ifeq ($(CONFIG_HOST_MACOS),y)
HOSTCFLAGS += -Wno-deprecated-declarations
endif
-HOSTSRCS = up_hostirq.c up_hostmemory.c up_hosttime.c up_simuart.c up_host_abort.c
+HOSTSRCS = up_hostirq.c up_hostmemory.c up_hosttime.c up_simuart.c up_hostmisc.c
STDLIBS += -lpthread
ifeq ($(CONFIG_HOST_MACOS),y)
ifeq ($(CONFIG_LIBCXX),y)
diff --git a/arch/sim/src/nuttx-names.in b/arch/sim/src/nuttx-names.in
index 3b3629a..24c6725 100644
--- a/arch/sim/src/nuttx-names.in
+++ b/arch/sim/src/nuttx-names.in
@@ -35,6 +35,7 @@ NXSYMBOLS(abort)
NXSYMBOLS(accept)
NXSYMBOLS(access)
NXSYMBOLS(atexit)
+NXSYMBOLS(backtrace)
NXSYMBOLS(bind)
NXSYMBOLS(calloc)
NXSYMBOLS(chmod)
diff --git a/arch/sim/src/sim/up_assert.c b/arch/sim/src/sim/up_assert.c
index 51526fa..ed96ace 100644
--- a/arch/sim/src/sim/up_assert.c
+++ b/arch/sim/src/sim/up_assert.c
@@ -73,6 +73,8 @@
void up_assert(const char *filename, int lineno)
{
+ FAR struct tcb_s *rtcb = running_task();
+
/* Flush any buffered SYSLOG data (prior to the assertion) */
syslog_flush();
@@ -82,7 +84,7 @@ void up_assert(const char *filename, int lineno)
#ifdef CONFIG_SMP
#if CONFIG_TASK_NAME_SIZE > 0
_alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
- up_cpu_index(), filename, lineno, running_task()->name);
+ up_cpu_index(), filename, lineno, rtcb->name);
#else
_alert("Assertion failed CPU%d at file:%s line: %d\n",
up_cpu_index(), filename, lineno);
@@ -90,13 +92,19 @@ void up_assert(const char *filename, int lineno)
#else
#if CONFIG_TASK_NAME_SIZE > 0
_alert("Assertion failed at file:%s line: %d task: %s\n",
- filename, lineno, running_task()->name);
+ filename, lineno, rtcb->name);
#else
_alert("Assertion failed at file:%s line: %d\n",
filename, lineno);
#endif
#endif
+ /* Show back trace */
+
+#ifdef CONFIG_SCHED_BACKTRACE
+ sched_dumpstack(rtcb->pid);
+#endif
+
/* Flush any buffered SYSLOG data (from the above) */
syslog_flush();
@@ -104,14 +112,14 @@ void up_assert(const char *filename, int lineno)
/* Allow for any board/configuration specific crash information */
#ifdef CONFIG_BOARD_CRASHDUMP
- board_crashdump(up_getsp(), running_task(), filename, lineno);
+ board_crashdump(up_getsp(), rtcb, filename, lineno);
#endif
/* Flush any buffered SYSLOG data */
syslog_flush();
- if (CURRENT_REGS || (running_task())->flink == NULL)
+ if (CURRENT_REGS || rtcb->flink == NULL)
{
/* Exit the simulation */
diff --git a/arch/sim/src/sim/up_host_abort.c b/arch/sim/src/sim/up_backtrace.c
similarity index 75%
copy from arch/sim/src/sim/up_host_abort.c
copy to arch/sim/src/sim/up_backtrace.c
index db288d3..fed2dde 100644
--- a/arch/sim/src/sim/up_host_abort.c
+++ b/arch/sim/src/sim/up_backtrace.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/sim/src/sim/up_host_abort.c
+ * arch/sim/src/sim/up_backtrace.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -22,7 +22,10 @@
* Included Files
****************************************************************************/
-#include <stdlib.h>
+#include <nuttx/arch.h>
+#include <sched/sched.h>
+
+#include <string.h>
#include "up_internal.h"
@@ -30,20 +33,23 @@
* Public Functions
****************************************************************************/
-/****************************************************************************
- * Name: host_abort
- *
- * Description:
- * Abort the simulation
- *
- * Input Parameters:
- * status - Exit status to set
- ****************************************************************************/
-
-void host_abort(int status)
+int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
{
- /* exit the simulation */
+ void *buf[skip + size];
+ int ret = 0;
- exit(status);
-}
+ if (tcb == running_task())
+ {
+ ret = host_backtrace(buf, skip + size);
+ }
+
+ if (ret <= skip)
+ {
+ return ret < 0 ? ret : 0;
+ }
+ ret -= skip;
+ memcpy(buffer, &buf[skip], ret * sizeof(void *));
+
+ return ret;
+}
diff --git a/arch/sim/src/sim/up_host_abort.c b/arch/sim/src/sim/up_hostmisc.c
similarity index 91%
rename from arch/sim/src/sim/up_host_abort.c
rename to arch/sim/src/sim/up_hostmisc.c
index db288d3..b7747ee 100644
--- a/arch/sim/src/sim/up_host_abort.c
+++ b/arch/sim/src/sim/up_hostmisc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/sim/src/sim/up_host_abort.c
+ * arch/sim/src/sim/up_hostmisc.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -22,6 +22,7 @@
* Included Files
****************************************************************************/
+#include <execinfo.h>
#include <stdlib.h>
#include "up_internal.h"
@@ -47,3 +48,9 @@ void host_abort(int status)
exit(status);
}
+int host_backtrace(void** array, int size)
+{
+ /* exit the simulation */
+
+ return backtrace(array, size);
+}
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index c2ae3e2..29da237 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -142,9 +142,10 @@ void up_copyfullstate(uint32_t *dest, uint32_t *src);
void *up_doirq(int irq, void *regs);
-/* up_head.c ****************************************************************/
+/* up_hostmisc.c ************************************************************/
void host_abort(int status);
+int host_backtrace(void** array, int size);
/* up_hostmemory.c **********************************************************/