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
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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>
|
2022-12-07 05:27:56 +01:00
|
|
|
#include <nuttx/board.h>
|
2024-01-30 09:08:04 +01:00
|
|
|
#include <nuttx/coredump.h>
|
2024-06-25 05:33:47 +02:00
|
|
|
#include <nuttx/fs/fs.h>
|
2024-08-29 13:00:21 +02:00
|
|
|
#include <nuttx/init.h>
|
2022-12-07 05:27:56 +01:00
|
|
|
#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>
|
2023-09-24 11:47:54 +02:00
|
|
|
#ifdef CONFIG_ARCH_LEDS
|
|
|
|
# include <arch/board/board.h>
|
|
|
|
#endif
|
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
|
|
|
|
|
2023-09-05 06:20:24 +02:00
|
|
|
#define DUMP_PTR(p, x) ((uintptr_t)(&(p)[(x)]) < stack_top ? (p)[(x)] : 0)
|
2024-05-10 08:30:57 +02:00
|
|
|
#define DUMP_STRIDE (sizeof(FAR void *) * 8)
|
|
|
|
|
|
|
|
#if UINTPTR_MAX <= UINT32_MAX
|
|
|
|
# define DUMP_FORMAT " %08" PRIxPTR ""
|
|
|
|
#elif UINTPTR_MAX <= UINT64_MAX
|
|
|
|
# define DUMP_FORMAT " %016" PRIxPTR ""
|
|
|
|
#endif
|
2023-09-05 06:20:24 +02:00
|
|
|
|
2024-04-22 15:49:05 +02:00
|
|
|
/* Architecture can overwrite the default XCPTCONTEXT alignment */
|
|
|
|
|
|
|
|
#ifndef XCPTCONTEXT_ALIGN
|
|
|
|
# define XCPTCONTEXT_ALIGN 16
|
|
|
|
#endif
|
|
|
|
|
2022-12-21 15:26:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-04-22 15:49:05 +02:00
|
|
|
static uintptr_t
|
|
|
|
g_last_regs[XCPTCONTEXT_REGS] aligned_data(XCPTCONTEXT_ALIGN);
|
2024-09-02 07:02:48 +02:00
|
|
|
static FAR const char * const g_policy[4] =
|
2023-02-17 08:54:57 +01:00
|
|
|
{
|
|
|
|
"FIFO", "RR", "SPORADIC"
|
|
|
|
};
|
|
|
|
|
|
|
|
static FAR const char * const g_ttypenames[4] =
|
|
|
|
{
|
|
|
|
"Task",
|
|
|
|
"pthread",
|
|
|
|
"Kthread",
|
|
|
|
"Invalid"
|
|
|
|
};
|
|
|
|
|
2023-12-27 10:32:53 +01:00
|
|
|
static bool g_fatal_assert = false;
|
|
|
|
|
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;
|
|
|
|
|
2024-05-10 08:30:57 +02:00
|
|
|
for (stack = sp; stack <= stack_top; stack += DUMP_STRIDE)
|
2022-12-14 02:58:38 +01:00
|
|
|
{
|
2024-05-10 08:30:57 +02:00
|
|
|
FAR uintptr_t *ptr = (FAR uintptr_t *)stack;
|
2023-09-05 06:20:24 +02:00
|
|
|
|
2024-05-10 08:30:57 +02:00
|
|
|
_alert("%p:"DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT
|
|
|
|
DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT "\n",
|
2023-09-05 06:20:24 +02:00
|
|
|
(FAR void *)stack, DUMP_PTR(ptr, 0), DUMP_PTR(ptr , 1),
|
|
|
|
DUMP_PTR(ptr, 2), DUMP_PTR(ptr, 3), DUMP_PTR(ptr, 4),
|
|
|
|
DUMP_PTR(ptr, 5), DUMP_PTR(ptr , 6), DUMP_PTR(ptr, 7));
|
2022-12-14 02:58:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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);
|
2023-09-15 05:47:46 +02:00
|
|
|
|
|
|
|
/* Get more information */
|
|
|
|
|
2024-05-10 08:30:57 +02:00
|
|
|
if (sp - DUMP_STRIDE >= base)
|
2023-09-15 05:47:46 +02:00
|
|
|
{
|
2024-05-10 08:30:57 +02:00
|
|
|
sp -= DUMP_STRIDE;
|
2023-09-15 05:47:46 +02:00
|
|
|
}
|
|
|
|
|
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
|
2024-05-29 07:44:50 +02:00
|
|
|
uintptr_t intstack_base = up_get_intstackbase(this_cpu());
|
2023-04-06 08:32:25 +02:00
|
|
|
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
|
2024-05-29 07:44:50 +02:00
|
|
|
up_check_intstack(this_cpu())
|
2022-12-14 02:58:38 +01:00
|
|
|
#else
|
2023-07-31 11:14:35 +02:00
|
|
|
0
|
2023-04-06 08:32:25 +02:00
|
|
|
#endif
|
2023-07-31 11:14:35 +02:00
|
|
|
);
|
2023-06-29 09:07:10 +02:00
|
|
|
|
2024-09-13 04:57:38 +02:00
|
|
|
tcbstack_sp = up_getusrsp((FAR void *)up_current_regs());
|
2023-06-29 09:07:10 +02:00
|
|
|
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-07-31 11:14:35 +02:00
|
|
|
up_check_tcbstack(rtcb)
|
2023-04-06 08:32:25 +02:00
|
|
|
#else
|
2023-07-31 11:14:35 +02:00
|
|
|
0
|
2023-04-06 08:32:25 +02:00
|
|
|
#endif
|
2023-07-31 11:14:35 +02:00
|
|
|
);
|
2023-04-06 08:32:25 +02:00
|
|
|
}
|
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
|
2023-10-26 15:03:16 +02:00
|
|
|
#ifndef CONFIG_SCHED_CPULOAD_NONE
|
2022-12-14 02:58:38 +01:00
|
|
|
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-11-10 11:56:10 +01:00
|
|
|
" %3d %-8s %-7s %c"
|
2023-02-17 08:54:57 +01:00
|
|
|
" %-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
|
2023-10-26 15:03:16 +02:00
|
|
|
#ifndef CONFIG_SCHED_CPULOAD_NONE
|
2022-12-14 02:58:38 +01:00
|
|
|
" %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_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
|
2023-10-26 15:03:16 +02:00
|
|
|
#ifndef CONFIG_SCHED_CPULOAD_NONE
|
2022-12-14 02:58:38 +01:00
|
|
|
, 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
|
|
|
|
|
2024-06-25 05:33:47 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: dump_filelist
|
|
|
|
****************************************************************************/
|
|
|
|
|
2024-09-18 10:41:12 +02:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2024-06-25 05:33:47 +02:00
|
|
|
static void dump_filelist(FAR struct tcb_s *tcb, FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct filelist *filelist = &tcb->group->tg_filelist;
|
|
|
|
files_dumplist(filelist);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-14 02:58:38 +01:00
|
|
|
/****************************************************************************
|
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
|
|
|
{
|
2024-03-28 10:57:03 +01:00
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0
|
|
|
|
int cpu;
|
2022-12-14 02:58:38 +01:00
|
|
|
#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
|
2023-10-26 15:03:16 +02:00
|
|
|
#ifndef CONFIG_SCHED_CPULOAD_NONE
|
2022-12-14 02:58:38 +01:00
|
|
|
" CPU"
|
|
|
|
#endif
|
|
|
|
" COMMAND\n");
|
|
|
|
|
|
|
|
#if CONFIG_ARCH_INTERRUPTSTACK > 0
|
2024-03-28 10:57:03 +01:00
|
|
|
for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
|
|
|
|
{
|
|
|
|
# ifdef CONFIG_STACK_COLORATION
|
|
|
|
size_t stack_used = up_check_intstack(cpu);
|
|
|
|
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
|
|
|
|
|
|
|
|
_alert(" ---- ---"
|
2022-12-14 02:58:38 +01:00
|
|
|
# ifdef CONFIG_SMP
|
2024-03-28 10:57:03 +01:00
|
|
|
" %4d"
|
2022-12-14 02:58:38 +01:00
|
|
|
# endif
|
2024-03-28 10:57:03 +01:00
|
|
|
" --- --------"
|
|
|
|
" ------- ---"
|
|
|
|
" ------- ----------"
|
|
|
|
" ----------------"
|
|
|
|
" %p"
|
|
|
|
" %7u"
|
2022-12-14 02:58:38 +01:00
|
|
|
# ifdef CONFIG_STACK_COLORATION
|
2024-03-28 10:57:03 +01:00
|
|
|
" %7zu %3zu.%1zu%%%c"
|
2022-12-14 02:58:38 +01:00
|
|
|
# endif
|
2023-10-26 15:03:16 +02:00
|
|
|
# ifndef CONFIG_SCHED_CPULOAD_NONE
|
2024-03-28 10:57:03 +01:00
|
|
|
" ----"
|
2022-12-14 02:58:38 +01:00
|
|
|
# endif
|
2024-03-28 10:57:03 +01:00
|
|
|
" irq\n"
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
, cpu
|
|
|
|
#endif
|
|
|
|
, (FAR void *)up_get_intstackbase(cpu)
|
|
|
|
, CONFIG_ARCH_INTERRUPTSTACK
|
2022-12-14 02:58:38 +01:00
|
|
|
# ifdef CONFIG_STACK_COLORATION
|
2024-03-28 10:57:03 +01:00
|
|
|
, stack_used
|
|
|
|
, stack_filled / 10, stack_filled % 10,
|
|
|
|
(stack_filled >= 10 * 80 ? '!' : ' ')
|
2022-12-14 02:58:38 +01:00
|
|
|
# endif
|
2024-03-28 10:57:03 +01:00
|
|
|
);
|
|
|
|
}
|
2022-12-14 02:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nxsched_foreach(dump_task, NULL);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_BACKTRACE
|
|
|
|
nxsched_foreach(dump_backtrace, NULL);
|
|
|
|
#endif
|
2024-06-25 05:33:47 +02:00
|
|
|
|
2024-09-18 10:41:12 +02:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2024-06-25 05:33:47 +02:00
|
|
|
nxsched_foreach(dump_filelist, NULL);
|
|
|
|
#endif
|
2022-12-14 02:58:38 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2024-01-11 04:35:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pause_all_cpu
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static void pause_all_cpu(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
|
|
|
|
{
|
|
|
|
if (cpu != this_cpu())
|
|
|
|
{
|
|
|
|
up_cpu_pause(cpu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
2024-08-29 13:00:21 +02:00
|
|
|
const bool os_ready = OSINIT_OS_READY();
|
2022-12-21 15:26:38 +01:00
|
|
|
FAR struct tcb_s *rtcb = running_task();
|
2023-10-02 16:36:18 +02:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
FAR struct tcb_s *ptcb = NULL;
|
|
|
|
#endif
|
2023-06-15 05:12:58 +02:00
|
|
|
struct panic_notifier_s notifier_data;
|
2022-12-30 07:17:32 +01:00
|
|
|
struct utsname name;
|
2023-12-27 13:42:39 +01:00
|
|
|
irqstate_t flags;
|
2023-04-03 20:30:39 +02:00
|
|
|
bool fatal = true;
|
2023-06-12 07:25:49 +02:00
|
|
|
|
2023-10-02 16:36:18 +02:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
if (rtcb->group && !(rtcb->flags & TCB_FLAG_TTYPE_KERNEL))
|
|
|
|
{
|
|
|
|
ptcb = nxsched_get_tcb(rtcb->group->tg_pid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-08-29 13:00:21 +02:00
|
|
|
flags = 0; /* suppress GCC warning */
|
|
|
|
if (os_ready)
|
|
|
|
{
|
|
|
|
flags = enter_critical_section();
|
|
|
|
}
|
2022-12-21 15:26:38 +01:00
|
|
|
|
2023-12-27 10:32:53 +01:00
|
|
|
if (g_fatal_assert)
|
|
|
|
{
|
|
|
|
goto reset;
|
|
|
|
}
|
|
|
|
|
2024-08-29 13:00:21 +02:00
|
|
|
if (os_ready && fatal)
|
2024-01-11 04:35:27 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
pause_all_cpu();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2023-11-15 12:29:53 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(g_last_regs, regs, sizeof(g_last_regs));
|
|
|
|
}
|
2023-04-10 15:19:12 +02:00
|
|
|
|
2022-12-07 05:27:56 +01:00
|
|
|
#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
|
|
|
}
|
2023-12-27 10:32:53 +01:00
|
|
|
else
|
2022-12-07 05:27:56 +01:00
|
|
|
#endif
|
2023-12-27 10:32:53 +01:00
|
|
|
{
|
|
|
|
g_fatal_assert = true;
|
|
|
|
}
|
2022-12-24 19:48:25 +01:00
|
|
|
|
2023-06-15 05:12:58 +02:00
|
|
|
notifier_data.rtcb = rtcb;
|
|
|
|
notifier_data.regs = regs;
|
2023-06-17 03:29:42 +02:00
|
|
|
notifier_data.filename = filename;
|
|
|
|
notifier_data.linenum = linenum;
|
|
|
|
notifier_data.msg = msg;
|
2023-06-15 05:12:58 +02:00
|
|
|
panic_notifier_call_chain(fatal ? PANIC_KERNEL : PANIC_TASK,
|
|
|
|
¬ifier_data);
|
2023-09-08 18:16:42 +02:00
|
|
|
#ifdef CONFIG_ARCH_LEDS
|
|
|
|
board_autoled_on(LED_ASSERTION);
|
|
|
|
#endif
|
2022-12-07 05:27:56 +01:00
|
|
|
|
2023-06-17 03:29:42 +02:00
|
|
|
/* Flush any buffered SYSLOG data (from prior to the assertion) */
|
|
|
|
|
|
|
|
syslog_flush();
|
|
|
|
|
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 "
|
2023-10-02 16:36:18 +02:00
|
|
|
"process: %s "
|
2023-02-02 04:05:56 +01:00
|
|
|
#endif
|
|
|
|
"%p\n",
|
|
|
|
msg ? msg : "",
|
|
|
|
filename ? filename : "", linenum,
|
|
|
|
#ifdef CONFIG_SMP
|
2024-03-20 03:26:36 +01:00
|
|
|
this_cpu(),
|
2023-02-02 04:05:56 +01:00
|
|
|
#endif
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
rtcb->name,
|
2023-10-02 16:36:18 +02:00
|
|
|
ptcb ? ptcb->name : "Kernel",
|
2023-02-02 04:05:56 +01:00
|
|
|
#endif
|
|
|
|
rtcb->entry.main);
|
2022-12-07 05:27:56 +01:00
|
|
|
|
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
|
|
|
|
|
2023-06-13 12:35:41 +02:00
|
|
|
/* Show back trace */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_BACKTRACE
|
|
|
|
sched_dumpstack(rtcb->pid);
|
|
|
|
#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-11-09 05:02:37 +01:00
|
|
|
#endif
|
2023-05-24 13:51:12 +02:00
|
|
|
|
2023-11-09 05:02:37 +01:00
|
|
|
#if defined(CONFIG_BOARD_COREDUMP_SYSLOG) || \
|
|
|
|
defined(CONFIG_BOARD_COREDUMP_BLKDEV)
|
2023-05-24 13:51:12 +02:00
|
|
|
/* Dump core information */
|
|
|
|
|
|
|
|
# ifdef CONFIG_BOARD_COREDUMP_FULL
|
2023-11-09 05:02:37 +01:00
|
|
|
coredump_dump(INVALID_PROCESS_ID);
|
2023-05-24 13:51:12 +02:00
|
|
|
# else
|
2023-11-09 05:02:37 +01:00
|
|
|
coredump_dump(rtcb->pid);
|
2023-05-24 13:51:12 +02:00
|
|
|
# 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();
|
2023-06-15 05:12:58 +02:00
|
|
|
panic_notifier_call_chain(PANIC_KERNEL_FINAL, ¬ifier_data);
|
2022-12-24 19:48:25 +01:00
|
|
|
|
2022-12-29 08:38:13 +01:00
|
|
|
reboot_notifier_call_chain(SYS_HALT, NULL);
|
|
|
|
|
2023-12-27 10:32:53 +01:00
|
|
|
reset:
|
2022-12-24 19:48:25 +01:00
|
|
|
#if CONFIG_BOARD_RESET_ON_ASSERT >= 1
|
|
|
|
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
|
|
|
|
#else
|
|
|
|
for (; ; )
|
|
|
|
{
|
2023-09-08 18:16:42 +02:00
|
|
|
#ifdef CONFIG_ARCH_LEDS
|
|
|
|
/* FLASH LEDs a 2Hz */
|
|
|
|
|
|
|
|
board_autoled_on(LED_PANIC);
|
|
|
|
up_mdelay(250);
|
|
|
|
board_autoled_off(LED_PANIC);
|
|
|
|
#endif
|
2022-12-24 19:48:25 +01:00
|
|
|
up_mdelay(250);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2023-06-12 07:25:49 +02:00
|
|
|
|
2024-08-29 13:00:21 +02:00
|
|
|
if (os_ready)
|
|
|
|
{
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
2020-06-07 08:51:54 +02:00
|
|
|
}
|