Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't see variable contents when debugging C++ code called from a managed app

I've got some native C DLLs which I'm calling from a Managed C++ Class library ("Rem"). In the "Rem" class library I've got one native C++ class (api) and one managed C++ class (API).

The managed class (API) is called from a C# console application for now (will be used in a web application later).

When debugging I can step through my native code just fine.

My problem is that when I'm debugging, I can't see the values of any variables other than simple types that are locally declared.

Function parameters are not available in the debugger and if I try to add them as a Watch it just says "error: identifier 'schema_name' out of scope" ('schema_name' is the variable name)

Any structs just show the value "{...}", both in the quick watch and the Watch-window. enter image description here

If I try and add a watch to a field in a struct I get the value "error: 'entryList.numItems' does not exist"

Stuff I've tried:

  • I've tried creating a Console application in Managed C++ and debug from that, same thing.

  • I tried unchecking the Tools->Options->Debugging->General->Managed C++ Compatibility Mode, then I couldn't step into the code at all (no symbols loaded for the breakpoints)

  • In the C# console app project, I've gone into Properties->Debug and checked "Enable native code debugging" (and unchecked it)

  • In the C++ class library I've gone into Properties->Debugging->Debugger Type and tried "Mixed", "Native", "Managed" and "Auto".

Any suggestions as to what I'm doing wrong?

like image 464
henriksen Avatar asked Apr 23 '13 14:04

henriksen


People also ask

How can you see variable references while debugging?

Hover over a variable to see its value. The most commonly used way to look at variables is the DataTip. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable.

How do you show variables in VS code?

Set a breakpoint in your code, and start debugging by pressing F5 or selecting Debug > Start Debugging. When paused at the breakpoint, hover over any variable in the current scope. A data tip appears, showing the name and current value of the variable.

Which of the following Windows displays the variables while debugging?

The Autos and Locals windows show variable values while you are debugging. The windows are only available during a debugging session. The Autos window shows variables used around the current breakpoint.


1 Answers

I guess you are using Visual Studio 2012 Update 2. In that case - this is a known bug with Update 2:

https://connect.microsoft.com/VisualStudio/feedback/details/783004/children-cannot-be-evaluated-on-c-cli-after-vs2012-update-2

Be careful though, the "workaround" of uninstalling Update 2 will leave you with a broken Visual Studio as seen in this bug-report (yes, Update 2 is broken):

https://connect.microsoft.com/VisualStudio/feedback/details/785396/uninstalling-vs2012-update-2-and-repair-of-vs-results-in-atl-files-missing

In case you are not using Update 2 this might not be the correct answer but it could help others who experience exactly this problem using Update 2.

like image 79
Excelcius Avatar answered Oct 19 '22 23:10

Excelcius