Skip to content

Commit 9062988

Browse files
committed
auto merge of #10552 : michaelwoerister/rust/ifstepping, r=brson
This PR improves the single-stepping experience for if-expression (no more jumping into the *else* branch before entering the *then* branch, no more jumping to the end of the *else* branch after finishing the *then* branch). Unfortunately I don't know of a straight-forward way of writing automated tests for this. Suggestions welcome!
2 parents 3d569df + d0872eb commit 9062988

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/librustc/middle/trans/controlflow.rs

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use middle::trans::base::*;
1414
use middle::trans::build::*;
1515
use middle::trans::callee;
1616
use middle::trans::common::*;
17+
use middle::trans::debuginfo;
1718
use middle::trans::expr;
1819
use middle::ty;
1920
use util::common::indenter;
@@ -75,6 +76,7 @@ pub fn trans_if(bcx: @mut Block,
7576
// if true { .. } [else { .. }]
7677
return do with_scope(bcx, thn.info(), "if_true_then") |bcx| {
7778
let bcx_out = trans_block(bcx, thn, dest);
79+
debuginfo::clear_source_location(bcx.fcx);
7880
trans_block_cleanups(bcx_out, block_cleanups(bcx))
7981
}
8082
} else {
@@ -86,6 +88,7 @@ pub fn trans_if(bcx: @mut Block,
8688
Some(elexpr) => {
8789
return do with_scope(bcx, elexpr.info(), "if_false_then") |bcx| {
8890
let bcx_out = trans_if_else(bcx, elexpr, dest);
91+
debuginfo::clear_source_location(bcx.fcx);
8992
trans_block_cleanups(bcx_out, block_cleanups(bcx))
9093
}
9194
}
@@ -98,6 +101,8 @@ pub fn trans_if(bcx: @mut Block,
98101
let then_bcx_in = scope_block(bcx, thn.info(), "then");
99102

100103
let then_bcx_out = trans_block(then_bcx_in, thn, dest);
104+
105+
debuginfo::clear_source_location(bcx.fcx);
101106
let then_bcx_out = trans_block_cleanups(then_bcx_out,
102107
block_cleanups(then_bcx_in));
103108

@@ -122,6 +127,9 @@ pub fn trans_if(bcx: @mut Block,
122127
debug!("then_bcx_in={}, else_bcx_in={}",
123128
then_bcx_in.to_str(), else_bcx_in.to_str());
124129

130+
// Clear the source location because it is still set to whatever has been translated
131+
// right before.
132+
debuginfo::clear_source_location(else_bcx_in.fcx);
125133
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
126134
return next_bcx;
127135

@@ -139,6 +147,7 @@ pub fn trans_if(bcx: @mut Block,
139147
// would be nice to have a constraint on ifs
140148
_ => else_bcx_in.tcx().sess.bug("strange alternative in if")
141149
};
150+
debuginfo::clear_source_location(else_bcx_in.fcx);
142151
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
143152
}
144153
}

src/librustc/middle/trans/debuginfo.rs

+11
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,17 @@ pub fn set_source_location(fcx: &FunctionContext,
509509
}
510510
}
511511

512+
/// Clears the current debug location.
513+
///
514+
/// Instructions generated hereafter won't be assigned a source location.
515+
pub fn clear_source_location(fcx: &FunctionContext) {
516+
if fn_should_be_ignored(fcx) {
517+
return;
518+
}
519+
520+
set_debug_location(fcx.ccx, UnknownLocation);
521+
}
522+
512523
/// Enables emitting source locations for the given functions.
513524
///
514525
/// Since we don't want source locations to be emitted for the function prelude, they are disabled

0 commit comments

Comments
 (0)