Recent

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

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #45 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

« Last Edit: December 02, 2018, 10:33:58 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #46 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.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #47 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.


bigDan

  • New Member
  • *
  • Posts: 43
    • BigDanzBlog
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #48 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

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #49 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
« Last Edit: December 03, 2018, 02:39:55 pm by Martin_fr »

bigDan

  • New Member
  • *
  • Posts: 43
    • BigDanzBlog
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #50 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!

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #51 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. 
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #52 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.


VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #53 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"?



“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #54 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!
« Last Edit: December 03, 2018, 10:48:13 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #55 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.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #56 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.
« Last Edit: December 03, 2018, 11:34:07 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #57 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.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #58 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.

Arvur

  • New Member
  • *
  • Posts: 48
    • My GitHub
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #59 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?

 

TinyPortal © 2005-2018