(gdb) Tips on printing variables
- Printing type of variable:
ptype <VARIABLE_SYMBOL>
- For class objects, prints the signature of the whole class
-
Printing a vector:
p[rint] <VECTOR>
- Printing an element in a vector:
- Often
operator[]
orat()
method don’t work in gdb - Instead, use
<VECTOR>._M_impl._M_start+<INDEX>
- This will return the pointer to the target element in the underlying array, so dereferencing the pointer would give the element
- Often
References:
Written on April 2, 2021