diff --git a/kernel/Makefile b/kernel/Makefile index 38df128..6014788 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -5,6 +5,7 @@ # make doc Generate docs # make asm Open the deassemble file of the last build # make header Open 'objdump -h' of the last build +# make addr2line Use addr2line to recover line info in backtrace # make clean Clean # # Options: @@ -262,3 +263,7 @@ install: $(bin) ## baudrate no more than 600000 @python3 ../tools/k210/kflash.py $(bin) -b 600000 endif + +.PHONY: +addr2line: + @python3 ../tools/addr2line.py $(prefix)addr2line $(arch) diff --git a/tools/addr2line.py b/tools/addr2line.py new file mode 100644 index 0000000..fa84228 --- /dev/null +++ b/tools/addr2line.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import sys +import re +import subprocess + +print('Paste backtrace here, and then input EOF(Ctrl-D or Ctrl-Z) to get annotated backtrace.') +lines = sys.stdin.readlines() +addrline = sys.argv[1] +arch = sys.argv[2] +print('--------------------------------------') +for line in lines: + match = re.search('(#[0-9]+ )(0x[0-9A-F]+)( fp 0x[0-9A-F]+)', line) + if match: + addr = match.group(2) + process = subprocess.run([addrline, '-e', 'target/{0}/debug/rcore'.format(arch), '-f', '-C', addr], capture_output=True) + res = process.stdout.decode('utf-8') + print('{0}{1}{3} {2}'.format(match.group(1), match.group(2), res.strip(), match.group(3))) + else: + print(line, end='')