Add addr2line tool for annotating backtrace

master
Jiajie Chen 6 years ago
parent e3262698be
commit 5350ecb09f

@ -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)

@ -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='')
Loading…
Cancel
Save