Skip to main content

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
16#[inline]
17pub fn backtrace_request_thread(koid: u64) {
18    unsafe { ext::backtrace_request_thread_for_rust(koid) };
19}
20
21pub fn is_debugger_attached() -> bool {
22    unsafe { ext::is_debugger_attached_for_rust() }
23}
24
25pub fn wait_for_debugger(seconds: u32) {
26    unsafe { ext::wait_for_debugger_for_rust(seconds) };
27}
28
29mod ext {
30    unsafe extern "C" {
31        pub(crate) fn backtrace_request_all_threads_for_rust();
32        pub(crate) fn backtrace_request_current_thread_for_rust();
33        pub(crate) fn backtrace_request_thread_for_rust(koid: u64);
34        pub(crate) fn is_debugger_attached_for_rust() -> bool;
35        pub(crate) fn wait_for_debugger_for_rust(seconds: u32);
36    }
37}
38
39#[cfg(test)]
40mod tests {
41
42    #[test]
43    fn call_backtrace() {
44        super::backtrace_request_all_threads();
45    }
46}