Lazarus

Announcements => Lazarus => Topic started by: Martin_fr on October 14, 2018, 09:05:00 pm

Title: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr 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
  2.  

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
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: dbannon 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
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Cyrax 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: josh 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?
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr 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)
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: jwdietrich 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?
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Cyrax 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: jwdietrich 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: jwdietrich on October 20, 2018, 03:38:30 pm
My first impressions are:
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: ChrisR on October 22, 2018, 08:23:50 pm

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
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: dbannon 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: ChrisR 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.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: baldzhang on November 02, 2018, 02:40:00 pm
testing passed.

macos: 10.13.6
lazarus: trunk
fpc: 3.0.4
widgets: cocoa

will this merge to 2.0 ?
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on November 02, 2018, 03:34:19 pm
This is already present in the 2.0 branch. So yes, it will be part of 2.0
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: RayoGlauco on November 03, 2018, 12:26:01 pm
I am using High Sierra on VirtualBox and Windows 10.
LLDB works well, and setup is easy in Lazarus.
Maybe a bit slow, but it's VirtualBox and my computer is not quite fast.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Akira1364 on November 03, 2018, 07:30:36 pm
I've mentioned this before, but it's worth noting that this debugger does also work fine (and quite well) on Windows (and should technically work on any platform that can run LLDB, which is all desktop platforms for the most part.)
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on November 03, 2018, 09:19:35 pm
On Windows you should get a much better experience with the gdb based debugger. Or if you want: fpdebug (which is used if the FpLldb debugger). If you want fpdebug (on win/linux) you can choose between pure fpdebug, or gdb+fpdebug.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Akira1364 on November 05, 2018, 12:54:45 am
On Windows you should get a much better experience with the gdb based debugger. Or if you want: fpdebug (which is used if the FpLldb debugger). If you want fpdebug (on win/linux) you can choose between pure fpdebug, or gdb+fpdebug.

I'm aware the GDB debugger is currently more feature-complete in Lazarus. I just meant that LLDB is not in any way only a "Mac" thing, and that generally speaking it's a better debugger than GDB (as all LLVM/Clang tools are compared to their GNU equivalents.)
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on November 05, 2018, 10:27:54 am
I'm aware the GDB debugger is currently more feature-complete in Lazarus. I just meant that LLDB is not in any way only a "Mac" thing, and that generally speaking it's a better debugger than GDB (as all LLVM/Clang tools are compared to their GNU equivalents.)
That comparison is currently hard to make...
First of all, lldb (6.0.1 on win) still prints a lot of warnings about dwarf tags that it does not know (If you watch variables without fpdebug). That may depend on the exact version of lldb, and for different OS, it is not always easy to get the latest version. (On fedora the only version I could get (6.0.1) crashed in my tests)

Also (and that may just be me), I could not get the "MI" interface to run on windows. That made lldb much harder to use, because there is no common way to detect when the output of a command finished. (The prompt is not printed in time, if using a pipe).

Further LLDB (unlike GDB) only understands c-based syntax. GDB has a (very) limited pascal understanding.
This means to get a pointer deref in lldb you have to write "*foo".
The reason you can do Pascal style in the IDE is that there is "lldb (with fpdebug)": fpdebug is a separate debugger, that handles the pascal syntax. It has its own dwarf reader, and uses lldb, to dump raw memory (watch the console, or "ide internals > debug output)

For many other things I dont have a comparison. And also I did not spent that much time on lldb, to really judge it. So I cant fully compare the two.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Igor Kokarev on November 13, 2018, 10:47:20 am
Thanks for the new lldb debugger! It works fine in macOS High Sierra.

I only noticed that starting of an app with LLDB debugger takes more time (4-6 seconds longer).

Also lldb can't show values for WideString variables.

One problem. I can't install lazdebuggerfplldb on macOS Mojave 10.14. Please include pre-built lldb debuger for Lazarus 2.0 RC2.

Because I can't compile any carbon or 32-bit app on macOS Mojave 10.14 in Lazarus, I get linking error. Only 64-bit / cocoa apps can be compiled and works fine.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on November 13, 2018, 12:55:00 pm
I only noticed that starting of an app with LLDB debugger takes more time (4-6 seconds longer).
Sorry about the slow down There is probably not much that can be done right now.
You can try the package LazDebuggerLLdb (without the FP). But that is pure lldb, no support for pascal style. All watches need to be specified in c syntax (*form1 or form1->FFooBar), and everything displays in c syntax. If that is slow too, then it is lldb itself (and nothing can be done at all, but hoping that lldb improves).
Also this may not support all datatypes. Or it may support more. Its not tested for that. (hence Alpha / also its more a proof of concept, so it will not get much fixes in that area)

Quote
Also lldb can't show values for WideString variables.
For LazDebuggerFpLLdb, (the "with fpdebug")  version, I added a workaround for widestring. They *should* work in the next version. WideChar is still broken (including SomeWideString[n]). Will have to see if it can be fixed in time.

Quote
One problem. I can't install lazdebuggerfplldb on macOS Mojave 10.14. Please include pre-built lldb debuger for Lazarus 2.0 RC2.
Because I can't compile any carbon or 32-bit app on macOS Mojave 10.14 in Lazarus, I get linking error. Only 64-bit / cocoa apps can be compiled and works fine.

Already committed for RC3, the IDE will have lazdebuggerfplldb pre-installed. (Only lazdebuggerfplldb, only the one with fpdebug).

EDIT:
widechar should also work

EDIT:
Quote
Also lldb can't show values for WideString variables.
Just for info/background: That is actually fpdebug. (Not tested if lldb itself can). The IDE bypasses lldb for all work on pascal related data. lldb just provides the memory dump (raw bytes)
But that is internal info...
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Igor Kokarev on November 13, 2018, 02:41:21 pm
Martin,

Many thanks for your quick reply and for all your efforts to improve LLDB debugger in Lazarus! I will try RC3 version once it ready.
Title: Re: New debugger for Mac based on lldb - "ignore exceptions" ineffective
Post by: kcandrews on November 27, 2018, 06:39:59 pm
Quick test with High Sierra OSX 10.13.6, Lazarus 2.0.0RC2, FPC 3.04, i386-darwin-carbon:  I don't yet have time to come up with test projects to prove this (in a simple way), but my big project consistently had troubles when debugging with lldb (fplldb) -- always stopping on every raised exception -- even when the exceptions were set to be ignored.  This made debugging totally impractical (and requires sticking with gdb for now).  I also had regular crashes when viewing objects/variables during debug breakpoints.  Do know that really I greatly appreciate the effort being made to move away from gdb on the mac since it is so messy to fool with codesigning, crsutil non-standard settings, etc.
Title: Re: New debugger for Mac based on lldb - "ignore exceptions" ineffective
Post by: Martin_fr on November 27, 2018, 07:49:37 pm
always stopping on every raised exception -- even when the exceptions were set to be ignored.

Thanks for pointing out. That was a simple oversight when putting the new debugger together. The code for this is identical with what all other debuggers do.
I fixed this, and it will be in RC3.

Also fixed incorrect classnames for exceptions (the 2 digits at the start).
And fixed a mem leak.

Quote
I also had regular crashes when viewing objects/variables during debug breakpoints. 
Crashes in the IDE, or crashes of lldb itself (is lldb still in the task list?)

If it is not to much trouble, run the logfile
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

You can do that always, but then I suggest to start the IDE from a script, that will first delete the old log. Or it will grow really big).
Then when the crash happens, attach or send the file.
(If you did inspect watches with sensitive data, or do not whish to reveal library names, or procedure names, that may be part of debugging, you can edit the file. You can also sent it in private)

There also already are various fixes (including some crashes) that will be in RC3. (fixes made after RC2)

Quote
Do know that really I greatly appreciate the effort being made to move away from gdb on the mac since it is so messy to fool with codesigning, crsutil non-standard settings, etc.
Thanks.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: kcandrews on November 28, 2018, 02:44:12 am
Martin,
Thanks so much for your response!  Great to know these things are already addressed.
I'll plan to do this again with logfile output sometime in the next few days and send it along!  I know how important getting the specifics on bugs can be (long time software architect/consultant/programmer, now retired mostly).
Keith
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on November 28, 2018, 03:50:34 pm
Martin,

Thanks, this is fantastic news! I just set up lldb with the latest Cocoa trunk. Installation went smoothly following your directions. So far so good, I'll try to run it through all of my projects and report back any issues.

Cheers,
VTwin
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Trenatos on November 28, 2018, 05:10:10 pm
Fantastic news, much appreciated!

Will give lldb a go very soon, would be nice to have a debugger working on my Mac!
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: MISV on November 30, 2018, 03:08:57 pm
Problem (lazarus trunk + Mojave):


Whenever I run my app with the new lldb debugger beta I get this error:

Unable to  to open file
Quote
"/users/example/lazarus64bit/config_lazarus/onlinepackagemanager/packages/Indy10/lib/x86-64-darwin/idServerIOHandlerStack.o"

I have of course:

Not quite sure what is to blame here or what is going on
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on November 30, 2018, 05:36:40 pm
Have you tried to increase "ulimit"? (allowed amount of open files / filehandles)

Unfortunately the debugger attempts to open a lot of files and runs into the limit.
It's a known issue, but may be a while until fixed.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: MISV on November 30, 2018, 10:27:22 pm
Had to Google it

If I in terminal write
Code: Pascal  [Select]
  1. launchctl limit maxfiles
I get
Quote
max files 256 unlimited


If I in terminal write
Code: Pascal  [Select]
  1. launchctl limit maxfiles 10240 unlimited
I get
Quote
Could not set resource limits: 1: Operation not permitted


If I in terminal write
Code: Pascal  [Select]
  1. sudo launchctl limit maxfiles 10240 unlimited
it appears I set maxfiles correctly :)

I will now test....

And it seems to work

Yay! :)
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 01, 2018, 03:19:31 am
For app I'm currently developing, using lldb(alpha) it worked, kind of (buggy but at least runs). With lldb(with fpdebug), it crashes immediately:

Unable to open file "/Developer/lazarus/components/tachart/lib/x86_64-darwin/qt5/tadatapointseditor.o".

Laz 2.0RCL2/64bit/Cocoa. Compling to 64bit/Qt5.

bigDan
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 01, 2018, 10:40:41 am
For app I'm currently developing, using lldb(alpha) it worked, kind of (buggy but at least runs). With lldb(with fpdebug), it crashes immediately:

Unable to open file "/Developer/lazarus/components/tachart/lib/x86_64-darwin/qt5/tadatapointseditor.o".

Laz 2.0RCL2/64bit/Cocoa. Compling to 64bit/Qt5.
See above
Code: Pascal  [Select]
  1. sudo launchctl limit maxfiles 10240 unlimited
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 01, 2018, 06:24:21 pm
That did the trick!

Looks like step-over still does a step-into, though.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 01, 2018, 09:16:49 pm
Looks like step-over still does a step-into, though.
32 and 64 bit?

Can you send a log when that happens?
(I was not aware that happens on the Mac at all)

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 01, 2018, 10:57:33 pm
I can only test for 64bit. Qt5 won't link for i386 for me.

I tried compiling 32bit/cocoa, but that results in the message

Code: Pascal  [Select]
  1. Lazarus IDE v2.0.0RC2 rexported - sjsconfig
  2. Access Violation
  3.  

I don't know how to provide the log you desire. If you send me a link to the procedure, I'll give it a shot.

Enclosed are 2 pics of the failure. In debug1.png, I am at breakpoint on line 596. When I press the step over button, instead of going to line 597, it goes into GridVisible as seen in debug2.png.

bigDan
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 02, 2018, 01:14:29 am
Instructions for the log file are in the first message of this grid.

I currently do not have a Mac, so I can not reproduce issues myself (many problems I can test with lldb on windows).


Did you get this stepping issue with "lldb (alpha)" too?
Probably, yes, because stepping is done the same in both of the lldb based debuggers.  The difference with the fpdebug version, is only about displaying watches and locals.

There are 2 possibilities here (and the log will tell which one)
1) The IDE sends the correct command, but lldb has a problem. Then there is little that can be done.
   (There is a very similar issue on win64 with gdb. It is not yet known what causes this. )
2) The IDE sends the wrong command. Or there was an ignored exception, and the IDE did not manage to recover that.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 02, 2018, 06:25:04 pm
Crud. Unable to get log working. I get the same 'unable to open file /Developer/....../qt5/taenumerators.o' even though I have done the 'launch limit maxfiles 10240 unlimited'.

Yes, this same issue occurs with the lldb(alpha) as well.

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 02, 2018, 07:02:50 pm
In this case, open the IDE normally, and before starting to debug go to menu:
   View > Ide Internals > Debug Output

Once you run your project, the window will fill with the IDE <> lldb communication.

When you press F8, you can see what the IDE issues:
thread step-in
thread step-over

Thought there will be plenty of more lines, as stack and watches gets done.

You can copy the content, and attach it.
Take the copy immediately after step-over went wrong, so I know the last step command should have been step over.

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 02, 2018, 08:19:18 pm
OK, finally got it!
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 02, 2018, 09:18:15 pm
Martin,

I managed to get lldb working on macOS cocoa lazarus 2.0 revision 59715, the latest fixes, after a great deal of fiddling. lldb seems to be working on very simple projects, but I tried to run one of my large projects with it, and get an access violation. The project runs fine without lldb.

I have attached the log in case it may be helpful.

VTwin
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 02, 2018, 09:24:19 pm
@bigDan

Ok, I had a look. LLDB actually believes that it stopped at the end of the "step over". Or in other words, lldb seems to think that the (first (few) ?) line(s) of the subroutine are part of the caller.

I have seen the same issue with gdb on win (but only 64 bit apps).

Given that 2 different external debuggers give that issue, I would currently guess that this is some problem with the debug info written by fpc.

I dont know what the equivalent of objcopy is on Mac, on Windows it seems the following may help: http://forum.lazarus-ide.org/index.php/topic,42183.msg294247.html#msg294247


Ultimately what is needed is a small project with as little dependencies as possible that allows to reproduce this, and then report it to the fpc bugtracker.
But sofar it has only occurred in  complex projects and was not reproduced: https://bugs.freepascal.org/view.php?id=34159
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 02, 2018, 09:34:30 pm
I managed to get lldb working on macOS cocoa lazarus 2.0 revision 59715, the latest fixes, after a great deal of fiddling. lldb seems to be working on very simple projects, but I tried to run one of my large projects with it, and get an access violation. The project runs fine without lldb.

I have attached the log in case it may be helpful.

Is that RC2 ?

There is one known crash (inspecting watches/locals/hint...) that is fixed for RC3 already.

If you want to apply the changes:
https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=59443


Unfortunately the log has no line numbers on the traces, there is a bug in FPC that prevents them from being printed.

If you run the IDE itself under lldb (probably easiest to use lldb from commandline for that / but you can debug the IDE inside the IDE too).
"access violation" should get caught, and lldb should be able to do a proper stack trace with lines.

---
EDIT:
just seen you are on svn.

If you could try to get the stacktrace please.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 02, 2018, 10:18:55 pm
I have not done a stack trace before, so am trying using instructions here:

http://wiki.lazarus.freepascal.org/Logging_exceptions

to override TApplication.OnException:

Code: Pascal  [Select]
  1. Application.OnException := @CustomExceptionHandler;
  2.  

Unfortunately, it is not triggered. Any suggestions?

EDIT: I'm now trying to override System.ExceptProc
EDIT: Can't seem to figure out how to do this

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 03, 2018, 12:48:58 am
lldb is working in another large project. One thing I notice is that "Step Over" does not seem to be working, it seems to "Step Into". I have to use "Step Out" to get back.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 03, 2018, 01:28:37 am
lldb is working in another large project. One thing I notice is that "Step Over" does not seem to be working, it seems to "Step Into". I have to use "Step Out" to get back.
The step problem appears to be related to some debug info that fpc writes for the exe. Since both gdb and lldb react the same way to it, I think it is a problem in fpc.

Quote
to override TApplication.OnException:
Tracking the exception from inside the running IDE may not work anyway. DumpStack and similar commands will produce the same address-only trace on Mac. Fpc does not have the line info reader for dwarf on Mac https://bugs.freepascal.org/view.php?id=32775

If you can start the IDE from inside lldb (on the command line), then lldb should stop it, once you get the access violation (for other exception that are "raise"d, you need a breakpoint at FPC_RAISEEXCEPTION). You can run the debugger in the IDE, even while the IDE is debugged in lldb. When the command line lldb stops the IDE at the error, you can get a trace (with filenames and lines).

If you want comfort (and have a big monitor):
Open the IDE, (with high file limit). Open the project ide/lazarus.lpi (in the lazarus install dir). Run F9. A 2nd IDE will be started, this is running in the debugger of the first. Get the error in the 2nd IDE, and then get the stack from the first.

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 03, 2018, 03:46:11 am
I've created a tiny application that will duplicate the DEBUG STEP OVER bug for me.

Instructions are at the top of the form unit.  It fails consistently on DARWIN. I don't have 2RCL2 installed on anything else to try at the moment.

bigDan
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 03, 2018, 12:04:11 pm
Instructions are at the top of the form unit.  It fails consistently on DARWIN. I don't have 2RCL2 installed on anything else to try at the moment.
It all comes down to if it will also fail for someone in the fpc team. See the bug report.

This is not going to change with further RC, or 2.0. The issue is in fpc. Last time I checked it was also present in fpc trunk. So it likely will be in 3.2 too.


--
For reference: http://lists.freepascal.org/pipermail/fpc-devel/2018-December/039813.html
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: bigDan on December 03, 2018, 04:48:30 pm
Thanks for looking into this, I appreciate it. Overall, the new lldb code is definitely much better!
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 03, 2018, 07:10:24 pm
Many thanks. Perhaps bigDan's bug report will help fix the step bug.

Thank you for the suggestions on stacktrace, I will keep working at it.

The exception is puzzling, as it occurs before even Application.Initialize. Perhaps I have an incorrect setting in the project options, possibly between setting up lldb and cocoa I made an error. 
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 03, 2018, 07:21:38 pm
The exception may be while fpdebug is getting ready. Maybe while it gathers dwarf info from the files on disk.

The debugger is kind of split into 2 parts.

1) LLDB: all interactions with the running exe. Used for breakpoints, stepping, running, pause, ....
  used to read memory dumps from the running app

  In the NONE fpdebug version lldb also does watches, locals ....  (no line info though, therefore the none-fpdebug version does not have the blue dots in the editors gutter)

2) Because lldb only understands C style input for watches (object->field), and displays all results in c style too, the IDE uses fpdebug for watches and locals...
Fpdebug is a debugger written in Pascal, for Pascal.
In the lldb(with fpdebug) debugger, Fpdebug reads the apps memory by getting raw memory dumps from lldb. Fpdebug loads its own copy of the dwarf info directly from the files on disk (bundle).

---------------
That means, if the IDE crashes, it could be Fpdebug. You can use the pure lldb. But getting watches will be all c style work... But better to get Fpdebug fixed.

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 03, 2018, 08:07:07 pm
Thanks! One puzzle is why it works on one of my projects, and not the other. They are configured the same (as far as I can figure out yet). This time, I at least got an error message:

Unable to open file "/pathtoproject/lib/x86_64-darwin/vsizedlg.o"

The file is, however, there. It is for a dialog box.

I had some initialization code in that unit (vsizedlg.pas/vsizedlg.lfm) that created a class (not a form), that the form later used. I rewrote the code to remove initialization (and finalization) code. Now it no longer crashes!  %)

Could that be "while fpdebug is getting ready"?



Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 03, 2018, 09:37:42 pm
Still not solved. Now it says it can not open:

"/Developer/lazarus_2_0/components/lazutils/lib/x86_64-darwin/laz2_xmlwrite.o"

which exists. :(

EDIT: I removed the initialization (and finalization) code from 3 other similar dialog units. For now lldb seems to be working again. Fingers crossed!
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 03, 2018, 09:44:27 pm
As for the "unable to open file"

Could you open and edit components\fpdebug\fpimgreaderbase.pas
line 166 in
constructor TDbgFileLoader.Create(AFileName: String);
Code: Pascal  [Select]
  1.   FStream := TFileStreamUTF8.Create(AFileName, fmOpenRead or fmShareDenyNone);
  2.  

into
Code: Pascal  [Select]
  1.   try
  2.   FStream := TFileStreamUTF8.Create(AFileName, fmOpenRead or fmShareDenyNone);
  3.   except
  4.     DebugLN(['Error opening file ', AFileName, ' error: ', GetLastOSError]);
  5.   end;
  6.  
and add "LazLogger" to the uses clause.

No need to reraise the exception. Lets see what happens, if it is ignored.

--------------------------------------------
About the crash:

If I read your log correctly, then you restarted the IDE
Code: Pascal  [Select]
  1. LAZARUS END - cleaning up ...
  2. [FORMS.PP] ExceptionOccurred
  3.   Sender=EAccessViolation
  4.   Exception=Access violation
  5.   Stack trace:
  6.   $000000010022F261
  7.   $00000001000825DB
  8.   $0000000100078F93
  9.  
and there where plenty of errors then. But they will be from something that happened before.

The next crash is shortly after (but not during)   
TFpLldbDebugger.LoadDwarf

It is right before the debugger should sent the "process launch" command. That is the one we are trying to catch.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 03, 2018, 11:31:42 pm
Ok, I made the edit (was in line 165). Deleted lazarus_2_0 units in case that helps. Then 'Clean up and Build'.

I'm getting the same unable to open warning dialog for "laz2_xmlutils.o" again.

BTW, I'm using "Dwarf with sets", that was default.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: VTwin on December 03, 2018, 11:36:52 pm
Code: Pascal  [Select]
  1.   //////////////////
  2.   ////FStream := TFileStreamUTF8.Create(AFileName, fmOpenRead or fmShareDenyNone);
  3.   try
  4.     FStream := TFileStreamUTF8.Create(AFileName, fmOpenRead or fmShareDenyNone);
  5.   except
  6.     DebugLN(['Error opening file ', AFileName, ' error: ', GetLastOSError]);
  7.   end;  
  8.   //////////////////
  9.  

Plus uses LazLogger.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 05, 2018, 02:57:40 am
Ok, I may have made progress on the too many file handles issue.  I found and tested where the linux loader opens its file. The Mac loader should do the same. The file(s) are no longer kept open.

Currently committed in trunk r59729.

If you could please test, and confirm if the problem with "unable to open file" is resolved?

For testing, set your file limit lower (not sure what else the IDE needs (project, units, lfm, lps, codetools may scan units that are not open...), but maybe try 30 to 50). Also do some debugging with this setting, to see if there are any issues while you inspect data (watches, locals, hints, opening new editor files (blue dots), ...)

Thanks for testing.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Arvur on December 06, 2018, 02:44:30 pm
It seems that unchecking "Use Application Bundle" in Project Options breaks debugger. Is this a known bug? Or should I check it deeper?
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 06, 2018, 06:22:47 pm
It seems that unchecking "Use Application Bundle" in Project Options breaks debugger. Is this a known bug? Or should I check it deeper?
No, not known. Please provide a log.

How exactly does the "break" manifest? What error is displayed, or what feature stops working.

Does it work or break with a simple program? (Just one pas file)

Are you testing with:
RC2
fixes2_0 branch svn
trunk svn
?

Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: carl_caulkett on December 07, 2018, 09:52:34 pm
I've installed Lazarus v2.0.0RC2 and have got the LLDB debugger working there. I've also installed separately v2.1.0 r59743 from SVN and built using the Cocoa widget set. I cannot find the option for LLDB in the options there. Is this expected behaviour?
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: carl_caulkett on December 07, 2018, 10:00:33 pm
Sorry! My mistake! In my eagerness I forgot what I did last night and forgot to install the LazDebuggerFpLLdb package. Seems to be working fine now.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Arvur on December 10, 2018, 02:49:27 pm
It seems that unchecking "Use Application Bundle" in Project Options breaks debugger. Is this a known bug? Or should I check it deeper?
No, not known. Please provide a log.

I didn't manage to reproduce it on a simple project.

Lazarus RC2, Mac OS Mojave (10.14.1), dwarf2 debug info, cleanup and build before run.
No error when I turn off bundle option, it just shows me Assembler window. So I supposed debug info cannot be found.
But... If I press Run to continue, Assembler window stucks to the same address point (938B7284 : 8b 50 04 movl 0x4(%eax), %edx).
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 10, 2018, 03:23:59 pm
Try to get a log file (see 1st message of this thread)

Stepping, Running, Stopping, are done by lldb. If lldb can not handle that situation, then there is probably nothing that can be done to fix it.

If you do change between app-bundle / no app-bundle, then make sure the old app bundle is no longer there. (The same, if you had compiled with external debug info, and change to none external, ensure the old external info is deleted).
If you have such remains, the debugger (both lldb, which for that part is outside our control / and fpdebug in the IDE) may find the old left overs. And that may cause hick ups.
(lldb may (?) give warnings, and they may show in the logfile).

Please also note, that once compiled, you must not touch any of the .o files that are in the project's and packages' lib directories. The debugger (lldb and fpdebug) will read those. They must match what is in the exe.

You may be able to notice this, if you try to debug the IDE itself within the IDE.
If you build the IDE with extra options (Tools menu), and then open the ide/lazarus.lpi and select Run. The project may get compiled again, but without the final linking (because the IDE project is setup specially). So the .o files will then be newer than the exe. (But the debug info might still match, IF the opt level, or other code generating related flags (asserts, range checks ...) have NOT changed.
If you run the IDE from console (or tail the logfile) you should see warnings in this case.
But then this case should not happen with normal projects.
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 11, 2018, 01:22:24 pm
You can also try to compile with -godwarfcpp
Title: Re: New debugger for Mac based on lldb (Call for testers)
Post by: Martin_fr on December 12, 2018, 11:44:47 pm
Could those on trunk please update to revision 59812

rev 59811: This enables capturing debug history.
 if you think it affects the speed of continuous stepping (repeated F7/F8), compile with -dLLDB_SKIP_IDLE
 if you have issues stepping (F8) over (ignored) exceptions, or stepping from raise to except/finally-block then try -dLLDB_SKIP_SNAP

Note: independent of this rev, stepping from raise to except/finally-block will always visually stop at the last statement before except. even though it is on except. (or finally)


rev 59812: some startup processing moved to thread. On very large apps this may lead to slightly faster start up.
  no side effects expected

Please let me know if those work well for you.