Recent

Author Topic: Data/Watch Breakpoint- How to.  (Read 1499 times)

ddev

  • New Member
  • *
  • Posts: 17
Data/Watch Breakpoint- How to.
« on: November 24, 2020, 02:13:14 am »
I am very happy with Lazarus and LLDB support. Much better than XCode for breakpoints and watches.

Only one thing I am not able to use are Data/Watch breakpoints. No way to make them working :(

Any issue with that on Mac? Does anybody have been able to use them? Any tips?

I googled the issue and I have see no comment about that.

Cheers

(Lazarus 2.0.10 with FPC 3.2.0, Mac OSX 10.14.6)
Lazarus 2.0.10
FPC 3.2.0
Mac OS X 10.14.6

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Data/Watch Breakpoint- How to.
« Reply #1 on: November 24, 2020, 02:53:01 am »
Just wrote a complete answer that they were not implemented, then checked, and found they are..... Well.

The way watches (not watchpoints, but watches/locals) work in Lazarus (with lldb) is that Lazarus does NOT ask lldb to retrieve the watch as typed data. Lazarus only reads raw memory from lldb, and uses its build in dwarf support to format the data.
Since the IDE knows Pascal, this yield better watches displays.


For Watchpoints the IDE currently just hands the name to lldb. (I cant currently test if it works / feel free to supply a log)
Log:
Code: Pascal  [Select][+][-]
  1.     /path/to/lazarus/lazarus.app/Contents/MacOS/lazarus --debug-log=/path/to/yourfiles/laz.log --debug-enable=DBG_CMD_ECHO,DBG_STATE,DBG_DATA_MONITORS,DBGMI_QUEUE_DEBUG,FPDBG_DWARF_ERRORS,FPDBG_DWARF_WARNINGS,FPDBG_DWARF_VERBOSE_LOAD,FPDBG_DWARF_DATA_WARNINGS,DBG_VERBOSE,DBG_WARNINGS,DBG_STATE,DBG_EVENTS,DBG_THREAD_AND_FRAME,DBG_ERRORS
  2.      

It should send something like
Code: Pascal  [Select][+][-]
  1. watchpoint set variable var

So lldb must deal with pascal types.

I would guess that may work for simple variables. but maybe not fields of a class, because then lldb must understand how to get the address of the field (it should be able, but not sure if it is in all cases)

Also note:
On intel (I do not know about the new M1), you usually have max 4 watchpoints. Each (up to) the size of a pointer.
So you can not watch an entire class (you can watch read access via the internal pointer, if you assume that every read will first access that pointer. (Well in theory the 4 pointers could cover one record of 32 bytes).
This limit is not lldb based, it is build into the cpu. (for hardware watchpoints. Single stepping and checking all the time is too slow).


Without more info, I cant comment.
Look at the logfile, and see if there is an error.

ddev

  • New Member
  • *
  • Posts: 17
Re: Data/Watch Breakpoint- How to.
« Reply #2 on: November 24, 2020, 03:39:11 am »
Thanks Martin!

I have tested in a simple project, using a class variable and a global variable both named 'gToto'. But this is not working for me.

Here is a copy of the log in the debug window:

Code: Pascal  [Select][+][-]
  1. >> version
  2. lldb-1100.0.30.12
  3. Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
  4. (lldb) breakpoint command add 1
  5. (lldb) version
  6. >> breakpoint set --file project1.lpr --line 82
  7. lldb-1100.0.30.12
  8. Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
  9. (lldb) breakpoint set --file project1.lpr --line 82
  10. Breakpoint 4: where = project1`PASCALMAIN + 121 at project1.lpr:82:1, address = 0x0000000100001399
  11. >> watchpoint set variable -w read_write gToto
  12. (lldb) watchpoint set variable -w read_write gToto
  13. error: invalid process
  14. >> watchpoint set variable -w read_write gToto
  15. (lldb) watchpoint set variable -w read_write gToto
  16. error: invalid process
  17.  

The source breakpoint on line 82 is working, but not my two watchpoints, declared as local and global.
Lazarus 2.0.10
FPC 3.2.0
Mac OS X 10.14.6

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Data/Watch Breakpoint- How to.
« Reply #3 on: November 24, 2020, 11:29:00 am »
Not sure if the output is cut down to relevant lines?

In case you tried to set them before starting the app (there is no run command seen in your log), try removing (or disabling) them.
Then run the app to a breakpoint and set (or enable) the watchpoint while the app is running.

Note that watchpoints for local vars can only be set while the variable is in scope (i.e. while you are in that function). Because the address of the variable is only known at that time.
The watchpoint is also only valid until the function is left. Upon re-enter of the function is must be set again (as the address may have changed). For recursive function it only watches the one instance to which it was set.
Note, that I am not sure if lldb automatically detects when the function is left. If not, then it will trigger as soon as something else touches the memory in question.


ddev

  • New Member
  • *
  • Posts: 17
Re: Data/Watch Breakpoint- How to.
« Reply #4 on: November 24, 2020, 07:02:01 pm »
Hi Martin!

Not sure if the output is cut down to relevant lines?

In case you tried to set them before starting the app (there is no run command seen in your log), try removing (or disabling) them.
Then run the app to a breakpoint and set (or enable) the watchpoint while the app is running.

Just created a small program (code below) and created the watchpoints when the program stopped on breakpoints set on the line before "gToto := 1" and "lToto := 1" to no avail.

Having a look at lldb log in Debug Output window, I can see that those variables are not recognised by the debugger, so the watchpoints appears as "Invalid" in the Breakpoints window.

Here the pascal code:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. var
  3.   gToto: longint = 0;
  4.  
  5.   procedure Test;
  6.   var
  7.     lToto: longint = 0;
  8.     dummy: longint;
  9.     begin
  10.       dummy := 1; // breakpoint sets here, creating watchpoints on 'lToto' when the execution stops inside the debugger
  11.       lToto := 1;
  12.     end;
  13.  
  14. begin
  15.   Test; // breakpoint sets here, creating watchpoints on 'gToto' when the execution stops inside the debugger
  16.   gToto := 1;
  17. end.
  18.  

and the relevant lldb log lines:

Code: Pascal  [Select][+][-]
  1. (lldb) version
  2. lldb-1100.0.30.12
  3. Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
  4. >> watchpoint set variable -w write
  5. (lldb) watchpoint set variable -w write
  6. error: required argument missing; specify your program variable to watch for
  7. >> watchpoint set variable -w read_write gToto
  8. (lldb) watchpoint set variable -w read_write gToto
  9. error: no variable named 'gToto' found in this frame
  10. >> watchpoint set variable -w write
  11. (lldb) watchpoint set variable -w write
  12. error: required argument missing; specify your program variable to watch for
  13. >> watchpoint set variable -w write gToto
  14. (lldb) watchpoint set variable -w write gToto
  15. error: no variable named 'gToto' found in this frame
  16. >> process continue
  17. (lldb) process continue

and later:

Code: Pascal  [Select][+][-]
  1. Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
  2. >> memory read --force --size 1 --format x --count 4 140732920756984
  3. >> version
  4. (lldb) memory read --force --size 1 --format x --count 4 140732920756984
  5. 0x7ffeefbffaf8: 0x00 0x00 0x00 0x00
  6. (lldb) version
  7. lldb-1100.0.30.12
  8. Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
  9. >> watchpoint set variable -w write
  10. (lldb) watchpoint set variable -w write
  11. error: required argument missing; specify your program variable to watch for
  12. >> watchpoint set variable -w write lToto
  13. (lldb) watchpoint set variable -w write lToto
  14. error: no variable named 'lToto' found in this frame
  15. >> watchpoint set variable -w write
  16. (lldb) watchpoint set variable -w write
  17. error: required argument missing; specify your program variable to watch for
  18. >> watchpoint set variable -w write lToto
  19. (lldb) watchpoint set variable -w write lToto
  20. error: no variable named 'lToto' found in this frame
  21. >> process continue
  22. (lldb) process continue
  23. Process 15462 resuming
  24. Process 15462 exited with status = 0 (0x00000000)
  25. >> breakpoint delete 4
  26. >> process kill
  27.  
Lazarus 2.0.10
FPC 3.2.0
Mac OS X 10.14.6

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Data/Watch Breakpoint- How to.
« Reply #5 on: November 24, 2020, 11:21:00 pm »
I don't currently have a Mac at the ready....

the "error: required argument missing; specify your program variable to watch for" can be ignored (not sure, but may even be fixed in Lazarus trunk). It is caused by the IDE object for the watchpoint being created, and then initialized.

Not sure why the variable is not found.
But a couple of ideas that may be worth trying:

Do you use dwarf 2 or 3? -gw  or -gw3 ?
Can you try either? And maybe also try, in the project options (under custom) to add -godwarfcpp. (with dwarf 3).

If you use dwarf 2, then try to specify the variable in all CAPS.

Are you using external debug info, or not? (Not sure if that would make a difference).

Before setting the watchpoint, check the thread and stack window. Is there more than one thread? If so does the output indicate which thread is selected (when the breakpoint is hit)?
Is there a "thread select nnn"  to select the thread with the local var (in case it is needed)?
(Since it is the top stackframe, the selected stack should not be an issue.)



The IDE can be recompiled with -dDBG_WITH_DEBUGGER_DEBUG
Then the "debug output" window, shows a edit field that can be used to directly inject lldb commands. That way it would be possible to  test if lldb can identify the variable.

Or install the package LazDebuggerLldb (without an "Fp" before the "Lldb") => that is a pure lldb debugger (very rudimentary). But it could be used to check if the variable is listed in the "locals" list. (listed by lldb itself).

 

TinyPortal © 2005-2018