2020-06-07 08:51:54 +02:00
|
|
|
/****************************************************************************
|
2022-12-06 07:33:13 +01:00
|
|
|
* sched/misc/assert.c
|
2020-06-07 08:51:54 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2020-06-07 08:51:54 +02:00
|
|
|
#include <nuttx/arch.h>
|
2023-05-24 13:51:12 +02:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2022-12-07 05:27:56 +01:00
|
|
|
#include <nuttx/board.h>
|
|
|
|
#include <nuttx/irq.h>
|
2022-12-16 19:34:26 +01:00
|
|
|
#include <nuttx/tls.h>
|
2023-03-23 21:36:14 +01:00
|
|
|
#include <nuttx/signal.h>
|
2022-12-16 19:34:26 +01:00
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
#include <nuttx/panic_notifier.h>
|
2022-12-29 08:38:13 +01:00
|
|
|
#include <nuttx/reboot_notifier.h>
|
2022-12-07 05:27:56 +01:00
|
|
|
#include <nuttx/syslog/syslog.h>
|
2022-12-16 19:34:26 +01:00
|
|
|
#include <nuttx/usb/usbdev_trace.h>
|
2020-06-07 08:51:54 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
2022-12-07 05:27:56 +01:00
|
|
|
#include <debug.h>
|
2022-12-16 19:34:26 +01:00
|
|
|
#include <stdio.h>
|
2022-12-21 15:26:38 +01:00
|
|
|
#include <stdint.h>
|
2022-12-30 07:17:32 +01:00
|
|
|
#include <sys/utsname.h>
|
2020-06-07 08:51:54 +02:00
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
#include "irq/irq.h"
|
|
|
|
#include "sched/sched.h"
|
2023-02-16 13:38:47 +01:00
|
|
|
#include "group/group.h"
|
2022-12-07 05:27:56 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-06-19 04:40:09 +02:00
|
|
|
#define DEADLOCK_MAX 8
|
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
#ifndef CONFIG_BOARD_RESET_ON_ASSERT
|
|
|
|
# define CONFIG_BOARD_RESET_ON_ASSERT 0
|
|
|
|
#endif
|
|
|
|
|
2022-12-14 02:58:38 +01:00
|
|
|
/* Check if an interrupt stack size is configured */
|
|
|
|
|
|
|
|
#ifndef CONFIG_ARCH_INTERRUPTSTACK
|
|
|
|
# define CONFIG_ARCH_INTERRUPTSTACK 0
|
|
|
|
#endif
|
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
/* USB trace dumping */
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBDEV_TRACE
|
|
|
|
# undef CONFIG_ARCH_USBDUMP
|
|
|
|
#endif
|
|
|
|
|
2022-12-21 15:26:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-06-19 15:47:29 +02:00
|
|
|
static uint8_t g_last_regs[XCPTCONTEXT_SIZE] aligned_data(16);
|
2022-12-21 15:26:38 +01:00
|
|
|
|
2023-05-24 13:51:12 +02:00
|
|
|
#ifdef CONFIG_BOARD_COREDUMP
|
|
|
|
static struct lib_syslogstream_s g_syslogstream;
|
|
|
|
static struct lib_hexdumpstream_s g_hexstream;
|
|
|
|
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
|
|
|
|
static struct lib_lzfoutstream_s g_lzfstream;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2023-02-17 08:54:57 +01:00
|
|
|
static FAR const char *g_policy[4] =
|
|
|
|
{
|
|
|
|
"FIFO", "RR", "SPORADIC"
|
|
|
|
};
|
|
|
|
|
|
|
|
static FAR const char * const g_ttypenames[4] =
|
|
|
|
{
|
|
|
|
"Task",
|
|
|
|
"pthread",
|
|
|
|
"Kthread",
|
|
|
|
"Invalid"
|
|
|
|
};
|
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: assert_tracecallback
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_USBDUMP
|
|
|
|
static int usbtrace_syslog(FAR const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
/* Let vsyslog do the real work */
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsyslog(LOG_EMERG, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg)
|
|
|
|
{
|
|
|
|
usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-14 02:58:38 +01:00
|
|
|
#ifdef CONFIG_ARCH_STACKDUMP
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-12-16 19:34:26 +01:00
|
|
|
* Name: stack_dump
|
2022-12-14 02:58:38 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-12-16 19:34:26 +01:00
|
|
|
static void stack_dump(uintptr_t sp, uintptr_t stack_top)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
|
|
|
uintptr_t stack;
|
|
|
|
|
|
|
|
for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32)
|
|
|
|
{
|
|
|
|
FAR uint32_t *ptr = (FAR uint32_t *)stack;
|
2023-01-17 10:21:42 +01:00
|
|
|
_alert("%p: %08" PRIx32 " %08" PRIx32 " %08" PRIx32
|
2022-12-14 02:58:38 +01:00
|
|
|
" %08" PRIx32 " %08" PRIx32 " %08" PRIx32 " %08" PRIx32
|
|
|
|
" %08" PRIx32 "\n",
|
2023-01-17 10:21:42 +01:00
|
|
|
(FAR void *)stack, ptr[0], ptr[1], ptr[2], ptr[3],
|
2022-12-14 02:58:38 +01:00
|
|
|
ptr[4], ptr[5], ptr[6], ptr[7]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: dump_stack
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void dump_stack(FAR const char *tag, uintptr_t sp,
|
2023-06-29 09:07:10 +02:00
|
|
|
uintptr_t base, size_t size, size_t used)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
|
|
|
uintptr_t top = base + size;
|
|
|
|
|
|
|
|
_alert("%s Stack:\n", tag);
|
2023-01-17 10:21:42 +01:00
|
|
|
_alert(" base: %p\n", (FAR void *)base);
|
2022-12-14 02:58:38 +01:00
|
|
|
_alert(" size: %08zu\n", size);
|
|
|
|
|
2023-06-29 09:07:10 +02:00
|
|
|
if (sp != 0)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
2023-06-08 11:11:22 +02:00
|
|
|
_alert(" sp: %p\n", (FAR void *)sp);
|
2022-12-16 19:34:26 +01:00
|
|
|
stack_dump(sp, top);
|
2022-12-14 02:58:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
2023-04-06 08:32:25 +02:00
|
|
|
size_t remain = size - used;
|
2022-12-14 02:58:38 +01:00
|
|
|
|
2023-04-06 08:32:25 +02:00
|
|
|
base += remain;
|
|
|
|
size -= remain;
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_ARCH_STACKDUMP_MAX_LENGTH > 0
|
2023-04-06 08:32:25 +02:00
|
|
|
if (size > CONFIG_ARCH_STACKDUMP_MAX_LENGTH)
|
|
|
|
{
|
|
|
|
size = CONFIG_ARCH_STACKDUMP_MAX_LENGTH;
|
|
|
|
}
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
2023-04-06 08:32:25 +02:00
|
|
|
stack_dump(base, base + size);
|
2022-12-14 02:58:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-06-20 03:49:44 +02:00
|
|
|
* Name: dump_stacks
|
2022-12-14 02:58:38 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-06-20 03:49:44 +02:00
|
|
|
static void dump_stacks(FAR struct tcb_s *rtcb, uintptr_t sp)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
2023-04-06 08:32:25 +02:00
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0
|
|
|
|
uintptr_t intstack_base = up_get_intstackbase();
|
|
|
|
size_t intstack_size = CONFIG_ARCH_INTERRUPTSTACK;
|
|
|
|
uintptr_t intstack_top = intstack_base + intstack_size;
|
2023-06-29 09:07:10 +02:00
|
|
|
uintptr_t intstack_sp = 0;
|
2023-04-06 08:32:25 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARCH_KERNEL_STACK
|
|
|
|
uintptr_t kernelstack_base = (uintptr_t)rtcb->xcp.kstack;
|
|
|
|
size_t kernelstack_size = CONFIG_ARCH_KERNEL_STACKSIZE;
|
|
|
|
uintptr_t kernelstack_top = kernelstack_base + kernelstack_size;
|
2023-06-29 09:07:10 +02:00
|
|
|
uintptr_t kernelstack_sp = 0;
|
2023-04-06 08:32:25 +02:00
|
|
|
#endif
|
|
|
|
uintptr_t tcbstack_base = (uintptr_t)rtcb->stack_base_ptr;
|
|
|
|
size_t tcbstack_size = (size_t)rtcb->adj_stack_size;
|
|
|
|
uintptr_t tcbstack_top = tcbstack_base + tcbstack_size;
|
2023-06-29 09:07:10 +02:00
|
|
|
uintptr_t tcbstack_sp = 0;
|
2023-06-08 11:11:22 +02:00
|
|
|
bool force = false;
|
2022-12-14 02:58:38 +01:00
|
|
|
|
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0
|
2023-04-06 08:32:25 +02:00
|
|
|
if (sp >= intstack_base && sp < intstack_top)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
2023-06-29 09:07:10 +02:00
|
|
|
intstack_sp = sp;
|
2022-12-14 02:58:38 +01:00
|
|
|
}
|
2023-04-06 08:32:25 +02:00
|
|
|
else
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
2023-04-06 08:32:25 +02:00
|
|
|
#ifdef CONFIG_ARCH_KERNEL_STACK
|
|
|
|
if (sp >= kernelstack_base && sp < kernelstack_top)
|
|
|
|
{
|
2023-06-29 09:07:10 +02:00
|
|
|
kernelstack_sp = sp;
|
2023-04-06 08:32:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (sp >= tcbstack_base && sp < tcbstack_top)
|
|
|
|
{
|
2023-06-29 09:07:10 +02:00
|
|
|
tcbstack_sp = sp;
|
2023-04-06 08:32:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-08 11:11:22 +02:00
|
|
|
force = true;
|
2023-04-06 08:32:25 +02:00
|
|
|
_alert("ERROR: Stack pointer is not within the stack\n");
|
2023-06-08 11:11:22 +02:00
|
|
|
}
|
2023-04-06 08:32:25 +02:00
|
|
|
|
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0
|
2023-06-29 09:07:10 +02:00
|
|
|
if (intstack_sp != 0 || force)
|
2023-06-08 11:11:22 +02:00
|
|
|
{
|
|
|
|
dump_stack("IRQ",
|
2023-06-29 09:07:10 +02:00
|
|
|
intstack_sp,
|
2023-04-06 08:32:25 +02:00
|
|
|
intstack_base,
|
|
|
|
intstack_size,
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
2023-06-29 09:07:10 +02:00
|
|
|
up_check_intstack());
|
2022-12-14 02:58:38 +01:00
|
|
|
#else
|
2023-06-29 09:07:10 +02:00
|
|
|
0);
|
2023-04-06 08:32:25 +02:00
|
|
|
#endif
|
2023-06-29 09:07:10 +02:00
|
|
|
|
|
|
|
tcbstack_sp = up_getusrsp((FAR void *)CURRENT_REGS);
|
|
|
|
if (tcbstack_sp < tcbstack_base || tcbstack_sp >= tcbstack_top)
|
|
|
|
{
|
|
|
|
tcbstack_sp = 0;
|
|
|
|
force = true;
|
|
|
|
}
|
2023-06-08 11:11:22 +02:00
|
|
|
}
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_KERNEL_STACK
|
2023-06-29 09:07:10 +02:00
|
|
|
if (kernelstack_sp != 0 || force)
|
2023-06-08 11:11:22 +02:00
|
|
|
{
|
|
|
|
dump_stack("Kernel",
|
2023-06-29 09:07:10 +02:00
|
|
|
kernelstack_sp,
|
2023-04-06 08:32:25 +02:00
|
|
|
kernelstack_base,
|
|
|
|
kernelstack_size,
|
2023-06-29 09:07:10 +02:00
|
|
|
0
|
2023-04-06 08:32:25 +02:00
|
|
|
);
|
2023-06-08 11:11:22 +02:00
|
|
|
}
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
2023-04-06 08:32:25 +02:00
|
|
|
|
2023-06-29 09:07:10 +02:00
|
|
|
if (tcbstack_sp != 0 || force)
|
2023-06-08 11:11:22 +02:00
|
|
|
{
|
|
|
|
dump_stack("User",
|
2023-06-29 09:07:10 +02:00
|
|
|
tcbstack_sp,
|
2023-04-06 08:32:25 +02:00
|
|
|
tcbstack_base,
|
|
|
|
tcbstack_size,
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
2023-06-29 09:07:10 +02:00
|
|
|
up_check_tcbstack(rtcb));
|
2023-04-06 08:32:25 +02:00
|
|
|
#else
|
2023-06-29 09:07:10 +02:00
|
|
|
0);
|
2023-04-06 08:32:25 +02:00
|
|
|
#endif
|
|
|
|
}
|
2022-12-14 02:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: dump_task
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-12-22 09:12:22 +01:00
|
|
|
static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
|
|
|
char args[64] = "";
|
2023-02-17 08:54:57 +01:00
|
|
|
char state[32];
|
|
|
|
FAR char *s;
|
2022-12-14 02:58:38 +01:00
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
|
|
|
size_t stack_filled = 0;
|
|
|
|
size_t stack_used;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
struct cpuload_s cpuload;
|
|
|
|
size_t fracpart = 0;
|
|
|
|
size_t intpart = 0;
|
|
|
|
size_t tmp;
|
|
|
|
|
|
|
|
clock_cpuload(tcb->pid, &cpuload);
|
|
|
|
|
|
|
|
if (cpuload.total > 0)
|
|
|
|
{
|
|
|
|
tmp = (1000 * cpuload.active) / cpuload.total;
|
|
|
|
intpart = tmp / 10;
|
|
|
|
fracpart = tmp - 10 * intpart;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
|
|
|
stack_used = up_check_tcbstack(tcb);
|
|
|
|
if (tcb->adj_stack_size > 0 && stack_used > 0)
|
|
|
|
{
|
|
|
|
/* Use fixed-point math with one decimal place */
|
|
|
|
|
|
|
|
stack_filled = 10 * 100 * stack_used / tcb->adj_stack_size;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-22 09:12:22 +01:00
|
|
|
/* Stringify the argument vector */
|
2022-12-14 02:58:38 +01:00
|
|
|
|
2023-02-16 13:38:47 +01:00
|
|
|
group_argvstr(tcb, args, sizeof(args));
|
2022-12-14 02:58:38 +01:00
|
|
|
|
2023-02-17 08:54:57 +01:00
|
|
|
/* get the task_state */
|
|
|
|
|
|
|
|
nxsched_get_stateinfo(tcb, state, sizeof(state));
|
|
|
|
if ((s = strchr(state, ',')) != NULL)
|
|
|
|
{
|
|
|
|
*s = ' ';
|
|
|
|
}
|
|
|
|
|
2022-12-14 02:58:38 +01:00
|
|
|
/* Dump interesting properties of this task */
|
|
|
|
|
2023-02-17 08:54:57 +01:00
|
|
|
_alert(" %4d %5d"
|
2022-12-14 02:58:38 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
" %4d"
|
|
|
|
#endif
|
2023-02-17 08:54:57 +01:00
|
|
|
" %3d %-8s %-7s %c%c%c"
|
|
|
|
" %-18s"
|
2023-03-23 21:36:14 +01:00
|
|
|
" " SIGSET_FMT
|
2023-02-17 08:54:57 +01:00
|
|
|
" %p"
|
2022-12-14 02:58:38 +01:00
|
|
|
" %7zu"
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
|
|
|
" %7zu %3zu.%1zu%%%c"
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
" %3zu.%01zu%%"
|
|
|
|
#endif
|
|
|
|
" %s%s\n"
|
2023-02-17 08:54:57 +01:00
|
|
|
, tcb->pid
|
|
|
|
, tcb->group ? tcb->group->tg_pid : -1
|
2022-12-14 02:58:38 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
, tcb->cpu
|
|
|
|
#endif
|
2023-02-17 08:54:57 +01:00
|
|
|
, tcb->sched_priority
|
|
|
|
, g_policy[(tcb->flags & TCB_FLAG_POLICY_MASK) >>
|
|
|
|
TCB_FLAG_POLICY_SHIFT]
|
|
|
|
, g_ttypenames[(tcb->flags & TCB_FLAG_TTYPE_MASK)
|
|
|
|
>> TCB_FLAG_TTYPE_SHIFT]
|
|
|
|
, tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : '-'
|
|
|
|
, tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : '-'
|
|
|
|
, tcb->flags & TCB_FLAG_EXIT_PROCESSING ? 'P' : '-'
|
|
|
|
, state
|
2023-03-23 21:36:14 +01:00
|
|
|
, SIGSET_ELEM(&tcb->sigprocmask)
|
2023-01-17 10:21:42 +01:00
|
|
|
, tcb->stack_base_ptr
|
2022-12-14 02:58:38 +01:00
|
|
|
, tcb->adj_stack_size
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
|
|
|
, up_check_tcbstack(tcb)
|
|
|
|
, stack_filled / 10, stack_filled % 10
|
|
|
|
, (stack_filled >= 10 * 80 ? '!' : ' ')
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
, intpart, fracpart
|
|
|
|
#endif
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
, tcb->name
|
|
|
|
#else
|
|
|
|
, "<noname>"
|
|
|
|
#endif
|
|
|
|
, args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: dump_backtrace
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_BACKTRACE
|
|
|
|
static void dump_backtrace(FAR struct tcb_s *tcb, FAR void *arg)
|
|
|
|
{
|
|
|
|
sched_dumpstack(tcb->pid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-06-20 03:49:44 +02:00
|
|
|
* Name: dump_tasks
|
2022-12-14 02:58:38 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-06-20 03:49:44 +02:00
|
|
|
static void dump_tasks(void)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
2022-12-16 19:34:26 +01:00
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0 && defined(CONFIG_STACK_COLORATION)
|
2022-12-14 02:58:38 +01:00
|
|
|
size_t stack_used = up_check_intstack();
|
|
|
|
size_t stack_filled = 0;
|
|
|
|
|
|
|
|
if (stack_used > 0)
|
|
|
|
{
|
|
|
|
/* Use fixed-point math with one decimal place */
|
|
|
|
|
|
|
|
stack_filled = 10 * 100 *
|
|
|
|
stack_used / CONFIG_ARCH_INTERRUPTSTACK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Dump interesting properties of each task in the crash environment */
|
|
|
|
|
2023-02-17 08:54:57 +01:00
|
|
|
_alert(" PID GROUP"
|
2022-12-14 02:58:38 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
" CPU"
|
|
|
|
#endif
|
2023-02-17 08:54:57 +01:00
|
|
|
" PRI POLICY TYPE NPX"
|
|
|
|
" STATE EVENT"
|
2023-06-10 19:25:05 +02:00
|
|
|
" SIGMASK "
|
2023-02-17 08:54:57 +01:00
|
|
|
" STACKBASE"
|
|
|
|
" STACKSIZE"
|
2022-12-14 02:58:38 +01:00
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
|
|
|
" USED FILLED "
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
" CPU"
|
|
|
|
#endif
|
|
|
|
" COMMAND\n");
|
|
|
|
|
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0
|
2023-01-11 04:57:07 +01:00
|
|
|
_alert(" ---- ---"
|
2022-12-14 02:58:38 +01:00
|
|
|
# ifdef CONFIG_SMP
|
|
|
|
" ----"
|
|
|
|
# endif
|
2023-02-17 08:54:57 +01:00
|
|
|
" --- --------"
|
|
|
|
" ------- ---"
|
|
|
|
" ------- ----------"
|
|
|
|
" --------"
|
|
|
|
" %p"
|
2022-12-14 02:58:38 +01:00
|
|
|
" %7u"
|
|
|
|
# ifdef CONFIG_STACK_COLORATION
|
|
|
|
" %7zu %3zu.%1zu%%%c"
|
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_SCHED_CPULOAD
|
|
|
|
" ----"
|
|
|
|
# endif
|
|
|
|
" irq\n"
|
2023-01-17 10:21:42 +01:00
|
|
|
, (FAR void *)up_get_intstackbase()
|
2022-12-14 02:58:38 +01:00
|
|
|
, CONFIG_ARCH_INTERRUPTSTACK
|
|
|
|
# ifdef CONFIG_STACK_COLORATION
|
|
|
|
, stack_used
|
|
|
|
, stack_filled / 10, stack_filled % 10,
|
|
|
|
(stack_filled >= 10 * 80 ? '!' : ' ')
|
|
|
|
# endif
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nxsched_foreach(dump_task, NULL);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_BACKTRACE
|
|
|
|
nxsched_foreach(dump_backtrace, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-05-24 13:51:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: dump_core
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOARD_COREDUMP
|
|
|
|
static void dump_core(pid_t pid)
|
|
|
|
{
|
|
|
|
FAR void *stream;
|
|
|
|
int logmask;
|
|
|
|
|
|
|
|
logmask = setlogmask(LOG_ALERT);
|
|
|
|
|
|
|
|
_alert("Start coredump:\n");
|
|
|
|
|
|
|
|
/* Initialize hex output stream */
|
|
|
|
|
|
|
|
lib_syslogstream(&g_syslogstream, LOG_EMERG);
|
|
|
|
|
|
|
|
stream = &g_syslogstream;
|
|
|
|
|
|
|
|
lib_hexdumpstream(&g_hexstream, stream);
|
|
|
|
|
|
|
|
stream = &g_hexstream;
|
|
|
|
|
|
|
|
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
|
|
|
|
|
|
|
|
/* Initialize LZF compression stream */
|
|
|
|
|
|
|
|
lib_lzfoutstream(&g_lzfstream, stream);
|
|
|
|
stream = &g_lzfstream;
|
|
|
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Do core dump */
|
|
|
|
|
|
|
|
core_dump(NULL, stream, pid);
|
|
|
|
|
|
|
|
# ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
|
|
|
|
_alert("Finish coredump (Compression Enabled).\n");
|
|
|
|
# else
|
|
|
|
_alert("Finish coredump.\n");
|
|
|
|
# endif
|
|
|
|
|
|
|
|
setlogmask(logmask);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-06-19 04:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: dump_deadlock
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_DEADLOCKDUMP
|
|
|
|
static void dump_deadlock(void)
|
|
|
|
{
|
|
|
|
pid_t deadlock[DEADLOCK_MAX];
|
|
|
|
size_t i = nxsched_collect_deadlock(deadlock, DEADLOCK_MAX);
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
_alert("Deadlock detected\n");
|
|
|
|
while (i-- > 0)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_BACKTRACE
|
|
|
|
sched_dumpstack(deadlock[i]);
|
|
|
|
#else
|
2023-07-10 22:49:36 +02:00
|
|
|
_alert("deadlock pid: %d\n", deadlock[i]);
|
2023-06-19 04:40:09 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-07 08:51:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-04-10 15:19:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: _assert
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void _assert(FAR const char *filename, int linenum,
|
|
|
|
FAR const char *msg, FAR void *regs)
|
2020-06-07 08:51:54 +02:00
|
|
|
{
|
2022-12-21 15:26:38 +01:00
|
|
|
FAR struct tcb_s *rtcb = running_task();
|
2022-12-30 07:17:32 +01:00
|
|
|
struct utsname name;
|
2023-04-03 20:30:39 +02:00
|
|
|
bool fatal = true;
|
2022-12-21 15:26:38 +01:00
|
|
|
|
2023-04-10 15:19:12 +02:00
|
|
|
/* try to save current context if regs is null */
|
|
|
|
|
|
|
|
if (regs == NULL)
|
|
|
|
{
|
|
|
|
up_saveusercontext(g_last_regs);
|
|
|
|
regs = g_last_regs;
|
|
|
|
}
|
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
/* Flush any buffered SYSLOG data (from prior to the assertion) */
|
|
|
|
|
|
|
|
syslog_flush();
|
|
|
|
|
|
|
|
#if CONFIG_BOARD_RESET_ON_ASSERT < 2
|
2023-04-03 20:30:39 +02:00
|
|
|
if (!up_interrupt_context() &&
|
|
|
|
(rtcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
|
2022-12-07 05:27:56 +01:00
|
|
|
{
|
2023-04-03 20:30:39 +02:00
|
|
|
fatal = false;
|
2022-12-07 05:27:56 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-12-24 19:48:25 +01:00
|
|
|
|
2022-12-29 07:06:08 +01:00
|
|
|
panic_notifier_call_chain(fatal ? PANIC_KERNEL : PANIC_TASK, rtcb);
|
2022-12-07 05:27:56 +01:00
|
|
|
|
2022-12-30 07:17:32 +01:00
|
|
|
uname(&name);
|
|
|
|
_alert("Current Version: %s %s %s %s %s\n",
|
2023-01-26 00:34:50 +01:00
|
|
|
name.sysname, name.nodename,
|
|
|
|
name.release, name.version, name.machine);
|
2022-12-30 07:17:32 +01:00
|
|
|
|
2023-02-02 04:05:56 +01:00
|
|
|
_alert("Assertion failed %s: at file: %s:%d task"
|
2022-12-07 05:27:56 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2023-02-02 04:05:56 +01:00
|
|
|
"(CPU%d)"
|
2022-12-07 05:27:56 +01:00
|
|
|
#endif
|
2023-02-02 04:05:56 +01:00
|
|
|
": "
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
"%s "
|
|
|
|
#endif
|
|
|
|
"%p\n",
|
|
|
|
msg ? msg : "",
|
|
|
|
filename ? filename : "", linenum,
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
up_cpu_index(),
|
|
|
|
#endif
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
rtcb->name,
|
|
|
|
#endif
|
|
|
|
rtcb->entry.main);
|
2022-12-07 05:27:56 +01:00
|
|
|
|
2022-12-14 02:58:38 +01:00
|
|
|
/* Show back trace */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_BACKTRACE
|
2022-12-21 15:26:38 +01:00
|
|
|
sched_dumpstack(rtcb->pid);
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
2022-12-21 15:26:38 +01:00
|
|
|
/* Register dump */
|
|
|
|
|
2023-04-10 15:19:12 +02:00
|
|
|
up_dump_register(regs);
|
2022-12-14 02:58:38 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_STACKDUMP
|
2023-06-20 03:49:44 +02:00
|
|
|
dump_stacks(rtcb, up_getusrsp(regs));
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
2022-12-24 19:48:25 +01:00
|
|
|
/* Flush any buffered SYSLOG data */
|
|
|
|
|
|
|
|
syslog_flush();
|
|
|
|
|
|
|
|
if (fatal)
|
|
|
|
{
|
2023-06-20 03:49:44 +02:00
|
|
|
dump_tasks();
|
2022-12-14 02:58:38 +01:00
|
|
|
|
2023-06-19 04:40:09 +02:00
|
|
|
#ifdef CONFIG_ARCH_DEADLOCKDUMP
|
|
|
|
/* Deadlock Dump */
|
|
|
|
|
|
|
|
dump_deadlock();
|
|
|
|
#endif
|
|
|
|
|
2022-12-21 15:26:38 +01:00
|
|
|
#ifdef CONFIG_ARCH_USBDUMP
|
2022-12-24 19:48:25 +01:00
|
|
|
/* Dump USB trace data */
|
2022-12-21 15:26:38 +01:00
|
|
|
|
2022-12-24 19:48:25 +01:00
|
|
|
usbtrace_enumerate(assert_tracecallback, NULL);
|
2022-12-21 15:26:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOARD_CRASHDUMP
|
2023-06-08 10:39:09 +02:00
|
|
|
board_crashdump(up_getsp(), rtcb, filename, linenum, msg, regs);
|
2023-05-24 13:51:12 +02:00
|
|
|
|
|
|
|
#elif defined(CONFIG_BOARD_COREDUMP)
|
|
|
|
/* Dump core information */
|
|
|
|
|
|
|
|
# ifdef CONFIG_BOARD_COREDUMP_FULL
|
|
|
|
dump_core(INVALID_PROCESS_ID);
|
|
|
|
# else
|
|
|
|
dump_core(rtcb->pid);
|
|
|
|
# endif
|
|
|
|
|
2022-12-21 15:26:38 +01:00
|
|
|
#endif
|
|
|
|
|
2022-12-24 19:48:25 +01:00
|
|
|
/* Flush any buffered SYSLOG data */
|
|
|
|
|
|
|
|
syslog_flush();
|
2022-12-29 07:06:08 +01:00
|
|
|
panic_notifier_call_chain(PANIC_KERNEL_FINAL, rtcb);
|
2022-12-24 19:48:25 +01:00
|
|
|
|
2022-12-29 08:38:13 +01:00
|
|
|
reboot_notifier_call_chain(SYS_HALT, NULL);
|
|
|
|
|
2022-12-24 19:48:25 +01:00
|
|
|
#if CONFIG_BOARD_RESET_ON_ASSERT >= 1
|
|
|
|
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
|
|
|
|
#else
|
|
|
|
/* Disable interrupts on this CPU */
|
|
|
|
|
|
|
|
up_irq_save();
|
|
|
|
|
|
|
|
# ifdef CONFIG_SMP
|
|
|
|
/* Try (again) to stop activity on other CPUs */
|
|
|
|
|
|
|
|
spin_trylock(&g_cpu_irqlock);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
for (; ; )
|
|
|
|
{
|
|
|
|
up_mdelay(250);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2020-06-07 08:51:54 +02:00
|
|
|
}
|