rt-thread-official/libcpu/arm/common/backtrace.c

64 lines
1.1 KiB
C
Raw Normal View History

2013-01-08 21:05:02 +08:00
/*
2021-03-27 17:51:56 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-01-08 21:05:02 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-01-08 21:05:02 +08:00
*
* Change Logs:
* Date Author Notes
* 2008-07-29 Bernard first version from QiuYi implementation
*/
#include <rtthread.h>
#ifdef __GNUC__
/*
-->High Address,Stack Top
2019-01-07 06:09:45 +08:00
PC<------|
LR |
IP |
FP |
...... |
PC <-| |
LR | |
IP | |
2013-01-08 21:05:02 +08:00
FP---|-- |
2019-01-07 06:09:45 +08:00
...... |
PC |
LR |
IP |
2013-01-08 21:05:02 +08:00
FP---
-->Low Address,Stack Bottom
*/
void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry)
{
2019-01-07 06:09:45 +08:00
rt_uint32_t i, pc, func_entry;
2013-01-08 21:05:02 +08:00
2019-01-07 06:09:45 +08:00
pc = *fp;
2022-07-25 10:21:18 +08:00
rt_kprintf("[0x%x]\n", pc - 0xC);
2013-01-08 21:05:02 +08:00
2022-07-25 10:21:18 +08:00
for (i = 0; i < 10; i++)
2019-01-07 06:09:45 +08:00
{
2022-07-25 10:21:18 +08:00
fp = (rt_uint32_t *) * (fp - 3);
2019-01-07 06:09:45 +08:00
pc = *fp ;
2013-01-08 21:05:02 +08:00
2019-01-07 06:09:45 +08:00
func_entry = pc - 0xC;
2013-01-08 21:05:02 +08:00
2022-07-25 10:21:18 +08:00
if (func_entry <= 0x30000000) break;
2013-01-08 21:05:02 +08:00
2022-07-25 10:21:18 +08:00
if (func_entry == thread_entry)
2019-01-07 06:09:45 +08:00
{
rt_kprintf("EntryPoint:0x%x\n", func_entry);
2013-01-08 21:05:02 +08:00
2019-01-07 06:09:45 +08:00
break;
}
2013-01-08 21:05:02 +08:00
2019-01-07 06:09:45 +08:00
rt_kprintf("[0x%x]\n", func_entry);
}
2013-01-08 21:05:02 +08:00
}
#else
void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry)
{
2019-01-07 06:09:45 +08:00
/* old compiler implementation */
2013-01-08 21:05:02 +08:00
}
#endif