且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何调试Python内使用的Windows DLL?

更新时间:2023-09-29 16:58:34

如果可以使用Microsoft Visual Studio,则

If you have Microsoft Visual Studio available,

1)打开您的DLL所在的Visual Studio项目(或创建一个新项目)。

1) open the Visual Studio project that your DLL is part of (or create a new project).

2)如果您已经设置了用于调试的DLL(已使用调试信息构建了它,它将成为您的python程序将使用的那个),您可以在DLL代码中设置断点。

2) If you have set up your DLL for debugging (you've built it with debugging info, and it will be the one that your python program will use), you can set breakpoints in the DLL code.

3)按照通常的方式启动要调试的程序。

3) Start the program you want to debug as you would do normally.

4)返回Visual Studio IDE,然后转到 Debug 菜单。选择附加到处理选项。然后,您将获得所有正在运行的进程的列表。

4) Go back to the Visual Studio IDE and go to the Debug menu. Choose the Attach to Process option. You will then get a list of all the running processes.

5)选择要调试的进程,它将是您的python程序,或者是正在运行您的运行时。

5) Choose the process you want to debug, which will be your python program, or runtime that is running your program.

6)坐下,等待您的一个断点被击中,或者您可以尝试全部破坏从调试菜单中暂时停止程序。

6) Sit back and wait for one of your breakpoints to be hit, or you can try a Break All from the Debug menu to temporarily halt the program.

这是一种开始调试的通用方法,不仅可以调试python程序,还可以调试任何需要调试该程序正在使用的DLL的程序。

This is a general way of starting out debugging not only python programs, but any program where you need to debug a DLL that is being used by the program.

请注意,如果您使用调试信息自己构建了DLL并且被python应用程序利用,则上述建议最有效。如果它是第三方DLL,而您没有源代码,则仍然可以从Visual Studio进行调试,但是需要知道汇编语言(因为源代码通常不可用)。

Note that the above advice works best if you have built the DLL yourself with debugging information and is being utilized by your python application. If it is a third-party DLL where you have no source code, you can still debug from Visual Studio, but will need to know assembly language (since the source code is usually not available).