简体   繁体   中英

Debugging C++/Cli: <Unknown function> and no Locals

I am trying to debug a project with a C# assembly and a C++/Cli assembly.

An interface defined in C# is inherited by a C++/Cli class, which in turn calls a native C++ class. Mixed-mode debugging is enabled in both C++ and C# assembly, as well as the startup .exe.

Now, when I try to debug into the C++ part, it gets tricky; if I simply set breakpoints in the C++ part, they are not hit (despite the fact that I know that they are hit because logs (etc) are written and throwing an exception there actually will throw it properly).

When I set a breakpoint at the latest call in C# before the call to the mixed-mode assembly, I can step into the C++/Cli code, and even into the native part. However, the Call stack is shown as

MyMixedMode.dll!<Unknown function> Line ... 

and I cannot inspect any locals (the locals view is just empty while inside the native code).

Any ideas what I might be doing wrong?

Unfortunately pieces of the tooling support in VS for C++/CLI projects keep falling off, they are struggling to keep it maintained. There's an issue with the new debug engine added to VS2012, the one that supports the new C++ debugging visualizers , it doesn't support C++/CLI anymore.

VS2012 Update 1 added a new setting in Tools + Options, Debugging, General, named "Managed C++ Compatibility Mode". Confusingly renamed to "Use Managed Compatibility Mode" in VS2013. Undocumented in the MSDN page for this settings page. What it does is force the debugger to use the old debugging engine instead of the new one.

This does have a side-effect, those shiny new debugging visualizers won't work when you have the option turned on. Keep this in mind if the debug info for your native code doesn't look right.

I found the solution: The mixed-mode debugging setting on the projects is not enough alone, in addition, Visual Studio requires enabling

[x] Use Managed Compatibility Mode

in Tool->Options->Debugging->General.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM