Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 573
Alikar Avatar asked Jan 06 '11 17:01

Alikar


People also ask

Why breakpoint is not hitting with VS Code?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

How do I fix breakpoint in Visual Studio?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

Do breakpoints stop before or after line?

The breakpoint will stop your program just before it executes any of the code on that line. Set a breakpoint at line linenum in source file filename .


1 Answers

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

like image 86
Mark Ransom Avatar answered Sep 24 '22 15:09

Mark Ransom