Vscode: See values in dec or hex in the debugger

Created on 5 Jun 2017  路  25Comments  路  Source: microsoft/vscode


I'd like to be able to select in which format I see the values of local and watched variables in the debugger. It would be preferred to have a generic setting but be able to change it per variable.

The way that it is now I often need to use a exteral dec-to-hex converter and copy the values from VS Code. Being able to see them in hex directly in the debugger would be a great help!

I mostly debug C/C++ programs but I imagine that this is generic for all languages.

  • VSCode Version: 1.12.2
  • OS Version: Linux Ubuntu 16.04 LTS

Steps to Reproduce:

  1. Start debugging
  2. Add a watched variable or two.
  3. Set a breakpoint and run
  4. When stopping at the breakpoint, take a look at the values of the watched and local variables. They are all given in decimal values (except pointers that are hex).
debug feature-request

Most helpful comment

I took a guess and tried to add a watch with the formVariable,x and it showed the values in hex as expected! This is on VS-insiders 1.27.0 and using the gdb debugger.

image

All 25 comments

I really want to view hex values too. Seems like a small thing to add to the otherwise very good VSCode.

I suggest to raise this request against the debugger extension you are using since the format of values id provided by the extension. VS Code does not have generic support for value formats.

I use gdb as debugger and there are commands for gdb to view variables as hex but how do I set-up VSCode to use those commands?
I guess this is not the place to ask such questions though.

As a said in my previous comment: VS Code does not have generic support for value formatting (e.g. to view variables in hex). This functionality must come from the debug extension that you are using.

I think it would be crazy to have to implement this over and over in every debugger!

The debugger frontend knows nothing about data types like integers, floats, or doubles. It only shows strings and leaves the formatting of these strings to the backend.

We've made this "crazy" design decision to keep the Debug Adapter Protocol simple.

I keep this issue open because I see a need for a customisable debugger frontend UI for changing the format of values/variables.

This UI could be similar to the "exception" configuration options in the breakpoints view. The backend (Debug Adapter) could provide a set of labels (and IDs) which are shown in the debugger UI without interpretation (e.g. as a context menu action on a variable). The IDs are passed back to the Debug Adapter and determine how values are formatted.

Thanks for looking at this again. VS Code is great because it does less rather than more and leaves a lot to plug-ins. I think this is a case VS Code to step up and implement this feature. The simple way CS Code works made me expect to have a prefix or post-fix to the variable name to implement this.

Just to be clear: my proposal from above does not suggest to let VS Code do the formatting (because it can not). It just proposes to make it easy for debug adapters to get their formatting implementation behind some VS Code provided UI.

I have no idea how vs code works behind the scenes and as long as we get a uniform way to format the contents of variables the detail is not critical. I have never seen an IDE that is as flexible as I would like. I would like to be able to select on a per variable basis one or more display formats.

So I could have my_byte and it shows "255 0xFF"

Hi @weinand ,

By checking the vscode debug protocol, I found this:

    export interface ValueFormat {
        /** Display the value in hex. */
        hex?: boolean;
    }

This comes with a VariablesRequest. So the debug client can actually tell the adapter to show values in hex format. We are trying to respond to this option. But I cannot find the UI entry to turn that on. Is this still work in progress or can you share more background on this?

Yes, these format options are not yet surfaced in VS Code (but they probably are in VS).

That's the reason for my comment from above:

I keep this issue open because I see a need for a customisable debugger frontend UI for changing the format of values/variables.

Thank you for the info. Then we are in the right direction. Inside the adapter, we support formatting options such as showing integers in hex format.

I am not sure if it works previously in VS Code, but in VS Code version 1.19.1 and in VS, you can use postfixes in Watch window to show numbers in hex format, for example:
Variable,h - show value of Variable in hex
Variable,o - show value as base 8 number
Unfortunately I didn't find any option to show numbers as hex in Variables window.

Even a global setting for hex display in the (mouse hovering) object inspector is very helpful.
Think someone doing buffer manipulations in JS.

I took a guess and tried to add a watch with the formVariable,x and it showed the values in hex as expected! This is on VS-insiders 1.27.0 and using the gdb debugger.

image

another work around.... cast to void* eg "(void*)myinteger"
This worked for me using gdb and open ocd for esp32. "myinteger,x" did not work.

i need this feature, pls dev it

A debugger front-end that works "only with strings" could support a feature that recognizes which strings can be parsed as decimal numbers and optionally prints a hexadecimal representation next to or instead of the decimal string. A front-end does not need to be told types or anything by a back-end to recognize and convert common formats.

any update?

another work around.... cast to void* eg "(void*)myinteger"

Nice trick. Works because of gdb's natural format: https://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI-Variable-Objects.html#The-_002dvar_002dset_002dformat-Command

This worked for me using gdb and open ocd for esp32. "myinteger,x" did not work.

That's a https://github.com/microsoft/vscode-cpptools specific feature inspired by VS.

Since VS Code 1.50 we have added functionality that enables debug extensions to implement data formats for variables:

* context menu items can be contributed to the Variables view. See https://code.visualstudio.com/updates/v1_49#_contributable-context-menu-for-variables-view

Hello!
Is this feature availaible out of the box? Or should i configure it?

@yaNePonedelnik Debug extensions must support this. I suggest to file feature requests against the debug extensions you are using.

@weinand Thank you for your reply

Was this page helpful?
0 / 5 - 0 ratings