13

My problem is basically that whenever I debug using Visual Studio (2015 Community edition on Windows 10 machine), and I try to hover over a variable or look at a variable in the locals or autos section of the debug view, I don't see the actual data saved in the variable.

This is a problem I have seen with both strings and vectors. For strings, it will show npos=4294967295

and if you keep clicking the drop down arrows, you will eventually get to the actual string saved in that variable; only after digging into the internal structure of the variable, like std::_String_alloc and _Mypair and _Myval, etc. Same for vectors.

Has anyone ever experienced this problem or knows how to fix it?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Denee McClain
  • 131
  • 2
  • 3
  • Do you show a screen shot of this? `std::string` does have a static member called `npos` that is max that `std::string::size_type` can hold. – NathanOliver Nov 10 '15 at 16:43
  • VS comes with XML-like files which describe how to visualize std data structures. Somehow, these aren't working for you. I've seen this happen on someone else's machine, but we never figured out how to solve it. – melak47 Nov 10 '15 at 17:09
  • Are you sure that the variables you try to visualize are in your current scope? Otherwise the uninitialized looking variables are normal. – Adrien Hamelin Nov 10 '15 at 17:18
  • 2
    melak47 is right, you should probably ask this on the [social.microsoft.com forums](https://social.msdn.microsoft.com/Forums) – BeyelerStudios Nov 10 '15 at 17:34
  • @melak47 and BeyelerStudios are both correct, you can also try reinstalling VS2015. – Jonathan Howard Nov 10 '15 at 17:59
  • Is this a mixed-mode app? Also trying enabling the "Enable Native Compatibility" checkbox under `Tools | Options | Debugging`? Still waiting for that **Update 1** to get released, at the moment though it is RC. – Chris O Nov 13 '15 at 00:17

5 Answers5

8

I had the same problem. I assume you are debugging an unmanaged (native) C++ DLL that is part of a solution that uses a managed EXE? In my case I have a C# WPF EXE which PInvokes functions in an unmanaged C++ DLL.

"Fixes" that worked in my case:

FIX 1: Uncheck "Use managed compatibility mode" in the debugger settings: You can do this at Tools/Options/Debugging/General. See: https://stackoverflow.com/a/33462362/5556801 For some discussion of what "managed compatibility mode" is, and why you normally want it unchecked, see: http://blogs.msdn.com/b/visualstudioalm/archive/2013/10/16/switching-to-managed-compatibility-mode-in-visual-studio-2013.aspx

"FIX" 2: As a partial work-around you can first start your process without the debugger (Ctrl+F5), then attach the VS2015 debugger to your process (Debug / Attach-to-Process), but only select "Native code" with the "Attach to / Select..." button. Now when a breakpoint in your native C++ DLL is hit you can hover over std::string variables and VS2015 will show their full contents as expected, including their data members. The disadvantage of this native-code-only work-around is that you won't be able to debug your managed code (e.g. C# or CppCli) at the same time.

Community
  • 1
  • 1
VictorK
  • 81
  • 3
1

In project properties select Debugging->Debugger Type->Native Only. In my case it was Mixed

Alex Isayenko
  • 679
  • 8
  • 7
1

Uncheck Debug->options->use native compatibility mode I got this working great after trying all the above answers.

S.Frank Richarrd
  • 488
  • 1
  • 3
  • 15
0

4294967295 is 0xffffffff that is a 32 bits word with all one bits. On most machines, that is also (unsigned)-1 which is the usual str::npos constant.

BTW, did you try using GCC to compile your code with g++ -Wall -g? Then use gdb for debugging.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 3
    I missed the point of the question in exactly that same way myself on first read. The question is not asking why std::string::npos is 4294967295. The question is asking why visual studio shows the value of `std::string::npos` instead of showing the value of the specific string that the cursor is held over. A std::string has multiple members, including the static member `npos` so a debugger needs some extra knowledge in order to show you the "value" of a string. – JSF Nov 10 '15 at 17:34
0

The thing that helped me is to run Visual Studio (2010 in my case) as Admin. The npos-bug would still occurr otherwise, even when I applied every other proposed solution.

Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46