-
Notifications
You must be signed in to change notification settings - Fork 146
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
Debugger Does Not Enumerate ctypes Arrays #1025
Comments
I wasn't even able to get past the Here's the code I ran: import ctypes
prime_numbers = [2, 3, 5, 7]
byte_array = bytearray(prime_numbers)
x = (ctypes.c_uint8 * len(byte_array)).from_buffer(byte_array)
print(x) Here's vscode running this just fine: But when I try the same code in VS, I get an exception from the debugger process:
And if I try to remove the import statement, I get an error that ctypes is not defined. |
@int19h Are you able to look into this whenever you can? I'm not really sure what's going on here. |
Very strange that you can't import ctypes in VS. At least it looks like you're able to reproduce it on VSCode. In VS |
@AdamYoblick The error is because your sample is named ctypes.py, so when you Aside from that I'm pretty sure the behavior is identical between VS and VSCode - we don't do anything special in debugpy that'd make a difference. ctypes arrays have |
aaaand I feel like a fool 😆 @TheRealQuantam I see what you're saying about the variable data being presented in a slightly different way. Here's VSCode: And here's VS: This has to do with Visual Studio variable presentation options found in If you don't want protected variables to be shown in a group, select Then the view will look like VSCode: Please let me know if this fixes your issue and I can close this out :) |
@int19h I was under the impression that VSCode used group for everything, but it sounds like it uses inline for some things. I'd like to change the default behavior of VS to match VSCode. Can you please point me to variable presentation options passed to debugpy from VSCode if the user doesn't change anything? |
VSCode doesn't actually wire it up in any special way - whatever is in launch.json is flown through as is, and if it's not there, debugpy defaults are used, which are to group everything except for "protected": debugpy/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py Lines 72 to 74 in db43846
Note though that showing |
Ok so I'll create a new issue to have protected variables be presented as Inline, to match the vs code defaults. And I'll move this issue to debugpy per Pavel's instructions. |
It looks like we don't actually handle collections in a sufficiently generic way for it to "just work": debugpy/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_xml.py Lines 36 to 114 in ea423ae
So far as I can see, TupleResolver should work as is if it's registered as a resolver for ctypes arrays. However, because different array sizes produce different types, this will have to be implemented as a TypeResolveProvider .
|
Use tuple resolver for ctypes.Array
When and how will this fix be deployed? |
Whenever a new version of debugpy is published on PyPI, the following PTVS release will normally pick it up. We do not have a regular release schedule for debugpy, so I can't specifically say when this will happen. Note that you can always deploy fixes locally by placing a more up-to-date version of debugpy under "c:\users\advolker\appdata\local\microsoft\visualstudio\17.0_f467929dexp\extensions\microsoft corporation\python". It should work even if you just get it directly from git and copy it over, although you'll need to build it first (via |
Describe the bug
The debugger in Visual Studio 2022 does not treat ctypes arrays as containers, and hovering over them or looking at them in the variables window does not show length or allow the items to be enumerated like a list or dict. This is a new problem in VS2022, and did not occur in VS2017 or VS2019, which is why I've only recently started using VS2022 and this problem is making it very unpleasant as I use ctypes extensively in my work.
Ordinarily I would post in a forum to ask if there is some setting that's set incorrectly (the settings are default for Python), but as there's no forum here I'm making a bug report.
Steps to Reproduce
For me this occurs any and all times I use ctypes arrays in any context, so I don't really have any specific instructions to reproduce. The only thing worth noting is that this occurs regardless of whether "Enable debugging of the Python standard library" is enabled (I mostly work with it enabled). Maybe read a random binary file into a bytearray and do something like
x = (ctypes.c_uint8 * len(file_bytes)).from_buffer(file_bytes)
Then hover over x (or look at it in the variables window). It will only show "special variables" and "protected variables".
Expected behavior
In past VS versions the debugger would display as if it was a list, showing the length and list of all elements.
Configuration information
VS Version: Community 2022 (64-bit) 17.3.0
PTVS version: 17.0.22179.3
Python version: 3.9.7 64-bit (x64)
Debugger Type: I don't think this is relevant for VS2022?
The text was updated successfully, but these errors were encountered: