@@ -31,24 +31,41 @@ pub enum Symbol {
31
31
filename : * const c_char ,
32
32
lineno : c_int ,
33
33
function : * const c_char ,
34
+ symname : * const c_char ,
34
35
} ,
35
36
}
36
37
37
38
impl Symbol {
38
39
pub fn name ( & self ) -> Option < SymbolName > {
39
- let ptr = match * self {
40
- Symbol :: Syminfo { symname, .. } => symname,
41
- Symbol :: Pcinfo { function, .. } => function,
42
- } ;
43
- if ptr. is_null ( ) {
44
- None
45
- } else {
40
+ let symbol = |ptr : * const c_char | {
46
41
unsafe {
47
- let len = libc:: strlen ( ptr) ;
48
- Some ( SymbolName :: new ( slice:: from_raw_parts (
49
- ptr as * const u8 ,
50
- len,
51
- ) ) )
42
+ if ptr. is_null ( ) {
43
+ None
44
+ } else {
45
+ let len = libc:: strlen ( ptr) ;
46
+ Some ( SymbolName :: new ( slice:: from_raw_parts (
47
+ ptr as * const u8 ,
48
+ len,
49
+ ) ) )
50
+ }
51
+ }
52
+ } ;
53
+ match * self {
54
+ Symbol :: Syminfo { symname, .. } => symbol ( symname) ,
55
+ Symbol :: Pcinfo { function, symname, .. } => {
56
+ // If possible prefer the `function` name which comes from
57
+ // debuginfo and can typically be more accurate for inline
58
+ // frames for example. If that's not present though fall back to
59
+ // the symbol table name specified in `symname`.
60
+ //
61
+ // Note that sometimes `function` can feel somewhat less
62
+ // accurate, for example being listed as `try<i32,closure>`
63
+ // isntead of `std::panicking::try::do_call`. It's not really
64
+ // clear why, but overall the `function` name seems more accurate.
65
+ if let Some ( sym) = symbol ( function) {
66
+ return Some ( sym)
67
+ }
68
+ symbol ( symname)
52
69
}
53
70
}
54
71
}
@@ -187,17 +204,8 @@ extern "C" fn pcinfo_cb(
187
204
pc : pc,
188
205
filename : filename,
189
206
lineno : lineno,
190
-
191
- // Favor the function name going into the `syminfo_cb`. That's
192
- // typically from the symbol table and is the full symbol name
193
- // whereas the `function` above is coming from debuginfo which
194
- // isn't always as descriptive when considering the whole
195
- // program.
196
- function : if !state. symname . is_null ( ) {
197
- state. symname
198
- } else {
199
- function
200
- } ,
207
+ symname : state. symname ,
208
+ function,
201
209
} ,
202
210
} ) ;
203
211
bomb. enabled = false ;
0 commit comments