Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: riscv & arm64: print symbol name in stack trace #72973

Merged
merged 5 commits into from
May 23, 2024

Conversation

ycsin
Copy link
Collaborator

@ycsin ycsin commented May 18, 2024

See each commit message for details

https://builds.zephyrproject.io/zephyr/pr/72973/docs/releases/release-notes-3.7.html

Standing issue

I was expecting the same can be applied to x86, but qemu_x86 crashes when I try to use something from the symtab.

Testing

RISCV

west build -p auto -b qemu_riscv32 zephyr/tests/arch/common/stack_unwind \
    -T arch.common.stack_unwind.riscv_sp \
    -t run -- \
    -DCONFIG_EXCEPTION_STACK_TRACE_SYMTAB=y
*** Booting Zephyr OS build v3.6.0-4306-g9c7c06afd3b6 ***
Hello World! qemu_riscv32
1: func1
2: func2
3: func1
4: func2
5: func1
6: func2
E:      a0: 00000003    t0: 00000000
E:      a1: 800081c3    t1: 0000004c
E:      a2: 0000000a    t2: 00000000
E:      a3: 8000a138    t3: 0000002a
E:      a4: 00000000    t4: 0000002e
E:      a5: 00000004    t5: 0000007f
E:      a6: 00000068    t6: 00000010
E:      a7: 0000006a
E:      sp: 8000bb80
E:      ra: 80000786
E:    mepc: 80000794 [func2+0x1e]
E: mstatus: 00021880
E: 
E:      s0: 8000a31c    s6: 00000000
E:      s1: 800024f2    s7: 00000000
E:      s2: 00000000    s8: 00000000
E:      s3: 00000000    s9: 00000000
E:      s4: 00000000   s10: 00000000
E:      s5: 00000000   s11: 00000000
E: 
E: call trace:
E:       0: sp: 8000bb8c   ra: 800007c6 [func1+0x24]
E:       1: sp: 8000bb9c   ra: 8000079a [func2+0x32]
E:       2: sp: 8000bbac   ra: 800007c6 [func1+0x24]
E:       3: sp: 8000bbbc   ra: 8000079a [func2+0x32]
E:       4: sp: 8000bbcc   ra: 800007c6 [func1+0x24]
E:       5: sp: 8000bbdc   ra: 800007ea [main+0x1c]
E:       6: sp: 8000bbe4   ra: 800024f2 [bg_thread_main+0x0]
E:       7: sp: 8000bbec   ra: 80002512 [bg_thread_main+0x20]
E:       8: sp: 8000bbf0   ra: 800024f2 [bg_thread_main+0x0]
E:       9: sp: 8000bbfc   ra: 80000bc6 [z_thread_entry+0x26]
E: 
E: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
E: Current thread: 0x8000a138 (main)
E: Halting system

ARM64

west build -p auto -b qemu_cortex_a53 zephyr/tests/arch/common/stack_unwind \
    -T arch.common.stack_unwind.arm64 \
    -t run -- \
    -DCONFIG_SYMTAB=y
*** Booting Zephyr OS build v3.6.0-4076-g98b58e2aef93 ***
Hello World! qemu_cortex_a53
1: func1
2: func2
3: func1
4: func2
5: func1
6: func2
E: ELR_ELn: 0x0000000040001270
E: ESR_ELn: 0x0000000056000002
E:   EC:  0x15 (Unknown)
E:   IL:  0x1
E:   ISS: 0x2
E: TPIDRRO: 0x010000004001aa08
E: x0:  0x0000000000000009  x1:  0x000000000000000a
E: x2:  0x00000000407ff000  x3:  0x0000000000000090
E: x4:  0x0000000000000000  x5:  0x000000000000002d
E: x6:  0x0000000000000000  x7:  0x0000000000000006
E: x8:  0x0000000000000003  x9:  0x0000000000000000
E: x10: 0x0000000000000000  x11: 0x0000000000000000
E: x12: 0x0000000000000000  x13: 0x0000000000000000
E: x14: 0x0000000000000000  x15: 0x0000000000000000
E: x16: 0x0000000000000000  x17: 0x0000000000000000
E: x18: 0x0000000000000000  lr:  0x0000000040001260
E: 
E: backtrace  0: fp: 0x000000004005daa0 lr: 0x00000000400012b4 [func1+48]
E: backtrace  1: fp: 0x000000004005dac0 lr: 0x0000000040001278 [func2+64]
E: backtrace  2: fp: 0x000000004005dae0 lr: 0x00000000400012b4 [func1+48]
E: backtrace  3: fp: 0x000000004005db00 lr: 0x0000000040001278 [func2+64]
E: backtrace  4: fp: 0x000000004005db20 lr: 0x00000000400012b4 [func1+48]
E: backtrace  5: fp: 0x000000004005db40 lr: 0x00000000400012e4 [main+36]
E: backtrace  6: fp: 0x000000004005db60 lr: 0x00000000400058a4 [bg_thread_main+56]
E: backtrace  7: fp: 0x000000004005db70 lr: 0x0000000040001734 [z_thread_entry+72]
E: backtrace  8: fp: 0x000000004005db80 lr: 0x0000000000000000 [?+0]
E: 
E: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
E: Current thread: 0x4001a330 (main)
E: Halting system

TODO

fkokosinski
fkokosinski previously approved these changes May 20, 2024
Copy link
Member

@fkokosinski fkokosinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISC-V changes from 6a32c2c LGTM

@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label May 21, 2024
@ycsin
Copy link
Collaborator Author

ycsin commented May 21, 2024

Polished a few things, should be final now.

@ycsin ycsin requested a review from fkokosinski May 21, 2024 07:42
@ycsin ycsin force-pushed the pr/gen_symtab branch 3 times, most recently from 2a3ad6e to e8078d6 Compare May 21, 2024 08:19
cfriedt
cfriedt previously approved these changes May 21, 2024
npitre
npitre previously approved these changes May 21, 2024
Copy link
Collaborator

@npitre npitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few ideas to shrink the ROM footprint but that may come later

ycsin added 5 commits May 22, 2024 10:05
Use pyelftools to extract the symbol table from the
link stage executable. Then, filter out the function names
and sort them based on their offsets before writing into the
`symtab.c`, this is similar to how the `isr_tables` works.

To access the structure, simply include the new header:
```c
#include <zephyr/debug/symtab.h>
```

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Selecting `CONFIG_EXCEPTION_STACK_TRACE_SYMTAB` will
enable the symtab generation which will be used in the
stack trace to print the function name of the return
address.

Updated the `stack_unwind` test to test the symbols in a
stack trace.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
The mepc register is the address of the instruction that was
interrupted, it will make debugging easier if we know the
name of the symbol, so print it if `CONFIG_SYMTAB` is enabled.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Selecting `CONFIG_SYMTAB` will
enable the symtab generation which will be used in the
stack trace to print the function name of the return
address.

Added `arm64` to the `arch.common.stack_unwind.symtab` test.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Current on x86 & risc-v that implement stack trace, the
maximum depth of the stack trace is defined by a macro.

Introduce a new Kconfig:EXCEPTION_STACK_TRACE_MAX_FRAMES
so that this is configurable in software.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
@ycsin ycsin dismissed stale reviews from npitre and cfriedt via ac62e1a May 22, 2024 02:05
@ycsin ycsin requested review from cfriedt and npitre May 22, 2024 02:05
@ycsin
Copy link
Collaborator Author

ycsin commented May 22, 2024

Rebased to fix merge conflict

@ycsin
Copy link
Collaborator Author

ycsin commented May 22, 2024

Failed CI passed locally:

west build -b qemu_riscv32_smp -p auto -t run zephyr/tests/kernel/spinlock -T kernel.multiprocessing.spinlock_fairness

@nashif nashif merged commit c118cd5 into zephyrproject-rtos:main May 23, 2024
35 checks passed
@ycsin ycsin deleted the pr/gen_symtab branch May 24, 2024 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM64 ARM (64-bit) Architecture area: Build System area: Debugging area: Kernel area: RISCV RISCV Architecture (32-bit & 64-bit) area: X86 x86 Architecture (32-bit) Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants