Skip to content

Commit f8bfc83

Browse files
committed
fixup! codegen: Generate dbg_value for the ref statement
1 parent 458ad93 commit f8bfc83

File tree

4 files changed

+89
-41
lines changed

4 files changed

+89
-41
lines changed

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
2626
&mut self,
2727
_dbg_var: Self::DIVariable,
2828
_dbg_loc: Self::DILocation,
29-
is_declared: bool,
30-
val: Self::Value,
29+
_variable_alloca: Self::Value,
3130
_direct_offset: Size,
3231
_indirect_offsets: &[Size],
3332
_fragment: Option<Range<Size>>,
3433
) {
3534
// FIXME(tempdragon): Not sure if this is correct, probably wrong but still keep it here.
3635
#[cfg(feature = "master")]
37-
if is_declared {
38-
val.set_location(_dbg_loc);
39-
}
36+
val.set_location(_dbg_loc);
37+
}
38+
39+
fn dbg_var_value(
40+
&mut self,
41+
dbg_var: Self::DIVariable,
42+
dbg_loc: Self::DILocation,
43+
value: Self::Value,
44+
direct_offset: Size,
45+
// NB: each offset implies a deref (i.e. they're steps in a pointer chain).
46+
indirect_offsets: &[Size],
47+
// Byte range in the `dbg_var` covered by this fragment,
48+
// if this is a fragment of a composite `DIVariable`.
49+
fragment: Option<Range<Size>>,
50+
) {
4051
}
4152

4253
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,19 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
160160
&mut self,
161161
dbg_var: &'ll DIVariable,
162162
dbg_loc: &'ll DILocation,
163-
is_declared: bool,
164-
val: Self::Value,
163+
variable_alloca: Self::Value,
165164
direct_offset: Size,
166165
indirect_offsets: &[Size],
167166
fragment: Option<Range<Size>>,
168167
) {
169-
use dwarf_const::{DW_OP_LLVM_fragment, DW_OP_deref, DW_OP_plus_uconst, DW_OP_stack_value};
168+
use dwarf_const::{DW_OP_LLVM_fragment, DW_OP_deref, DW_OP_plus_uconst};
170169

171170
// Convert the direct and indirect offsets and fragment byte range to address ops.
172171
let mut addr_ops = SmallVec::<[u64; 8]>::new();
173172

174173
if direct_offset.bytes() > 0 {
175174
addr_ops.push(DW_OP_plus_uconst);
176175
addr_ops.push(direct_offset.bytes() as u64);
177-
if !is_declared {
178-
addr_ops.push(DW_OP_stack_value);
179-
}
180176
}
181177
for &offset in indirect_offsets {
182178
addr_ops.push(DW_OP_deref);
@@ -193,31 +189,64 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
193189
addr_ops.push((fragment.end - fragment.start).bits() as u64);
194190
}
195191

196-
if is_declared {
197-
unsafe {
198-
llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
199-
DIB(self.cx()),
200-
val,
201-
dbg_var,
202-
addr_ops.as_ptr(),
203-
addr_ops.len() as c_uint,
204-
dbg_loc,
205-
self.llbb(),
206-
);
207-
}
208-
} else {
209-
unsafe {
210-
llvm::LLVMRustDIBuilderInsertDbgValueAtEnd(
211-
DIB(self.cx()),
212-
val,
213-
dbg_var,
214-
addr_ops.as_ptr(),
215-
addr_ops.len() as c_uint,
216-
dbg_loc,
217-
self.llbb(),
218-
);
192+
unsafe {
193+
llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
194+
DIB(self.cx()),
195+
variable_alloca,
196+
dbg_var,
197+
addr_ops.as_ptr(),
198+
addr_ops.len() as c_uint,
199+
dbg_loc,
200+
self.llbb(),
201+
);
202+
}
203+
}
204+
205+
fn dbg_var_value(
206+
&mut self,
207+
dbg_var: &'ll DIVariable,
208+
dbg_loc: &'ll DILocation,
209+
value: Self::Value,
210+
direct_offset: Size,
211+
indirect_offsets: &[Size],
212+
fragment: Option<Range<Size>>,
213+
) {
214+
use dwarf_const::{DW_OP_LLVM_fragment, DW_OP_deref, DW_OP_plus_uconst, DW_OP_stack_value};
215+
216+
// Convert the direct and indirect offsets and fragment byte range to address ops.
217+
let mut addr_ops = SmallVec::<[u64; 8]>::new();
218+
219+
if direct_offset.bytes() > 0 {
220+
addr_ops.push(DW_OP_plus_uconst);
221+
addr_ops.push(direct_offset.bytes() as u64);
222+
addr_ops.push(DW_OP_stack_value);
223+
}
224+
for &offset in indirect_offsets {
225+
addr_ops.push(DW_OP_deref);
226+
if offset.bytes() > 0 {
227+
addr_ops.push(DW_OP_plus_uconst);
228+
addr_ops.push(offset.bytes() as u64);
219229
}
220230
}
231+
if let Some(fragment) = fragment {
232+
// `DW_OP_LLVM_fragment` takes as arguments the fragment's
233+
// offset and size, both of them in bits.
234+
addr_ops.push(DW_OP_LLVM_fragment);
235+
addr_ops.push(fragment.start.bits() as u64);
236+
addr_ops.push((fragment.end - fragment.start).bits() as u64);
237+
}
238+
239+
unsafe {
240+
llvm::LLVMRustDIBuilderInsertDbgValueAtEnd(
241+
DIB(self.cx()),
242+
value,
243+
dbg_var,
244+
addr_ops.as_ptr(),
245+
addr_ops.len() as c_uint,
246+
dbg_loc,
247+
self.llbb(),
248+
);
249+
}
221250
}
222251

223252
fn set_dbg_loc(&mut self, dbg_loc: &'ll DILocation) {

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
288288
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { return };
289289
let DebugInfoOffset { direct_offset, indirect_offsets, result: _ } =
290290
calculate_debuginfo_offset(bx, projection, layout);
291-
bx.dbg_var_addr(
291+
bx.dbg_var_value(
292292
dbg_var,
293293
dbg_loc,
294-
false,
295294
base.llval,
296295
direct_offset,
297296
&indirect_offsets,
@@ -467,7 +466,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
467466
bx.dbg_var_addr(
468467
dbg_var,
469468
dbg_loc,
470-
true,
471469
alloca.val.llval,
472470
Size::ZERO,
473471
&[Size::ZERO],
@@ -477,7 +475,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
477475
bx.dbg_var_addr(
478476
dbg_var,
479477
dbg_loc,
480-
true,
481478
base.val.llval,
482479
direct_offset,
483480
&indirect_offsets,
@@ -503,7 +500,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
503500
let base = FunctionCx::spill_operand_to_stack(operand, Some(name), bx);
504501
bx.clear_dbg_loc();
505502

506-
bx.dbg_var_addr(dbg_var, dbg_loc, true, base.val.llval, Size::ZERO, &[], fragment);
503+
bx.dbg_var_addr(dbg_var, dbg_loc, base.val.llval, Size::ZERO, &[], fragment);
507504
}
508505
}
509506
}

compiler/rustc_codegen_ssa/src/traits/debuginfo.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,19 @@ pub trait DebugInfoBuilderMethods: BackendTypes {
7171
&mut self,
7272
dbg_var: Self::DIVariable,
7373
dbg_loc: Self::DILocation,
74-
is_declared: bool,
75-
val: Self::Value,
74+
variable_alloca: Self::Value,
75+
direct_offset: Size,
76+
// NB: each offset implies a deref (i.e. they're steps in a pointer chain).
77+
indirect_offsets: &[Size],
78+
// Byte range in the `dbg_var` covered by this fragment,
79+
// if this is a fragment of a composite `DIVariable`.
80+
fragment: Option<Range<Size>>,
81+
);
82+
fn dbg_var_value(
83+
&mut self,
84+
dbg_var: Self::DIVariable,
85+
dbg_loc: Self::DILocation,
86+
value: Self::Value,
7687
direct_offset: Size,
7788
// NB: each offset implies a deref (i.e. they're steps in a pointer chain).
7889
indirect_offsets: &[Size],

0 commit comments

Comments
 (0)