Recent

Author Topic: Variable Watching and Modification in the Debugger  (Read 239 times)

WonderNomad

  • Newbie
  • Posts: 1
Variable Watching and Modification in the Debugger
« on: May 08, 2025, 10:29:10 am »
Hello,

I'm currently debugging a section of my code where I suspect a variable is not holding the value I expect. I've added the variable to the "Watches" window, and I can see its current value.

I have some questions:

How can I add different types of variables (e.g., records, arrays, pointers) to the watch window effectively?
Is it possible to modify the value of a variable directly in the watch window during a debugging session? If so, how is this done, and are there any potential risks or things to be aware of when doing this?

Thanks in advance!
« Last Edit: May 13, 2025, 11:59:21 am by WonderNomad »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11342
  • Debugger - SynEdit - and more
    • wiki
Re: Variable Watching and Modification in the Debugger
« Reply #1 on: May 08, 2025, 11:13:32 am »
By default when you are in the code editor, Ctrl-F5 will add the "word at text cursor" to the watches list.

If your setup is correct, the when you add records/classes you can unfold them in the watches to see all the fields (same for arrays).

You can drag and drop (click, hold and move the TEXT part of the watch NAME) to reorder them (only top level, not within expanded fields), or drag entries from the expanded fields to the top).

The "Evaluate/Modify" window allows to edit SOME watches. (Windows/Linux / not sure about Mac, but iirc not). You can right click the watch to get there.

You may also want to explore other windows like the "Inspect" window. (it has a search filter, that can find field-names or fields with matching data).


https://wiki.lazarus.freepascal.org/IDE_Window:_Evaluate/Modify

To change the value, use the EDIT at the very BOTTOM of the window.

Press the ":=" button at the bottom, or use return while the "new value" edit at the bottom is active, and that will apply the new value.

NOTE:
You can only change simple types (integer, byte, qword, ... enum, (not sure about sets), boolean, char, ...)

Within class,record,array you can change individual fields/entries. But not the entire variable at once.

You can not change the length of an array.

You can not edit strings as a whole. You can edit individual chars "MyString[1]", but that does not do "copy on write".
Code: Pascal  [Select][+][-]
  1. s1:=s2;
If after that line, you change "s1[1]" then that affects s2 too.  (except for shortstrings)
So be carefully about strings.
You can not change the length of the string.



On Windows/Linux with Intel/Amd, this works best if your debugger setup is set to FpDebug (default).

See also
- https://wiki.freepascal.org/Debugger_Status
- https://wiki.lazarus.freepascal.org/Category:IDE_Window_-_Debug
For watches:
- https://wiki.lazarus.freepascal.org/IDE_Window:_IDE_Options_-_Debugger_Value-Formatter
- https://wiki.lazarus.freepascal.org/FpDebug-Watches-Intrinsic-Functions (with FpDebug)



 

TinyPortal © 2005-2018