Skip to content

Commit

Permalink
debuginfo: Improve source code position assignment for inlined functi…
Browse files Browse the repository at this point in the history
…ons.

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)
  • Loading branch information
michaelwoerister authored and alexcrichton committed Apr 10, 2014
1 parent 5bcb761 commit 43e8ace
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,21 +533,26 @@ pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) {
pub fn set_source_location(fcx: &FunctionContext,
node_id: ast::NodeId,
span: Span) {
if fn_should_be_ignored(fcx) {
return;
}

let cx = fcx.ccx;
match fcx.debug_context {
DebugInfoDisabled => return,
FunctionWithoutDebugInfo => {
set_debug_location(fcx.ccx, UnknownLocation);
return;
}
FunctionDebugContext(~ref function_debug_context) => {
let cx = fcx.ccx;

debug!("set_source_location: {}", cx.sess().codemap().span_to_str(span));
debug!("set_source_location: {}", cx.sess().codemap().span_to_str(span));

if fcx.debug_context.get_ref(cx, span).source_locations_enabled.get() {
let loc = span_start(cx, span);
let scope = scope_metadata(fcx, node_id, span);
if function_debug_context.source_locations_enabled.get() {
let loc = span_start(cx, span);
let scope = scope_metadata(fcx, node_id, span);

set_debug_location(cx, DebugLocation::new(scope, loc.line, loc.col.to_uint()));
} else {
set_debug_location(cx, UnknownLocation);
set_debug_location(cx, DebugLocation::new(scope, loc.line, loc.col.to_uint()));
} else {
set_debug_location(cx, UnknownLocation);
}
}
}
}

Expand Down Expand Up @@ -590,6 +595,10 @@ pub fn create_function_debug_context(cx: &CrateContext,
return DebugInfoDisabled;
}

// Clear the debug location so we don't assign them in the function prelude. Do this here
// already, in case we do an early exit from this function.
set_debug_location(cx, UnknownLocation);

if fn_ast_id == -1 {
return FunctionWithoutDebugInfo;
}
Expand Down Expand Up @@ -740,9 +749,6 @@ pub fn create_function_debug_context(cx: &CrateContext,
fn_metadata,
&mut *fn_debug_context.scope_map.borrow_mut());

// Clear the debug location so we don't assign them in the function prelude
set_debug_location(cx, UnknownLocation);

return FunctionDebugContext(fn_debug_context);

fn get_function_signature(cx: &CrateContext,
Expand Down

0 comments on commit 43e8ace

Please sign in to comment.