@@ -697,6 +697,7 @@ struct FunctionDebugContextData {
697
697
fn_metadata : DISubprogram ,
698
698
argument_counter : Cell < uint > ,
699
699
source_locations_enabled : Cell < bool > ,
700
+ source_location_override : Cell < bool > ,
700
701
}
701
702
702
703
enum VariableAccess < ' a > {
@@ -1176,6 +1177,12 @@ pub fn set_source_location(fcx: &FunctionContext,
1176
1177
return ;
1177
1178
}
1178
1179
FunctionDebugContext :: RegularContext ( box ref function_debug_context) => {
1180
+ if function_debug_context. source_location_override . get ( ) {
1181
+ // Just ignore any attempts to set a new debug location while
1182
+ // the override is active.
1183
+ return ;
1184
+ }
1185
+
1179
1186
let cx = fcx. ccx ;
1180
1187
1181
1188
debug ! ( "set_source_location: {}" , cx. sess( ) . codemap( ) . span_to_string( span) ) ;
@@ -1194,6 +1201,35 @@ pub fn set_source_location(fcx: &FunctionContext,
1194
1201
}
1195
1202
}
1196
1203
1204
+ /// This function makes sure that all debug locations emitted while executing
1205
+ /// `wrapped_function` are set to the given `debug_loc`.
1206
+ pub fn with_source_location_override < F , R > ( fcx : & FunctionContext ,
1207
+ debug_loc : DebugLoc ,
1208
+ wrapped_function : F ) -> R
1209
+ where F : FnOnce ( ) -> R
1210
+ {
1211
+ match fcx. debug_context {
1212
+ FunctionDebugContext :: DebugInfoDisabled => {
1213
+ wrapped_function ( )
1214
+ }
1215
+ FunctionDebugContext :: FunctionWithoutDebugInfo => {
1216
+ set_debug_location ( fcx. ccx , UnknownLocation ) ;
1217
+ wrapped_function ( )
1218
+ }
1219
+ FunctionDebugContext :: RegularContext ( box ref function_debug_context) => {
1220
+ if function_debug_context. source_location_override . get ( ) {
1221
+ wrapped_function ( )
1222
+ } else {
1223
+ debug_loc. apply ( fcx) ;
1224
+ function_debug_context. source_location_override . set ( true ) ;
1225
+ let result = wrapped_function ( ) ;
1226
+ function_debug_context. source_location_override . set ( false ) ;
1227
+ result
1228
+ }
1229
+ }
1230
+ }
1231
+ }
1232
+
1197
1233
/// Clears the current debug location.
1198
1234
///
1199
1235
/// Instructions generated hereafter won't be assigned a source location.
@@ -1414,6 +1450,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1414
1450
fn_metadata : fn_metadata,
1415
1451
argument_counter : Cell :: new ( 1 ) ,
1416
1452
source_locations_enabled : Cell :: new ( false ) ,
1453
+ source_location_override : Cell :: new ( false ) ,
1417
1454
} ;
1418
1455
1419
1456
0 commit comments