Skip to main content

## build_slice_type_di_node

# Function build_slice_type_di_node

Source

    fn build_slice_type_di_node<'ll, 'tcx>(
        cx: &GenericCx<'ll, FullCx<'ll, 'tcx>>,
        slice_type: Ty<'tcx>,
        unique_type_id: UniqueTypeId<'tcx>,
    ) -> DINodeCreationResult<'ll>

Expand description

Create debuginfo for `[T]` and `str`. These are unsized.

NOTE: We currently emit just emit the debuginfo for the element type here (i.e. `T` for slices and `u8` for `str`), so that we end up with `*const T` for the `data_ptr` field of the corresponding wide-pointer debuginfo of `&[T]`.

It would be preferable and more accurate if we emitted a DIArray of T without an upper bound instead. That is, LLVM already supports emitting debuginfo of arrays of unknown size. But GDB currently seems to end up in an infinite loop when confronted with such a type.

As a side effect of the current encoding every instance of a type like `struct Foo { unsized_field: [u8] }` will look like `struct Foo { unsized_field: u8 }` in debuginfo. If the length of the slice is zero, then accessing `unsized_field` in the debugger would result in an out-of-bounds access.