Skip to content

Commit e2da849

Browse files
authored
wamr/arm: Add CFI directives to Thumb VFP assembly for better debugging (#4697)
Add Call Frame Information (CFI) directives to invokeNative_thumb_vfp.s to improve stack unwinding and debugging capabilities on ARM platforms. This enables better backtrace generation and crash analysis. Changes include: - Add .cfi_startproc/.cfi_endproc directives for proper frame tracking - Add .cfi_def_cfa_offset and .cfi_def_cfa to track stack pointer changes - Add .cfi_offset directives to track saved register locations - Convert local labels to use .L prefix following assembly conventions These CFI directives allow debuggers and exception handlers to properly unwind the stack through native function calls, improving the debugging experience for WAMR applications on ARM targets. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
1 parent a41d343 commit e2da849

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

core/iwasm/common/arch/invokeNative_thumb_vfp.s

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ invokeNative:
1212
.globl _invokeNative
1313
_invokeNative:
1414
#endif /* end of BH_PLATFORM_DARWIN */
15-
15+
.cfi_startproc
1616
/*
1717
* Arguments passed in:
1818
*
@@ -24,10 +24,17 @@ _invokeNative:
2424
push {r4, r5, r6, r7}
2525
push {lr}
2626
sub sp, sp, #4 /* make sp 8 byte aligned */
27+
.cfi_def_cfa_offset 24
28+
.cfi_offset lr, -20
29+
.cfi_offset r4, -16
30+
.cfi_offset r5, -12
31+
.cfi_offset r6, -8
32+
.cfi_offset r7, -4
2733
mov ip, r0 /* ip = function ptr */
2834
mov r4, r1 /* r4 = argv */
2935
mov r5, r2 /* r5 = nstacks */
3036
mov r7, sp
37+
.cfi_def_cfa r7, 24
3138

3239
/* Fill all int args */
3340
ldr r0, [r4, #0] /* r0 = *(int*)&argv[0] = exec_env */
@@ -57,7 +64,7 @@ _invokeNative:
5764
vldr s15, [r4, #60]
5865
/* Directly call the function if no args in stack */
5966
cmp r5, #0
60-
beq call_func
67+
beq .Lcall_func
6168

6269
mov lr, r2 /* save r2 */
6370

@@ -73,30 +80,31 @@ _invokeNative:
7380
mov r7, sp
7481
mov sp, r6
7582

76-
loop_stack_args: /* copy stack arguments to stack */
83+
.Lloop_stack_args: /* copy stack arguments to stack */
7784
cmp r5, #0
78-
beq call_func1
85+
beq .Lcall_func1
7986
ldr r2, [r4] /* Note: caller should insure int64 and */
8087
add r4, r4, #4 /* double are placed in 8 bytes aligned address */
8188
str r2, [r6]
8289
add r6, r6, #4
8390

8491
sub r5, r5, #1
85-
b loop_stack_args
92+
b .Lloop_stack_args
8693

87-
call_func1:
94+
.Lcall_func1:
8895
mov r2, lr /* restore r2 */
8996

90-
call_func:
97+
.Lcall_func:
9198
blx ip
9299
mov sp, r7 /* restore sp */
93100

94-
return:
101+
.Lreturn:
95102
add sp, sp, #4 /* make sp 8 byte aligned */
96103
pop {r3}
97104
pop {r4, r5, r6, r7}
98105
mov lr, r3
99106
bx lr
107+
.cfi_endproc
100108

101109
#if defined(__linux__) && defined(__ELF__)
102110
.section .note.GNU-stack,"",%progbits

0 commit comments

Comments
 (0)