1

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 = ()
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.