开发者

Debugging native code when called from managed

I've written a C# application, where much of the work is done in a C++ back-end. Now I've been actively developing both sides, and the current iteration of the back end throws 开发者_开发知识库an access violation in a specific function. How can I go and debug this? VS won't break on exceptions or breakpoints in native code, nor show the call stack or locals of the native code, even though both projects are built in the same solution. I'd rather avoid having to go back and litter all my native code with logging statements.


VS will debug the native code, too, if you switch on mixed-mode debugging (and recompile your project).

See the Microsoft's explanation: http://msdn.microsoft.com/en-us/library/kbaht4dh.aspx


From Visual Studio 2016

  1. Project > Right Click > Properties
  2. Debug > Enable native code debugging.

Debugging native code when called from managed


Using Visual Studio you can attach the debugger from your native C++ project to your running C# application.

Before attaching the debugger and running your C# application

  1. Open your native C++ project in VS.
  2. Make sure you are configured to Debug mode. Then rebuild your native C++ code.

  3. Add breakpoints where you want to break and begin stepping through the code. Make sure your have placed your breakpoints in code which the C# application calls into.

  4. If your C# application is the start up project of your solution, under the Debug node in your projects Properties Pages make sure to check the ‘Enable Native Code debugging’, then rebuild the entire solution.

    Otherwise you will need to rebuild the C# application referencing the newly compiled DLLs. Run the application and attach the VS debugger of the C++ project to the C# application.
    To do this go to the Debug Tab -> Attach to Process -> select the C# application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜