拜读了您的cmbacktrace代码,在阅读到cm_backtrace_call_stack函数的时候,有两个点不是很理解,请您赐教。代码段如下:
/ copy called function address /
for (; sp < stack_start_addr + stack_size; sp += sizeof(size_t)) {
/ the sp value may be LR, so need decrease a word to PC /
pc = ((uint32_t ) sp) - sizeof(size_t); // ------------------------------------ 1
/ the Cortex-M using thumb instruction, so the pc must be an odd number /
if (pc % 2 == 0) {
continue;
}
/ fix the PC address in thumb mode /
pc = ((uint32_t ) sp) - 1;
if ((pc >= code_start_addr + sizeof(size_t)) && (pc <= code_start_addr + code_size) && (depth < CMB_CALL_STACK_MAX_DEPTH)
/ check the the instruction before PC address is 'BL' or 'BLX' /
&& disassembly_ins_is_bl_blx(pc - sizeof(size_t)) && (depth < size)) {
/ the second depth function may be already saved, so need ignore repeat */
if ((depth == 2) && regs_saved_lr_is_valid && (pc == buffer[1])) {
continue;
}
buffer[depth++] = pc; // ------------------------------------- 2
}
}
Hi~,Armink:
拜读了您的cmbacktrace代码,在阅读到cm_backtrace_call_stack函数的时候,有两个点不是很理解,请您赐教。代码段如下: / copy called function address / for (; sp < stack_start_addr + stack_size; sp += sizeof(size_t)) { / the sp value may be LR, so need decrease a word to PC / pc = ((uint32_t ) sp) - sizeof(size_t); // ------------------------------------ 1 / the Cortex-M using thumb instruction, so the pc must be an odd number / if (pc % 2 == 0) { continue; } / fix the PC address in thumb mode / pc = ((uint32_t ) sp) - 1; if ((pc >= code_start_addr + sizeof(size_t)) && (pc <= code_start_addr + code_size) && (depth < CMB_CALL_STACK_MAX_DEPTH) / check the the instruction before PC address is 'BL' or 'BLX' / && disassembly_ins_is_bl_blx(pc - sizeof(size_t)) && (depth < size)) { / the second depth function may be already saved, so need ignore repeat */ if ((depth == 2) && regs_saved_lr_is_valid && (pc == buffer[1])) { continue; } buffer[depth++] = pc; // ------------------------------------- 2 } }