Recent

Author Topic: Raise breakpoint with code  (Read 312 times)

dodgebros

  • Full Member
  • ***
  • Posts: 106
Raise breakpoint with code
« on: September 16, 2020, 10:55:11 pm »
I need to have a break point created when certain conditions are met in my code.  How can I do this?

TD

jamie

  • Hero Member
  • *****
  • Posts: 3538
Re: Raise breakpoint with code
« Reply #1 on: September 16, 2020, 10:57:01 pm »
Raise Exception.Create('My Text');

You can also place a break point on the source line when the condition holds true for you and it will stop there ..
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6622
  • Debugger - SynEdit - and more
    • wiki
Re: Raise breakpoint with code
« Reply #2 on: September 16, 2020, 11:12:32 pm »
Code: Pascal  [Select][+][-]
  1. if foo = bar then
  2. asm
  3.   int3
  4. end

Depending on asm-mode, it may be "int 3".

Also I am not sure, how the different debugger back-ends deal with it.
IIRC gdb-based should handle it, FpDebug handles this in trunk.

Code: Pascal  [Select][+][-]
  1. if foo=bar then
  2.   sleep(1); // normal breakpoint here
Or any no-op operation. In asm: nop


Using a breakpoint on a normal code line, you can specify a condition. However string comparison does not work in gdb based. It works with FpDebug (at leat in trunk).

Further more, you can influence breakpoints depending on other code being executed.
https://wiki.lazarus.freepascal.org/IDE_Window:_Breakpoints#Breakpoint_properties "enable/disable group"
A none breaking breakpoint in some code, can enable or disable another breakpoint.
That can for example be used in calling code, so breakpoint are only active when code is called from certain locations.
(This should work with all backends)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6622
  • Debugger - SynEdit - and more
    • wiki
Re: Raise breakpoint with code
« Reply #3 on: September 16, 2020, 11:14:26 pm »

dodgebros

  • Full Member
  • ***
  • Posts: 106
Re: Raise breakpoint with code
« Reply #4 on: September 17, 2020, 05:04:45 pm »
I get "Identifier not found "int3"

My code:
Code: Pascal  [Select][+][-]
  1. if C = 35 then
  2.   begin
  3.     int3;
  4.   end;
  5.  

Is there a unit I need to add to the uses section in order to use the "int3"?
TD

440bx

  • Hero Member
  • *****
  • Posts: 2001
Re: Raise breakpoint with code
« Reply #5 on: September 17, 2020, 05:21:25 pm »
I get "Identifier not found "int3"

My code:
Code: Pascal  [Select][+][-]
  1. if C = 35 then
  2.   begin
  3.     int3;
  4.   end;
  5.  

Is there a unit I need to add to the uses section in order to use the "int3"?
TD
Put a space between "int" and "3" and it will work (Martin_fr mentioned it.)

HTH.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6622
  • Debugger - SynEdit - and more
    • wiki
Re: Raise breakpoint with code
« Reply #6 on: September 17, 2020, 05:25:51 pm »
I get "Identifier not found "int3"

My code:
Code: Pascal  [Select][+][-]
  1. if C = 35 then
  2.   begin
  3.     int3;
  4.   end;
  5.  

Is there a unit I need to add to the uses section in order to use the "int3"?
TD
You do not have an "asm" block.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6622
  • Debugger - SynEdit - and more
    • wiki
Re: Raise breakpoint with code
« Reply #7 on: September 17, 2020, 05:27:32 pm »
I get "Identifier not found "int3"

My code:
Code: Pascal  [Select][+][-]
  1. if C = 35 then
  2.   begin
  3.     int3;
  4.   end;
  5.  

Is there a unit I need to add to the uses section in order to use the "int3"?
TD
You do not have an "asm" block.

And then maybe also, above the block, or at the unit start
Code: Pascal  [Select][+][-]
  1. {$asmmode intel}

dodgebros

  • Full Member
  • ***
  • Posts: 106
Re: Raise breakpoint with code
« Reply #8 on: September 17, 2020, 05:54:20 pm »
This fixed it:

Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. uses dm;
  4.  
  5. {$R *.lfm}
  6.  
  7. {$asmmode intel}
  8.  
  9. ..........
  10.  
  11. if C = 35 then
  12.   asm
  13.     int 3;
  14.   end;            
  15.  

Thanks everyone for the great help!
TD  :D

440bx

  • Hero Member
  • *****
  • Posts: 2001
Re: Raise breakpoint with code
« Reply #9 on: September 17, 2020, 06:39:55 pm »
You do not have an "asm" block.
Good catch.  I missed that.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

 

TinyPortal © 2005-2018