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

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

问题描述

在 Windows7 上,我有一个使用 Windows DLL 的 python 脚本,使用 .NET 公共语言运行时 (CLR).使用的 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 菜单.选择 Attach to Process 选项.然后,您将获得所有正在运行的进程的列表.

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) 坐下来等待您的断点之一被命中,或者您可以尝试从调试"菜单中使用 Break All 来暂时停止程序.

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天全站免登陆