arch/sim: Implement up_backtrace

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-12-25 23:28:16 +08:00 committed by archer
parent f061766801
commit f302e8fd40
6 changed files with 83 additions and 7 deletions

View File

@ -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)

View File

@ -35,6 +35,7 @@ NXSYMBOLS(abort)
NXSYMBOLS(accept)
NXSYMBOLS(access)
NXSYMBOLS(atexit)
NXSYMBOLS(backtrace)
NXSYMBOLS(bind)
NXSYMBOLS(calloc)
NXSYMBOLS(chmod)

View File

@ -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 */

View File

@ -0,0 +1,55 @@
/****************************************************************************
* 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
* 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/arch.h>
#include <sched/sched.h>
#include <string.h>
#include "up_internal.h"
/****************************************************************************
* Public Functions
****************************************************************************/
int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
{
void *buf[skip + size];
int ret = 0;
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;
}

View File

@ -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);
}

View File

@ -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 **********************************************************/