Suppose this situation :
I have a dll which was written in standard c++, having a Class ,Native_Class, with function Native_F().
and I have a wrapper written in C++/CLI for Native_Class called Managed_Class with function Managed_F().
Then I use Manage_Class in C# and call its Managed_F().
When I add a breakpoint at the Managed_F() and press F11 in runtime it goes inside the function and if I press F11 again for going inside Native_F(), it does not work, indeed I can debug only to C++/CLI level and can not debug inside C++ implementations.
It is necessary for me to debug inside of c++ functions, please help me.
Maybe if I can introduce the pdb file of C++ project to C++/CLI project, I will solve it.
Consider the remote debugging. From visual studio with your c++ source code press Tools -> Attach To Process while running C# application.
Related
I want to write an extension for Visual Studio Code (VSCode) which will allow me to debug a C++ program with Visual Studio's native C++ debugger instead of gdb (which currently is the only option VSCode supports). I looked at the Visual Studio Debugger Extensibility. But it only explains how you can create a new debug engine and call it from Visual Studio as a front end. What I want to do is the opposite. I want to call the existing Visual Studio C++ debug engine from a different front end, which happens to be VSCode. There is no documentation on the Internet how I can achieve this. Can anyone please help?
I'm on the VSCode team. To use the VS debugger from VSCode, you will need to author a debug adapter extension. Here's some documentation on getting started, and here's the complete debug adapter protocol reference.
Try look at some existing implementations to get started:
Mock debugger – simple example debugger
Node debugger - node.js debug adapter
For C++, also check out C++ tools for VSCode.
Hope that helps.
Edit - Seems I misunderstood the problem. Here are some thoughts on consuming the VS C++ debugger from an external application.
To my knowledge, Visual C++ does not have public APIs or interfaces that allows external programs to easily interface with them. Other languages have better stories, since they often leverage external libraries or were designed with documented debugger protocols. The GDB machine interface is a good example of this sort of design.
My best suggestion is that you could try to leverage the Visual Studio Env.DTE interfaces to control VS programmatically. EnvDTE is not well documented and may not be exactly what you are after, but it is pretty powerful.
I'm working on an universal app with visual studio and I'm using a custom MFT wrote in C++.
The problem is since I'm using the debugger for the C++ project, I can't use the debugger for the C# project anymore. For example if I put some breaking point in my main Class in the C# project, visual studio says "The breakpoint will not currently be hit. No symbols have been loaded for this document".
so finally Debug -> properties and then for application process and background task process switch between native only and managed only, depending if you are debugging the C++ or the C#
I'm developing a C# MVC project in Visual Studio 2013 Express for Web. An external C++ DLL is imported into the project and a function which is exported from the DLL is consumed.
I would like to be able to debug into the C++ DLL. However at the moment when I try to step into the function call the debugger steps over instead. The C++ DLL is one I created myself in Visual Studio 2013 Express for Windows Desktop. I have generated the .pdb debug symbols for the DLL and they are in the same folder as the DLL.
I have read in similar posts that suggest perhaps there is a properties setting to enable debugging into external an DLL. However in the MVC 5 project properties I can't find this option. In fact there doesn't even appear to be a debugging tab.
Is debugging into an external C++ DLL possible in Visual Studio 2013 Express for Web? If it is how do I enable this feature? If it is not possible, is there another Visual Studio Express where this is possible?
Thanks for your help!
I don't have VS Express, but the following applies to VS Professional and should apply to Express as well. You need to set your Debugger Type to Native Only (best, but then you have to break in the native code to debug it) or Mixed (may or may not work, I don't use it, so not sure it's limitations), and make sure the DLL is freshly build and matches the source code you have available. I suspect the setting you refer to is called 'Just My Code' (in Options->Debugging), but I don't think it matters in this case.
I'm not sure about VS2013 but with VS2015 you need to set "Enable Native Code Debugging". Right click on your C# project. In the right pane, click Debug. Under Enable Debuggers click the check box on Enable Native Code Debugging.
I have a c# solution A in my Visual Studio 2010. I have added a dll of solution B as a Reference. I have built solution B with "Debug".
If I run solution A in debug mode I can debug into solution B (Step Into F11) and see the code. That's nice. If I am NOT in debug mode and I "Go to definition (F12)" of external code Visual Studio opens a file without the body/logic of the methods :-( It looks something like an Interface.
Is it possible to "Go to definition (F12)" of external code in edit mode? Do I need a plugin?
I do not want to edit the external code. I just want to read the logic and set breakpoints.
This situation only happens in non-Debug modes. It's better to run both in Debug when you are going to debug and set breakpoints.
Run both in the Debug mode.
My C# code is calling an unmanaged third-party library function via P/Invoke, and the unmanaged function is having some strange side effects. I want to debug into it and see what it's doing.
If I debug my C# code, and try to "Step Into" the P/Invoke call, it steps over instead. No surprise there -- I expected that; it doesn't have the source for this DLL, and I didn't tell it I was okay with seeing the disassembly view.
So I switch the debugger to disassembly view (Debug > Windows > Disassembly). Now I see the individual x86 instructions in my JITted code. Again I try to step into the P/Invoke call. Again, it steps over instead -- even though I clearly told it to Step Into an x86 CALL instruction. How hard is it to step into an x86 CALL?
My Googling thus far has shown me a couple of options that can affect this, and I've already set them:
In Tools > Options > Debugging > General, "Enable Just My Code" is unchecked.
In Project > Properties > Debug tab, "Enable unmanaged code debugging" is checked.
No good. Visual Studio still refuses to step in.
I don't have a PDB for the third-party DLL, but that shouldn't matter. I don't care about source code or symbol information. (Well, actually they'd be really nice, but I already know I'm not going to get them.) Visual Studio can do x86 debugging (that's what the Disassembly view is for), and all I want to do is step into the x86 code.
What else do I need to do to get VS to allow me to step into the x86 instructions inside a P/Invoke call?
This may help you solve the problem:
(by Graviton)
CallingConvention = CallingConvention.Cdecl
Also this mentions that you need to detach managed debugger and re-attach unmanaged when crossing the boundaries. You might need to check the capabilities of mixed debugger and it's preferences from MSDN.
And finally, using Ed Dore' answer:
Under Tools.Options dialog, select the
Debugging category, and make sure the
"Enable Just My Code" setting is
unchecked. From the Project
properties, select the Debug tab, and
then ensure that "Enable unmanaged
code debugging" is checked.
Once you've got these squared away,
you should get the mixed mode
debugging support working.
Also, if you use "Debug.Attach To
Process" , be sure to hit the
"Select..." button in the "Attach To
Process" dialog, and select both
Managed and Native debugging support.
One thing I would try is going from C# to C++/CLI code, and then from C++ to the third-party code. Once you're in C++ (and free of the P/Invoke infrastructure), you might have better luck with the disassembly view.
In your C# project properties, in the Debug tab, check Enable native code debugging. Worked for me in VS 2012.
Credit goes to billb.
Also, since it's a third party library, ensure Enable Just My Code is unchecked in Options > Debugging.
I had a similar issue where I was debugging a C# exe that called my own C++ dll via PInvoke, all part of the same solution. Enabling native code debugging in my c# project allowed me to debug my C++ code.
Had same issue today.
What helped in my case was to run Visual Studio as administrator.
My setup:
Visual Studio 2019
Windows 10