1 | use core::ffi::c_void; |
2 | use core::marker::PhantomData; |
3 | |
4 | use super::super::backtrace::miri::{resolve_addr, Frame}; |
5 | use super::BytesOrWideString; |
6 | use super::{ResolveWhat, SymbolName}; |
7 | |
8 | pub unsafe fn resolve(what: ResolveWhat<'_>, cb: &mut dyn FnMut(&super::Symbol)) { |
9 | let sym: Symbol<'_> = match what { |
10 | ResolveWhat::Address(addr: *mut c_void) => Symbol { |
11 | inner: resolve_addr(ptr:addr), |
12 | _unused: PhantomData, |
13 | }, |
14 | ResolveWhat::Frame(frame: &Frame) => Symbol { |
15 | inner: frame.inner.clone(), |
16 | _unused: PhantomData, |
17 | }, |
18 | }; |
19 | cb(&super::Symbol { inner: sym }) |
20 | } |
21 | |
22 | pub struct Symbol<'a> { |
23 | inner: Frame, |
24 | _unused: PhantomData<&'a ()>, |
25 | } |
26 | |
27 | impl<'a> Symbol<'a> { |
28 | pub fn name(&self) -> Option<SymbolName<'_>> { |
29 | Some(SymbolName::new(&self.inner.inner.name)) |
30 | } |
31 | |
32 | pub fn addr(&self) -> Option<*mut c_void> { |
33 | Some(self.inner.addr) |
34 | } |
35 | |
36 | pub fn filename_raw(&self) -> Option<BytesOrWideString<'_>> { |
37 | Some(BytesOrWideString::Bytes(&self.inner.inner.filename)) |
38 | } |
39 | |
40 | pub fn lineno(&self) -> Option<u32> { |
41 | Some(self.inner.inner.lineno) |
42 | } |
43 | |
44 | pub fn colno(&self) -> Option<u32> { |
45 | Some(self.inner.inner.colno) |
46 | } |
47 | |
48 | #[cfg (feature = "std" )] |
49 | pub fn filename(&self) -> Option<&std::path::Path> { |
50 | Some(std::path::Path::new( |
51 | core::str::from_utf8(&self.inner.inner.filename).unwrap(), |
52 | )) |
53 | } |
54 | } |
55 | |
56 | pub unsafe fn clear_symbol_cache() {} |
57 | |