Recent

Author Topic: How to monitor changes in a control's property value during debugging  (Read 115 times)

yinhuajian

  • New Member
  • *
  • Posts: 21
The Lazarus example code is as follows:

procedure TForm1.FormCreate(Sender: TObject);
begin
   dowork_1();
   dowork_2();
   //dowork_3();
   //dowork_...();
   dowork_n();
end;

procedure TForm1.dowork_1;
begin
  Edit1.Enabled := False;
end;

procedure TForm1.dowork_2;
begin

end;

//procedure dowork_3;

//procedure dowork_...

procedure TForm1.dowork_n;
begin
  Edit1.Enabled := True;
end;


I would like to monitor the value change of Edit1.Enabled just like a normal variable during debugging, because when the codebase is large, it's hard to find where the value of Edit1.Enabled is modified. However, I found that it is not possible. In the Watch window, the value is displayed as: "Edit1.Enabled = Error: Member not found: Enabled". Why is that? Is there a good way to achieve this monitoring requirement?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12560
  • Debugger - SynEdit - and more
    • wiki
In short: FPC (the compiler) does not yet support this. https://forum.lazarus.freepascal.org/index.php/topic,73965.0.html

If it is going to be implemented, then availability may depend on your platform.

That is in order to get the value of that property the debugger must call
Code: Pascal  [Select][+][-]
  1. Edit1.GetEnbled();
Function call are currently only supported by the FpDebug debugger. And only on i386 or x86 architectures under Windows and Linux. Other platforms don't support that.

Also the above patch for the compiler will currently only be understood by FpDebug (albeit, when DWARF-6 is released, any other debugger could adapt it... But I don't know if they will)



As for you specific issue.

If you are using FpDebug and your platform is Windows/Linux i386 or x86.
- Go to: Tools > Options > Debugger > General. And enable the checkbox "allow function calls in watches"
- Add a Watch: Edit1.GetEnabled()
  The "()" are mandatory
- In the watch properties enable "Allow function calls"

And then you will see the value.

Mind you, if that call has side effects, those side effects will be in your app, just as if the app itself had called the function.
I don't expect "GetEnabled" to have any side effects, but if it had.. If you do that for other functions... E.g. some functions may create a handle. And that can affect what the app does later.

In case of TEdit the call to GetEnabled should just return "Edit1.FEnabled".
So you may instead watch that field.

If you watch the field, you can also create a "watchpoint" => then you can run the app with F9, and the debugger will pause it when the field is written to.




And one more note.

Due to another shortcoming of FPC, some functions are not available in the final exe. Either the code is not even compiled in, or the compiler did not create the info for the debugger where the code is. In those cases the debugger can not call it.

Afaik, GetEnabled should always be included. Others may not. If a function is not included, check if your code uses it. (ideally have it called within the unit that wants to debug it / the actual rule is more complicated...)

Hope this helps.

 

TinyPortal © 2005-2018