Gdb/lldb display pointer members from structs

I'm learning howto write low-level stuff in Rust and I was trying to display members of following structs:

use std::{ptr::NonNull, marker::PhantomData};
    
    pub struct Node<T> {
        value: T,
        pub(crate) next: Option<NonNull<Node<T>>>,
        pub(crate) prev: Option<NonNull<Node<T>>>,
    }

    pub struct LinkedList<T> {
        pub(crate) head: Option<NonNull<Node<T>>>,
        pub(crate) tail: Option<NonNull<Node<T>>>,
        marker: PhantomData<T>,
    }

In VSCode I can only see value member but not next prev members:
obraz

Under rust-gdb/rust-lldb I'm a little bit lost and cannot display those members at all:

(gdb) p list
$1 = linked_list::linked_list::LinkedList<i32> {head: core::option::Option<core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>>>::Some(core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>> {pointer: 0x7ffff0000df0}), tail: core::option::Option<core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>>>::Some(core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>> {pointer: 0x7ffff0000dd0}), marker: core::marker::PhantomData<i32>}
(gdb) p list.head
$2 = core::option::Option<core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>>>::Some(core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>> {pointer: 0x7ffff0000df0})
(gdb) p list.head.next
Attempting to access named field next of tuple variant core::option::Option<core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>>>::Some, which has only anonymous fields

How can I display list.head.next/list.head.prev members and check where they actually point to?

BR,
Dariusz

What does p list.head.0.pointer show?

1 Like

Thank you for your help, the command that you asked gives me the output that I would expect:

(gdb) p list.head.0.pointer
$3 = (*mut linked_list::linked_list::Node<i32>) 0x7ffff0000df0
(gdb) p *list.head.0.pointer
$4 = linked_list::linked_list::Node<i32> {value: 2, next: core::option::Option<core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>>>::Some(core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>> {pointer: 0x7ffff0000dd0}), prev: core::option::Option<core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>>>::Some(core::ptr::non_null::NonNull<linked_list::linked_list::Node<i32>> {pointer: 0x0})}

One more question how can I show/learn about compiler created union(?) members so that I won't ask such simple questions?

BR,
Dariusz

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.