简体   繁体   English

如何调试解决方案中包含的不受管理的C ++代码

[英]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.

相关问题 托管 C# 代码未发生非托管调用 - Unamanaged call is not happening from the managed C# code 使用 <thread> 在C ++ / CLI代码中包含的代码中。 寻找更好的解决方案 - Using <thread> in code which is included in C++/CLI code. Looking for a better solution c++,如何在代码中获取解决方案目录 - c++, how to Get the solution directory in the code 如何在Android Studio中调试c ++代码? - How to debug c++ code in Android Studio? 如何在VSCode上调试C ++代码? 苹果系统 - How to debug C++ code on VSCode? MacOS 如何使用 Visual Studio Code 从 Visual Studio 2019 构建、调试和运行现有的 C++ 解决方案 (.sln)? - How do I use Visual Studio Code to build, debug and run existing C++ solution (.sln) from Visual Studio 2019? 如何使用x [i] [j]在C ++中索引矩阵? 包括最终解决方案。 - how to use x[i][j] to index a matrix in C++? Final solution included. 如何在Eclipse中调试R包(使用C和C ++代码)? - How to debug an R package (with C and C++ code) in Eclipse? 如何在 Mac 上的 VS Code 上调试 C++ 代码? - How can I debug C++ code on VS Code on Mac? 创建包含Python代码的C ++应用程序 - Creating a C++ application with Python code included
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM