File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Windows only currently
2
+ use std:: os:: windows:: prelude:: AsRawHandle ;
3
+ use backtrace:: { Backtrace , BacktraceFrame } ;
4
+
5
+
6
+ fn worker ( ) {
7
+ foo ( ) ;
8
+ }
9
+ fn foo ( ) {
10
+ bar ( )
11
+ }
12
+ fn bar ( ) {
13
+ baz ( )
14
+ }
15
+ fn baz ( ) {
16
+ println ! ( "Hello from thread!" ) ;
17
+ // Sleep for simple sync. Can't read thread that has finished running
18
+ //std::thread::sleep(std::time::Duration::from_millis(1000));
19
+ loop {
20
+ print ! ( "" ) ;
21
+ } ;
22
+ }
23
+
24
+
25
+ fn main ( ) {
26
+ let thread = std:: thread:: spawn ( || {
27
+ worker ( ) ;
28
+ } ) ;
29
+ let os_handle = thread. as_raw_handle ( ) ;
30
+
31
+ // Allow the thread to start
32
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
33
+
34
+ let mut frames = Vec :: new ( ) ;
35
+ unsafe {
36
+ backtrace:: trace_thread_unsynchronized ( os_handle, |frame| {
37
+ frames. push ( BacktraceFrame :: from ( frame. clone ( ) ) ) ;
38
+ true
39
+ } ) ;
40
+ }
41
+
42
+ let mut bt = Backtrace :: from ( frames) ;
43
+ bt. resolve ( ) ;
44
+ println ! ( "{:?}" , bt) ;
45
+ }
You can’t perform that action at this time.
0 commit comments