Vscode-cpptools: Debugger Option to View Pointer as Array.

Created on 27 Aug 2016  路  12Comments  路  Source: microsoft/vscode-cpptools

For dynamically allocated arrays are simply represented as a pointer, which has no other indicator that it is an array. It would be nice to have a feature to view a pointer as an array as to view more than simply the first element of the array. In the "variables" tab and also when previewing a variable by hovering over it while debugging.

Feature Request debugger

Most helpful comment

Thanks for getting back to me, have a decent solution now. For anyone who found themselves here Googling this same problem, you can put this in the watch window:
*(int(*)[10])some_pointer
to print "some_pointer" as a 10-element array of type int.

Would still argue that having a simpler solution is a basic debugger feature that should be added, this is way too much syntax/thinking/remembering to do something basic. Debuggers should get out of your way, not challenge you when you're trying to think about your actual code.

All 12 comments

@sprinkle131313 with our 0.9.3 release, we updated to enable gdb's pretty-printing in launch.json as a default. This should resolve this issue. Please comment/reopen with more information if it doesn't

It would make a HUGE difference if I could type "some_pointer,x" in the watch window to view some_pointer as an array with x elements.

As it stands I have to use LLDB's memory read syntax, which I constantly have to google and sometimes doesn't seem to work. I've actually resorted to printf debugging for large arrays the last few days. Could we please reopen this issue or can I open another to look into something like that being implemented? It's my number 1 gripe with VSCode debugging at the moment (one of my only gripes).

@kevinmoran We have updated our version of the shipped LLDB to allow lldb's python pretty printer to work. Your other option is to look at our Natvis visualizer option. The commands you are putting in the watch window are sent to the underlying debugger to evaluate.

Thanks for getting back to me, have a decent solution now. For anyone who found themselves here Googling this same problem, you can put this in the watch window:
*(int(*)[10])some_pointer
to print "some_pointer" as a 10-element array of type int.

Would still argue that having a simpler solution is a basic debugger feature that should be added, this is way too much syntax/thinking/remembering to do something basic. Debuggers should get out of your way, not challenge you when you're trying to think about your actual code.

I agree with kevinmoran, that retyping the pointer is too complicated by hand and should be done by debugger.

@salda We will take it as a feature request but the underlying debugger is lldb or gdb so the change would need to happen in the debugger itself and not the extension.

https://github.com/Microsoft/vscode-cpptools/issues/172#issuecomment-277376704
Has this feature been added for pointer to pointers? e.g. char**

@noobling Yes, I am having trouble printing pointer to pointers as well

For anyone who found themselves here Googling this same problem, you can put this in the watch window:
*(int(*)[10])some_pointer
to print "some_pointer" as a 10-element array of type int.

or, even simpler: *some_pointer@3. Bonus point, check out *argv@argc!

If you do what @giuscri suggests and put a breakpoint in the function that computes the pointer, the watch will stall indefinitely and cannot be deleted (Windows 10)

eg *tests()@4 will stall if there is a breakpoint in tests(), a function which returns a pointer to a list of test results.

reloading the window after this happens seems to fix it.

or, even simpler: *some_pointer@3. Bonus point, check out *argv@argc!

If you have the array length in a variable (e.g., length) you can do this: *some_pointer@length

Thanks @giuscri!
If anyone else was wanting to use *s@strlen(s) to display a c-string without typing in the length, it turns out that the thing to do in gdb is to use: $_strlen. So if you have a c-string, s, you can display the underlying char array by using the following as a watch expression (the + 1 is for showing the terminating null char): *s@$_strlen(s)+1

Was this page helpful?
0 / 5 - 0 ratings