Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are breakpoints green and not working?

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?

like image 404
Oh nooo Avatar asked Oct 13 '15 11:10

Oh nooo


People also ask

Why is my breakpoint not working?

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 you activate a breakpoint?

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.

Why debug is not working in IntelliJ?

To solve this, simply remove the jar of the debugged module from all modules' dependencies in the Project Structure. If you do not know which modules have the debugged module jar as dependencies, you can use some tools (Eg. Sublime Text, bash, ...) to search for the module name which is stored in Intellij *.


2 Answers

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

like image 138
asd-tm Avatar answered Sep 30 '22 03:09

asd-tm


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).

like image 25
AlainD Avatar answered Sep 30 '22 01:09

AlainD