Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hex/Binary display of debug variables in C++ #557

Closed
nilanjan opened this issue Mar 13, 2017 · 37 comments
Closed

Hex/Binary display of debug variables in C++ #557

nilanjan opened this issue Mar 13, 2017 · 37 comments

Comments

@nilanjan
Copy link

OS - Linux and Mac

Hex (Octal, Binary etc.) display of variables in watch or variable window in debug is not available. This is absolutely imperative for the C++ developers.

Please provide support.

@pieandcakes
Copy link
Contributor

@nilanjan I'll add it to the backlog but in the meantime you can use the gdb-mi command: -var-set-format in the debugConsole by typing -exec -var-set-format <name of variable> <format>. The difficulty we have is offering context menu options to allow the change of the format, which would require VSCode changes. You can also add the variable specifiers in the watch window to change the format.

This is the same request as #319

@nilanjan
Copy link
Author

Does it work for lldb too?

@pieandcakes
Copy link
Contributor

@nilanjan I don't have my MacBook with me but I can try it tomorrow and let you know.

@thecoder138
Copy link

Tried this on MacBook, but this does not work. Got following message.

Driver. Received command '45-exec -var-set-format hex'. It was not handled. Command 'exec' not in Command Factory (from exec -var-set-format hex)_

@nilanjan
Copy link
Author

Any update on this? This is significantly affecting productivity. Can you point where to add this feature?

@Numinel
Copy link

Numinel commented Jun 16, 2017

How do I specify the variable name with the below command in the debug console?
-exec -var-set-format

If I use the above command while on a breakpoint (using gbg) I always get the error "msg: Variable object not found" but adding the variable name to the watch window works.

@pieandcakes
Copy link
Contributor

@Numinel Are you doing this on Mac or Linux?

So the format of -var-set-format seems to be -var-set-format <NAME> <FORMAT> where name is the automatic variable name assigned by gdb/lldb.

I enabled "logging": { "engineLogging": true } and I looked for the lines where -var-create was called for Variables and the response will have the that you need to specify.

1: (918) <-1023-var-create - * "a"
1: (928) ->1023^done,name="var1",numchild="0",value="0",type="int",thread-id="1",has_more="0"

So for instance, my variable here is a and it is expecting to be "var1".

@Numinel
Copy link

Numinel commented Jun 19, 2017

I use Linux. The log show that my variable is mapped to the internal name "var29" and when using the command '-exec -var-set-format "var29" hex' the output will be shown as hexadecimal.
It was unclear to me that I had to use a different name that the variable name.

Adding a variable to the watch window with ",h" is way better though.

@nilanjan
Copy link
Author

Is there any timeline for this feature implementation?

@pieandcakes
Copy link
Contributor

@nilanjan Not at this time. If you feel like it is something you would like to contribute we welcome community support. You can find source code at: https://github.com/Microsoft/MIEngine.

@EmbeddedBacon
Copy link

This feature has been on the backlog for a while now, any plans to resurrect this feature request from the dead?

@EmbeddedBacon
Copy link

EmbeddedBacon commented Nov 19, 2019

When I enabled the logging to decipher the transposed variable name the out on the Debug Console shows me the value in hex, but the Variable in the Debug tab still remains as decimal

-exec -var-set-format var158.param1 hexadecimal
1: (1205572) <-1599-var-set-format var158.param1 hexadecimal
1: (1205573) ->1599^done,format="hexadecimal",value="0xffffff01"
1: (1205573) ->(gdb)
1: (1205573) 1599: elapsed time 1
result-class: done
format: hexadecimal
value: 0xffffff01

From this particular experiment this is not a viable long term work around

@pieandcakes
Copy link
Contributor

@EmbeddedBacon That is the expected behavior. If you change the var-set-format, it will change it for all future calls but existing data is not updated as the UI hasn't requested to refresh yet.

We don't have a gesture in the UI to change the value and I haven't had time to investigate if VS Code's extensibility contains the ability to add this feature.

@EmbeddedBacon
Copy link

EmbeddedBacon commented Nov 20, 2019

@pieandcakes Thanks for the info, but I still couldn't get it to work. This will not work with Locals under Variables since I don't control those. I did try this in the Watch panel, but this doesn't seem to work correctly. I also noticed the translated variable is always changing. In one case the varible "pFsaCmd" was initially var39, then var40, then var42, then var43, then etc. If I didn't have pFasCmd in the Watch panel, then after trying to set its format. I tried setting the format to pFasCmd and pFasCmd.param1, but unfortunately neither worked for me. I am not sure what I am doing wrong.

Here is the output from the Debug Console. If I were to look into this, what area of the code base would I look at?

MI Log
1: (1213357) ->(gdb)
1: (1213357) 1296: elapsed time 1
1: (1213357) <-1297-var-create - * "pFsaCmd"
1: (1213363) ->1297^done,name="var39",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1213363) ->(gdb)
1: (1213363) 1297: elapsed time 5
1: (1213637) <-1298-stack-list-variables 0
1: (1213637) ->1298^done,variables=[{name="pFsaCmd"},{name="status"}]
1: (1213638) ->(gdb)
1: (1213638) 1298: elapsed time 0
1: (1213638) <-1299-var-create - * "pFsaCmd"
1: (1213643) ->1299^done,name="var40",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1213643) ->(gdb)
1: (1213643) 1299: elapsed time 4
1: (1213643) <-1300-var-create - * "status"
1: (1213644) ->1300^done,name="var41",numchild="0",value="VS_STAT_COMMAND_SUCCESS",type="VsProtocolStatusCode_t",thread-id="137",has_more="0"
1: (1213644) ->(gdb)
1: (1213644) 1300: elapsed time 1
1: (1213728) <-1301-var-list-children --simple-values "var40" 0 1000
1: (1213734) ->1301^done,numchild="5",children=[child={name="var40.task",exp="task",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var40.param1",exp="param1",numchild="0",value="4294967041",type="uint32_t",thread-id="137"},child={name="var40.param2",exp="param2",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var40.param3",exp="param3",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var40.data",exp="data",numchild="0",type="uint8_t []",thread-id="137"}],has_more="0"
1: (1213734) ->(gdb)
1: (1213735) 1301: elapsed time 6
-exec -var-set-format var40.param1 hexadecimal
1: (1242036) <-1302-var-set-format var40.param1 hexadecimal
1: (1242037) ->1302^done,format="hexadecimal",value="0xffffff01"
1: (1242037) ->(gdb)
1: (1242037) 1302: elapsed time 0

1: (1242043) <-1303-var-create - * "pFsaCmd"
1: (1242045) ->1303^done,name="var42",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1242045) ->(gdb)
1: (1242045) 1303: elapsed time 1
1: (1248577) <-1304-var-list-children --simple-values "var42" 0 1000
1: (1248584) ->1304^done,numchild="5",children=[child={name="var42.task",exp="task",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var42.param1",exp="param1",numchild="0",value="4294967041",type="uint32_t",thread-id="137"},child={name="var42.param2",exp="param2",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var42.param3",exp="param3",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var42.data",exp="data",numchild="0",type="uint8_t []",thread-id="137"}],has_more="0"
1: (1248584) ->(gdb)
1: (1248584) 1304: elapsed time 7
1: (1258554) <-1305-var-create - * "pFsaCmd"
1: (1258558) ->1305^done,name="var43",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1258558) ->(gdb)
1: (1258558) 1305: elapsed time 4
1: (1258567) <-1306-var-create - * "pFsaCmd"
1: (1258571) ->1306^done,name="var44",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1258572) ->(gdb)
1: (1258572) 1306: elapsed time 4
1: (1261053) <-1307-var-list-children --simple-values "var44" 0 1000
1: (1261060) ->1307^done,numchild="5",children=[child={name="var44.task",exp="task",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var44.param1",exp="param1",numchild="0",value="4294967041",type="uint32_t",thread-id="137"},child={name="var44.param2",exp="param2",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var44.param3",exp="param3",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var44.data",exp="data",numchild="0",type="uint8_t []",thread-id="137"}],has_more="0"
1: (1261060) ->(gdb)
1: (1261060) 1307: elapsed time 7
1: (1268111) <-1308-var-create - * "part"
1: (1268126) ->1308^error,msg="-var-create: unable to create variable object"
1: (1268126) ->(gdb)
1: (1268126) 1308: elapsed time 14
-exec -var-set-format var40 hexadecimal
1: (1390499) <-1309-var-set-format var40 hexadecimal
1: (1390500) ->1309^done,format="hexadecimal",value="0xaa57d4c"
1: (1390500) ->(gdb)
1: (1390500) 1309: elapsed time 0

1: (1402256) <-1310-var-create - * "pFsaCmd"
1: (1402260) ->1310^done,name="var46",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1402260) ->(gdb)
1: (1402260) 1310: elapsed time 4
1: (1402270) <-1311-var-create - * "pFsaCmd"
1: (1402271) ->1311^done,name="var47",numchild="5",value="0xaa57d4c <ddrMemory+18033228>",type="VsFsaOperateReq_t *",thread-id="137",has_more="0"
1: (1402271) ->(gdb)
1: (1402271) 1311: elapsed time 1
1: (1404271) <-1312-var-list-children --simple-values "var47" 0 1000
1: (1404278) ->1312^done,numchild="5",children=[child={name="var47.task",exp="task",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var47.param1",exp="param1",numchild="0",value="4294967041",type="uint32_t",thread-id="137"},child={name="var47.param2",exp="param2",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var47.param3",exp="param3",numchild="0",value="0",type="uint32_t",thread-id="137"},child={name="var47.data",exp="data",numchild="0",type="uint8_t []",thread-id="137"}],has_more="0"
1: (1404278) ->(gdb)
1: (1404278) 1312: elapsed time 7

@pieandcakes
Copy link
Contributor

pieandcakes commented Nov 20, 2019

@EmbeddedBacon if you are trying to view just a few items as hex for gdb, you can add to the watch window as <variable>,x where x is the hex format and it should give you the value correctly.

Every time a -var-create is issued, the name assigned to it is new. When you step and a stackwalk is performed, this causes all the variables to be refreshed and in that instance the variable names are also refreshed.

As a reference, here is the documentation for variables through mi commands`. The problem is unless we have a way for the user to ask for it in the UI, we don't have a way to know to change the value. VS Code has an open issue microsoft/vscode#28025 which should be upvoted so they can add the gesture in the UI.

Depending if they make it a global or per variable flag, we would need to do work to let the Eval call know that we want something other than the gdb default.

@Trass3r
Copy link

Trass3r commented Aug 26, 2020

For watch variables and natvis you can use format specifiers. See microsoft/MIEngine#1031.

@heartacker
Copy link

microsoft/vscode#70377
https://code.visualstudio.com/api/references/contribution-points#contributes.menus
seem that vscode has add something to invest debugging view. it's time to pick it up

@heartacker
Copy link

https://code.visualstudio.com/updates/v1_49#_contributable-context-menu-for-variables-view
looks like delicious on 1.49.0
image

@heartacker
Copy link

FYIScreenshot_2020-11-06-08-25-43-271_GitHub.png

@Trass3r
Copy link

Trass3r commented Nov 6, 2020

You should link to it instead of posting a screenshot: microsoft/vscode#28025 (comment)

asialasr pushed a commit to asialasr/vscode-cpptools that referenced this issue Mar 12, 2021
@windweed
Copy link

windweed commented Mar 12, 2021

Today I had this problem too. 'b'(binary) and 'o'(octal) both work, but, 'x' or 'h' dosen't work,
I work on C++ on Linux.
Any updates?

@danielbee
Copy link

I'm also seeing that ,x and ,h don't work but the rest of them do work.

@Trass3r
Copy link

Trass3r commented Mar 17, 2021

Which version of gdb are you using?
Also you can check what's going on with the debug launch options:

			"logging": {
				"engineLogging": true
			},

@windweed
Copy link

@Trass3r My gdb version: 7.3.1. I'll try that "engineLogging" option tomorrow.
Thanks.
Maybe it's because my gdb's version is too low ? I'll try a higher version on Fedora33 later

@Trass3r
Copy link

Trass3r commented Mar 17, 2021

Indeed, it may not support the format specifier.

@danielbee
Copy link

I can also try the logging when j get a chance. Note that doing ,b does work and I see the variable in binary. I'm also able to just use the debug console to print my variable in hex with -exec p/x <var_name>.

@Trass3r
Copy link

Trass3r commented Mar 17, 2021

Well binary wasn't implemented before so it looks like my https://github.com/microsoft/MIEngine/pull/1031/files got silently integrated by now. I can only imagine your gdb version not supporting zero-hexadecimal. Please try -exec p/z.

@danielbee
Copy link

Yeah -exec p/z doesn't work on my GDB.

Does this mean your changes actually always use p/z (var,z) even if we only specify ,x which is supported as p/x?

@Trass3r
Copy link

Trass3r commented Mar 18, 2021

There is no ,z in https://docs.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-cpp.
Yes ,x maps to /z which seems to have been introduced in 7.11, available even in Ubuntu 16.04.

@danielbee
Copy link

Yeah I'm using GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-110.el7.
Is there any chance of this changing? p/x gives the functionality that I'd want, and the error message when i try ,x is slightly misleading.

image
I have correctly specified ,x for hexadecimal. But because my GDB is outdated and doesn't support /z, I get this error message.

At least, I think we should catch this scenario and say something like:
"To display hexadecimal values in watch. Please use a GDB version >= 7.11"
Then link to some documentation that explains the workaround to use the debug console directly with /x.

@Trass3r
Copy link

Trass3r commented Mar 18, 2021

Well that's not my decision. But I personally wouldn't support those old versions. I had to work with gdb 7 last year and it was unusably slow at loading symbols and had annoying bugs. So I manually compiled gdb 10 and never looked back.
Developing with Docker containers could also be an option.
The error message is indeed a bit misleading as it comes directly from gdb as a response to the -var-set-format command happening under the hood.

@windweed
Copy link

@Trass3r @danielbee I figure it out now after reading you two's discuss, Thanks a lot ! Time to upgrade my GDB.

@PterX
Copy link

PterX commented Nov 12, 2021

Make it happen, please!

@heartacker
Copy link

heartacker commented Apr 14, 2023

GPT4:
向 Microsoft 反馈问题或请求功能是一个很好的方法,因为他们通常会关注社区的反馈。在这种情况下,该问题已经在 GitHub 上的 vscode-cpptools 仓库中提交,并且获得了一些关注。您可以通过以下途径尽量使微软员工尽快实现这个功能:

在 GitHub issue 上发表评论,提供详细的需求说明和使用场景,以便微软团队更好地理解您的需求。
对已有的评论进行点赞或表达同样的需求,以表明此功能对更多用户有价值。
在其他与该项目相关的论坛、讨论组或社区中分享此 issue,以便更多人能够发表评论和提出建议。
关于给微软员工开通 GPT-PLUS 会员的想法,虽然这听起来很有趣,但目前没有任何证据表明这样做可以提高他们的编码效率。微软团队通常会根据社区的关注度、实际需求和开发者的能力来决定实现特定功能的优先级。因此,在这种情况下,积极参与讨论并向微软提供有价值的反馈是更实际的方法。


Providing feedback or feature requests to Microsoft is a great approach, as they usually pay attention to the community's input. In this case, the issue has already been submitted in the vscode-cpptools repository on GitHub and has gained some attention. To try to get Microsoft employees to implement this feature more quickly, you can do the following:

Comment on the GitHub issue, providing a detailed explanation of your requirements and use cases, so that the Microsoft team can better understand your needs.
Upvote existing comments or express similar needs to show that this feature is valuable to more users.
Share the issue in other project-related forums, discussion groups, or communities to allow more people to comment and provide suggestions.
As for the idea of ​​giving Microsoft employees GPT-PLUS memberships, while it sounds interesting, there is currently no evidence to suggest that doing so would improve their coding efficiency. Microsoft teams usually determine the priority of implementing specific features based on the community's interest, actual needs, and developer capabilities. Therefore, in this case, actively participating in discussions and providing valuable feedback to Microsoft is a more practical approach.

@chang803
Copy link

This would be a great feature to have especially for cpp/c developer, and since vscode provide the menu option, could you please take a look on this feature again?

@riscy00
Copy link

riscy00 commented May 7, 2024

Is there any new/progress? It seems to be an essential feature for C++. ESP32 has moved into VSC from eclipse IDE.

@mrx23dot
Copy link

mrx23dot commented Jul 9, 2024

Duplicate of #319
see my last entry

@bobbrow bobbrow closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests