Class Variable Not Found When Debugging - c++

I'm currently using Visual Studio Express 2013 for Windows Desktop. When debugging my program, I'm running into an odd issue. When mousing over a class variable, instead of showing the value of it, nothing pops up. I then tried creating a watch for the variable. Instead of finding the variable, the value displayed in the Watch window simply says: "class "class" has no member "variable name". Here is a screenshot to demonstrate what I'm describing:
http://i.imgur.com/6cAOb8S.png
As shown here, the variable m_lineProgramID's value is unable to be displayed in the watch screen. None of the variables that start with m_line are found in the local variables list, yet the line "m_lineProgramID = 0;" doesn't cause an issue. In addition, I tried adding the variable to the constructor's initialization list and initialize it to 0, which also does not cause an issue.
Edit: Just to add a little extra info. I am compiling my program in Debug mode as a 64-bit executable. I've made sure to get 64-bit versions of the libraries I use and have not had an issue running my program until now. Additionally, I renamed both the class and the header & implementation files. I now get a new error: http://i.imgur.com/TozmJZJ.png
Edit 2: I figured out the error that was causing the "Internal Error". I was storing my class in a std::map, and forgot to change the name when using std::make_pair to add an entry (although the class name was correct when I defined the map). This fixed the C1001 error I got and renaming the class and files seems to have fixed the original issue. If anyone could shed some light on why I had the issue in the first place, I would be extremely grateful.

Related

Greyed out code in VS Code C/C++ Extension

i'm trying to solve the following issue with VS Code and the C/C++ Extension from Microsoft.
The mentioned Extension adds a reference count above every function/object definition in the source code. That's a helpful feature so far, but for me it doesn't work as intended I think.
In my example I started implementing a thread-safe linked list to practice (please ignore the code, thats not what this topic is about). The whole class is greyed out although I import the header-file and instantiate an object of that class in the main.cpp file in the main-function. Also, the whole main function is greyed out because no references to the main-function are found. That makes no sense to me, why would I ever reference the main-function in my code? It's the entry point to the program and shouldn't be referenced in my project source code afaik.
When I disable the C/C++ Extension, the reference counts are gone and the source code is highlighted again. But I would really like to keep the reference count and only get rid of the greyed out code (or make it work properly so that main function and definitions I reference in my code are not greyed out).
Also by disabling the extension, code auto completion is gone. So that's not a good trade.
I spent hours of reading the configuration and searching the web for solutions, but I couldn't find anything helpful.
The only thing slightly realted to the greying out of code I found is the option "Dim inactive regions" found in the C/C++ Extension's setting. But it didn' solve my problem.
Thank you in advance for reading/trying to help!
Example of greyed out code and reference count:
greyed out main function because of 0 references to main:
Dim inactive code option:
Update:
So it turned out that the reference counter not only disappears when I disable the C/C++ extension but also when I disable the TypeLens extension. That does not solve my problem but at least I can get rid of the greyed out code by disabling TypeLens and still use the auto completion the C++ extension provides.
Possibly you should declare your main function with
int main(void)
or
int main(int argc, char * argv [])
As I mentioned in the updated question, the problem isn't realted to the C/C++ Extension. It is acutally the TypeLens extension that causes problems here.
The best solution I have found is to configure TypeLens to not grey out unreferenced code. This way I can keep the reference counter and the code completion feature from the C/C++ extension but prevent the source code from being greyed out by TypeLens.
To achieve this, you have to set the Typelens:Unusedcolor value from #999 to nothing (just delete the value).

VS,C++. No errors in the Code Editor however when debugging, the Output Window has lots of errors that don't make sense

So I have written a program in the Code Editor window and when checking it, it all makes sense. There are no errors (the red squigly line) and the warnings/advice that are there I understand.
However then I go to build the code and run it, it will not run because it finds errors. 29 of them at the time of writing. It shows them in the Output Window. The worst part is that the Code Editor itself does not display the corresponding errors. The Output Window will say at line 13 is an error, but I'll go there and the Code Editor says it's all fine and there is no error. So which one is correct?
A few examples:
I have a vector class of
vector<Point>points;
and the Editor says it's fine, however the Output windows is saying "error: missing ';' before '<'" so on paper it wants me to fix it to
vector;<Point>points;
But that is clearly wrong and then the Editor also highlights it as wrong. Other errors also don't make sense. I have a function called
string toString(){}
And the Output windows will again, say "error: missing '('" however there isn't the function is complete with no missing bits.
How do I get the Code Editor and Output Window to work together and display errors that are actually there, because right now they're both at conflict with each other.
About There are no errors (the red squigly line), I suggest that you could check if your VS setting Tools->Options->Text Editor->C/C++->Advanced->Disable IntelliSense is False.
All C++ standard library types and functions are declared in the std namespace or namespaces nested inside std. So, if you use functions like vector, you could add std::vector. I suggest that you could use std::function rather than using namespace std; Also, you could refer to Microsoft Docs about namespace.

"Unable to open file libc++abi.dylib". Program builds, but crashes upon being run. Using xcode 10.1 (10B61)

newbie here. I am following along this SFML flappy bird tutorial. I am currently stuck at this portion of stage creation where a "Splash State" (or logo loading screen) is made. The code of which is exactly the same as what is shown here.
I am using xcode 10.1.
The project builds. But when I tried running it, it crashes and I am greeted with the following:
Failed to load image "Resouces/res/Splash Background.png". Reason: Unable to open file
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: map::at: key not found
(lldb)"
If I understand it correctly, it's saying it cannot perform the action of loading the image at the aforementioned path because it is not able to open "libc++abi.dylib". And now the program is being terminated. (please help me understand this problem better by either confirming or correcting me here).
When I tried looking for "libc++abi.dylib", it is missing. Instead, I can only find "libc++abi.td".
This thread says to add that under Link Binary With Libraries. That did not produce any result.
The tutorial shows that the code runs and a "Splash State" or logo screen is expected to appear. Instead my program crashes and I am greeted with the aforementioned error.
I was wondering if anyone else ran into similar issues?
It's solved. It is made by a typo on my end... sorry.
I'll try my best to explain it here for those of you who may have the same issues:
The game asset is governed by a map, which is a private member variable of a "AssetManager" class. The typo is at the file path. Because of this, the map never inserted the key since the file path isn't valid.
When the map is later accessed, it would be out of range since nothing ever got inserted (since the asset did not load).
Basically, the error of not being to open "libc++abi.dylib" is caused by the map being out of range.

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.
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?
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.

Visual Studio: Garbled debug watch of std::string's?

When I'm debugging C++ mixed (managed/unmanaged) projects in Visual Studio 2005, I often get weird data from the debug watches, like below :
(btw, the variable i_processName is a const std::string & )
alt text http://img175.imageshack.us/img175/3561/43419953av1.jpg
Note that the variable actually holds valid data - if i print it to stdout, the printed string is just fine, thanks for asking.
The simpler types of data (e.g. ints) (usually?) get their correct values shown.
Did this ever happen to you too?
This is a major PITA when debugging, so ... any ideas on how to make the watches show the correct data, or what's causing this?
Debug display of custom types (this includes the STL) depends on the file autoexp.dat located in the <install_path>\Common7\Packages\Debugger folder. Make sure that yours matches your library version and that an older version of this file hasn't been kept around (when upgrading for example).
Note that you can also write your own visualizers for other types, more info here and here. This is a major time saver for complex projects, well worth the (small) effort put into writing custom visualizers.
Yes, i see this problem in my debuger, in my case its connected to Unicode vs NonUnicode.
Looks like your debugging symbols are incorrect.
Check the modules debug window (menu: Debug>Windows). Check that modules you are debugging have "Symbols loaded." listed under the Symbol Status column. Check that the Symbol File listed is the file you think it should be. You can right click a module and get more info about how VS loaded the symbols and you can reload them as well.
If you're having symbol loading problems you can set paths and other settings under Tools>Options>Debugging>Symbols.
A bad call stack can cause issues like this as well. Make sure the stack doesn't have any entries like "the stack may be incorrect for this point...". Does it?
It also can be something odd with Visual Studio confusing native and manged data types in the visualizer, but I doubt it. The popup in your screen shot looks like the debugger know what the variable is.
One thought -- the STLPort implementation of std::string uses a split buffer implementation. It has a small static buffer (I want to say 14 characters) and a pointer to a char array. One of these will be invalid and the other will contain the string data, depending on the length of the stored string. If you're using STLPort or a similar implementation, your string visualizer might be looking at the wrong buffer, which happens to contain junk data.
I beleive that Aardvark is probably onto the correct answer. If i remember correctly when you are compiling mixed mode, the compiler will turn as much of the C++ code it can into code that runs on the CLR, and consequently memory that is owned by the CLR. My geuss is that the debugger is confused about where the string is held - unmanaged or managed memory.
This is a bug that has been in the Visual Studio debugger since forever and still occurs in Visual Studio 2019.
It is random.
Sometimes making a code change and recompiling resolves the problem, and sometimes it doesn't.