Visual Studio - Debugger Breakpoints Move and no longer hit the lines they are supposed to

我是研究僧i 提交于 2021-02-07 05:45:08

问题


Currently I'm seeing an oddity in functions in one of my programs in visual studio is acting. VS allows me to put break points at certain points in the file, but then in debug mode it moves these break points to spaces and comments.

Things I've already tried:

  1. Deleted the PDB file and rebuilt.
  2. Deleted the EXE file and rebuilt.
  3. Rebuilt the whole project. (Clean, Rebuild)
  4. Checked that Optimization is off.
  5. Checked that the debug path is the same as the build output path.
  6. "Require source files to exactly match the original version" flag is checked.

In case there is simply something odd with my code causing this here is the function it happens in:

bool BManager::Record(string _strFile)
{
   bool bSuccess = false;
   CBitmap * bitmap = new CBitmap();
   HBITMAP  handle = NULL;
   HPALETTE hPalette = NULL;
   //LoadBitmapFromBMPFile( (LPTSTR)_strFile.c_str(), &handle, &hPalette);
   ofstream out;
   out.open(_strFile.c_str());

   handle = (HBITMAP)LoadImage(NULL, (LPTSTR)_strFile.c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);

   bitmap->FromHandle(handle);
   bSuccess = ImageBitmap_Record(bitmap);
   delete bitmap;
   bitmap = NULL;
   CloseHandle(handle);
   return bSuccess;
}

Any thoughts?


回答1:


Make sure the file containing that code doesn't have any optimization flags that override the global settings.




回答2:


I found end-of-line could cause the problem like this. Once I changed some lines from the windows style carriage to linux style carriage by accident, the debugging point no longer hit the line. What I did to solve the problem was using notepad++ to fix EOL




回答3:


When I see things like this the first thing i always do is to open up the Debug->Modules window and make sure that the binary I'm debugging was loaded from the place I think it should be.




回答4:


Here are some ideas:

  1. Your source file has been changed since you last ran the debugger.
  2. Your code has been optimized and perhaps some lines removed by the compiler through optimization.
  3. VS doesn't like the actually line the breakpoint is assigned to. It always likes the the last line of a statement spread across several lines.
  4. The source file your displaying is different than the source file that was compiled (they could be from two different folders).



回答5:


I had the same problem and worked around it by creating a new "solution" in VS and importing the existing .h and .cpp files into it.

Debugging problems gone.

I'm sure the issue was somewhere in the config settings.



来源:https://stackoverflow.com/questions/4617554/visual-studio-debugger-breakpoints-move-and-no-longer-hit-the-lines-they-are-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!