debug/
lib.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/// Issues a backtrace request to the system crash service.
6#[inline]
7pub fn backtrace_request_all_threads() {
8    unsafe { ext::backtrace_request_all_threads_for_rust() };
9}
10
11#[inline]
12pub fn backtrace_request_current_thread() {
13    unsafe { ext::backtrace_request_current_thread_for_rust() };
14}
15
16pub fn is_debugger_attached() -> bool {
17    unsafe { ext::is_debugger_attached_for_rust() }
18}
19
20pub fn wait_for_debugger(seconds: u32) {
21    unsafe { ext::wait_for_debugger_for_rust(seconds) };
22}
23
24mod ext {
25    extern "C" {
26        pub(crate) fn backtrace_request_all_threads_for_rust();
27        pub(crate) fn backtrace_request_current_thread_for_rust();
28        pub(crate) fn is_debugger_attached_for_rust() -> bool;
29        pub(crate) fn wait_for_debugger_for_rust(seconds: u32);
30    }
31}
32
33#[cfg(test)]
34mod tests {
35
36    #[test]
37    fn call_backtrace() {
38        super::backtrace_request_all_threads();
39    }
40}