Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

launch.json env option to display numbers as hex while debugging #1801

Closed
wants to merge 19 commits into from

Conversation

valerino
Copy link

@valerino valerino commented Jul 22, 2018

wonder why this was missing.......

…as hex together with the decimal value (i.e. 10 is displayed as 0x0a (10))
@valerino valerino changed the title while debugging, primitive types (i.e. int, uint, ...) are displayed … while debugging, primitive types (i.e. int, uint, ...) are displayed as hex together with the decimal value (i.e. 10 is displayed as 0x0a (10)) Jul 22, 2018
valerino and others added 3 commits July 22, 2018 22:56
in launch.json: 
...
"env": {
                // controls numbers display while debugging
                // "hex" (shows hex only) "hexdec" ( shows hex (dec) )
                // default: shows dec only
                "DBG_SHOW_NUMBERS_HEX": "hexdec"
            },
...
@msftclas
Copy link

msftclas commented Jul 23, 2018

CLA assistant check
All CLA requirements met.

@valerino valerino changed the title while debugging, primitive types (i.e. int, uint, ...) are displayed as hex together with the decimal value (i.e. 10 is displayed as 0x0a (10)) launch.json env option to display numbers as hex while debugging Jul 23, 2018
@ramya-rao-a
Copy link
Contributor

Can you elaborate on some examples where this will be useful?
Is the need for this Golang specific or a generic requirement?
Is this a common enough requirement or a very special case?

@valerino
Copy link
Author

valerino commented Aug 4, 2018

hi ramya,
well..... in a debugger, you should be able to display int values as hex.
for example, i'm developing a computer emulator in golang (commodore 64 emulator) and in this situation having hex values displayed while debugging is vital.
but well...... this is not the only case, i mean ..... just to display a buffer in memory while debugging, without relying to printf, and so on ..... there should be no debugger without 'show as hex' as an option imho.

Copy link
Member

@jhendrixMSFT jhendrixMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There have been times I've wanted this functionality (e.g. being able to view ACSII characters for structs marshalled to JSON), needs some clean-up before we can merge though.

@@ -519,6 +517,19 @@ class GoDebugSession extends DebugSession {
if (/^(\w:[\\/]|\\\\)/.test(path)) return '\\';
return path.includes('/') ? '/' : '\\';
}
protected convertToHex(v) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sig should be private convertToHex(v: string): string. Also missing a new-line character between 519 and 520.

return {
result: v.value || ('<' + v.type + '>'),
variablesReference: this._variableHandles.create(v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect and will cause boolean types to display like they have child elements. It should remain variablesReference: v.children.length > 0 ? this._variableHandles.create(v) : 0 like below which means the two clauses can be refactored.

};
} else {
return {
result: this.convertToHex(v.value) || ('<' + v.type + '>'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For types v.value will be an empty string, so convertToHex() needs to handle this case and return an empty string (with the current implementation you get 0xNaN in the variables window).

protected convertToHex(v) {
let s = v;
if (this.numAsHex === 'hex') {
s = '0x' + parseInt(v).toString(16);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will truncate floating-point numbers. Perhaps this functionality should be limited to integers?

@jhendrixMSFT
Copy link
Member

Related microsoft/vscode#28025

@ramya-rao-a
Copy link
Contributor

@jhendrixMSFT Does microsoft/vscode#28025 (comment) work for Go?

@jhendrixMSFT
Copy link
Member

@ramya-rao-a no it doesn't work, would be great to fix it.

@marco-m-pix4d
Copy link

Hello, is this PR still valid?

@ramya-rao-a
Copy link
Contributor

Closing this PR as it has not seen any activity after the review by @jhendrixMSFT last year #1801 (review)

If anyone is interested in reviving this PR, please create a new one in https://github.com/golang/vscode-go as we are moving the repo for this extension.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants