0
votes

I have a project in Visual Studio that I have been working on for a while, and I have used the debugger extensively. Recently I changed some settings and I have lost the ability to stop the program and step through code. I can't figure out what I had changed that might have affected this.

If I put a breakpoint in my code and try to have the program stop there, it doesn't. The break point shows up white with a red outline. If I hover the mouse over it, it says "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line. Possible causes include: conditional compilation, compiler optimizations, or the target architecture of this line is not supported by the current debugger code type."

I know for a fact that the program executes the code where the breakpoint is because I put the breakpoint in the beginning of the InitializeComponent method. The program displays the window fine, but does not stop at the breakpoint. Yes, I am running in debug mode.

It seems as though there is a disconnect between the compiled code and the source code displayed. Does anyone know what that would be, or know which compiler settings I should check to re-enable debugging?

Here are the compiler options:

/GS /analyze- /W3 /Zc:wchar_t /I"D:\dev\libcurl-7.19.3-win32-ssl-msvc\include" /Zi /Od /sdl /Fd"Debug\vc110.pdb" /fp:precise /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Oy- /clr /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\mscorlib.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Data.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Drawing.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Windows.Forms.DataVisualization.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Windows.Forms.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Xml.dll" /MDd /Fa"Debug\" /EHa /nologo /Fo"Debug\" /Fp"Debug\Prog.pch"

The linker options are:

/OUT:"D:\dev\Prog\Debug\Prog.exe" /MANIFEST /NXCOMPAT /PDB:"D:\dev\Prog\Debug\Prog.pdb" /DYNAMICBASE "curllib.lib" "winmm.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /FIXED:NO /DEBUG /MACHINE:X86 /ENTRY:"Main" /INCREMENTAL /PGD:"D:\dev\Prog\Debug\Prog.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\Prog.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"D:\dev\libcurl-7.19.3-win32-ssl-msvc\lib\Debug" /ASSEMBLYDEBUG /TLBID:1

4

4 Answers

0
votes

Not pretend to be a full answer, but here are some thoughts:

  • Make a backup copy of your project (to prevent further damage)
  • Delete all compiled binaries and object files: whole Debug folder and maybe something else. Leave just source files, project files and solution files (and assets, forms, databases etc. if you use it). It is also good idea to remove other build folders, e.g. Release.
  • Rebuild project
  • Make sure that debugger starts project that you expect: right click on a project in Solution Explorer and choose Set as StartUp project
  • Make sure that debugger starts binary that you expect: Project Properties - Debugging - Command
  • Close all files opened in VS. Reopen source file with breakpoint by clicking in Solution Explorer. Make sure that your source file with breakpoint is the same that used during compilation: go to source folder and open it by double click. Compare path to file opened in editor and file in source folder. Also make sure that you saving file before compilation.
  • Try start debugging using Step Into. Then click Show next statement. If it will not step into main() something really broken ;(
  • If nothing helps, just create new project, copy your source files in its folder and add them recursively to your new project.

How to prevent it in future:

To prevent time loss, code loss and frustration in such situations, programmers use Version control systems. They allow to save your coding results incrementally, in a way you can quickly compare any two steps, observe what was changed, and roll back if needed.

Most popular systems are: Subversion (SVN), Git, Mercurial (Hg). All thee can be integrated to Visual Studio.

Love your code and never loose/break your work results!

Hope it helps. Happy coding! =)

0
votes

I had a similar problem, it was resolved by setting the linker option "Debugging/Generate Debug Info" to "Yes(/DEBUG)". (Although I see you already have this set in your linker options...)

0
votes

I am new to Visual Studio and C++,hope support a clue for you.My expression is poor,so I choose use code to show my suffer.

#include <stdio.h>
#include <iostream>
class Circle
{
public:
    int x;
    Circle() {
        x = 2;
    }
};
int main() {
    Circle circle; 
    printf("%p\n", &circle);
    printf("yyy\n");
    system("pause");
    return 0;
}

this is a very simple example.However if you put a break pointer in main(){}(any line before system("pause")),then debug it.As you said before,it will warn you

The breakpoint will not currently be hit.No executable code of the debugger's target code type is associated with this line. Possible causes include:conditional compilation,compiler optimizations,of the target architecture of this line is not supported by the current debugger code type.

However,if you put class Circle in a .h ,it will allow you debug main().The code as below: Header.h

class Circle
{
public:
    int x;

    Circle() {
        x = 1;
    }
};

Source.cpp

#include <stdio.h>
#include <iostream>
#include "Header.h"
int main() {
    Circle circle; 
    printf("%p\n", &circle);
    printf("yyy\n");
    system("pause");
    return 0;
}

It's contructor make a trick.

0
votes

This behavior is possible when compiler does automatic optimizations. You can try disabling Compiler optimization and rerun.

Select Project Properties -> C/C++ -> Optimization.
In Optimization, choose option Disabled (/Old).