调试包装在C ++ / CLI DLL中的静态库时,调试器不会进入本机代码 [英] Debugger does not step into native code when debugging a static lib wrapped in a C++/CLI DLL

查看:109
本文介绍了调试包装在C ++ / CLI DLL中的静态库时,调试器不会进入本机代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#应用程序中,我引用的是本机C静态库,该库包装在C ++ / CLI DLL中。我选择静态库而不是DLL,因为我还有其他与应用程序向用户发布过程相关的约束。在该论坛上可用的众多主题中,我发现了以下实现。

In a C# app, I'm referencing a native C static lib, that I wrapped in a C++/CLI DLL. I chose a static lib versus a DLL because I have other constraints related to the release process of the app to the user. Among the many topics available on this forum I found the following implementation.

Main:

{
  MyCLRDLL test = new MyCLRDLL();
  if(test.go()) Console.WriteLine("Hello, wrld");
}

在DLL项目中,文件 MyCLRDLL.hpp >

In the DLL project, the file MyCLRDLL.hpp

#include "MyNativeLib.h"
#pragma comment(lib, "MyNativeLib.lib")
namespace InteropTest {
public ref class MyCLRDLL
{
  CMyNativeLib* mInt ;
  public:
    MyCLRDLL()  { mInt = CMyNativeLib_New() ;} ;
    ~MyCLRDLL() { CMyNativeLib_Delete(mInt) ;} ;
    bool go() { return mInt->areYouThere()  ;} ;
};
}

在本机项目中, MyNativeLib.h

namespace InteropTest
{
class __declspec(dllexport) CMyNativeLib
{
public:
  CMyNativeLib() {};
    ~CMyNativeLib(){};
  bool areYouThere() ;
} ;
extern "C" __declspec(dllexport) CMyNativeLib* CMyNativeLib_New();
extern "C" __declspec(dllexport) void CMyNativeLib_Delete(CMyNativeLib* pLib);
}

MyNativeLib.cpp

#include "MyNativeLib.h"
namespace InteropTest {
extern "C" __declspec(dllexport) CMyNativeLib* CMyNativeLib_New(){return new CMyNativeLib() ;}
extern "C" __declspec(dllexport) void CMyNativeLib_Delete(CMyNativeLib* pLib){delete pLib;}
bool CMyNativeLib::areYouThere() { return true ; }
}

调试器没有进入mInt-> areYouThere()函数。为什么?

The debugger is not stepping into mInt->areYouThere() function. Why is that so? Breakpoints in the native part are not caught either.

为MyCLRDLL加载了符号,C#项目上的启用非托管代码调试处于活动状态, Debugging / Debugger Type为对于C项目和常规选项都设置为混合,似乎已检查了大多数相关内容。

Symbols are loaded for MyCLRDLL, "Enable unmanaged code debugging" is active on C# project, "Debugging/Debugger Type" is set to Mixed for both C projects and in the general options, most relevant things seem checked.

这是否意味着MyCLRDLL.pdb文件不包含来自以下位置的调试信息:库代码?

Does it mean that the MyCLRDLL.pdb file does not contain the debug information from the lib code? How to check?

(可能与未回答的调试CLR .dll中包含的非托管C ++静态库。

推荐答案

我尝试了与您相同的设置。 C#exe项目,对具有CLR支持的.dll项目的引用,该项目对具有纯本机C ++代码的.lib的引用。

I tried the same setup that you have. C# exe project, with a reference to a .dll project that has CLR support which has a reference to a .lib with pure Native C++ code.

首先,在可执行项目的属性中您必须在调试选项卡的本机代码中启用调试。
接下来,您将无法在连接调试器的情况下运行,因为它将不会加载CLR本机部分的符号。我通过不连接调试器的情况下成功运行,然后将CLR项目设置为Startup Project。之后,您必须使用CTRL + ALT + P附加到该过程,并在附加到:中添加本机代码。
这对我有用。

First of all, in the executable project properties you must enable Debugging in Native code unde Debug tab. Next, you won't be able to run with debugger attached since it won't load the symbols for the native part of the CLR. I succeded by running without debugger attached, then setting the CLR project to as Startup Project. After that you must attach to the process with CTRL+ALT+P, with Native code in "Attach to:". That for me worked.

这篇关于调试包装在C ++ / CLI DLL中的静态库时,调试器不会进入本机代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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