Print lazy_static! variables in GDB?

38 Views Asked by At

I am writing a program in Rust and when debugging in GDB, I noticed that the variables defined within the lazy_static! macro were not displaying as expected.

#[derive(Clone, Copy)]
struct Addr(usize);

lazy_static! {
    static ref LAPIC_ADDRESS: Addr = {
        if some_parameter_from_other_source_code {
            Addr(0xfee00000)
        } else {
            Addr(0xfee00000 + 0x1000_0000_0000)
        }
    };
}

When printed by GDB, LAPIC_ADDRESS looks like this:

(gdb) p LAPIC_ADDRESS 
$1 = LAPIC_ADDRESS {
  __private_field: ()
}

When LAPIC_ADDRESS is accessed, it is initialized to either Addr(0xfee00000) or Addr(0xfee00000 + 0x1000_0000_0000). Does anyone have any good ideas for displaying the value in GDB after initialization?

Under the action of lazy_static, it appears that LAPIC_ADDRESS is defined as a structure, but there is no idea to display the value of its contents after initialization.

(gdb) ptype LAPIC_ADDRESS
type = struct LAPIC_ADDRESS {
  __private_field: (),
}
(gdb) p LAPIC_ADDRESS.__private_field 
$2 = ()
0

There are 0 best solutions below