1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Issues a backtrace request to the system crash service.
#[inline]
pub fn backtrace_request_all_threads() {
    unsafe { ext::backtrace_request_all_threads_for_rust() };
}

#[inline]
pub fn backtrace_request_current_thread() {
    unsafe { ext::backtrace_request_current_thread_for_rust() };
}

pub fn is_debugger_attached() -> bool {
    unsafe { ext::is_debugger_attached_for_rust() }
}

pub fn wait_for_debugger(seconds: u32) {
    unsafe { ext::wait_for_debugger_for_rust(seconds) };
}

mod ext {
    extern "C" {
        pub(crate) fn backtrace_request_all_threads_for_rust();
        pub(crate) fn backtrace_request_current_thread_for_rust();
        pub(crate) fn is_debugger_attached_for_rust() -> bool;
        pub(crate) fn wait_for_debugger_for_rust(seconds: u32);
    }
}

#[cfg(test)]
mod tests {

    #[test]
    fn call_backtrace() {
        super::backtrace_request_all_threads();
    }
}