7

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?

Community
  • 1
  • 1
henriksen
  • 1,137
  • 1
  • 11
  • 24
  • 4
    +1 for a concise and well-formed question. – Moo-Juice Apr 23 '13 at 14:22
  • 1
    potential duplicate of [this](http://stackoverflow.com/questions/10489205/visual-studio-2010-cant-see-the-value-of-the-variable) – ldgorman Apr 23 '13 at 14:24
  • 1
    Are you running in release mode or debug mode? In release mode, you are still allowed to step through the code, but with no debug symbols you cannot actually see anything. – IdeaHat Apr 23 '13 at 14:45
  • @ldgorman, the question you reference as a potential duplicate only deals with C# and not a combination of managed and unmanaged - though of course, it may be the same issue :) – Moo-Juice Apr 23 '13 at 14:58
  • @MadScienceDreams, I'm running in debug mode and all optimizations are disabled. I can see the values of locally declared variables. For instance: int count = result->numOfItems After that line I can see the value of "count" and Watch it, but result is just a {...} and numOfItems is unavailable. – henriksen Apr 23 '13 at 19:39
  • @Idgorman, good suggestion, but I'm already in debug mode and have disabled optimizations. – henriksen Apr 23 '13 at 19:40
  • I can't offer any solutions only say how I might investigate it, which you have may have thought of already. If you create a simplified version of your C dll do you get the same problem, e.g. create a new project from scratch and extract out one file from your C dll and stub out most of the implementation from that file? (I'm assuming that if you create a C++ console application doing the equivalent of your C# console application then the debugging works ok.) – TooTone Apr 24 '13 at 13:09
  • @TooTone I created a managed C++ console app, doing the same as the C# app and I have the same problem. I have another project with a pure C console app using the same native library and there the debugging works fine. It seems like there is a problem when debugging native code when comming from a managed app. – henriksen Apr 24 '13 at 13:18
  • @henriksen I don't think your problem is a problem in general with debugging native from managed. I checked a solution I wrote last year in vs2008 with c# calling managed C++ calling native c++ and I could expand the underlying stl structs in my native lib. – TooTone Apr 24 '13 at 13:58
  • @henriksen I also tried a test case for your problem. In vs2010 I created a managed c++ console app, and then a native dll (Win32Project / DLL). I added a simple struct in the cpp file, instantiated a global variable of that struct, and then edited the example of an exported function to modify the global variable and `printf` it out http://codepad.org/A3Pc8o56. I was able to debug into the native dll and see the struct members. I then tried modifying various compile and link options in the dll. None of these messed up my debugging. Can you get this to work? If so, maybe edit in your C code...? – TooTone Apr 24 '13 at 14:03
  • I really appreciate all the effort you guys made trying to help me! This is what makes SO such a great place! Too bad it turned out to be a bug in VS :P Thanks! – henriksen Apr 30 '13 at 13:43
  • I have the same problem with Visual Studio 2012 Update 4. As a workaround I just copy function parameters (e.g. pointers to struct) into local variables of the same type. These local variables show up correct. Of course I do this only if DEBUG is set. – MTR Jun 11 '15 at 14:39

1 Answers1

2

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.

Excelcius
  • 1,680
  • 1
  • 14
  • 31
  • Looks like this is it. I've got Update 2 installed. I'll just have to hold on for the next CTP of Update 3. Thanks! – henriksen Apr 30 '13 at 13:42