Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to step into unmanaged C++ library from my C++/CLI code

I have the following three projects in my solution: 1. C# library 2. C++/CLI managed code 3. C++ unmanaged code

I did check "Enable Unmanaged Code Debugging" in my C# project, and built both C++ projects in Debug/Win32. However, I cannot step into unmanaged code - when I F11 on the call of any unmanaged method, it shows me some random/wrong code then exits.

Because my unit tests pass, I know that my unmanaged code does execute.

What am I missing?

like image 692
Arne Lund Avatar asked Aug 02 '11 19:08

Arne Lund


2 Answers

When I've had this problem it has come from one of these things:

1) Enable unmanaged code debugging not checked. You already fixed this.

2) Built the EXE as x64 or Any CPU (they say x64 works, but it doesn't). I think you already fixed this.

3) "Just my code" being turned on sometimes causes trouble with unmanaged code debugging (Tools, Options, Debugger, Just My Code)

4) Incorrect debug options in the C++ project settings

5) Missing, corrupted or mismatched PDB files. You can check for this by trying to set a breakpoint in your C++ code while running in the debugger. If the breakpoint turns into a hollow circle, something is wrong with your debug info. Also check your output window as you run in debug mode -- it should tell you whose symbols got loaded.

like image 86
Ed Bayiates Avatar answered Oct 23 '22 04:10

Ed Bayiates


I've seen this issue going the "other" way from time to time (ie, from native C++ to C++/CLI) and it's usually caused by the debugger not really picking up that it's supposed to debug both native and managed code.

Usually for me, setting the Debugger Type in Configuration Properties -> Debugging in your startup project from 'Auto' to 'Mixed' solves the problem.

like image 30
Timo Geusch Avatar answered Oct 23 '22 05:10

Timo Geusch