Skip to content

Commit 4b7b021

Browse files
committed
rustc_codegen_llvm/gcc: Add debug locations to write_operand_repeatedly()
So that stepping with a debugger over lines such as: let h = ["whatever"; 8]; works. Use the same technique as we already do in `cfi_type_test()`. Since all emitted LLVM instructions are looped over, a debugger will unfortunately step as many times as we repeat. Not sure how to solve that. It can become quite annoying if you have say `1024` repetitions.
1 parent ff5be13 commit 4b7b021

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10831083
let start = dest.project_index(self, zero).val.llval;
10841084
let end = dest.project_index(self, count).val.llval;
10851085

1086+
// Sibling blocks have the same debug location as the original block.
1087+
let dbg_loc = self.get_dbg_loc();
10861088
let header_bb = self.append_sibling_block("repeat_loop_header");
10871089
let body_bb = self.append_sibling_block("repeat_loop_body");
10881090
let next_bb = self.append_sibling_block("repeat_loop_next");
@@ -1095,10 +1097,16 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10951097
self.br(header_bb);
10961098

10971099
self.switch_to_block(header_bb);
1100+
if let Some(dbg_loc) = dbg_loc {
1101+
self.set_dbg_loc(dbg_loc);
1102+
}
10981103
let keep_going = self.icmp(IntPredicate::IntNE, current_val, end);
10991104
self.cond_br(keep_going, body_bb, next_bb);
11001105

11011106
self.switch_to_block(body_bb);
1107+
if let Some(dbg_loc) = dbg_loc {
1108+
self.set_dbg_loc(dbg_loc);
1109+
}
11021110
let align = dest.val.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
11031111
cg_elem.val.store(self, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align));
11041112

@@ -1111,6 +1119,9 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11111119
self.br(header_bb);
11121120

11131121
self.switch_to_block(next_bb);
1122+
if let Some(dbg_loc) = dbg_loc {
1123+
self.set_dbg_loc(dbg_loc);
1124+
}
11141125
}
11151126

11161127
fn range_metadata(&mut self, _load: RValue<'gcc>, _range: WrappingRange) {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,19 +770,27 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
770770
let zero = self.const_usize(0);
771771
let count = self.const_usize(count);
772772

773+
// Sibling blocks have the same debug location as the original block.
774+
let dbg_loc = self.get_dbg_loc();
773775
let header_bb = self.append_sibling_block("repeat_loop_header");
774776
let body_bb = self.append_sibling_block("repeat_loop_body");
775777
let next_bb = self.append_sibling_block("repeat_loop_next");
776778

777779
self.br(header_bb);
778780

779781
let mut header_bx = Self::build(self.cx, header_bb);
782+
if let Some(dbg_loc) = dbg_loc {
783+
header_bx.set_dbg_loc(dbg_loc);
784+
}
780785
let i = header_bx.phi(self.val_ty(zero), &[zero], &[self.llbb()]);
781786

782787
let keep_going = header_bx.icmp(IntPredicate::IntULT, i, count);
783788
header_bx.cond_br(keep_going, body_bb, next_bb);
784789

785790
let mut body_bx = Self::build(self.cx, body_bb);
791+
if let Some(dbg_loc) = dbg_loc {
792+
body_bx.set_dbg_loc(dbg_loc);
793+
}
786794
let dest_elem = dest.project_index(&mut body_bx, i);
787795
cg_elem.val.store(&mut body_bx, dest_elem);
788796

@@ -791,6 +799,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
791799
header_bx.add_incoming_to_phi(i, next, body_bb);
792800

793801
*self = Self::build(self.cx, next_bb);
802+
if let Some(dbg_loc) = dbg_loc {
803+
self.set_dbg_loc(dbg_loc);
804+
}
794805
}
795806

796807
fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) {
@@ -1825,6 +1836,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18251836
cfi::typeid_for_fnabi(self.tcx, fn_abi, options)
18261837
};
18271838
let typeid_metadata = self.cx.create_metadata(typeid.as_bytes());
1839+
// Sibling blocks have the same debug location as the original block.
18281840
let dbg_loc = self.get_dbg_loc();
18291841

18301842
// Test whether the function pointer is associated with the type identifier using the

tests/debuginfo/basic-stepping.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,25 @@
2020
// FIXME(#33013): gdb-command: next
2121
// FIXME(#33013): gdb-check: let g = b'9';
2222
// FIXME(#33013): gdb-command: next
23-
// FIXME(#33013): gdb-check: let h = ["whatever"; 8];
24-
// FIXME(#33013): gdb-command: next
23+
// FIXME(#33013): Don't step 8 times. Tricky, because all emitted LLVM instructions are looped over.
24+
// gdb-check: let h = ["whatever"; 8];
25+
// gdb-command: next
26+
// gdb-check: let h = ["whatever"; 8];
27+
// gdb-command: next
28+
// gdb-check: let h = ["whatever"; 8];
29+
// gdb-command: next
30+
// gdb-check: let h = ["whatever"; 8];
31+
// gdb-command: next
32+
// gdb-check: let h = ["whatever"; 8];
33+
// gdb-command: next
34+
// gdb-check: let h = ["whatever"; 8];
35+
// gdb-command: next
36+
// gdb-check: let h = ["whatever"; 8];
37+
// gdb-command: next
38+
// gdb-check: let h = ["whatever"; 8];
39+
// gdb-command: next
40+
// gdb-check: let h = ["whatever"; 8];
41+
// gdb-command: next
2542
// gdb-check: let i = [1,2,3,4];
2643
// gdb-command: next
2744
// gdb-check: let j = (23, "hi");

0 commit comments

Comments
 (0)