Skip to content

Commit 1d0b473

Browse files
committed
f use symbol addr, not instruction pointer, solving inlining issues
1 parent 873c711 commit 1d0b473

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lightning/src/debug_sync.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,24 @@ impl LockMetadata {
104104

105105
#[cfg(feature = "backtrace")]
106106
{
107-
let mut ip = None;
107+
let mut symbol_ptr = None;
108108
// Find the first frame which is after `debug_sync` (or which is in our tests) and use
109109
// that as the mutex construction site. Note that the first few frames may be in
110110
// `backtrace`, so we have to ignore those.
111111
let sync_mutex_constr_regex = regex::Regex::new(r"lightning.*debug_sync.*new").unwrap();
112112
let mut found_debug_sync = false;
113-
for frame in backtrace.frames() {
114-
// If a constructor was inlined we should take the frame in which it was inlined
115-
// (as its specific to the callsite), thus we look at the last available symbol,
116-
// which the `backtrace` docs say will be the caller.
117-
let symbol_name = frame.symbols().last().unwrap().name().unwrap().as_str().unwrap();
118-
if !sync_mutex_constr_regex.is_match(symbol_name) {
119-
if found_debug_sync {
120-
ip = Some(frame.ip() as usize as u64);
121-
break;
122-
}
123-
} else { found_debug_sync = true; }
113+
'trace_walk: for frame in backtrace.frames() {
114+
for symbol in frame.symbols() {
115+
let symbol_name = symbol.name().unwrap().as_str().unwrap();
116+
if !sync_mutex_constr_regex.is_match(symbol_name) {
117+
if found_debug_sync {
118+
symbol_ptr = Some(symbol.addr().unwrap() as usize as u64);
119+
break 'trace_walk;
120+
}
121+
} else { found_debug_sync = true; }
122+
}
124123
}
125-
lock_idx = ip.unwrap();
124+
lock_idx = symbol_ptr.unwrap();
126125
LOCKS_INIT.call_once(|| { unsafe { LOCKS = Some(StdMutex::new(HashMap::new())); } });
127126
if let Some(metadata) = unsafe { LOCKS.as_ref() }.unwrap().lock().unwrap().get(&lock_idx) {
128127
return Arc::clone(&metadata);

0 commit comments

Comments
 (0)