Skip to content

Commit d8562f0

Browse files
committed
f
1 parent 7d9ba2f commit d8562f0

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

lightning/src/debug_sync.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,34 @@ impl LockMetadata {
105105
#[cfg(feature = "backtrace")]
106106
{
107107
let mut ip = None;
108-
// Find the first frame which was *not* in debug_sync (or which is in our tests) and
109-
// use that as the mutex construction site. The second frame should always be in
110-
// debug_sync (the first may be in Backtrace itself).
108+
// Find the first frame which is after `debug_sync` (or which is in our tests) and use
109+
// that as the mutex construction site. Note that the first few frames may be in
110+
// `backtrace`, so we have to ignore those.
111111
let sync_mutex_constr_regex = regex::Regex::new(r"lightning.*debug_sync.*new").unwrap();
112112
for frame in backtrace.frames() {
113113
for symbol in frame.symbols() {
114114
eprint!("{} ", symbol.name().unwrap().as_str().unwrap());
115115
}
116116
eprintln!("- {:p}", frame.ip());
117117
}
118-
assert!(sync_mutex_constr_regex.is_match(backtrace.frames()[0].symbols().last().unwrap().name().unwrap().as_str().unwrap()) ||
119-
sync_mutex_constr_regex.is_match(backtrace.frames()[1].symbols().last().unwrap().name().unwrap().as_str().unwrap()) ||
120-
sync_mutex_constr_regex.is_match(backtrace.frames().get(2).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
121-
sync_mutex_constr_regex.is_match(backtrace.frames().get(3).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
122-
sync_mutex_constr_regex.is_match(backtrace.frames().get(4).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
123-
sync_mutex_constr_regex.is_match(backtrace.frames().get(5).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
124-
sync_mutex_constr_regex.is_match(backtrace.frames().get(6).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")),
125-
"should contain lightning...debug_sync...new");
118+
assert!(sync_mutex_constr_regex.is_match(backtrace.frames()[0].symbols().last().unwrap().name().unwrap().as_str().unwrap()) ||
119+
sync_mutex_constr_regex.is_match(backtrace.frames()[1].symbols().last().unwrap().name().unwrap().as_str().unwrap()) ||
120+
sync_mutex_constr_regex.is_match(backtrace.frames().get(2).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
121+
sync_mutex_constr_regex.is_match(backtrace.frames().get(3).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
122+
sync_mutex_constr_regex.is_match(backtrace.frames().get(4).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
123+
sync_mutex_constr_regex.is_match(backtrace.frames().get(5).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")) ||
124+
sync_mutex_constr_regex.is_match(backtrace.frames().get(6).map(|f| f.symbols().last().unwrap().name().unwrap().as_str().unwrap()).unwrap_or("")),
125+
"should contain lightning...debug_sync...new");
126+
let mut found_debug_sync = false;
126127
for frame in backtrace.frames() {
127128
let symbol_name = frame.symbols().last().unwrap().name().unwrap().as_str().unwrap();
128129
if !sync_mutex_constr_regex.is_match(symbol_name) {
130+
if found_debug_sync {
129131
eprintln!("Picked framepointer {:p}", frame.ip());
130-
ip = Some(frame.ip() as usize as u64);
131-
break;
132-
}
132+
ip = Some(frame.ip() as usize as u64);
133+
break;
134+
}
135+
} else { found_debug_sync = true; }
133136
}
134137
lock_idx = ip.unwrap();
135138
LOCKS_INIT.call_once(|| { unsafe { LOCKS = Some(StdMutex::new(HashMap::new())); } });

0 commit comments

Comments
 (0)