【优化】函数调用栈回溯功能。由于 thumb 指令下状态下,PC 地址都是奇数,所以去除可能为偶数的脏数据。

pull/15/merge
armink 8 years ago
parent 2dc2d0bfd9
commit 10b5653da9

@ -374,6 +374,10 @@ size_t cm_backtrace_call_stack(uint32_t *buffer, size_t size, uint32_t sp) {
for (; sp < stack_start_addr + stack_size; sp += sizeof(size_t)) { for (; sp < stack_start_addr + stack_size; sp += sizeof(size_t)) {
/* the *sp value may be LR, so need decrease a word to PC */ /* the *sp value may be LR, so need decrease a word to PC */
pc = *((uint32_t *) sp) - sizeof(size_t); pc = *((uint32_t *) sp) - sizeof(size_t);
/* the Cortex-M using thumb instruction, so the pc must be an odd number */
if (pc % 2 == 0) {
continue;
}
if ((pc >= code_start_addr) && (pc <= code_start_addr + code_size) && (depth < CMB_CALL_STACK_MAX_DEPTH) if ((pc >= code_start_addr) && (pc <= code_start_addr + code_size) && (depth < CMB_CALL_STACK_MAX_DEPTH)
&& (depth < size)) { && (depth < size)) {
/* the second depth function may be already saved, so need ignore repeat */ /* the second depth function may be already saved, so need ignore repeat */

@ -34,7 +34,7 @@
#include <stdlib.h> #include <stdlib.h>
/* library software version number */ /* library software version number */
#define CMB_SW_VERSION "1.2.0" #define CMB_SW_VERSION "1.2.1"
#define CMB_CPU_ARM_CORTEX_M0 0 #define CMB_CPU_ARM_CORTEX_M0 0
#define CMB_CPU_ARM_CORTEX_M3 1 #define CMB_CPU_ARM_CORTEX_M3 1

Loading…
Cancel
Save