diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index 8a0a97a5634..949e1dd92a6 100644 --- a/src/librustc_trans/mir/mod.rs +++ b/src/librustc_trans/mir/mod.rs @@ -138,13 +138,20 @@ pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> (DIScope, Span) { while span.expn_id != NO_EXPANSION && span.expn_id != COMMAND_LINE_EXPN { if let Some(callsite_span) = cm.with_expn_info(span.expn_id, |ei| ei.map(|ei| ei.call_site.clone())) { + // When the current function itself is a result of macro expansion, + // we stop at the function body level because no line stepping can occurr + // at the level above that. + if self.mir.span.expn_id != NO_EXPANSION && + span.expn_id == self.mir.span.expn_id { + break; + } span = callsite_span; } else { break; } } let scope = self.scope_metadata_for_loc(source_info.scope, span.lo); - // Use span of the outermost call site, while keeping the original lexical scope + // Use span of the outermost expansion site, while keeping the original lexical scope. (scope, span) } } diff --git a/src/test/debuginfo/macro-stepping.inc b/src/test/debuginfo/macro-stepping.inc new file mode 100644 index 00000000000..6aaf7ed421e --- /dev/null +++ b/src/test/debuginfo/macro-stepping.inc @@ -0,0 +1,17 @@ +// Copyright 2013-2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn included() { + foo!(); // #inc-loc1 + + foo2!(); // #inc-loc2 + + zzz(); // #inc-loc3 +} diff --git a/src/test/debuginfo/macro-stepping.rs b/src/test/debuginfo/macro-stepping.rs index 37355ed377b..ca2c1e0c8f0 100644 --- a/src/test/debuginfo/macro-stepping.rs +++ b/src/test/debuginfo/macro-stepping.rs @@ -44,6 +44,17 @@ // gdb-command:frame // gdb-check:[...]#loc6[...] +// gdb-command:continue +// gdb-command:step +// gdb-command:frame +// gdb-check:[...]#inc-loc1[...] +// gdb-command:next +// gdb-command:frame +// gdb-check:[...]#inc-loc2[...] +// gdb-command:next +// gdb-command:frame +// gdb-check:[...]#inc-loc3[...] + // === LLDB TESTS ================================================================================== // lldb-command:set set stop-line-count-before 0 @@ -68,6 +79,17 @@ // lldb-command:frame select // lldb-check:[...]#loc5[...] +// lldb-command:continue +// lldb-command:step +// lldb-command:frame select +// lldb-check:[...]#inc-loc1[...] +// lldb-command:next +// lldb-command:frame select +// lldb-check:[...]#inc-loc2[...] +// lldb-command:next +// lldb-command:frame select +// lldb-check:[...]#inc-loc3[...] + macro_rules! foo { () => { let a = 1; @@ -99,6 +121,10 @@ fn main() { "world"); zzz(); // #loc6 + + included(); // #break } fn zzz() {()} + +include!("macro-stepping.inc");