0

GDB: GNU gdb (GDB) 7.6.1
VS Code: 1.52.1(system setup)

I just want to get the hexadecimal value of some variable while debugging.

I tried to add the variable like "variable,h" and "variable,x" but it shows the error

Must specify the format as: 'natural', 'binary', 'decimal', 'hexadecimal', or 'octal'

Is there any proper solution to this situation?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
usan
  • 81
  • 1
  • 8
  • Does this answer your question? [How to display the hex value in the Watch panel of VS Code?](https://stackoverflow.com/questions/39973214/how-to-display-the-hex-value-in-the-watch-panel-of-vs-code) – Gino Mempin Jul 22 '22 at 10:40

1 Answers1

2

Format specifiers <variable>,h and <variable>,x are mapped in GDB to the zero-hexadecimal output format (/z). It is like /x formatting, the value is treated as an integer and printed as hexadecimal, but leading zeros are printed to pad the value to the size of the integer type. A newer GDB version (>=7.11) is required to support it. For more information, you can read this issue on the repository of the C/C++ extension for VS Code.

If you want to get the hexadecimal value, a workaround would be to watch the variable as a void pointer: (void *)variable

giusepped
  • 122
  • 3
  • 13