Data/Watch Breakpoint- How to. lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- ddev · 2020-11-24 01:13 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) ---------------------------------------------------------------------- Martin_fr · 2020-11-24 01:53 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     /path/to/lazarus/lazarus.app/Contents/MacOS/lazarus --debug- log=/path/to/yourfiles/laz.log --debug-enable=DBG_CMD_ECHO,DBG_STATE,D BG_DATA_MONITORS,DBGMI_QUEUE_DEBUG,FPDBG_DWARF_ERRORS,FPDBG_DWARF_WARN INGS,FPDBG_DWARF_VERBOSE_LOAD,FPDBG_DWARF_DATA_WARNINGS,DBG_VERBOSE,DB G_WARNINGS,DBG_STATE,DBG_EVENTS,DBG_THREAD_AND_FRAME,DBG_ERRORS    It should send something like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2020-11-24 02:39 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i >> versionlldb-1100.0.30.12Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)(lldb) breakpoint command add 1(lldb) version>> breakpoint set --file project1.lpr --line 82lldb-1100.0.30.12Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)(lldb) breakpoint set --file project1.lpr --line 82Breakpoint 4: where = project1`PASCALMAIN + 121 at project1.lpr:82:1, address = 0x0000000100001399>> watchpoint set variable -w read_write gToto(lldb) watchpoint set variable -w read_write gTotoerror: invalid process>> watchpoint set variable -w read_write gToto(lldb) watchpoint set variable -w read_write gTotoerror: invalid process  The source breakpoint on line 82 is working, but not my two watchpoints, declared as local and global. ---------------------------------------------------------------------- Martin_fr · 2020-11-24 10:29 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 · 2020-11-24 18:02 Hi Martin! Quote from: Martin_fr on November 24, 2020, 11:29:00 amNot 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;var  gToto: longint = 0;   procedure Test;  var    lToto: longint = 0;    dummy: longint;    begin      dummy := 1; // breakpoint sets here, creating watchpoints on 'lToto' when the execution stops inside the debugger      lToto := 1;    end; begin  Test; // breakpoint sets here, creating watchpoints on 'gToto' when the execution stops inside the debugger  gToto := 1;end.  and the relevant lldb log lines: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i (lldb) versionlldb-1100.0.30.12Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)>> watchpoint set variable -w write (lldb) watchpoint set variable -w write error: required argument missing; specify your program variable to watch for>> watchpoint set variable -w read_write gToto(lldb) watchpoint set variable -w read_write gTotoerror: no variable named 'gToto' found in this frame>> watchpoint set variable -w write (lldb) watchpoint set variable -w write error: required argument missing; specify your program variable to watch for>> watchpoint set variable -w write gToto(lldb) watchpoint set variable -w write gTotoerror: no variable named 'gToto' found in this frame>> process continue(lldb) process continue and later: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)>> memory read --force --size 1 --format x --count 4 140732920756984>> version(lldb) memory read --force --size 1 --format x --count 4 1407329207569840x7ffeefbffaf8: 0x00 0x00 0x00 0x00(lldb) versionlldb-1100.0.30.12Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)>> watchpoint set variable -w write (lldb) watchpoint set variable -w write error: required argument missing; specify your program variable to watch for>> watchpoint set variable -w write lToto(lldb) watchpoint set variable -w write lTotoerror: no variable named 'lToto' found in this frame>> watchpoint set variable -w write (lldb) watchpoint set variable -w write error: required argument missing; specify your program variable to watch for>> watchpoint set variable -w write lToto(lldb) watchpoint set variable -w write lTotoerror: no variable named 'lToto' found in this frame>> process continue(lldb) process continueProcess 15462 resumingProcess 15462 exited with status = 0 (0x00000000) >> breakpoint delete 4>> process kill ---------------------------------------------------------------------- Martin_fr · 2020-11-24 22:21 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).