mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 13:52:22 +08:00
arch/arm64: fix backtrace return address precision
The return address stored in the frame should point to the instruction after the call. To get the actual call site, we need to subtract the instruction size (sizeof(void *)) from the saved return address. This ensures that backtrace addresses correctly point to the calling instruction rather than the next instruction. Signed-off-by: yinshengkai <yinshengkai@bytedance.com>
This commit is contained in:
@@ -44,6 +44,19 @@
|
||||
* Description:
|
||||
* backtrace() parsing the return address through frame pointer
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* The stack layout is as follows:
|
||||
*
|
||||
* Stack (grows downward):
|
||||
* +--------------------+
|
||||
* high addr | locals of A |
|
||||
* +--------------------+
|
||||
* | prev_fp(A)=0 | ← FP of A (first frame)
|
||||
* | saved_lr(A) |
|
||||
* +--------------------+
|
||||
* | locals of B |
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
nosanitize_address
|
||||
@@ -57,7 +70,7 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
|
||||
{
|
||||
if ((*skip)-- <= 0)
|
||||
{
|
||||
buffer[i++] = pc;
|
||||
buffer[i++] = (void *)((uintptr_t)pc - sizeof(void *));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +83,7 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,
|
||||
|
||||
if ((*skip)-- <= 0)
|
||||
{
|
||||
buffer[i++] = (void *)*(fp + 1);
|
||||
buffer[i++] = (void *)(*(fp + 1) - sizeof(void *));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user