On google I got 2 results for my question, on SO I did not find a question that would answer mine. I searched for "gdb cast struct to unsigned int c" on google and the results did not address gdb but were about casting between structs in general. I am debugging a piece of code that has structs like this:
typedef struct L1_valid_entry{
uint32_t PXN:1;
uint32_t index_1:1;
uint32_t C_B:2;
uint32_t XN:1;
uint32_t DOMAIN:4;
uint32_t IMPL:1;
uint32_t AP_11_10:2;
uint32_t TEX_14_12:3;
uint32_t AP_15:1;
uint32_t nG_S:2;
uint32_t zero:1;
uint32_t NS_19:1;
uint32_t base_address:12;
}L1_valid_entry;
now in GDB I inspect such a struct instance and want to print it but instead of its bitfields as values I want to print it as an unsigned int. I tried p/x and p/t but it changes nothing.
Edit: p/x (unsigned int) works!!
You can use the x
command to print the contents of memory starting at that struct's address:
x/wx &e
Or alternately:
x/4bx &e