nuttx/libs/libc/sched/sched_dumpstack.c

96 lines
3.0 KiB
C
Raw Normal View History

/****************************************************************************
* libs/libc/sched/sched_dumpstack.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/config.h>
libs/dumpstack: add support for print symbol name ap> mw -1 [ EMERG] arm_usagefault: PANIC!!! Usage Fault: [ EMERG] arm_usagefault: IRQ: 6 regs: 0x3c24fa48 [ EMERG] arm_usagefault: BASEPRI: 000000e0 PRIMASK: 00000000 IPSR: 00000006 CONTROL: 00000004 [ EMERG] arm_usagefault: CFSR: 01000000 HFSR: 00000000 DFSR: 00000000 BFAR: 40101000 AFSR: 00000000 [ EMERG] arm_usagefault: Usage Fault Reason: [ EMERG] arm_usagefault: Unaligned access [ EMERG] up_assert: Assertion failed at file:armv8-m/arm_usagefault.c line: 113 task: init [ EMERG] backtrace|10: 0x2c325bde 0x2c319b98 0x2c3261cc 0x2c316b20 0x2c32699c 0x2c303a50 0x2c326072 0x2c3206ea [ EMERG] backtrace|10: 0x2c3428cc 0x2c33ed14 0x2c342e8e 0x2c34403a 0x2c344ac0 0x2c319b60 0x2c3080ba [ EMERG] [10][ 0] [<0x2c325bde>] up_backtrace+0xa/0x13c [ EMERG] [10][ 1] [<0x2c319b98>] sched_dumpstack+0x10/0xc0 [ EMERG] [10][ 2] [<0x2c3261cc>] up_assert+0x48/0x414 [ EMERG] [10][ 3] [<0x2c316b20>] _assert+0x4/0x10 [ EMERG] [10][ 4] [<0x2c32699c>] arm_usagefault+0xa8/0x138 [ EMERG] [10][ 5] [<0x2c303a50>] irq_dispatch+0x1c/0x40 [ EMERG] [10][ 6] [<0x2c326072>] arm_doirq+0x1a/0x2c [ EMERG] [10][ 7] [<0x2c3206ea>] exception_common+0x4a/0xac [ EMERG] [10][ 8] [<0x2c3428cc>] cmd_mw+0xec/0x11c [ EMERG] [10][ 9] [<0x2c33ed14>] nsh_parse_command+0x684/0xcf0 [ EMERG] [10][10] [<0x2c342e8e>] nsh_session+0x92/0x168 [ EMERG] [10][11] [<0x2c34403a>] nsh_consolemain+0x1e/0x38 [ EMERG] [10][12] [<0x2c344ac0>] nsh_main+0x30/0x50 [ EMERG] [10][13] [<0x2c319b60>] nxtask_startup+0x40/0x68 [ EMERG] [10][14] [<0x2c3080ba>] nxtask_start+0x46/0x60 Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-07 14:12:42 +01:00
#include <nuttx/allsyms.h>
#include <sys/types.h>
#include <stdio.h>
#include <syslog.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DUMP_DEPTH 16
#define DUMP_NITEM 8
#define DUMP_WIDTH (int)(2 * sizeof(FAR void *) + 2)
#define DUMP_LINESZ (DUMP_NITEM * (DUMP_WIDTH + 1))
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sched_dumpstack
*
* Description:
* Dump thread backtrace from specified tid.
*
****************************************************************************/
void sched_dumpstack(pid_t tid)
{
int size = DUMP_DEPTH;
int skip;
for (skip = 0; size == DUMP_DEPTH; skip += size)
{
FAR void *address[DUMP_DEPTH];
libs/dumpstack: add support for print symbol name ap> mw -1 [ EMERG] arm_usagefault: PANIC!!! Usage Fault: [ EMERG] arm_usagefault: IRQ: 6 regs: 0x3c24fa48 [ EMERG] arm_usagefault: BASEPRI: 000000e0 PRIMASK: 00000000 IPSR: 00000006 CONTROL: 00000004 [ EMERG] arm_usagefault: CFSR: 01000000 HFSR: 00000000 DFSR: 00000000 BFAR: 40101000 AFSR: 00000000 [ EMERG] arm_usagefault: Usage Fault Reason: [ EMERG] arm_usagefault: Unaligned access [ EMERG] up_assert: Assertion failed at file:armv8-m/arm_usagefault.c line: 113 task: init [ EMERG] backtrace|10: 0x2c325bde 0x2c319b98 0x2c3261cc 0x2c316b20 0x2c32699c 0x2c303a50 0x2c326072 0x2c3206ea [ EMERG] backtrace|10: 0x2c3428cc 0x2c33ed14 0x2c342e8e 0x2c34403a 0x2c344ac0 0x2c319b60 0x2c3080ba [ EMERG] [10][ 0] [<0x2c325bde>] up_backtrace+0xa/0x13c [ EMERG] [10][ 1] [<0x2c319b98>] sched_dumpstack+0x10/0xc0 [ EMERG] [10][ 2] [<0x2c3261cc>] up_assert+0x48/0x414 [ EMERG] [10][ 3] [<0x2c316b20>] _assert+0x4/0x10 [ EMERG] [10][ 4] [<0x2c32699c>] arm_usagefault+0xa8/0x138 [ EMERG] [10][ 5] [<0x2c303a50>] irq_dispatch+0x1c/0x40 [ EMERG] [10][ 6] [<0x2c326072>] arm_doirq+0x1a/0x2c [ EMERG] [10][ 7] [<0x2c3206ea>] exception_common+0x4a/0xac [ EMERG] [10][ 8] [<0x2c3428cc>] cmd_mw+0xec/0x11c [ EMERG] [10][ 9] [<0x2c33ed14>] nsh_parse_command+0x684/0xcf0 [ EMERG] [10][10] [<0x2c342e8e>] nsh_session+0x92/0x168 [ EMERG] [10][11] [<0x2c34403a>] nsh_consolemain+0x1e/0x38 [ EMERG] [10][12] [<0x2c344ac0>] nsh_main+0x30/0x50 [ EMERG] [10][13] [<0x2c319b60>] nxtask_startup+0x40/0x68 [ EMERG] [10][14] [<0x2c3080ba>] nxtask_start+0x46/0x60 Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-07 14:12:42 +01:00
#ifndef CONFIG_ALLSYMS
const char *format = " %0*p";
char line[DUMP_LINESZ + 1];
int ret = 0;
libs/dumpstack: add support for print symbol name ap> mw -1 [ EMERG] arm_usagefault: PANIC!!! Usage Fault: [ EMERG] arm_usagefault: IRQ: 6 regs: 0x3c24fa48 [ EMERG] arm_usagefault: BASEPRI: 000000e0 PRIMASK: 00000000 IPSR: 00000006 CONTROL: 00000004 [ EMERG] arm_usagefault: CFSR: 01000000 HFSR: 00000000 DFSR: 00000000 BFAR: 40101000 AFSR: 00000000 [ EMERG] arm_usagefault: Usage Fault Reason: [ EMERG] arm_usagefault: Unaligned access [ EMERG] up_assert: Assertion failed at file:armv8-m/arm_usagefault.c line: 113 task: init [ EMERG] backtrace|10: 0x2c325bde 0x2c319b98 0x2c3261cc 0x2c316b20 0x2c32699c 0x2c303a50 0x2c326072 0x2c3206ea [ EMERG] backtrace|10: 0x2c3428cc 0x2c33ed14 0x2c342e8e 0x2c34403a 0x2c344ac0 0x2c319b60 0x2c3080ba [ EMERG] [10][ 0] [<0x2c325bde>] up_backtrace+0xa/0x13c [ EMERG] [10][ 1] [<0x2c319b98>] sched_dumpstack+0x10/0xc0 [ EMERG] [10][ 2] [<0x2c3261cc>] up_assert+0x48/0x414 [ EMERG] [10][ 3] [<0x2c316b20>] _assert+0x4/0x10 [ EMERG] [10][ 4] [<0x2c32699c>] arm_usagefault+0xa8/0x138 [ EMERG] [10][ 5] [<0x2c303a50>] irq_dispatch+0x1c/0x40 [ EMERG] [10][ 6] [<0x2c326072>] arm_doirq+0x1a/0x2c [ EMERG] [10][ 7] [<0x2c3206ea>] exception_common+0x4a/0xac [ EMERG] [10][ 8] [<0x2c3428cc>] cmd_mw+0xec/0x11c [ EMERG] [10][ 9] [<0x2c33ed14>] nsh_parse_command+0x684/0xcf0 [ EMERG] [10][10] [<0x2c342e8e>] nsh_session+0x92/0x168 [ EMERG] [10][11] [<0x2c34403a>] nsh_consolemain+0x1e/0x38 [ EMERG] [10][12] [<0x2c344ac0>] nsh_main+0x30/0x50 [ EMERG] [10][13] [<0x2c319b60>] nxtask_startup+0x40/0x68 [ EMERG] [10][14] [<0x2c3080ba>] nxtask_start+0x46/0x60 Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-07 14:12:42 +01:00
#endif
int i;
size = sched_backtrace(tid, address, DUMP_DEPTH, skip);
if (size <= 0)
{
break;
}
libs/dumpstack: add support for print symbol name ap> mw -1 [ EMERG] arm_usagefault: PANIC!!! Usage Fault: [ EMERG] arm_usagefault: IRQ: 6 regs: 0x3c24fa48 [ EMERG] arm_usagefault: BASEPRI: 000000e0 PRIMASK: 00000000 IPSR: 00000006 CONTROL: 00000004 [ EMERG] arm_usagefault: CFSR: 01000000 HFSR: 00000000 DFSR: 00000000 BFAR: 40101000 AFSR: 00000000 [ EMERG] arm_usagefault: Usage Fault Reason: [ EMERG] arm_usagefault: Unaligned access [ EMERG] up_assert: Assertion failed at file:armv8-m/arm_usagefault.c line: 113 task: init [ EMERG] backtrace|10: 0x2c325bde 0x2c319b98 0x2c3261cc 0x2c316b20 0x2c32699c 0x2c303a50 0x2c326072 0x2c3206ea [ EMERG] backtrace|10: 0x2c3428cc 0x2c33ed14 0x2c342e8e 0x2c34403a 0x2c344ac0 0x2c319b60 0x2c3080ba [ EMERG] [10][ 0] [<0x2c325bde>] up_backtrace+0xa/0x13c [ EMERG] [10][ 1] [<0x2c319b98>] sched_dumpstack+0x10/0xc0 [ EMERG] [10][ 2] [<0x2c3261cc>] up_assert+0x48/0x414 [ EMERG] [10][ 3] [<0x2c316b20>] _assert+0x4/0x10 [ EMERG] [10][ 4] [<0x2c32699c>] arm_usagefault+0xa8/0x138 [ EMERG] [10][ 5] [<0x2c303a50>] irq_dispatch+0x1c/0x40 [ EMERG] [10][ 6] [<0x2c326072>] arm_doirq+0x1a/0x2c [ EMERG] [10][ 7] [<0x2c3206ea>] exception_common+0x4a/0xac [ EMERG] [10][ 8] [<0x2c3428cc>] cmd_mw+0xec/0x11c [ EMERG] [10][ 9] [<0x2c33ed14>] nsh_parse_command+0x684/0xcf0 [ EMERG] [10][10] [<0x2c342e8e>] nsh_session+0x92/0x168 [ EMERG] [10][11] [<0x2c34403a>] nsh_consolemain+0x1e/0x38 [ EMERG] [10][12] [<0x2c344ac0>] nsh_main+0x30/0x50 [ EMERG] [10][13] [<0x2c319b60>] nxtask_startup+0x40/0x68 [ EMERG] [10][14] [<0x2c3080ba>] nxtask_start+0x46/0x60 Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-07 14:12:42 +01:00
#ifndef CONFIG_ALLSYMS
for (i = 0; i < size; i++)
{
ret += snprintf(line + ret, sizeof(line) - ret,
format, DUMP_WIDTH, address[i]);
if (i == size - 1 || ret % DUMP_LINESZ == 0)
{
syslog(LOG_EMERG, "backtrace|%2d:%s\n", tid, line);
ret = 0;
}
}
libs/dumpstack: add support for print symbol name ap> mw -1 [ EMERG] arm_usagefault: PANIC!!! Usage Fault: [ EMERG] arm_usagefault: IRQ: 6 regs: 0x3c24fa48 [ EMERG] arm_usagefault: BASEPRI: 000000e0 PRIMASK: 00000000 IPSR: 00000006 CONTROL: 00000004 [ EMERG] arm_usagefault: CFSR: 01000000 HFSR: 00000000 DFSR: 00000000 BFAR: 40101000 AFSR: 00000000 [ EMERG] arm_usagefault: Usage Fault Reason: [ EMERG] arm_usagefault: Unaligned access [ EMERG] up_assert: Assertion failed at file:armv8-m/arm_usagefault.c line: 113 task: init [ EMERG] backtrace|10: 0x2c325bde 0x2c319b98 0x2c3261cc 0x2c316b20 0x2c32699c 0x2c303a50 0x2c326072 0x2c3206ea [ EMERG] backtrace|10: 0x2c3428cc 0x2c33ed14 0x2c342e8e 0x2c34403a 0x2c344ac0 0x2c319b60 0x2c3080ba [ EMERG] [10][ 0] [<0x2c325bde>] up_backtrace+0xa/0x13c [ EMERG] [10][ 1] [<0x2c319b98>] sched_dumpstack+0x10/0xc0 [ EMERG] [10][ 2] [<0x2c3261cc>] up_assert+0x48/0x414 [ EMERG] [10][ 3] [<0x2c316b20>] _assert+0x4/0x10 [ EMERG] [10][ 4] [<0x2c32699c>] arm_usagefault+0xa8/0x138 [ EMERG] [10][ 5] [<0x2c303a50>] irq_dispatch+0x1c/0x40 [ EMERG] [10][ 6] [<0x2c326072>] arm_doirq+0x1a/0x2c [ EMERG] [10][ 7] [<0x2c3206ea>] exception_common+0x4a/0xac [ EMERG] [10][ 8] [<0x2c3428cc>] cmd_mw+0xec/0x11c [ EMERG] [10][ 9] [<0x2c33ed14>] nsh_parse_command+0x684/0xcf0 [ EMERG] [10][10] [<0x2c342e8e>] nsh_session+0x92/0x168 [ EMERG] [10][11] [<0x2c34403a>] nsh_consolemain+0x1e/0x38 [ EMERG] [10][12] [<0x2c344ac0>] nsh_main+0x30/0x50 [ EMERG] [10][13] [<0x2c319b60>] nxtask_startup+0x40/0x68 [ EMERG] [10][14] [<0x2c3080ba>] nxtask_start+0x46/0x60 Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-07 14:12:42 +01:00
#else
syslog(LOG_EMERG, "backtrace:\n");
for (i = 0; i < size; i++)
{
syslog(LOG_EMERG, "[%2d] [<%p>] %pS\n",
tid, address[i], address[i]);
}
libs/dumpstack: add support for print symbol name ap> mw -1 [ EMERG] arm_usagefault: PANIC!!! Usage Fault: [ EMERG] arm_usagefault: IRQ: 6 regs: 0x3c24fa48 [ EMERG] arm_usagefault: BASEPRI: 000000e0 PRIMASK: 00000000 IPSR: 00000006 CONTROL: 00000004 [ EMERG] arm_usagefault: CFSR: 01000000 HFSR: 00000000 DFSR: 00000000 BFAR: 40101000 AFSR: 00000000 [ EMERG] arm_usagefault: Usage Fault Reason: [ EMERG] arm_usagefault: Unaligned access [ EMERG] up_assert: Assertion failed at file:armv8-m/arm_usagefault.c line: 113 task: init [ EMERG] backtrace|10: 0x2c325bde 0x2c319b98 0x2c3261cc 0x2c316b20 0x2c32699c 0x2c303a50 0x2c326072 0x2c3206ea [ EMERG] backtrace|10: 0x2c3428cc 0x2c33ed14 0x2c342e8e 0x2c34403a 0x2c344ac0 0x2c319b60 0x2c3080ba [ EMERG] [10][ 0] [<0x2c325bde>] up_backtrace+0xa/0x13c [ EMERG] [10][ 1] [<0x2c319b98>] sched_dumpstack+0x10/0xc0 [ EMERG] [10][ 2] [<0x2c3261cc>] up_assert+0x48/0x414 [ EMERG] [10][ 3] [<0x2c316b20>] _assert+0x4/0x10 [ EMERG] [10][ 4] [<0x2c32699c>] arm_usagefault+0xa8/0x138 [ EMERG] [10][ 5] [<0x2c303a50>] irq_dispatch+0x1c/0x40 [ EMERG] [10][ 6] [<0x2c326072>] arm_doirq+0x1a/0x2c [ EMERG] [10][ 7] [<0x2c3206ea>] exception_common+0x4a/0xac [ EMERG] [10][ 8] [<0x2c3428cc>] cmd_mw+0xec/0x11c [ EMERG] [10][ 9] [<0x2c33ed14>] nsh_parse_command+0x684/0xcf0 [ EMERG] [10][10] [<0x2c342e8e>] nsh_session+0x92/0x168 [ EMERG] [10][11] [<0x2c34403a>] nsh_consolemain+0x1e/0x38 [ EMERG] [10][12] [<0x2c344ac0>] nsh_main+0x30/0x50 [ EMERG] [10][13] [<0x2c319b60>] nxtask_startup+0x40/0x68 [ EMERG] [10][14] [<0x2c3080ba>] nxtask_start+0x46/0x60 Signed-off-by: chao.an <anchao@xiaomi.com>
2021-12-07 14:12:42 +01:00
#endif
}
}