如何调试Python内使用的Windows DLL? [英] How to debug a Windows DLL used inside Python?

查看:173
本文介绍了如何调试Python内使用的Windows DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows7上,我有一个使用Windows DLL和.NET公共语言运行时(CLR)的python脚本。使用的DLL之一内部发生错误,但是标准的Python调试器仅在Python代码级别(而不是DLL)上调试。

On Windows7 I have a python script that uses Windows DLLs, using the .NET Common Language Runtime (CLR). An error occurs inside one of the used DLL, but the standard Python debugger only debugs on the Python code level (and not the DLL).

如何调试是什么在DLL内部进行?

How can I debug what is going on inside the DLL(s)?

推荐答案

如果可以使用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).

这篇关于如何调试Python内使用的Windows DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆