Delphi: why breakpoints from time to time are not usable (green highlighted line on IDE)?

Solution 1:

Debug info isn't present in the file.

Make sure that you're using the Debug configuration. (Project Manager tree, expand Build Configurations, make sure Debug is bold. If it's not, right click Debug and choose Activate from the context menu.) Make sure you then do a Build of your project, not just a Compile.

If that still doesn't work, go to Project->Options from the IDE's main menu, click on Compiling under Delphi Compiler, and check the Debugging section on the right half of the window. Make sure that Debug Information and Local Symbols are both checked. If you're trying to trace into the VCL's own source, also check Use debug .dcus (you'll want to turn this off and do a full build of your project as soon as you're done, as it gets annoying when you're debugging normally). Again, you'll want to build and not compile.

If all of the above fails, another possibility is that the code unit you have open in the Code Editor isn't the same one being seen by the compiler. Make sure you don't have multiple copies of the file on your computer in a location that the compiler might find first. If you're not sure, delete the .dcu files with that unit name and then do a build of your project, and see if the newly created .dcu is in the location you'd expect.

Solution 2:

I found a better way.

From the Project Manager tree, right click on the project and choose "Clean" from the popupmenu.

The breakpoints reappear magically and it is a very fast method.

Solution 3:

I suspect this happens when you have done a release build, with debug disabled. Then you switch back to debug configuration and do a compile rather than a build. The files where you can't set breakpoints correspond to those with DCUs produced by a compile with debug disabled.

Simply doing a build to re-generate all DCU files will make your breakpoints work again.

Solution 4:

Here's one more reason to misaligned code vs breakpoint markers (blue/red "pill" in the gutter).

The editor recognices three different line endings,

  • CRLF (Carriage Return - Line Feed pair)
  • CR only
  • LF only

Of these, CRLF is the default in the editor.

The compiler however, doesn't seem to consider CR only as a line ending, only CRLF and LF only. Thus if your source file happens to have one or more CR only, the "blue pills" will be offset from the source.

You might have got source files with CR only EOL (end of line) character from e.g. the internet. I recall MAC OS used CR only as EOL.

To verify the EOL's in your file, you can turn on the displaying of EOL's in the editor

( Tools - Options - Editor options - Source options - Show line breaks).

The symbols look weird (see images below), but are just C on top of L for CRLF, C on top of R for CR and L on top of F for LF.

The following images show the normal EOL's (CRLF) and the EOLS's after I forced CR only for one line and LF only for another line in a hex editor. As said above, it is the CR only that offsets the break point markers from the source code.

Normal CRLF EOL's:

enter image description here

One line with CR only and one with LF only:

enter image description here

Fix
To reset all EOL's to CRLF, untick Preserve line ends in Editor Options

( Tools - Options - Editor options),

make a trivial change, so that the file is marked as modified, close the file, save changes to XYZ.pas? YES, and reopen.
Now all line endings are CRLF. Rebuilt the project and all the breakpoint balls will be in the correct locations.