Question

I need to disable some code when run under the debugger.

So, I just imagine that doing:

{$IFNDEF DEBUG} 
  ...
{$ENDIF}

However, the code inside the ifndef is executed in the debugger, makin it crash.

I have lazarus 0.9.29 & FPC 2.4.0

Was it helpful?

Solution

The compiler directives that you mention are actually THAT: compiler directives, not debugging directives.

They relate to the compilation process, witch is completely separate from the debugging system.

What you have to do is:

  • When you want to debug the program, define the DEBUG symbol. This will NOT compile the blocks that exist inside the tests and will not run on the debugging session.
  • When you do want to release that code just un-define DEBUG and all is ready to ship.

You are confusing compilation and debugging and putting them in the same context.
They actually reside in complete separate contexts.
This could be due to the fact that you compile and debug under the same GUI system, but if you compile a program the only thing the debugger looks for is break points.

Hope it helps.

Edit: You can define it by a Simple {$DEFINE DEBUG} somewhere at the top of your Program/Unit or use the Lazarus Options pane to add it as a command line param.

To complete my answer.

OTHER TIPS

 {$IFOPT D-}
  //code
 {$ENDIF}

if $DEBUGINFO is on that is run with debugger!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top