此问题类似于以下未解答的问题:Debugger does not step into native code when debugging a static lib wrapped in a C++/CLI DLL
设置相同。我有一个纯C ++静态库,该库链接到C ++ / CLI DLL,然后由C#可执行文件使用。根据设置,我可以调试C#层,也可以调试C#和C ++ / CLI。无论我尝试什么,都无法调试C ++层。我正在使用Visual Studio 2019。
这是我尝试过的结果。对于下面描述的所有情况,我都在C ++ / CLI和C ++函数(不是C#)上设置了断点。
This breakpoint will not currently be hit. Breakpoints in module clr.dll are not alowed. This module contains the implementation of the underlying runtime you are trying to debug.
This breakpoint will not currently be hit. No executable code of the debugger's target code is associated with this line. Possible causes include: conditional compilation, compiler optimizations, or the target architecture of this line is not supported by the current debugger code type.
我的代码如下:
C ++ Native.hpp:
#pragma once
namespace native
{
class Native
{
public:
Native();
bool here() const;
};
}
C ++ Native.cpp:
#include "Native.hpp"
#include <iostream>
namespace native
{
Native::Native()
{
std::cout << "Created native entity!" << std::endl; // breakpoint here
}
bool Native::here() const
{
std::cout << "Native is here!" << std::endl; // breakpoint here
return true;
}
}
C ++ / CLI Wrapper.h:
#pragma once
#include "../cpp/Native.hpp"
using namespace System;
namespace clr
{
public ref class Wrapper
{
public:
Wrapper()
{
Console::WriteLine("Building wrapper for native"); // breakpoint here
mNative = new native::Native();
}
~Wrapper() { delete mNative; }
bool go()
{
Console::WriteLine("In wrapper to find native..."); // breakpoint here
return mNative->here();
}
private:
native::Native* mNative;
};
}
和C#:
using System;
using clr;
namespace csharp
{
class Program
{
static void Main(string[] args)
{
Wrapper w = new Wrapper();
Console.WriteLine("Finding native through wrapper...");
w.go();
Console.WriteLine("Waiting...");
Console.Read();
}
}
}
我已经尝试了几乎所有可以想到的东西,并且无法调试C ++方面。我真的很感激能解决这个问题。
答案 0 :(得分:0)
可能很简单,例如在Visual Studio中未启用Enable native code debugging
。
docs.microsoft.com的Tutorial: Debug C# and C++ in the same debugging session包含成功进行c#+ c ++调试会话的步骤。