Skip to content

Commit

Permalink
Rollup merge of rust-lang#39678 - vadimcn:top-level-expn, r=michaelwo…
Browse files Browse the repository at this point in the history
…erister

Exclude top-level macro expansions from source location override.

It occurred to me that a simple heuristic can address the issue rust-lang#36382: any macros that expand into items (including `include!()`) don't need to be stepped over because there's not code to step through above a function scope level.

r? @michaelwoerister
  • Loading branch information
frewsxcv committed Feb 9, 2017
2 parents 711b95f + d113b39 commit 7bd0da7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/librustc_trans/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
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)
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/debuginfo/macro-stepping.inc
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
26 changes: 26 additions & 0 deletions src/test/debuginfo/macro-stepping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ extern crate macro_stepping; // exports new_scope!()
// 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
Expand All @@ -68,6 +79,17 @@ extern crate macro_stepping; // exports new_scope!()
// 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;
Expand Down Expand Up @@ -99,6 +121,10 @@ fn main() {
"world");

zzz(); // #loc6

included(); // #break
}

fn zzz() {()}

include!("macro-stepping.inc");

0 comments on commit 7bd0da7

Please sign in to comment.