Merge pull request #1 from jiegec/master
Fix AArch64 toolchain downloading in Travis CItoolchain_update
commit
3690a4ea3b
@ -0,0 +1,66 @@
|
|||||||
|
use core::mem::size_of;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn stext();
|
||||||
|
fn etext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the current frame pointer.
|
||||||
|
#[inline(always)]
|
||||||
|
#[cfg(any(target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64"))]
|
||||||
|
pub fn fp() -> usize {
|
||||||
|
let ptr: usize;
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
unsafe {
|
||||||
|
asm!("mov $0, x29" : "=r"(ptr));
|
||||||
|
}
|
||||||
|
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
|
||||||
|
unsafe {
|
||||||
|
asm!("mv $0, s0" : "=r"(ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the current link register.
|
||||||
|
#[inline(always)]
|
||||||
|
#[cfg(any(target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64"))]
|
||||||
|
pub fn lr() -> usize {
|
||||||
|
let ptr: usize;
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
unsafe {
|
||||||
|
asm!("mov $0, x30" : "=r"(ptr));
|
||||||
|
}
|
||||||
|
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
|
||||||
|
unsafe {
|
||||||
|
asm!("mv $0, ra" : "=r"(ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the backtrace starting from the caller
|
||||||
|
pub fn backtrace() {
|
||||||
|
#[cfg(any(target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64"))]
|
||||||
|
unsafe {
|
||||||
|
let mut current_pc = lr();
|
||||||
|
let mut current_fp = fp();
|
||||||
|
let mut stack_num = 0;
|
||||||
|
while current_pc >= stext as usize && current_pc <= etext as usize && current_fp as usize != 0 {
|
||||||
|
println!("#{} {:#018X} fp {:#018X}", stack_num, current_pc - size_of::<usize>(), current_fp);
|
||||||
|
stack_num = stack_num + 1;
|
||||||
|
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
|
||||||
|
{
|
||||||
|
current_fp = *(current_fp as *const usize).offset(-2);
|
||||||
|
current_pc = *(current_fp as *const usize).offset(-1);
|
||||||
|
}
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
{
|
||||||
|
current_fp = *(current_fp as *const usize);
|
||||||
|
if current_fp != 0 {
|
||||||
|
current_pc = *(current_fp as *const usize).offset(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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…
Reference in new issue