arch/sim: Implement up_backtrace
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
f061766801
commit
f302e8fd40
@ -61,6 +61,10 @@ CSRCS += up_heap.c up_uart.c up_assert.c up_puts.c
|
|||||||
CSRCS += up_copyfullstate.c
|
CSRCS += up_copyfullstate.c
|
||||||
CSRCS += up_sigdeliver.c
|
CSRCS += up_sigdeliver.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
|
||||||
|
CSRCS += up_backtrace.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
|
ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
|
||||||
ifeq ($(CONFIG_SCHED_WAITPID),y)
|
ifeq ($(CONFIG_SCHED_WAITPID),y)
|
||||||
CSRCS += up_vfork.c
|
CSRCS += up_vfork.c
|
||||||
@ -75,7 +79,7 @@ ifeq ($(CONFIG_HOST_MACOS),y)
|
|||||||
HOSTCFLAGS += -Wno-deprecated-declarations
|
HOSTCFLAGS += -Wno-deprecated-declarations
|
||||||
endif
|
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
|
STDLIBS += -lpthread
|
||||||
ifeq ($(CONFIG_HOST_MACOS),y)
|
ifeq ($(CONFIG_HOST_MACOS),y)
|
||||||
ifeq ($(CONFIG_LIBCXX),y)
|
ifeq ($(CONFIG_LIBCXX),y)
|
||||||
|
@ -35,6 +35,7 @@ NXSYMBOLS(abort)
|
|||||||
NXSYMBOLS(accept)
|
NXSYMBOLS(accept)
|
||||||
NXSYMBOLS(access)
|
NXSYMBOLS(access)
|
||||||
NXSYMBOLS(atexit)
|
NXSYMBOLS(atexit)
|
||||||
|
NXSYMBOLS(backtrace)
|
||||||
NXSYMBOLS(bind)
|
NXSYMBOLS(bind)
|
||||||
NXSYMBOLS(calloc)
|
NXSYMBOLS(calloc)
|
||||||
NXSYMBOLS(chmod)
|
NXSYMBOLS(chmod)
|
||||||
|
@ -73,6 +73,8 @@
|
|||||||
|
|
||||||
void up_assert(const char *filename, int lineno)
|
void up_assert(const char *filename, int lineno)
|
||||||
{
|
{
|
||||||
|
FAR struct tcb_s *rtcb = running_task();
|
||||||
|
|
||||||
/* Flush any buffered SYSLOG data (prior to the assertion) */
|
/* Flush any buffered SYSLOG data (prior to the assertion) */
|
||||||
|
|
||||||
syslog_flush();
|
syslog_flush();
|
||||||
@ -82,7 +84,7 @@ void up_assert(const char *filename, int lineno)
|
|||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
#if CONFIG_TASK_NAME_SIZE > 0
|
#if CONFIG_TASK_NAME_SIZE > 0
|
||||||
_alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
|
_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
|
#else
|
||||||
_alert("Assertion failed CPU%d at file:%s line: %d\n",
|
_alert("Assertion failed CPU%d at file:%s line: %d\n",
|
||||||
up_cpu_index(), filename, lineno);
|
up_cpu_index(), filename, lineno);
|
||||||
@ -90,13 +92,19 @@ void up_assert(const char *filename, int lineno)
|
|||||||
#else
|
#else
|
||||||
#if CONFIG_TASK_NAME_SIZE > 0
|
#if CONFIG_TASK_NAME_SIZE > 0
|
||||||
_alert("Assertion failed at file:%s line: %d task: %s\n",
|
_alert("Assertion failed at file:%s line: %d task: %s\n",
|
||||||
filename, lineno, running_task()->name);
|
filename, lineno, rtcb->name);
|
||||||
#else
|
#else
|
||||||
_alert("Assertion failed at file:%s line: %d\n",
|
_alert("Assertion failed at file:%s line: %d\n",
|
||||||
filename, lineno);
|
filename, lineno);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Show back trace */
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_BACKTRACE
|
||||||
|
sched_dumpstack(rtcb->pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Flush any buffered SYSLOG data (from the above) */
|
/* Flush any buffered SYSLOG data (from the above) */
|
||||||
|
|
||||||
syslog_flush();
|
syslog_flush();
|
||||||
@ -104,14 +112,14 @@ void up_assert(const char *filename, int lineno)
|
|||||||
/* Allow for any board/configuration specific crash information */
|
/* Allow for any board/configuration specific crash information */
|
||||||
|
|
||||||
#ifdef CONFIG_BOARD_CRASHDUMP
|
#ifdef CONFIG_BOARD_CRASHDUMP
|
||||||
board_crashdump(up_getsp(), running_task(), filename, lineno);
|
board_crashdump(up_getsp(), rtcb, filename, lineno);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Flush any buffered SYSLOG data */
|
/* Flush any buffered SYSLOG data */
|
||||||
|
|
||||||
syslog_flush();
|
syslog_flush();
|
||||||
|
|
||||||
if (CURRENT_REGS || (running_task())->flink == NULL)
|
if (CURRENT_REGS || rtcb->flink == NULL)
|
||||||
{
|
{
|
||||||
/* Exit the simulation */
|
/* Exit the simulation */
|
||||||
|
|
||||||
|
55
arch/sim/src/sim/up_backtrace.c
Normal file
55
arch/sim/src/sim/up_backtrace.c
Normal 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;
|
||||||
|
}
|
@ -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
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -22,6 +22,7 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <execinfo.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "up_internal.h"
|
#include "up_internal.h"
|
||||||
@ -47,3 +48,9 @@ void host_abort(int status)
|
|||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int host_backtrace(void** array, int size)
|
||||||
|
{
|
||||||
|
/* exit the simulation */
|
||||||
|
|
||||||
|
return backtrace(array, size);
|
||||||
|
}
|
@ -142,9 +142,10 @@ void up_copyfullstate(uint32_t *dest, uint32_t *src);
|
|||||||
|
|
||||||
void *up_doirq(int irq, void *regs);
|
void *up_doirq(int irq, void *regs);
|
||||||
|
|
||||||
/* up_head.c ****************************************************************/
|
/* up_hostmisc.c ************************************************************/
|
||||||
|
|
||||||
void host_abort(int status);
|
void host_abort(int status);
|
||||||
|
int host_backtrace(void** array, int size);
|
||||||
|
|
||||||
/* up_hostmemory.c **********************************************************/
|
/* up_hostmemory.c **********************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user