Reputation: 611
Is VSCode able to display hex values for local variables in debug mode ? I have been searching for a way to make this happen but with no success.
Upvotes: 51
Views: 50127
Reputation: 11
For those who still debug Python 2 project, you can use the Watch window with following format:
'{:02X}'.format(myVariable)
Upvotes: 0
Reputation: 21
If using the CodeLLDB debugger, the display setting for variables can be changed in the VSCode setting Lldb: Display Format
. It can be found by typing lldb.displayFormat
in the search bar in VSCode settings.
Note that this changes the display setting for all variables.
Picture showing the LLDB Display Format settings
Upvotes: 2
Reputation: 31
Using GDB, you can cast it to void*: (void*)var
, and it will treat it as a pointer, and show it in hex.
Upvotes: 3
Reputation: 4929
This answer applies to GDB debugging.
For an active debug session, type the following in the debug console:
-exec set output-radix 16
To apply this every time the debugger runs, add text "set output-radix 16" in the "setupCommands" section of launch.json
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{ "text": "set output-radix 16" }
]
Upvotes: 18
Reputation: 1332
It has been a while since last activity on this, but I found by looking through links from this thread on the Cortex-Debug github (Issues) a solution for me. From the (GDB) Debug Console use -exec set output-radix 16
for hex, set it to 10 for decimal.
Upvotes: 23
Reputation: 59
actually you could open debug console and using hex() function to convert values
Upvotes: 1
Reputation: 1154
I know this is an old thread, but it was at the top of my Google search so I thought I'd add some new information, which I found in the issues thread linked by Burt_Harris.
You can't seem to change the formatting of values displayed in the Locals pane or in tooltips, but you can force the formatting on variables in the Watch pane by appending ,x
to the variable name.
Other formats exist, such as ,b
for binary, ,o
for octal. I believe it's based on the GDB display modifiers uses (e.g. display/x myVariable
)
Suffixes used in VSCode's Watch pane:
Upvotes: 97
Reputation: 435
As @some said, you can add an expression in the watch. Here is the expression you would have to add to display a slice of bytes as a hex string:
call hex.EncodeToString(mySliceOfBytes)
Upvotes: 3
Reputation: 49612
I was looking for the same thing and ended up here, and I saw that the feature request has been denied at this time.
But then it hit me: In the watch window, you can add an expression, and Number have a toString method, where you can choose what radix (2-36) to convert the number to. And it works:
Instead of just watching value
, watch value.toString(16)
for hex.
I tried to add more methods to the Number prototype in my code (I wanted a grouped display), but unfortunately it is only shown as "[Object object]".
I know that this is not exactly what you where looking for, but it is something that works without any plugins.
Upvotes: 12
Reputation: 6874
You can't currently, but there are feature requests outstanding for this. According to VSCode core developers, this needs to be implemented in the specific debugger extension for the environment you are debugging.
Links to known related debugger extension feature requests listed below:
Vote your preferences by adding thumbs-up to the feature request
Upvotes: 4