Recent

Author Topic: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)  (Read 9308 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10668
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #30 on: January 21, 2024, 03:45:17 pm »
That's the Call Stack window, right?

Didn't work for me without the patch.

But with the patch it does work? I.e it works no matter if the Callstack is open or closed?

It's curious what the exact details are...
If it had failed for every one then there would have been more complains (most likely). And the code shows that if the register fails (which indeed it did), then the callstack can be used as fallback... But only if it has been retrieved already. Usually if the stack window is open it gets retrieved before watches...

I can't tell if in your case that retrieval order for some reason is not the case, or if the fallback does not work...

Please test the following
Set a breakpoint in some subroutine that is called by your code.
E.g.
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Foo;
  2. begin
  3.   sleep(1);         // break here
  4. end;
  5. Procedure TForm1.Button1Click;
  6. var
  7.   MyTestVal: integer;
  8. begin
  9.   MyTestVal := 12300;
  10.   Foo;
  11. end;

The select the caller  "Button1Click" in the stack. That means "select" = "make it current". Either the green arrow in the toolbar (check the hint(, or the context menu.

Can you then see the value of "MyTestVal" in the watches window?


OK, so the findings got odd enough, and my curiosity overcame my "Mac-aversion" -ish.

A friend of mine always says "welcome to the dark side" once one onboards Macs. I have always wondered why! Just asked him, but he has ignored the question before.
I don't know? For  me it is just inconvenient. The entire user interface is alien to me. I press "home" on my keyboard, which on every OS gets me to the start of the line. On Mac, it takes me to the top of the file (line 1). Ouch. Maybe it's VNC. But without VNC I can't get "dvorak with UK punctuation" (I have that on Windows and on Linux). And that is just one of what feels like a thousand obstacles.


msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #31 on: January 21, 2024, 11:36:09 pm »
I am still looking, but in the meantime.

1) Please try with this patch

Code: Text  [Select][+][-]
  1. diff --git a/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas b/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas
  2. index 78d21029f5..2a4fa9c37a 100644
  3. --- a/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas
  4. +++ b/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas
  5. @@ -1554,6 +1554,9 @@ function TFpLldbDebugger.GetLocationForContext(AThreadId, AStackFrame: Integer):
  6.    r := Registers.CurrentRegistersList[AThreadId, AStackFrame];
  7.    if (r <> nil) and (r.DataValidity = ddsValid) then
  8.      try
  9. +      if FDwarfInfo.TargetInfo.machineType in [mtARM, mtARM64] then
  10. +        v := r.EntriesByName['PC'].ValueObjFormat[rdDefault].Value[rdDefault]
  11. +      else
  12.        if TargetWidth = 64 then
  13.          v := r.EntriesByName['RIP'].ValueObjFormat[rdDefault].Value[rdDefault]
  14.        else
  15.  

2) Does it affect all stackframes?

If you open the stackwindow and select any of the caller frames.
Ideally you do that in some code where the callers have debug info, e.g if you make calls from your code to other parts of your code).

Can you then get watches for the caller to work?

1) Finally got to try this. It fixed the problem!

Great job, congratulations!!!

Do I still need to complete #2?

msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #32 on: January 21, 2024, 11:46:58 pm »
That's the Call Stack window, right?

Didn't work for me without the patch.

But with the patch it does work? I.e it works no matter if the Callstack is open or closed?

Yes, as I just found out; after doing a Lazarus rebuild with the Normal IDE profile.

It's curious what the exact details are...
If it had failed for every one then there would have been more complains (most likely). And the code shows that if the register fails (which indeed it did), then the callstack can be used as fallback... But only if it has been retrieved already. Usually if the stack window is open it gets retrieved before watches...

I can't tell if in your case that retrieval order for some reason is not the case, or if the fallback does not work...

Please test the following
Set a breakpoint in some subroutine that is called by your code.
E.g.
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Foo;
  2. begin
  3.   sleep(1);         // break here
  4. end;
  5. Procedure TForm1.Button1Click;
  6. var
  7.   MyTestVal: integer;
  8. begin
  9.   MyTestVal := 12300;
  10.   Foo;
  11. end;

The select the caller  "Button1Click" in the stack. That means "select" = "make it current". Either the green arrow in the toolbar (check the hint(, or the context menu.

Can you then see the value of "MyTestVal" in the watches window?

I didn't run this test case either, but I did select the first stack frame displayed (before applying the patch) and it had made no difference (with my original test project). Do you really need these stack based tests anymore?

Can I finally delete my original test project? Do we understand how the mechanism was for the IDE to "remember" the broken variable watches even across IDE restarts (since they worked for the first time they were added only)? This is a huge mystery for me still, but one that is safe to ignore of course.

OK, so the findings got odd enough, and my curiosity overcame my "Mac-aversion" -ish.

A friend of mine always says "welcome to the dark side" once one onboards Macs. I have always wondered why! Just asked him, but he has ignored the question before.
I don't know? For  me it is just inconvenient. The entire user interface is alien to me. I press "home" on my keyboard, which on every OS gets me to the start of the line. On Mac, it takes me to the top of the file (line 1). Ouch. Maybe it's VNC. But without VNC I can't get "dvorak with UK punctuation" (I have that on Windows and on Linux). And that is just one of what feels like a thousand obstacles.

Yes this was a mess for me also. The shortcuts are all different and not all of them seem to make a ton of sense.

Command + Left / Command + Right are the equivalents of Home and End (Command would be the Windows key).

Don't hesitate to ask if you have any other shortcut questions! Once you get used to it, it is quite addictive - like using a PC was in the good days of the PC.

Oh, my friend also replied to my question as follows:

"Just for fun.  I could easily say welcome to the light side, but it is not as fun."
« Last Edit: January 21, 2024, 11:53:22 pm by msintle »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10668
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #33 on: January 22, 2024, 12:49:44 am »
I don't know for sure how the IDE "remembered". Too many possibilities.

The IDE has/had 2 ways of getting the data
- the broken register (never worked)
- via the internal data for the stack

For the top stack frame:
The latter is by design "not required to work", because the first should always work.
The latter is just there because there is an "exit" missing, if the first fails. (but then it's ok to be there...)

So it is not important to find why the 2nd does not always work (it isn't meant to)
Well, that is: If it did not work, because the data was not available. If the data was broken, then that is an issue.

As for the difference between your and my experience:
The latter (data availability) depends on lots of things. In the end it is a timing issue (almost like a race condition, though often a bit more predictable). Like for me it worked when the stackwindow was open.
But that part did not work for you. So there is some other factor. It is possible that whatever caused this different gets saved into the session or project.




About the "select the 2nd stack frame".

When you select any stackframe, other than the top, then the above rules change.
- The register is never used
- the stack data is always used

But, then the data should always be available.
- The above "not working" meant "not working, because data not avail".
- So if for the 2nd frame the data is avail, then it should work.

That is why I asked the question.
- Until now, I can just assume that when you had the stack open, but it still did not work => it was timing (data not available)
- But in theory, maybe something was wrong with that data (a 2nd independent bug)

Checking if watches work in the 2nd frame, would tell for sure which one it is.

Otherwise you or someone find out one day, when they really need it.
(I kind of assume (again..., I assume a lot) that it works for most, because no one complained yet, and at least when I debug I use the stackframes all the time.

But since on the machine I logged into, the behaviour is a little different from yours, I can't rely on my tests alone.



In the end, most bugs get fixed when they get reported.

- For Windows and Linux I have limited automated tests.
- On Windows I use the debugger a lot, so it gets heavily tested
- On Linux I use it a little, so it gets some testing
- On Mac, I relay entirely on others reporting issues (exception like now, when I have a report and jump over my shadow and log into a Mac)

However, there are a few people in the developer team who use Mac, and they obviously to debugging. So there is at least some regular use of the debugger on Mac.


msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #34 on: January 22, 2024, 02:08:02 am »
Thanks for sharing all that!

So do you need me to do anything else right now for you?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10668
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #35 on: January 22, 2024, 10:05:36 am »
Well as I said, if you can, please test the 2nd stack frame
https://forum.lazarus.freepascal.org/index.php/topic,65438.msg503159.html#msg503159

Otherwise all good.

msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #36 on: January 22, 2024, 12:46:34 pm »
Well as I said, if you can, please test the 2nd stack frame
https://forum.lazarus.freepascal.org/index.php/topic,65438.msg503159.html#msg503159

Otherwise all good.

No worries, I sure can.

So before doing this test, you would like me to roll back the patch of course, right?

Just making sure so by the time I get to it, I'll have all the remaining answers you need.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10668
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #37 on: January 22, 2024, 01:48:49 pm »
Well as I said, if you can, please test the 2nd stack frame
https://forum.lazarus.freepascal.org/index.php/topic,65438.msg503159.html#msg503159

Otherwise all good.

No worries, I sure can.

So before doing this test, you would like me to roll back the patch of course, right?

Just making sure so by the time I get to it, I'll have all the remaining answers you need.

No, you can keep the patch in.

msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #38 on: January 22, 2024, 03:07:27 pm »
Well as I said, if you can, please test the 2nd stack frame
https://forum.lazarus.freepascal.org/index.php/topic,65438.msg503159.html#msg503159

Otherwise all good.

No worries, I sure can.

So before doing this test, you would like me to roll back the patch of course, right?

Just making sure so by the time I get to it, I'll have all the remaining answers you need.

No, you can keep the patch in.

I don't understand. With the patch, there's no issue at all with the variable watches window; but the post you linked to for the test you'd like me to do asks if the variable watches resolve correctly after doing something with the call stack window - which by that point serves no purpose, doesn't it?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10668
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #39 on: January 22, 2024, 03:41:55 pm »
If you select ("set as current" any stackframe other than the top frame, then the register will never be used.
So it does not matter if the register-patch is applied or not.

In other words:
1- The bug I fixed, does not (and never has) affected any watches on the 2nd (or further down) stackframe
2- But, the open stack window, did not help as workaround on your setup (yet it did on mine).

(2) Can be explained by either
- This can happen, and it can happen without any bug present
- This can happen if there is a 2nd bug (of which we don't yet know).

So to make sure there is not such 2nd bug, it should be tested.




See the image.

The stack can be selected with either the "green button" or from the context menu.
The selected stack has the small green arrow at the left side of the line (before the number, where the grey dots are).

If you select the 2nd stack, then variables from the current function/procedure may show "Identifier not found" => that is correct.
Instead you can see variables from the selected stack.

msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #40 on: January 22, 2024, 10:37:09 pm »
If you select ("set as current" any stackframe other than the top frame, then the register will never be used.
So it does not matter if the register-patch is applied or not.

In other words:
1- The bug I fixed, does not (and never has) affected any watches on the 2nd (or further down) stackframe
2- But, the open stack window, did not help as workaround on your setup (yet it did on mine).

(2) Can be explained by either
- This can happen, and it can happen without any bug present
- This can happen if there is a 2nd bug (of which we don't yet know).

So to make sure there is not such 2nd bug, it should be tested.




See the image.

The stack can be selected with either the "green button" or from the context menu.
The selected stack has the small green arrow at the left side of the line (before the number, where the grey dots are).

If you select the 2nd stack, then variables from the current function/procedure may show "Identifier not found" => that is correct.
Instead you can see variables from the selected stack.

Great news, it worked just fine.

OK to delete the test project now?

Very interesting trick to know, by the way.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10668
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #41 on: January 23, 2024, 12:51:44 am »
Great news, it worked just fine.
Good, thanks for testing.

Quote
OK to delete the test project now?
Yes, well, as you like.

Quote
Very interesting trick to know, by the way.
;)

msintle

  • Sr. Member
  • ****
  • Posts: 259
Re: Lazarus 3.9.9 Variable Watches Fail (But Debugger Tooltips Work!)
« Reply #42 on: January 23, 2024, 01:57:41 am »
Thanks for all the help!

 

TinyPortal © 2005-2018