简体   繁体   English

C ++ DLL调试

[英]C++ DLL debugging

I have a DLL written in C++. 我有一个用C ++编写的DLL。 It wraps a static library. 它包装了一个静态库。 I am calling it from python with ctypes. 我用python用ctypes调用它。 So far, so good. 到现在为止还挺好。 I need to debug some calls in the DLL. 我需要调试DLL中的一些调用。 I can hit breakpoints in the static library, but, not the DLL. 我可以在静态库中找到断点,但不是DLL。 I am doing this by using Attach to Process from the Debug menu. 我通过使用Debug菜单中的Attach to Process来完成此操作。 The code looks something like this: 代码看起来像这样:

extern "C"
{
    __declspec(dllexport) 
    void foo()
    {
    int i = 0; // Can't hit breakpoint here
    }
}

I am generating debug info. 我正在生成调试信息。 The pdb is sitting right next to the DLL. pdb正好位于DLL的旁边。 I am loading the DLLI think I am loading. 我正在加载DLLI认为我正在加载。 What am I missing? 我错过了什么?

Edit I recreated the project. 编辑我重新创建了项目。 Problem went away. 问题消失了。 Perhaps the difference is I went from a managed C project to an MFC DLL? 也许差别是我从托管C项目转到MFC DLL?

When you attach to a running process using MS Visual Studio, make sure you have the options set for both "Managed Code" and "Native Code". 使用MS Visual Studio附加到正在运行的进程时,请确保为“托管代码”和“本机代码”设置了选项。 This will ensure your breakpoints in any type of code, native or managed, will be honored by the MS Visual Studio debugger. 这将确保MS Visual Studio调试器能够遵守任何类型的本机代码或托管代码中的断点。 Otherwise, MS Visual Studio will use its "automatic" settings, which results in it only honoring break points that it sees in its "type" of project (for instance: a MFC project is native code (unmanged) and therefore won't normally debug managed code sections, while a .Net project is managed code and won't bother to stop for break points in "unmanaged" native code.) 否则,MS Visual Studio将使用其“自动”设置,这导致它只记录它在项目的“类型”中看到的断点(例如:MFC项目是本机代码(未管理),因此通常不会调试托管代码段,而.Net项目是托管代码,不会在“非托管”本机代码中停止断点。)

You can set this option at attach time by selecting the "Select..." button, and swapping the radio button from "Automatic" to "Debug these code types". 您可以通过选择“选择...”按钮在连接时设置此选项,并将单选按钮从“自动”交换为“调试这些代码类型”。 Under "Debug these code types", check the box beside "Managed" and "Native". 在“调试这些代码类型”下,选中“托管”和“本机”旁边的框。 You can select more options if you work with other types that MS Visual Studio recognizes (like T-SQL for SQL Server code, etc). 如果使用MS Visual Studio可识别的其他类型(如SQL Server代码的T-SQL等),则可以选择更多选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM