Skip to content

Commit 0634aed

Browse files
committed
Implement debug_type for tuples
1 parent 55a2446 commit 0634aed

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/debuginfo/types.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl DebugContext {
5656
// ty::FnDef(..) | ty::FnPtr(..)
5757
// ty::Closure(..)
5858
// ty::Adt(def, ..)
59-
// ty::Tuple(_)
59+
ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, *components),
6060
// ty::Param(_)
6161
// FIXME implement remaining types and add unreachable!() to the fallback branch
6262
_ => self.placeholder_for_type(tcx, type_dbg, ty),
@@ -144,6 +144,51 @@ impl DebugContext {
144144
}
145145
}
146146

147+
fn tuple_type<'tcx>(
148+
&mut self,
149+
tcx: TyCtxt<'tcx>,
150+
type_dbg: &mut TypeDebugContext<'tcx>,
151+
tuple_type: Ty<'tcx>,
152+
components: &'tcx [Ty<'tcx>],
153+
) -> UnitEntryId {
154+
let components = components
155+
.into_iter()
156+
.map(|&ty| (ty, self.debug_type(tcx, type_dbg, ty)))
157+
.collect::<Vec<_>>();
158+
159+
return_if_type_created_in_meantime!(type_dbg, tuple_type);
160+
161+
let name = type_names::compute_debuginfo_type_name(tcx, tuple_type, false);
162+
let layout = RevealAllLayoutCx(tcx).layout_of(tuple_type);
163+
164+
let tuple_type_id =
165+
self.dwarf.unit.add(self.dwarf.unit.root(), gimli::DW_TAG_structure_type);
166+
let tuple_entry = self.dwarf.unit.get_mut(tuple_type_id);
167+
tuple_entry.set(gimli::DW_AT_name, AttributeValue::StringRef(self.dwarf.strings.add(name)));
168+
tuple_entry.set(gimli::DW_AT_byte_size, AttributeValue::Udata(layout.size.bytes()));
169+
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.pref.bytes()));
170+
171+
for (i, (ty, dw_ty)) in components.into_iter().enumerate() {
172+
let member_id = self.dwarf.unit.add(tuple_type_id, gimli::DW_TAG_member);
173+
let member_entry = self.dwarf.unit.get_mut(member_id);
174+
member_entry.set(
175+
gimli::DW_AT_name,
176+
AttributeValue::StringRef(self.dwarf.strings.add(format!("__{i}"))),
177+
);
178+
member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
179+
member_entry.set(
180+
gimli::DW_AT_alignment,
181+
AttributeValue::Udata(RevealAllLayoutCx(tcx).layout_of(ty).align.pref.bytes()),
182+
);
183+
member_entry.set(
184+
gimli::DW_AT_data_member_location,
185+
AttributeValue::Udata(layout.fields.offset(i).bytes()),
186+
);
187+
}
188+
189+
tuple_type_id
190+
}
191+
147192
fn placeholder_for_type<'tcx>(
148193
&mut self,
149194
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)