Этот вопрос похож на этот вопрос без ответа: Отладчик не входит в нативный код при отладке статической библиотеки, обернутой в C ++ / CLI DLL
Настройка такая же. У меня есть чистая статическая библиотека C ++, которая связана с C ++ / CLI DLL, которая затем используется исполняемым файлом C #. В зависимости от настроек, я могу отлаживать слой C # или C # и C ++ / CLI. Что бы я ни пытался, я не могу отладить слой C ++. Я использую Visual Studio 2019.
Вот что я попробовал и результаты. Для всех сценариев, описанных ниже, у меня установлены контрольные точки для функций C ++ / CLI и C ++ (не C #).
- C # с встроенной отладкой, C ++ и C ++ / CLI с автоматической отладкой: отладчик останавливаетсяпри вызовах в C #, которые будут вызывать функции C ++ / CLI, но я не могу установить их. Visual Studio не имеет сообщений для точек останова на стороне C ++ / CLI (они активны, но не могут быть поражены). На стороне 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.
C # без встроенной отладки, C ++ и C ++ / CLI со смешанной отладкой: точки останова в C ++ / CLI являются активными и активными. Точки останова C ++ либо исчезают, либо имеют следующее сообщение:
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 # со встроенной отладкой, C ++ и C ++ / CLI со смешанной отладкой: см. Первый пункт, поведение идентично. C # без встроенной отладки, C ++ с встроенной отладкой и C ++ / CLI со смешанной отладкой: аналогично пункту 2.
У меня следующий код:
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 ++. Я был бы очень признателен за любую помощь в выяснении этого.