Skip to content

Commit 43e8ace

Browse files
michaelwoeristeralexcrichton
authored andcommitted
debuginfo: Improve source code position assignment for inlined functions.
This commit makes sure that code inlined from other functions isn't assigned the source position of the call site, since this leads to undesired behavior when setting line breakpoints (issue rust-lang#12886)
1 parent 5bcb761 commit 43e8ace

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/librustc/middle/trans/debuginfo.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -533,21 +533,26 @@ pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) {
533533
pub fn set_source_location(fcx: &FunctionContext,
534534
node_id: ast::NodeId,
535535
span: Span) {
536-
if fn_should_be_ignored(fcx) {
537-
return;
538-
}
539-
540-
let cx = fcx.ccx;
536+
match fcx.debug_context {
537+
DebugInfoDisabled => return,
538+
FunctionWithoutDebugInfo => {
539+
set_debug_location(fcx.ccx, UnknownLocation);
540+
return;
541+
}
542+
FunctionDebugContext(~ref function_debug_context) => {
543+
let cx = fcx.ccx;
541544

542-
debug!("set_source_location: {}", cx.sess().codemap().span_to_str(span));
545+
debug!("set_source_location: {}", cx.sess().codemap().span_to_str(span));
543546

544-
if fcx.debug_context.get_ref(cx, span).source_locations_enabled.get() {
545-
let loc = span_start(cx, span);
546-
let scope = scope_metadata(fcx, node_id, span);
547+
if function_debug_context.source_locations_enabled.get() {
548+
let loc = span_start(cx, span);
549+
let scope = scope_metadata(fcx, node_id, span);
547550

548-
set_debug_location(cx, DebugLocation::new(scope, loc.line, loc.col.to_uint()));
549-
} else {
550-
set_debug_location(cx, UnknownLocation);
551+
set_debug_location(cx, DebugLocation::new(scope, loc.line, loc.col.to_uint()));
552+
} else {
553+
set_debug_location(cx, UnknownLocation);
554+
}
555+
}
551556
}
552557
}
553558

@@ -590,6 +595,10 @@ pub fn create_function_debug_context(cx: &CrateContext,
590595
return DebugInfoDisabled;
591596
}
592597

598+
// Clear the debug location so we don't assign them in the function prelude. Do this here
599+
// already, in case we do an early exit from this function.
600+
set_debug_location(cx, UnknownLocation);
601+
593602
if fn_ast_id == -1 {
594603
return FunctionWithoutDebugInfo;
595604
}
@@ -740,9 +749,6 @@ pub fn create_function_debug_context(cx: &CrateContext,
740749
fn_metadata,
741750
&mut *fn_debug_context.scope_map.borrow_mut());
742751

743-
// Clear the debug location so we don't assign them in the function prelude
744-
set_debug_location(cx, UnknownLocation);
745-
746752
return FunctionDebugContext(fn_debug_context);
747753

748754
fn get_function_signature(cx: &CrateContext,

0 commit comments

Comments
 (0)