Jump to content
Daniel

Debugger activates breakpoint - do not understand yet why

Recommended Posts

Not sure if we have a confused debugger, but for sure we do have a confused developer.


Take the following code:

procedure TForm1.Button1Click(Sender: TObject);
var
  i ,j : integer;
begin
  for i:= 0 to 1 do
    for j:= 1 to 2 do
      if i+j > 1000 then
        ShowMessage( 'Möp!' );
end;

Just run the code and see that no message appears on the screen. Now set a breakpoint on the line with the "ShowMessage"-statement.

Run the code again the see that the breakpoint will be triggered and the programs stops.

:classic_blink:

 

Now place a "begin" and an "end" around the "ShowMessage"-statement - run the code again, the breakpoint will not be triggered anymore.

  for i:= 0 to 1 do
    for j:= 1 to 2 do
      if i+j > 1000 then
      begin
        ShowMessage( 'Möp!' );  // <  breakpoint still here
      end;

 

What is going on here?

 

For me it looks like it has something to do with the loops, as the following breakpoint is (as expected) also not triggered:

  j := Random(10);
  if j > 1000 then
    ShowMessage( 'Meep' );  // <-- set breakpoint here (will not be triggered)

 

 

Share this post


Link to post

wow, strange codegen, de debugger/debuginfo and the pas are out of sync

Edited by Attila Kovacs

Share this post


Link to post

The irrational "Confused debugger" cases seems to move on, its now the third one in short time with Rx1042.

Definitively worth to look deeper into it.

Maybe we have to wait until patch 1 is online :classic_smile: ?

Edited by Rollo62
  • Haha 1

Share this post


Link to post

The original cry for help reached me from a developer using 10.3.x - so this is not limited to 10.4.2.

Share this post


Link to post

Maybe its just an optimizing issue ?

for i:= 0 to 1 do
    for j:= 1 to 2 do
      if i+j > 1000 then //<== This can never be reached, or am I wrong ?

 

Edited by Rollo62

Share this post


Link to post
Just now, Rollo62 said:

Maybe its just an optimizing issue ?

You wish. The Delphi compiler doesn't optimize at that level.

  • Like 1
  • Sad 1

Share this post


Link to post

Good catch - but the is a reduced code-sample. Same situation still applies when comparing values from an array with values that are generated at runtime.

Share this post


Link to post
20 minutes ago, Daniel said:

so this is not limited to 10.4.2.

No, in berlin the same.

The loop is converted to a repeat until and the debug info does not follow this transition.

Share this post


Link to post
Guest

here, on RAD 10.3.3 Arch  and RAD 2010 same resulted:

  • in Debug mode, the cursor stop on "ShowMessage" as above, but dont executed!!!

hug

Share this post


Link to post

If you look into the debugger you see what causes the breakpoint to stop 

 

image.thumb.png.c03eda572d3c3372ad564833873e536a.png

 

It looks to me as the many situations where the compiler produces debug symbols that are a little off - as you can see in the asm view you have two different pieces being affected by the breakpoint.

The thing is that every line generated by the compiler - even the implicit for the looping goes somewhere in terms of what line of code they belong to - and in this case its the piece of code happening for the outer loop.

 

We had another situation where this happened just recently: 

 

Edited by Stefan Glienke

Share this post


Link to post

I had the same issue a few times, during the last 10 years.
Everytime the solution was the same: CUT the whole text, PASTE it on notepad, then cut and paste back on Delphi IDE.

This workaround worked for me because there was some tricky char in the text, or maybe there is something incorrect out of nowhere.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×