Why doesn't Edit & Continue work for me in VS2008 with a legacy C++ win32 project? - c++

If I create a new win32 C++ project in VS2008 I can use Edit & Continue with it just fine, but with this legacy project I'm working with my attempts to use / enable it have failed.
Here are things I've checked:
Tools -> Options -> Debugging -> Edit and Continue -> Enable Edit and Continue is ON.
Debug Information Format: Program Database (/Zi)
Code Generation -> Enable Function-Level Linking: Yes (/Gy)
Looked for a corrupt .ILK file. I can't find any .ILK files - are they still used in 2008?
But when I step into the program, change the next line, and step again, I get:
"This source file has changed. It no longer matches..."
rather than
"Would you like Edit & Continue to apply your code changes."
What's wrong with this project that E&C doesn't work?

I assume you have debugging symbols/etc and the legacy C++ application had been compiled with this support...
If not, then you will run into the problem that the code was not 'instrumented' to allow for injection of alternate code.
I would suspect that the changes in output code format would make VC++ 2008 incompatible... as I doubt Microsoft added such backwards compatibility in (until VS 2008, I think they even made it hard to use older versions of .Net without using the specific VS)

This messagebox
This source file has changed. It no longer matches the version of the file used to build the application being debugged.
seems only to be appearing when I made a code change on the exact line where the breakpoint is.
I've found that I can just click the OK button. And when I then press F10 to actually execute the line that has changed, "Edit and Continue" kicks in and recompiles the code.
After that, the breakpoint is disabled though (it shows a yellow triangle with an exclamation mark):
To re-enable it, you can just right-click the breakpoint and choose "Location...":
which brings you to this dialog:
:
where you need to check the "Allow the source code to be different from the original version" checkbox. Click OK and your breakpoint will be enabled again.

Related

Visual Studio 2008 c++ Executable (Debug and Release) not working

hope someone can help.
I'm currently writing a 2D game engine in c++. When I run the application from within Visual Studio 2008 using either debug or release all goes fine.
When I then run the executable files (either debug or release) from Windows Explorer, neither work and just display a blank Window.
Does anyone know what is causing this?
Load project into VS 2008
Change configuration to "Debug"
Click the "Start Debugging" button
Application compiles and builds, all is ok
Application runs, all is ok
Close Application
Output window in VS shows "The program '[16672] Mouse Engine v2.exe: Native' has exited with code 0 (0x0)."
Open Windows Explorer window and locate executable file from the Debug folder in project.
Run executable, blank window is shown.
Change configuration to "Release"
Click the "Start Debugging" button
Application compiles and builds, all is ok
Application runs, all is ok
Close Application
Output window in VS shows "The program '[18872] Mouse Engine v2.exe: Native' has exited with code 0 (0x0)."
Open Windows Explorer window and locate executable file from the Release folder in project.
Run executable, blank window is shown.
Some things to look for are missing dependencies such as config files and data files that your program can't find.
You can also try Dependency Walker to make sure all your dll's are available. http://www.dependencywalker.com
There are a few things to check to resolve this sort of problem.
Check all variables are initialised. Seems obvious but this can be crucial. I found best way to solve this is to #DEFINE _LOG at start and output variable values to a log file in each function using #IFDEF _LOG. This way you can turn it on or off.
If your application is just a blank window, check if it is running (using CPU time). This is a good indication that something is preventing it to find any image or font files.
Check that the Debug or Release folder structure matches that within your project folder to ensure links to files and textures work.
Make sure in project preferences to set the Runtime Library entry to Multi-threaded (/MT). This should make your application less dependent on additional dll’s.
Check for problems in your code. See point 1 with using log files to help with this.

Debugg mode isn't working in Visual Studio 2015

I just made a new Console Aplication project in Visual Studio C++. I changed the setup to see the Console when compile&run ( CTRL + F5 ).
However, when it comes to running into debugging mode ( F5 ), the program is ending even if i do have breakpoints in several places.
The red circles turn to white and have an exclamation mark during those 2 seconds while it tries to debugg.
Anyone knows how to fix it ?
(1) Please make sure that your app is in debug mode(not release mode).
(2) Please enable the options like the following screen shot.
Reference:
https://connect.microsoft.com/VisualStudio/feedback/details/797465/visual-c-debugger-does-not-stop-on-breakpoint
There are several things you can check.
First of all assure that the code where the breakpoint is set is reachable. Put it on the entry point of your application.
There is a possibility that the debug symbols where somehow messed up. Hence, try cleaning/rebuilding the project (you can try to delete the bin/build dirs manually).
You could also check under Build->Configuration Manager whether the "Debug" for solution configuration actually makes your project be executed in Debug mode.

Source code is different from original version?

I'm setting break points in Visual Studio before running the Local Windows Debugger, and they all say this when the debugger is running, with a small warning label on each break point. I can't see why this would be happening; people have talked about using different versions of Visual Studio and getting this error, but I made this project earlier today, pasting the base code from my professor into a new project created on my copy of Visual Studio 2012.
I found this when trying to fix a strange error in my program that wouldn't go away even though I manually fixed things (it was a string error that claimed I was using an index outside the bounds of the string; setting this value to 0 explicitly did not fix it) so I presume that this is the actual culprit.
Make sure you're properly building the code (Build Solution or Rebuild Solution).
In the output panel you should now be able to locate where the binaries are located.
Make sure you're debugging the said binaries by looking in the Debugging page of your project properties, the Command property should most likely be set at $(TargetPath).
Other things to look for. The project should be "Set as startup project", the program database option should be activated (by default). Don't modify the source after you started debugging.

Visual Studio 2013 C++ variable watch does not work

I found a thread of another user on another website with the same problem except he is using Fortran while I am using C++:
https://software.intel.com/en-us/forums/topic/508718
In fact, I can cite her/him:
The problem:
My problem is that in the debug mode the program algorithm works fine except it does not show the values of the variables.
I tried the watch window and also moving mouse over the variable but neither of them works.
I tried very simple codes like Hello World and just defined an integer but the program is unable to show the value of the variable in debug mode.
From time to time the debug mode works correctly. Sometimes I have to restart the debugger 10 times and then it works for 1 time. It does not matter whether I add or remove breakpoints.
My setup:
Windows 7 64 Bit
Visual Studio Ultimate 2013 (from MSDNAA, all original stuff) Version 12.0.30501.00 Update 2.
I have another notebook with Windows 7 64 Bit and the same Visual Studio Version installed -> same problem!
I have the same problem once in a while and the following steps help me solving it:
Make sure optimizations are deactivated in your Debug build. If they are enabled you compiler removes stack frames, puts variable values into cpu registers or inlines whole functions. The debugger does not like optimizations.
Make sure you use a Debug Runtime Library (check 'Runtime Library' in 'Code generation' and select Multithreaded-Debug or Multithreaded-Debug-DLL)
Rebuild your application (right click Project -> "Rebuild"). Sometimes there are problems which can be solved by a rebuild (i.e. when you update source files from repository which are older then your binaries but newer then the source you built the binaries from; or when you update your compiler or libraries and only parts of your application are rebuild).
Disable Minimal Rebuild in 'code generation' option page. It may mess up you program database.
If everything fails you may try to create a clean new project with default settings and add all your existing .cpp/.h files. This way you make sure your settings are not messed up.
If you are using global variables defined within a namespace you always have to enter the namespace into the watch window (i.e. a variable 'x' defined in namespace 'Y' must be watched as 'Y::x')
Use getchar(); at the end of the program or at the end of a cout statement. In my experience, I had to use getchar(); multiple times to show the variables and the solution. Try it!

Visual Studio Questions/C++

I'm a hobbyist developer and have a background with Java (IDE of choice was Eclipse). I'm using Visual Studio Express 2010 and wanting to learn C++.
Few questions:
I create a "HelloWorld" in C++ and compiles/runs in VS/Windows. When I try to compile it under Linux/GCC, it obviously throws tons of errors. Default windows console project includes windows specific files; but if just create an "Empty Project" it throws tons of linker/build errors. What's the best practices here to keep my code portable?
Why is it creating 47 files for 8 lines of code?
How do you format code? You can do Edit->Format Selection, but the hotkeys don't work?
How do I output to VS's 'Output' Window? ( like eclipse does when you run a console java app )
It keeps reverting my "Project Location" to my "home directory" every time I restart. How do you change it? Is it a bug? Because it's Express edition?
Is there a way to keep it from switching to Debug view when it runs?
I create a "HelloWorld" in C++ and
compiles/runs in VS/Windows. When I
try to compile it under Linux/GCC, it
obviously throws tons of errors.
Default windows console project
includes windows specific files; but
if just create an "Empty Project" it
throws tons of linker/build errors.
What's the best practices here to keep
my code portable?
For portable code, avoid VS wizards entirely. Use Make/NMake if you're starting with rocks and sticks, or the portable build system of your preference (Ant, CMake, etc.) Some of these will spit out a VS solution/project file for you to use.
Why is it creating 47 files for 8
lines of code?
Wizards are magical like that.
How do you format code? You can do
Edit->Format Selection, but the
hotkeys don't work?
Ctrl-K Ctrl-F (under Edit, Advanced)
How do I output to VS's 'Output'
Window? ( like eclipse does when you
run a console java app )
Lookup OutputDebugString() for the debug window. Output window should get all cout/cerr output.
It keeps reverting my "Project
Location" to my "home directory" every
time I restart. How do you change it?
Is it a bug? Because it's Express
edition?
Probably hidden in options somewhere - don't know that one, sorry.
Is there a way to keep it from
switching to Debug view when it runs?
Launch using Ctrl+F5 to run without the debugger attached.
Have fun!
I create a "HelloWorld" in C++ and compiles/runs in VS/Windows. When I try to compile it under Linux/GCC, it obviously throws tons of errors. Default windows console project includes windows specific files; but if just create an "Empty Project" it throws tons of linker/build errors. What's the best practices here to keep my code portable?
It's fairly difficult to keep your code truly portable if you're writing Windows applications. Standard C++ will obviously work on either platform, but Linux can't run Windows applications, and vice versa. Remember that console applications are also considered Windows applications. They're not any more "pure" just because they are text-based, rather than graphical. Windows applications have their own entry point, different from the standard main function found in ANSI C++ (technically, main is still there, but it's hidden and called internally by the Windows libraries).
The best thing to do is not to link to any of the Windows headers. Unfortunately, you won't be very satisfied with the results. About all that you'll be able to generate is library code. You can't get a UI on the screen unless you use the Windows functions to do it.
An "Empty Project" is just what it says—empty. I assume the build errors are because you're trying to call functions that aren't defined anywhere. You'll find that you need to include windows.h to get off the ground, which instantly makes your code non-portable.
Why is it creating 47 files for 8 lines of code?
This is obviously an exaggeration; none of the wizards produce anywhere near that many code files. Especially not the "Empty Project", which doesn't create any at all.
A Win32 console application includes the following 5 files:
stdafx.h and stdafx.cpp — these files are used to enable "precompiled headers", meaning that Visual Studio will compile all of your headers once, and only recompile them when they change, rather than recompiling them each time you build the project. This used to provide enormous speed boosts, and still does on large projects. You probably don't need or care about this for small projects, but it's not a bad idea to get familiar with their usage if you're going to be developing in Visual Studio.
A targetver.h file, whose only purpose is to specify the earliest version of Windows that you want your application to run on. This is necessary because later versions of Windows add additional functionality that wasn't available in previous versions. Your app won't run if you link to functions or libraries that don't exist. Set this up once and then forget about it.
A <projectname>.cpp file, which is the implementation code for your application. This is pretty standard stuff—it includes the _tmain function, which is the entry point for a console app.
A ReadMe.txt file, which you can immediately delete. It contains some introductory information and describes the files that have been added to your project. (Yes, reading this yourself could have answered this question.)
A Win32 application would have a few more files, but most of the same ones as well. In particular, you'll see a resource file (with the extension .rc) that contains the icons, dialogs, bitmaps, cursors, etc. used in your program.
If you don't like this structure, you can either forgo the use of a wizard, or modify it yourself. There's nothing set in stone about it.
How do you format code? You can do Edit->Format Selection, but the hotkeys don't work?
Formatting code works fine. I'm not sure why people are telling you that Visual Studio doesn't support this, or that you'll need a third-party plug-in. There's no "Format Document" command as there is in C#, but the "Format Selection" command works just fine. The only difference is, you have to select something in order for it to be enabled.
The default keyboard extension for that command is CtrlK, Ctrl+F. It also works fine, right out of the box. My typical workflow is to hit Ctrl+A first to select all.
How do I output to VS's 'Output' Window? ( like eclipse does when you run a console java app )
I don't know what Eclipse does, nor do I know anything about Java. What do you want this to do? When and what things do you want to get written to the "Output" window? A console application will run in a console window, not in the "Output" window. That's not what it's for.
It's intended for debugging purposes. The OutputDebugString function is one way of utilizing it. The output of the standard cerr keyword should be automatically redirected to the "Output" window.
It keeps reverting my "Project Location" to my "home directory" every time I restart. How do you change it? Is it a bug? Because it's Express edition?
This isn't a bug, it's a feature. Visual Studio is designed for working with projects and solutions, not one-off code files. So by default, it prompts you to specify a project folder, a location to store your files. And what better place for the default location than your home folder?
If you don't like that location, you can change it. Under the "Tools" menu, select "Options". Expand the "Projects and Solutions" category, and click the "General" item. Then, change the path of the "Projects location" (the top textbox). Couldn't get much simpler than that.
Is there a way to keep it from switching to Debug view when it runs?
I frankly don't understand how this question makes any sense at all. When you run an application with the debugger attached, Visual Studio switches to a different window layout specifically optimized for debugging. I just answered a similar question. The upshot is that there's no way of telling Visual Studio to use the same window layout for both design and debug view, but I also can't imagine why you'd want to, either. Different things are useful, depending on what you're currently doing.
The two window layouts are customizable, and your changes are remembered. I've customized mine heavily from the defaults; it's very likely that your tastes vary as well. There are lots of great features, like the "Locals" window, which shows a listing of all the values of the local variables in scope at the point where you break into your program's execution.
Also remember that the default "Debug" and "Release" build configurations have nothing to do with whether or not Visual Studio automatically attaches the debugger to your application's process. If you want to start your app without the debugger attached, select "Start without Debugging" from the Debug menu, or press Ctrl+F5. There are lots of side effects to this though, and it's probably not what you wanted. Without the debugger attached, you lose most of what Visual Studio provides to you as an IDE. You might as well just run the app from Windows Explorer without even launching VS.
Finally, if you prefer Eclipse (or at least are already accustomed to its nuances and prefer not to learn Visual Studio's), you can still use it for C++ development. Download it here.
If you're just wanting to learn C++ and you don't necessarily care about the platform, I would probably avoid using Visual Studio to start with. Visual Studio provides some functionality for managing projects and builds, but honestly, I think you're better off learning how to manage code files and use the compiler on the command line first, then working up from there.
If you're on Windows, I'd recommend installing Cygwin and getting the GNU compiler tools through the Cygwin setup utility (gcc or g++).
This is a bit of an opinionated answer, but my experience with C++ on Windows leads me to believe that you'd be better served trying to learn C++ from more of a unix-like angle. Windows C++ adds a whole layer of crap that will just confuse you when you're getting started.