Basically, I want to get typeid(*this).name()
, i.e. the real type of this
.
I want to get this in GDB (without modifying the source code). I
As @Star Brilliant says here, this:
ptype my_var
returns things like type = unsigned short
, but I want it to return type = uint16_t
instead, so I can truly know how many bytes it is when inspecting memory. The best I can figure out to get this effect is to do:
print &my_var
which prints (uint16_t *) 0x7ffffffefc2c
, thereby revealing that its pointer type is uint16_t*
, meaning its type is uint16_t
.
I find this to be more-useful than ptype my_var
, but a more direct way to get this effect is desired in case you have any suggestions.
Sample gdb commands and output:
(gdb) ptype my_var
type = unsigned short
(gdb) print &my_var
$27 = (uint16_t *) 0x7ffffffefc2c
Again, notice ptype my_var
reveals it is an unsigned short
, whereas print &my_var
reveals the more-detailed and desired answer which is that it is a uint16_t
.