Stopping the debugger under a certain condition lazarus / 12-Debugger ---------------------------------------------------------------------- zoltanleo · 2019-09-24 11:49 Hi guys. I need your help. In my application, in each iteration loop, I parse the string and remove the "extra" characters, e.g.: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           //get position #10 in the line          LineEndingPos_10:= Pos(#10,Buffer);           repeat {until LineEndingPos_10 = 0;}          case LineEndingPos_10 of              0:                begin                {I need to stop the debugger here...}                  BufferStg:= BufferStg + Buffer;                end;              1: //#10 at the beginning of the line                begin                Inc(StrCounter);                  if Length(BufferStg) > 0 then                begin                    //dump the buffer storage to memo ...                    memoOutput.Lines.Add(Format(ConstFormatStr,[Str Counter,'B',BufferStg]));{B}                    memoOutput.SelStart:= UTF8Length(memoOutput.Text);                  end;                  Application.ProcessMessages;                   //clear the storage buffer                  BufferStg:='';                   //clip the first character #10(LF) from the buffer                  Delete(Buffer,1,1);                   //... and continue the cycle further                end              else //#10(LF) in the middle or at the end of the buffer                 ...  The total number of iteration cycles is more than 4400. An error can occur on a cycle with the number 2531, e.g.: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 2528. {C}~ gbak:0 records written 2529. {C}~ gbak:    writing index PK_TBL_LS_INFECTION_HIV 2530. {C}~ gbak:    writing data for table TBL_LS_INFECTION_HIV gbak:0 records written 2531. {C}~ gbak:    writing index PK_TBL_LS_INFECTION_HERPES6 2532. {C}~ gbak:    writing data for table TBL_LS_INFECTION_HERPES6 It will take a very long time if I press F8 2530 times. Can I stop debugging under a certain condition, e.g. when the iteration counter reaches the number 2528? ---------------------------------------------------------------------- lucamar · 2019-09-24 12:12 If you have any kind of counter (say, you¡'re using a for loop or increasing a "total" counter with each iteration) you can set a conditional breakpoint. You can either use "Run -> Add breakpoint" and set the breakpoint properties or set a breakpoint with F5 and then edit its properties by using "View -> Debug Windows -> Breakpoints" ---------------------------------------------------------------------- RayoGlauco · 2019-09-24 12:15 Surely there is a more elegant way to do it, but I usually add temporarily a counter and an extra instruction inside the loop: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  loopcount: integer;{...}repeat   ...  if loopcount = 2531 then    sleep(10);  ...  Then, I set a breakpoint on sleep(10); ---------------------------------------------------------------------- zoltanleo · 2019-09-24 12:32 @lucamar thanks for the advice Quote from: RayoGlauco on September 24, 2019, 02:15:40 pmThen, I set a breakpoint on sleep(10);This is exactly what I wanted to hear. Thank you very much. ---------------------------------------------------------------------- valdir.marcos · 2019-09-24 12:33 Quote from: zoltanleo on September 24, 2019, 01:49:24 pmHi guys. I need your help. In my application, in each iteration loop, I parse the string and remove the "extra" characters, e.g.: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           //get position #10 in the line          LineEndingPos_10:= Pos(#10,Buffer);           repeat {until LineEndingPos_10 = 0;}          case LineEndingPos_10 of              0:                begin                {I need to stop the debugger here...}                  BufferStg:= BufferStg + Buffer;                end;              1: //#10 at the beginning of the line                begin                Inc(StrCounter);                  if Length(BufferStg) > 0 then                begin                    //dump the buffer storage to memo ...                    memoOutput.Lines.Add(Format(ConstFormatStr,[Str Counter,'B',BufferStg]));{B}                    memoOutput.SelStart:= UTF8Length(memoOutput.Text);                  end;                  Application.ProcessMessages;                   //clear the storage buffer                  BufferStg:='';                   //clip the first character #10(LF) from the buffer                  Delete(Buffer,1,1);                   //... and continue the cycle further                end              else //#10(LF) in the middle or at the end of the buffer                 ... The total number of iteration cycles is more than 4400. An error can occur on a cycle with the number 2531, e.g.: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 2528. {C}~ gbak:0 records written 2529. {C}~ gbak:    writing index PK_TBL_LS_INFECTION_HIV 2530. {C}~ gbak:    writing data for table TBL_LS_INFECTION_HIV gbak:0 records written 2531. {C}~ gbak:    writing index PK_TBL_LS_INFECTION_HERPES6 2532. {C}~ gbak:    writing data for table TBL_LS_INFECTION_HERPES6 It will take a very long time if I press F8 2530 times. Can I stop debugging under a certain condition, e.g. when the iteration counter reaches the number 2528?It's not beautiful, but it might be helpful sometimes: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           //get position #10 in the line          LineEndingPos_10:= Pos(#10,Buffer);          Counter := 0;          repeat {until LineEndingPos_10 = 0;}            Counter := Counter + 1;            case LineEndingPos_10 of              0:                begin                {I need to stop the debugger here...}                  if (Counter = 2530) then                     ShowMessage('Counter is now 2530 or any number you want.');                  BufferStg:= BufferStg + Buffer;                end; ---------------------------------------------------------------------- Martin_fr · 2019-09-24 12:35 Breakpoints do have conditions. If you right click a breakpoint you can go to "breakpoint properties". Or you can do so via the "breakpoint window" from menu view>debugger- win. https://wiki.lazarus.freepascal.org/IDE_Window:Breakpoints#Breakpoint_ properties If you set condition to:   i=2000 It will only stop if that evals to true. The only issue: gdb does not understand strings. So   s='abc' will NOT work. I personally had some success with the following (but others said it did not work for them). Note the double quotes:    $_streq(^char(s), "abc") https://sourceware.org/gdb/current/onlinedocs/gdb/Convenience- Funs.html#Convenience-Funs Alternatively you can use the hitcount property. ---------------------------------------------------------------------- zoltanleo · 2019-09-24 17:55 @valdir.marcos @Martin_fr Thanks so much for the valuable advice.