From 43e8ace76b01820032679f276f3e298b92288ad6 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 27 Mar 2014 13:43:01 +0100 Subject: [PATCH] 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 #12886) --- src/librustc/middle/trans/debuginfo.rs | 36 +++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 8a7f30ee2c4..6f6484ae1a5 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -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; - } + match fcx.debug_context { + DebugInfoDisabled => return, + FunctionWithoutDebugInfo => { + set_debug_location(fcx.ccx, UnknownLocation); + return; + } + FunctionDebugContext(~ref function_debug_context) => { + let cx = fcx.ccx; - 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 function_debug_context.source_locations_enabled.get() { + let loc = span_start(cx, span); + let scope = scope_metadata(fcx, node_id, 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); - - 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); + } + } } } @@ -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; } @@ -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,