Skip to content

Commit 092cae1

Browse files
committed
Dont single step into macros
Fixes #782
1 parent ce4c514 commit 092cae1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/debuginfo/line_info.rs

+15
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,23 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
122122
blocks.sort_by_key(|block| func.offsets[*block]); // Ensure inst offsets always increase
123123

124124
let line_strings = &mut self.debug_context.dwarf.line_strings;
125+
let function_span = self.mir.span;
125126
let mut last_file = None;
126127
let mut create_row_for_span = |line_program: &mut LineProgram, span: Span| {
128+
// Based on https://github.com/rust-lang/rust/blob/e369d87b015a84653343032833d65d0545fd3f26/src/librustc_codegen_ssa/mir/mod.rs#L116-L131
129+
// In order to have a good line stepping behavior in debugger, we overwrite debug
130+
// locations of macro expansions with that of the outermost expansion site
131+
// (unless the crate is being compiled with `-Z debug-macros`).
132+
let span = if !span.from_expansion() ||
133+
tcx.sess.opts.debugging_opts.debug_macros {
134+
span
135+
} else {
136+
// Walk up the macro expansion chain until we reach a non-expanded span.
137+
// We also stop at the function body level because no line stepping can occur
138+
// at the level above that.
139+
rustc_span::hygiene::walk_chain(span, function_span.ctxt())
140+
};
141+
127142
let loc = tcx.sess.source_map().lookup_char_pos(span.lo());
128143

129144
// line_program_add_file is very slow.

0 commit comments

Comments
 (0)