2021-03-31 05:28:07 +02:00
|
|
|
/****************************************************************************
|
2021-07-30 06:05:33 +02:00
|
|
|
* libs/libc/sched/sched_dumpstack.c
|
2021-03-31 05:28:07 +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
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2021-12-07 14:12:42 +01:00
|
|
|
#include <nuttx/allsyms.h>
|
2021-03-31 05:28:07 +02:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
2021-12-26 04:40:32 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2021-03-31 05:28:07 +02:00
|
|
|
|
|
|
|
#define DUMP_DEPTH 16
|
|
|
|
#define DUMP_NITEM 8
|
2021-12-26 04:40:32 +01:00
|
|
|
#define DUMP_WIDTH (int)(2 * sizeof(FAR void *) + 2)
|
|
|
|
#define DUMP_LINESZ (DUMP_NITEM * (DUMP_WIDTH + 1))
|
2021-03-31 05:28:07 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-07-30 06:15:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_dumpstack
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump thread backtrace from specified tid.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void sched_dumpstack(pid_t tid)
|
2021-03-31 05:28:07 +02:00
|
|
|
{
|
2021-12-24 08:38:14 +01:00
|
|
|
int size = DUMP_DEPTH;
|
|
|
|
int skip;
|
|
|
|
|
|
|
|
for (skip = 0; size == DUMP_DEPTH; skip += size)
|
|
|
|
{
|
|
|
|
FAR void *address[DUMP_DEPTH];
|
2021-12-07 14:12:42 +01:00
|
|
|
#ifndef CONFIG_ALLSYMS
|
2021-12-24 08:38:14 +01:00
|
|
|
const char *format = " %0*p";
|
|
|
|
char line[DUMP_LINESZ + 1];
|
|
|
|
int ret = 0;
|
2021-12-07 14:12:42 +01:00
|
|
|
#endif
|
2021-12-24 08:38:14 +01:00
|
|
|
int i;
|
2021-03-31 05:28:07 +02:00
|
|
|
|
2021-12-24 08:38:14 +01:00
|
|
|
size = sched_backtrace(tid, address, DUMP_DEPTH, skip);
|
|
|
|
if (size <= 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-03-31 05:28:07 +02:00
|
|
|
|
2021-12-07 14:12:42 +01:00
|
|
|
#ifndef CONFIG_ALLSYMS
|
2021-12-24 08:38:14 +01:00
|
|
|
for (i = 0; i < size; i++)
|
2021-03-31 05:28:07 +02:00
|
|
|
{
|
2021-12-24 08:38:14 +01:00
|
|
|
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;
|
|
|
|
}
|
2021-03-31 05:28:07 +02:00
|
|
|
}
|
2021-12-07 14:12:42 +01:00
|
|
|
#else
|
2022-03-22 10:37:39 +01:00
|
|
|
if (skip == 0)
|
|
|
|
{
|
|
|
|
syslog(LOG_EMERG, "backtrace:\n");
|
|
|
|
}
|
|
|
|
|
2021-12-24 08:38:14 +01:00
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
syslog(LOG_EMERG, "[%2d] [<%p>] %pS\n",
|
|
|
|
tid, address[i], address[i]);
|
|
|
|
}
|
2021-12-07 14:12:42 +01:00
|
|
|
#endif
|
2021-12-24 08:38:14 +01:00
|
|
|
}
|
2021-03-31 05:28:07 +02:00
|
|
|
}
|