@@ -105,31 +105,34 @@ impl LockMetadata {
105
105
#[ cfg( feature = "backtrace" ) ]
106
106
{
107
107
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 .
111
111
let sync_mutex_constr_regex = regex:: Regex :: new ( r"lightning.*debug_sync.*new" ) . unwrap ( ) ;
112
112
for frame in backtrace. frames ( ) {
113
113
for symbol in frame. symbols ( ) {
114
114
eprint ! ( "{} " , symbol. name( ) . unwrap( ) . as_str( ) . unwrap( ) ) ;
115
115
}
116
116
eprintln ! ( "- {:p}" , frame. ip( ) ) ;
117
117
}
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 ;
126
127
for frame in backtrace. frames ( ) {
127
128
let symbol_name = frame. symbols ( ) . last ( ) . unwrap ( ) . name ( ) . unwrap ( ) . as_str ( ) . unwrap ( ) ;
128
129
if !sync_mutex_constr_regex. is_match ( symbol_name) {
130
+ if found_debug_sync {
129
131
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 ; }
133
136
}
134
137
lock_idx = ip. unwrap ( ) ;
135
138
LOCKS_INIT . call_once ( || { unsafe { LOCKS = Some ( StdMutex :: new ( HashMap :: new ( ) ) ) ; } } ) ;
0 commit comments