Skip to content
Permalink
Browse files

fix frame-pointer stackwalking

  • Loading branch information...
gterzian committed Jan 6, 2019
1 parent aaf2c5a commit dcccceff24ff583fc954ccb17a2a5e67b9340927
Showing with 12 additions and 1 deletion.
  1. +12 −1 components/background_hang_monitor/sampler_mac.rs
@@ -96,14 +96,22 @@ unsafe fn frame_pointer_stack_walk(regs: Registers) -> NativeStack {
// --dev,
// or --with-frame-pointer.

let stackaddr = libc::pthread_get_stackaddr_np(libc::pthread_self());
let pthread_t = libc::pthread_self();
let stackaddr = libc::pthread_get_stackaddr_np(pthread_t);
let stacksize = libc::pthread_get_stacksize_np(pthread_t);
let mut native_stack = NativeStack::new();
let pc = regs.instruction_ptr as *mut std::ffi::c_void;
let stack = regs.stack_ptr as *mut std::ffi::c_void;
let _ = native_stack.process_register(pc, stack);
let mut current = regs.frame_ptr as *mut *mut std::ffi::c_void;
while !current.is_null() {
if (current as usize) < stackaddr as usize {
// Reached the end of the stack.
break;
}
if current as usize >= stackaddr.add(stacksize * 8) as usize {
// Reached the beginning of the stack.
// Assumining 64 bit mac(see the stacksize * 8).
break;
}
let next = *current as *mut *mut std::ffi::c_void;
@@ -112,6 +120,9 @@ unsafe fn frame_pointer_stack_walk(regs: Registers) -> NativeStack {
if let Err(()) = native_stack.process_register(*pc, *stack) {
break;
}
if (next <= current) || (next as usize & 3 != 0) {
break;
}
current = next;
}
native_stack

0 comments on commit dccccef

Please sign in to comment.
You can’t perform that action at this time.