[英]How to Debug Unamanaged C++ code Included in Solution
I am using a third-party, proprietary DLL for which the source code is not available to me. 我正在使用第三方专有的DLL,其源代码不可用。 Wrapper code that appears to have been auto-generated using SWIG 1.3.39 is, however, available to me. 但是,似乎可以使用SWIG 1.3.39自动生成的包装器代码。 The wrapper code consists of a C++ file that compiles (using some headers that describe the DLL) to a DLL and of a C# project that makes PInvoke calls to the C++ wrapper DLL. 包装代码包括一个C ++文件(使用一些描述DLL的标头)编译为DLL,以及一个C#项目,该项目对C ++包装DLL进行PInvoke调用。
Those C++ projects I have included in my project Solution , however when I set the break point in the C++ code , I never get there. 我已将其包含在项目解决方案中的那些C ++项目,但是当我在C ++代码中设置断点时,我再也无法实现。 When I try to F11 in my C#, to go inside the C++ function , I get "Show Assembly" instead. 当我尝试在C#中使用F11进入C ++函数时,我得到的是“ Show Assembly”。
I have trie Solution > Proporties > Configuration Proporties but don't find anything with the option to debug Unmanaged/Native Code. 我有“ 解决方案”>“比例”>“配置比例”,但是找不到调试非托管/本机代码选项的任何内容。
Edit 编辑
The wrapper C++ code is available to me and I need to see the values I am passing from C# are actually getting passed to the C# code . 包装器C ++代码可供我使用,我需要查看从C#传递的值实际上已传递给C#代码。
// In one file of the C# wrapper:
public string GetKey()
{
// swigCPtr is a HandleRef to an object already created
string ret = csWrapperPINVOKE.mdMUHybrid_GetKey(swigCPtr);
return ret;
}
// In the csWrapperPINVOKE class in another file in the C# wrapper:
[DllImport("csWrapper.dll", EntryPoint="CSharp_mdMUHybrid_GetKey")]
public static extern StringBuilder mdMUHybrid_GetKey(HandleRef jarg1);
And the C++ code from the C++ wrapper . 还有来自C ++包装器的C ++代码。
SWIGEXPORT char * SWIGSTDCALL CSharp_mdMUHybrid_GetKey(void * jarg1) {
char * jresult ;
mdMUHybrid *arg1 = (mdMUHybrid *) 0 ;
char *result = 0 ;
arg1 = (mdMUHybrid *)jarg1;
result = (char *)(arg1)->GetKey();
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
Now As I am trying to pass swigCPtr
from the C# wrapper by using csWrapperPINVOKE.mdMUHybrid_GetKey(swigCPtr);
现在,当我尝试使用csWrapperPINVOKE.mdMUHybrid_GetKey(swigCPtr);
从C#包装器传递swigCPtr
csWrapperPINVOKE.mdMUHybrid_GetKey(swigCPtr);
Now I want to see if jarg1 is getting the value from swigCPtr; 现在,我想看看jarg1是否正在从swigCPtr获取值;
SWIGEXPORT char * SWIGSTDCALL CSharp_mdMUHybrid_GetKey(void * jarg1) {
char * jresult ;
mdMUHybrid *arg1 = (mdMUHybrid *) 0 ;
char *result = 0 ;
arg1 = (mdMUHybrid *)jarg1;
result = (char *)(arg1)->GetKey();
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
When you have a managed exe and want to debug the native DLL it uses you need to tell the debugger about that. 当您拥有托管的exe并想调试其使用的本机DLL时,您需要将其告知调试器。 Don't use the Debugger Type Auto , what's the default. 不要使用Debugger Type Auto ,这是默认值。 Use Mixed instaed. 使用混合即时。
The auto will identify the managed exe and allowes managed debugging. 自动将识别托管的exe,并允许托管的调试。 That's not what you need to debug native C++ code. 这不是调试本机C ++代码所需要的。
You find the Debugger Type setting in the Debugging section of the project properties. 您可以在项目属性的“ 调试”部分中找到“ 调试器类型”设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.