-
Notifications
You must be signed in to change notification settings - Fork 676
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
Issues Attaching Debugger to Python Application #8052
Comments
Thanks for the issue. I'm going to need some more information to diagnose the problem. My guess is that you're trying this with Python 3.10 or higher. Python (Native) debugging isn't currently supported on anything higher than 3.9. |
Hey rchiodo, Thanks for the quick response. First question is there an expectation when Python 3.10 will be supported by Native debugging? We have run into this issue with both Python 3.7.7 and 3.10. Below is some additional output. Please let me know what else I can provide.
|
That callstack looks like you're doing plain 'Python' debugging, not mixed mode. That would require python to actually be loaded in the embedded app before attaching. In VS 2022 we switched how our debugging works. For normal python debugging (non mixed mode), we use something called https://github.com/Microsoft/DEBUGPY. Debugpy is a soft-mode debugger, meaning it runs using APIs provided by the python runtime in order to debug. If the Python runtime isn't started yet, you'd get the error you show above. For mixed mode debugging (also called Python Native), we use concord to implement a hard-mode debugger that uses the native C++ debugger in VS to listen to Windows debug events. You might also be selecting both types of debugging at the same time. That isn't necessary. If you want to debug in mixed mode, just pick |
Support for 3.10/11/12/13 is a work in progress for mixed mode. Not sure when it will ship. |
We did mixed mode debugging (Native and Python (native)) using both 3.7.7 and 3.10 with VS2022. It connects but if you set a breakpoint in the Python code it will not stop at the breakpoint. We don't get any other output. Is there any log we can check for more information? |
"That callstack looks like you're doing plain 'Python' debugging, not mixed mode. That would require python to actually be loaded in the embedded app before attaching." The main developer wanted to also provide a note for this comment. The embedded Python is loaded before attaching. We utilize the PyObject_CallObject to first run our script. Further calls to PyObject_CallObject occur due to Window OS events such, as button presses. None of breakpoints are hit on these. |
With mixed mode you can actually just debug the C++ app from the start. That might fix the breakpoints binding. There was a bug in 3.9 mixed mode where breakpoints wouldn't bind during attach. Launching would have fixed that problem. Maybe there's something wrong in 3.7. 3.10 shouldn't work at all. I'd be surprised if the debugger even started. Ideally if you could share your app, I could just debug the problem. You could also try the sample app we have here and see if attach works. I wrote it to debug another customer's attach situation. |
I'm not entirely sure But mixed mode should work regardless how you load Python. |
Thanks for this info. The Main dev is going to look at your mention of the bug above and the sample you provided. He is also going to setup a Github account to be able to respond directly on the thread. I am asking internally if we have permission to share the app. Do you have a private upload location that we can use if we can? |
Just my e-mail address. It's my github id at microsoft dot com. |
I confirmed with our Infosec team we are unable to share the app. We can test the sample app instead. |
I took a look at the example code. We perform some different steps when we first run a python script from our C++ code, as we are importing a module rather than running a simple file... if (m_pModule)// finalize the last ran module (if there was one) just before reload We do have a number of embedded methods we regester using PyImport_AppendInittab and its callbacks. Also, on exit we call the above Py_Finalize block. |
None of that should matter if you're using mixed mode debugging. Mixed mode is actually all just a C++ debugger that displays C++ frames as their equivalent Python frames. It's only the normal Python debugging that might not work with those calls. |
"Launching would have fixed that problem. Maybe there's something wrong in 3.7." - so if I do launch the C++ app with embedded python 3.10, how do I tell it to use mixed mode? I normally just press F5 to launch the C++ app btw... I've only noticed the "Python (native)" and "Native" options when using the Attach method. |
We were able to get Python 3.7.7 working with mixed mode debugging with the direct debugger and attach to process. Thank you for all the helpful information! Could we please get an update in this ticket once Python 3.10 is supported with mixed mode debugging? |
I can try but it's unlikely that I'd remember. We have 1000s of tickets. Your better solution would be to watch for when we ship 3.13 support in VS 2022. There should be an announcement for that. I think we're shooting for early next year. |
Or you can just ping me here because I do get an e-mail every time somebody updates an issue I'm assigned. |
Sounds good! Ill set a reminder to watch out for it early next year. I can ping you if we need to follow up. |
Hi ! |
Hey... just wanted to add a note this comment from Tim "We were able to get Python 3.7.7 working with mixed mode debugging with the direct debugger and attach to process"... this is true for VS2022, however I cannot change the execution line after hitting a breakpint, eg I cannot change the Py Program Counter via the "Set Next Statement" right click option. Just a heads up on that, as that works with VS2017. |
The old debugger was hacking CPython to let it do that:
It seems it could be possible to do the same in the new debugger though, just it was never implemented: |
I'll enter a new bug to see how popular set next statement is. |
This issue has been moved from a ticket on Developer Community.
We have an Embedded Python specific application that we can’t use breakpoints when attaching with the debugger using Visual Studio 2022. Visual Studio 2017 does not have the issue.
We can successfully debug with Python 3.7.7 and Visual Studio 2017 with breakpoints using these steps:
We can successfully attach to the process, but not use breakpoints, with Visual Studio 2022 with these steps:
If we use Python code instead of Python (native), we get the following error or something similar:
“Failed to launch debug adapter. Timed out waiting for debug server to connect.”
If we compile the application and run the debugger through the sln, we can debug the C++ code. We cant debug py code this way either.
Original Comments
Tim Lakdawala on 10/30/2024, 08:56 AM:
(private comment, text removed)
Tim Lakdawala on 10/30/2024, 09:02 AM:
(private comment, text removed)
Feedback Bot on 10/30/2024, 09:39 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
Feedback Bot solved on 10/30/2024, 04:57 PM, undefined votes:
Thanks for taking the time to report this issue! It seems to us that it’s describing the same thing as another one. We’ve closed this one as a duplicate and transferred all votes from this ticket to the other one. Please follow along on the linked ticket to communicate with the team, see updates on status, and help provide any needed diagnostic info. For more information, see our issue reporting guidelines.
Happy coding!
Tim Lakdawala on 10/31/2024, 03:06 AM:
Could we please get a link to the ticket this was moved over to? I don’t see one in the resolution.
Tim Lakdawala on 10/31/2024, 06:13 AM:
I never received the link to the other ticket so I can’t confirm if they are different.
Lisa Gao (CSI Interfusion Inc) [MSFT] on 11/1/2024, 01:14 PM:
Hi, this issue was traced by #6993.
Tim Lakdawala on 11/2/2024, 01:18 AM:
Hey Lisa,
Thanks for sharing the github issue. The issue isnt exactly our issue. In our case we are attempting to attach to an already compiled exe that has embedded python. Can we please have this request reopened?
The text was updated successfully, but these errors were encountered: