4

I am trying to run a debug on my code, but somehow it stopped working. Here is a snippet and the green lines it is showing:

snippet

  • I have tried to right click on my project and clean it.
  • Tried to delete temporary files, like .stat and .dcu.
  • Switching back and forth to Release and Debug modes, rebuilding, recompiling them.
  • The Debugging options under Project -> Options -> Delphi compilingare all set to true.
  • Checked if there are no duplicate files in the search paths.
  • Other projects are working correctly.
  • Also tried swearing.

What am I doing wrong?

Oh nooo
  • 478
  • 5
  • 19
  • Did you do Build project after change settings? – Roman Marusyk Oct 13 '15 at 11:24
  • 2
    And are you making a debug build? – Jens Borrisholt Oct 13 '15 at 11:26
  • Are there any other breakpoints working? If yes then the code you want to debug is not used in the application. – Wosi Oct 13 '15 at 11:29
  • No, breakpoints are not working at all. Nowhere in the code. Yes, as I said, I tried to rebuild everything again in debug mode. – Oh nooo Oct 13 '15 at 11:31
  • 3
    Well if swearing didn't help, I don't know what to say. – Jerry Dodge Oct 13 '15 at 11:36
  • 1
    Maybe you have an host application set which does not suit your needs in *Run -> Parameters -> Debugger -> Host application*? Or *Run -> Attach to process* have to be set before start debugging? – fantaghirocco Oct 13 '15 at 11:39
  • @fantaghirocco good idea, but sadly no, it is empty. – Oh nooo Oct 13 '15 at 11:41
  • Does it work if you place a breakpoint in the project main file on `Application.Initialize`? – Jerry Dodge Oct 13 '15 at 11:43
  • Then it must be something in the project settings. – Jerry Dodge Oct 13 '15 at 11:56
  • SO question: [why breakpoints from time to time are not usable?](http://stackoverflow.com/questions/5679989/delphi-why-breakpoints-from-time-to-time-are-not-usable-green-highlighted-line) – fantaghirocco Oct 13 '15 at 12:07
  • 1
    Try renaming the `.dproj` file to something else, for example adding an extension `.old` and then re-load your project. It will auto-generate a new one. Sure, you might lose a bunch of settings, but it seems the easiest solution. – Jerry Dodge Oct 13 '15 at 12:15
  • We occasionally have this problem building using MSBuild rather than the old-school IDE compiler on XE8 – Matt Allwood Oct 13 '15 at 12:40
  • 2
    Have have this issue on a regular basis. It exists since several Delphi version up to the latest. I never found a way to reproduce it easily. Nevertheless, to make it work again, I follow those steps: 1) Do a clean, 2) Stop the IDE, 3) Do a full build. – fpiette Oct 13 '15 at 14:06
  • what about • The Debugging options under Project -> Options -> L:inking ? Do you build monolithic EXE or with BPLs? What can you see in View -> Debug windows -> modules ? – Arioch 'The Oct 15 '15 at 17:14

2 Answers2

8

It is a kind of normal compiler behaviour. It ever happens when the procedure (code line) is never called from anywhere inside your program. Compiler skips such procedures and functions (all the code lines within them). See the picture.

enter image description here

You just need to check if the procedure (line) is really at least once called from anywhere inside your application.

Appended

This also takes place when the code line can never be called and this (the logic statement) can be evaluated at compilation (the result is known in advance and can not be affected at runtime). The compiler optimizes the code skipping such lines. That is why it does not accept breaks at them.

enter image description here

Here is a diassembly of the latter procedure. The if false then ... statement at lines 37 and 38 is omitted:

enter image description here

asd-tm
  • 3,381
  • 2
  • 24
  • 41
1

Adding to the answer from asd-tm, I include the following line in all my units:

unit SomeRandomUnit;
{$I ProjOptions.inc}

In the ProjOptions.inc file, I include the following code:

// Compiler switches:
//              Debug Info      Optimisation
// DEBUG            On              Off
// RELEASE          Off             On
{$IFDEF DBG}
    {$D+}
    {$O-}
{$ELSE}
    {$D-}
    {$O+}
{$ENDIF}

In this way, optimisation is off and debug information switched on when I am debugging without me worrying about accidentally toggling something in Project > Options. Manually deleting DCU files from the PROJECT\objects folder (combined with the above .inc file) should guarantee breakpoints working again (at least in DEBUG builds).

AlainD
  • 5,413
  • 6
  • 45
  • 99