Skip to content

Commit d113b39

Browse files
committed
Exclude top-level macro expansions from source location override.
1 parent c14f87e commit d113b39

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/librustc_trans/mir/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,20 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
138138
while span.expn_id != NO_EXPANSION && span.expn_id != COMMAND_LINE_EXPN {
139139
if let Some(callsite_span) = cm.with_expn_info(span.expn_id,
140140
|ei| ei.map(|ei| ei.call_site.clone())) {
141+
// When the current function itself is a result of macro expansion,
142+
// we stop at the function body level because no line stepping can occurr
143+
// at the level above that.
144+
if self.mir.span.expn_id != NO_EXPANSION &&
145+
span.expn_id == self.mir.span.expn_id {
146+
break;
147+
}
141148
span = callsite_span;
142149
} else {
143150
break;
144151
}
145152
}
146153
let scope = self.scope_metadata_for_loc(source_info.scope, span.lo);
147-
// Use span of the outermost call site, while keeping the original lexical scope
154+
// Use span of the outermost expansion site, while keeping the original lexical scope.
148155
(scope, span)
149156
}
150157
}

src/test/debuginfo/macro-stepping.inc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013-2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn included() {
12+
foo!(); // #inc-loc1
13+
14+
foo2!(); // #inc-loc2
15+
16+
zzz(); // #inc-loc3
17+
}

src/test/debuginfo/macro-stepping.rs

+26
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ extern crate macro_stepping; // exports new_scope!()
4444
// gdb-command:frame
4545
// gdb-check:[...]#loc6[...]
4646

47+
// gdb-command:continue
48+
// gdb-command:step
49+
// gdb-command:frame
50+
// gdb-check:[...]#inc-loc1[...]
51+
// gdb-command:next
52+
// gdb-command:frame
53+
// gdb-check:[...]#inc-loc2[...]
54+
// gdb-command:next
55+
// gdb-command:frame
56+
// gdb-check:[...]#inc-loc3[...]
57+
4758
// === LLDB TESTS ==================================================================================
4859

4960
// lldb-command:set set stop-line-count-before 0
@@ -68,6 +79,17 @@ extern crate macro_stepping; // exports new_scope!()
6879
// lldb-command:frame select
6980
// lldb-check:[...]#loc5[...]
7081

82+
// lldb-command:continue
83+
// lldb-command:step
84+
// lldb-command:frame select
85+
// lldb-check:[...]#inc-loc1[...]
86+
// lldb-command:next
87+
// lldb-command:frame select
88+
// lldb-check:[...]#inc-loc2[...]
89+
// lldb-command:next
90+
// lldb-command:frame select
91+
// lldb-check:[...]#inc-loc3[...]
92+
7193
macro_rules! foo {
7294
() => {
7395
let a = 1;
@@ -99,6 +121,10 @@ fn main() {
99121
"world");
100122

101123
zzz(); // #loc6
124+
125+
included(); // #break
102126
}
103127

104128
fn zzz() {()}
129+
130+
include!("macro-stepping.inc");

0 commit comments

Comments
 (0)