Recent

Author Topic: New debugger for Mac based on lldb (Call for testers)  (Read 68444 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
New debugger for Mac based on lldb (Call for testers)
« on: October 14, 2018, 09:05:00 pm »
With the Lazarus Release Candidate 1 for 2.0 a new debugger for Mac users has been shipped.
It is based on LLDB, which is provided by apple and is ready to use. So there should no longer be a need to build and codesign gdb.

As the LLDB integration is all new, it needs a lot of testing. So this is a ...

call to all Mac users:
Please test the new LLDB based Lazarus debugger.

To test the new debugger, please download the Lazarus 2.0RC1.

- Open the IDE and install the package "LazDebuggerFpLLdb".
  It should be in the list of available packages, but if not it is in components/lazdebuggers/lazdebuggerfplldb
  Make sure to use the one with "Fp" in the name. (There also is LazDebuggerLLdb, but it is not as good.)
  Restart the IDE.


- Go to Tools > Options > Debugger
  In the "debugger type" dropdown, you should find and select "LLDB debugger (with fpdebug)"
  The edit below this (where you normally have the path to gdb), should be changed to the path of lldb.
  (lldb comes with the tools from Apple; and as such it is already codesigned by Apple).


To report any problems:
Start Lazarus from a shell with the following command line (replace pathes according to your installation):

You may need to use startlazarus, or specify the re-build lazarus which may be in your home folder / pcp.

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.  

EDIT ON 16 DEC 2020:
Please also add to the list of keywords for logging
  ,FPDBG_COMMANDS,FPDBG_THREADS,FPDBG_QUEUE


Attach the log file after reproducing the error.

--------------------
EDIT:
If you have a lot of units with debug info (eg all of LCL with debug info) you may have to increase ulimit.
https://bugs.freepascal.org/view.php?id=34467
(should be fixed in RC3)

Known Issues in the 2.0 release that are fixed for 2.0.2:
Svn users can update in fixes branch. None svn users can download replacement files via http as directed below.
  • Single stepping, may sometimes step the wrong thread (if paused in a multithreading app)
    To apply the fix in Lazarus 2.0.0 go to https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=60339 and download the 2 files. You can replace the entire files in your 2.0.0 install. Rebuild the IDE and restart.
  • Fix a crash for local/watches on begin/end of procedure.
    To apply the fix in Lazarus 2.0.0 go to https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=60353 and download the file. You can replace the entire files in your 2.0.0 install. Rebuild the IDE and restart.
  • Fix several issues when debugging multi-threaded apps:
    - Eval watches,hints,locals according to selected thread (and stackframe)
    - Select correct thread at breakpoint
    - Select correct Stackframe for thread, when switching threads
    To apply the fix in Lazarus 2.0.0 go to https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=60436 and download the file. You can replace the entire files in your 2.0.0 install.
    In order for this to work you must also install the file lldbinstructions.pas from for revision=60339 / 1st in this list. (the file lldbdebugger.pas must be taken from this changeset (revision=60436): lldbdebugger.pas@60436 includes lldbdebugger.pas@60339.
    Rebuild the IDE and restart.
  • Detect and warn, if debugger path points to gdb instead of lldb (wrong config after upgrade)
  • Improved handling of lldb warnings during startup. Do not terminate debug session, if warnings where issued.
  • If debug session stops due to error, close debugged application. Otherwise it could not be terminated.
  • Speed up single stepping. (remove/reduce lag before next step could be executed)

Known Issues that will be in 2.0 release:
  • Small remaining risk of: A workaround (for currently known cases) has been applied. (r59895)
    Evaluating of local var and param while paused on procedure/function begin or end line may cause crashes.
    This applies to Locals/Watches/Evaluate/... views.
    Currently the problem is know for variable len type data (string/dyn array), including structures containing such types.
    See https://bugs.freepascal.org/view.php?id=34746
  • Strings and Arrays are limited to a max len of 5000 / 3000. Currently this is not configurable. Sometimes less. Nested arrays are limited to just the first few items.
  • Low risk of PChar, WideStrings, (maybe AnsiString in Dwarf 2) may be cut off, even if below there max len limit. The Debugger sees WideString as PWideCHar and has to guess how far to look for the terminating #0. The guess is adjusted in steps, and may miss the correct len.

Known Issues in RC3 fixed for 2.0:
  • Nested array (including dyn array in structures that are nested in arrays, may not display correct.
    This applies when the any of the inner arrays is a dynamic array. All indexes may show data from the first index.
    This problem may be worse for dwarf-3, but can appear with dwarf-2 too.
    Fixed r59962 and other revisions before
  • Some Global values may return wrong results. (Not clear under which conditions. Possible such variables that are not accessed within the unit that declares them, but only from outside the unit... But not sure) Fixed in r60015
  • A 32bit IDE may have issues with some watches when debugging a 64 bit target. (The other way round should be ok, after r60041) fixed in r60085


For the testcase please see: http://forum.lazarus-ide.org/index.php/topic,42869.msg307134.html#msg307134

More on "debug info type" (dwarf): http://forum.lazarus-ide.org/index.php/topic,42869.msg311363.html#msg311363
« Last Edit: December 16, 2020, 03:09:54 pm by Martin_fr »

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #1 on: October 15, 2018, 03:10:30 am »
Martin, forgive my ignorance, I am unsure of how gdb / LLdb interact with heaptrc.

Specifically about memory leaks, will using LLdb give me the same sort of info on the Mac I am used to getting on Linux ?

Even if not, this is an astounding step forward. We loose so many potential Mac user who just read through those code signing instructions and shake their heads sadly...

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #2 on: October 15, 2018, 12:19:58 pm »
GDB/lldb have nothing to do with heaptrc functionality. Heaptrc uses compiler generated debug info to display the lines and their numbers where the leak happened.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #3 on: October 15, 2018, 01:08:09 pm »
Heaptrc, works without the debugger.

GDB/LLDB is for setting breakpoints, single stepping, inspecting variables.

The LLDB based does not yet have all the features. E.G. "step to cursor" does not yet work. And the disassembler may not always work.

As for properties (with getter function): They can not be watched, same as under gdb.

Josh

  • Hero Member
  • *****
  • Posts: 1270
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #4 on: October 15, 2018, 02:30:36 pm »
Hi

Had a quick look and did not see a folder for mac osx x86_64 to test? Just OSXi386

Am I missing something?
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #5 on: October 15, 2018, 03:25:16 pm »
Had a quick look and did not see a folder for mac osx x86_64 to test? Just OSXi386

Am I missing something?

Not really related to the debugger, you may want to follow this up on the RC announcment. http://forum.lazarus-ide.org/index.php/topic,42868.0.html

Afaik currently only carbon is pre-build. cocoa (64bit) is still alpha/beta.
But I believe (not sure) that the fpc package installs both, 64 and 32 bit. Then you can rebuild the IDE for 64 bit.

The debugger should work for both 64 and 32 bit. (As long as Apple does not remove 32bit support from lldb)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #6 on: October 18, 2018, 08:35:44 pm »
Sorry, but I can't find the package, see screenshot in the attachment. Did I overlook anything?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #7 on: October 18, 2018, 08:58:02 pm »
Sorry, but I can't find the package, see screenshot in the attachment. Did I overlook anything?

Are you using the Lazarus Release Candidate 1 for 2.0? I don't think that OPM have it. You need to install it standard/old way (Package->Install/Uninstall Packages), not via OPM.
« Last Edit: October 18, 2018, 09:00:09 pm by Cyrax »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #8 on: October 18, 2018, 10:16:14 pm »
It is not it OPM.

The installer for 2.0RC1 contains the files, and they will be on your disk.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #9 on: October 19, 2018, 10:23:48 pm »
Thanks, it woks now.

In Lazarus 2.0RC1 the package is in /Developer/lazarus/components/lazdebuggers/lazdebuggerfplldb/. The path to the debugger can easily be found by typing which lldb in the terminal.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #10 on: October 20, 2018, 03:38:30 pm »
My first impressions are:
  • It works quite well
  • Program execution is rather slow, especially at startup.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #11 on: October 22, 2018, 08:23:50 pm »
  • Works for me too
  • A bit of delay at launch and when opening dialogs, but fully useable

I realize that the debugger and heaptrc are separate, but having the combination of a simple-to-install debugger and a heaptrc that provides line numbers would be a terrific advance for Lazarus. Here is a simple project that shows that heaptrc is able to report leaks, but on the Mac you do not get the line numbers seen when run on Linux or Windows:
http://forum.lazarus.freepascal.org/index.php/topic,42755.0.html

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #12 on: October 28, 2018, 01:06:05 pm »
About HeapTrc
but on the Mac you do not get the line numbers seen when run on Linux or Windows:
If that is the case, and if the settings are correct (e.g the debugger gets line info, but the heaptrc does not), then this is an issue in fpc (and may need reporting there)

HeapTrc is entirely part of fpc.

There are several possible issues though:
1) It may affect dwarf only (or be limited to certain versions of it), or stabs only.
2) It may be broken only for external / none-external debug info.

Additionally the stacktrace dumping code in fpc has a safety feature, that can have "side effects".
If an address in the trace can not be resolved, the code will disable address resolving for all further addresses. This is, in case there was an error, which could lead to the error dumping another trace, ending in endless recursion. But this also happens, if there just is no data for that one address. (At least that is what it used to be, may have changed).

So if your top address, is not resolvable....
You can try (not tested myself on Mac), to load/paste the trace into the IDE's "Leaks and traces", then click resolve. In the following open dialog, select the application executable.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #13 on: October 28, 2018, 11:28:30 pm »
Said Martin_Fr :
Quote
About HeapTrc
Quote from: ChrisR on October 23, 2018, 04:23:50 am

    but on the Mac you do not get the line numbers seen when run on Linux or Windows:

If that is the case, and if the settings are correct (e.g the debugger gets line info, but the heaptrc does not), then this is an issue in fpc (and may need reporting there)

Has been reported -
https://bugs.freepascal.org/view.php?id=32775

The mytest.pas demo pasted there is just fpc, no lazarus component. On Linux shows a line number, actually the number of the line where  BadProcedure() is called from rather than the new() statement but thats still enough to track leaks down. On mac, no line number or unit name.
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #14 on: October 29, 2018, 03:18:53 am »
@dbannon Thanks for issue 32775, a very elegant bug report, as you note, shows this is a fpc issue, not Lazarus. Thanks.

 

TinyPortal © 2005-2018