How stack trace on ARM works

Stack unwind through frames

/* The stack backtrace structure is as follows:
fp points to here:
| save code pointer | [fp]
| return link value | [fp, #-4]
| return sp value | [fp, #-8]
| return fp value | [fp, #-12]
[| saved r10 value |]
[| saved r9 value |]
[| saved r8 value |]
[| saved r7 value |]
[| saved r6 value |]
[| saved r5 value |]
[| saved r4 value |]
[| saved r3 value |]
[| saved r2 value |]
[| saved r1 value |]
[| saved r0 value |]
r0-r3 are not normally saved in a C function. */
static int my_func1(int a) {
my_func2(7);
return 0;
}
00008134 <my_func1>:8134:   b084        sub sp, #16
8136: b580 push {r7, lr}
8138: aa06 add r2, sp, #24
813a: 9203 str r2, [sp, #12]
813c: 467a mov r2, pc
813e: 9205 str r2, [sp, #20]
8140: 465a mov r2, fp
8142: 9202 str r2, [sp, #8]
8144: 4672 mov r2, lr
8146: 9204 str r2, [sp, #16]
8148: aa05 add r2, sp, #20
814a: 4693 mov fp, r2
814c: b082 sub sp, #8
814e: af00 add r7, sp, #0
000081f8 <my_func1>:81f8:   e1a0c00d    mov ip, sp
81fc: e92dd800 push {fp, ip, lr, pc}
8200: e24cb004 sub fp, ip, #4
8204: e24dd008 sub sp, sp, #8

Stack unwind through exceptions

/* Stack unwinding tables */
#define ARM_UNWIND_SECTIONS \
. = ALIGN(8); \
.ARM.unwind_idx : { \
__start_unwind_idx = .; \
*(.ARM.exidx*) \
__stop_unwind_idx = .; \
} \
struct unwind_idx {
unsigned long addr_offset;
unsigned long insn;
};
$ arm-none-eabi-readelf -u build/base/bin/emboxUnwind table index '.ARM.exidx' at offset 0xaa6d4 contains 2806 entries:
<...>
0x1c3c <kernel_start>: @0xafe40
Compact model index: 1
0x9b vsp = r11
0x40 vsp = vsp - 4
0x84 0x80 pop {r11, r14}
0xb0 finish
0xb0 finish
<...>
00001c3c <kernel_start>:
void kernel_start(void) {
1c3c: e92d4800 push {fp, lr}
1c40: e28db004 add fp, sp, #4
<...>
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0005a600 08000000 08000000 00004000 2**14
CONTENTS, ALLOC, LOAD, CODE
1 .ARM.exidx 00003fd8 0805a600 0805a600 0005e600 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .ARM.extab 000049d0 0805e5d8 0805e5d8 000625d8 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .rodata 0003e380 08062fc0 08062fc0 00066fc0 2**5
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00058b1c 08000000 08000000 00004000 2**14
CONTENTS, ALLOC, LOAD, CODE
1 .ARM.exidx 00000008 08058b1c 08058b1c 0005cb1c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .rodata 0003e380 08058b40 08058b40 0005cb40 2**5

Is such a stack trace needed for ARM? What are the alternatives?

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store