Why can the .exe file under the Release folder be used to debug in VC++? - windows

I'm using Visual C++ 2010 to develop a Win32 application (without MFC). When I pressed F5 to debug my application, a new .exe file was produced under the Release folder rather than the Debug folder, because the project configuration in the current active solution configuration(which was Debug) was Release for some reason.
I was wondering why the .exe under Release folder, which seemed to be of a smaller size than the one under the Debug folder, could also be debugged.

Debug and Release are just a configuration names and a debugger knows nothing about which one is intended for debugging purposes right now.
Internally they are equal. The default property values is the only difference. You can easily swap them manually in order to debug optimized code, for example.

1) In Debug mode there are no optimizations performed by the compiler, while in Release mode there are optimizations. In release mode compiler performs some low-level changes to the code ,so that some pieces of code gets modified to achieve optimization.
2)In debug mode we have few settings enabled by default with help in generation of debug symbols and files related to it like Map file, PDB etc .These files are essential in debugging a crash dump .

Related

TwinCAT Is there a difference when building a project in release or debug mode?

I've always wondered if there is a difference if you build a PLC project in the Debug or Release configuration. I don't think there is since the .compileinfo file in the _CompileInfo folder is the same size and it has the same filename (some hash I guess). Also when I log in after building with the other configuration, I do not get the prompt if I want to log in with online changes.
Does anyone know if the build configuration has an influence on the compiled code?
Short answer:
No, there is no change to the built code.
Long Answer:
The Build Configuration Tools that are referred to are primarily designed for implementation with general text based languages, rather than the TwinCAT layer that Beckhoff has stacked on top of Visual Studio.
Under standard languages there are a lot of properties that can be managed at the project level, and these properties are what are being modified when you change from debug to release configuration.
Twincat projects however are made up of two separate projects (proj_a.tsproj, proj_a.plcproj), and Visual Studio only recognizes one of these as a project file that can be modified, the .tsproj.
So if you want to see what properties will be modified by swapping between debug and release, have a look at what properties are available from the .tsproj file.
If you want to test this yourself you can disable a project file (proj_a.tsproj) and swap between debug/release to see the disabled status change as a result of swapping between the two build configurations.

How to tell linker that I want my dll build in debug mode to have d suffix

I'm building a library in debug mode and it builds fine, but the built version of this library doesn't indicate in any way that it is built in debug mode. What I mean is that if the library is called mylib and after building it in debug mode I'm getting mylib.dll I don't really know in what mode did I built it. I'd prefer that I would have my output called mylibd.dll or mylib_d_.dll, but is this possible to specify something like it in Visual Studio 2015?
In Visual Studio you can have settings that differ per build configuration. Therefore, to achieve what you want, you would change the library names only for the Debug configuration.
In Solution Explorer, right click on the library in question, and go to Properties. Make sure the Configuration combo is set to Debug. Then, in Configuration Properties select the General group and change the Target Name setting as you like.
There are also several individual settings for the output files generated:
Linker/General/Output File
Linker/Manifest File/Manifest File
Linker/Debugging/Generate Program Database File
Linker/Advanced/Import Library
You can double check the full command line in Linker/Command Line to make sure all the filenames match your expectations.
Similarly, this can be done for static libraries as well. The appropriate configuration properties group in this case is called Librarian.

Add Step Debugging to Release Build

I have a C++ project experiencing one of those annoying problems that show up in Release but not Debug build.
So I want to create a third build configuration that is identical to Release except that it generates the PDB files (anything else?) that are needed to support step debugging and value inspection within a VS debug session when it hits an exception.
What Compiler and Linker settings do I need to change to enable this?
Once you enable optimizations, you aren't able to inspect things that are optimized away.
When you see such an entity, switching to Assembly mode with source lines alongside and looking at the processor instructions can give you hints where it went (e.g. a variable could have been moved into a register, then you can inspect the register instead).
PDB generation is enabled by default in Release configuration in VS2008. If not, the linked question lists the relevant settings.

Debugging issues

I have a certain application in MSVC6.0 all C code. I have it as two workspaces :
1.) First workspace creates a static library file, *.lib after compiling the source.
2.)Second workspace has a test application(main()) and links the previously generated *.lib library and creates and exe.
When i try to single step the test application, i am not able to do so.
It keeps asking for a file crt0.c and even after pointing it to that file, i am not able to step in my main function at all, it exits without even entering my main.
[The same setup works if i just exectute Ctrl-F5. It works fine with correct output, so no issues in execution]
But i need to debug/single-step.
So i did one thing to verify.
Created one new workspace in MSVC6.0 (Win32 console application without generating this library et al. A single workspace generating an exe. In this new setup, i am able to debug through the main().
1.) Any pointers what is happening? Why am i not able to debug in my library-executable setup?
2.) How can i do the debugging in that setup? Any project settings i am missing on?
-AD
Under Project Settings / C++ / General, ensure you have debug information enabled, e.g. set to Program Database. Under Project Settings / Link / Debug, make sure Debug info is ticked and Microsoft format is selected.

Attaching to a foreign executable in Visual C++ 2003

I have an executable (compiled by someone else) that is hitting an assertion near my code. I work on the code in Visual C++ 2003, but I don't have a project file for this particular executable (the code is used to build many different tools). Is it possible to launch the binary in Visual C++'s debugger and just tell it where the sources are? I've done this before in GDB, so I know it ought to be possible.
Without the PDB symbols for that application you're going to have a tough time making heads or tails of what is going on and where. I think any source code information is going to be only in that PDB file that was created when whoever built that application.
This is assuming that the PDB file was EVER created for this application - which is not the default configuration for release mode VC++ projects I think. Since you're asserting, I guessing this is a debug configuration?
Short of any other answers, I would try attaching to the executable process in Visual Studio, setting a break point in your code and when you step into the process you don't have source to, it should ask for a source file.
Yes, it's possible. Just set up an empty project and specify the desired .exe file as debug target. I don't remember exactly how, but I know it's doable, because I used to set winamp.exe as debug target when I developed plug-ins for Winamp.
Since you don't have the source file it will only show the assembly code, but that might still be useful as you can also inspect memory, registers, etc.
Update
If you are debugging an assertion in your own program you should be able to see the source just fine, since the path to the source file is stored in the executable when you compile it with debug information.

Resources