Recent

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

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #75 on: December 24, 2018, 01:06:06 pm »
I installed new Lazarus 2.0 RC3 on macOS Mojave.

New LLDB debugger is available by default. It works fine on first glance.

Also I can see values of WideString under debugger.

Thanks, Martin!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #76 on: December 24, 2018, 01:32:20 pm »
I added "known issues" to my initial post on page 1.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #77 on: January 02, 2019, 09:48:34 am »
Which command will build an IDE from zero with this lldb installed? Because I was using "make bigide" and it wasn't available, but maybe my revision was too old?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #78 on: January 02, 2019, 12:49:30 pm »
Which command will build an IDE from zero with this lldb installed? Because I was using "make bigide" and it wasn't available, but maybe my revision was too old?

Afaik it should be part of bigide (but I have to test). But only in fixes 2.0 (probably past RC2) and in trunk (2.1).

Not a direct answer to your quesition: You can always install the package LazDebuggerFpLldb

Also once build bigide, check that the package is installed, to make sure the error (of its absence) is not something else/unexpected.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #79 on: January 03, 2019, 04:45:05 pm »
Indeed, it seams to be available in "make bigide LCL_PLATFORM=cocoa"! I must have been using too old revisions. Thanks for the great work by the way!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #80 on: January 05, 2019, 06:05:52 pm »
I added a testcase for "lldb with fpdebug".

Currently it only focuses on watch evaluations. Stepping, breakpoints and the like are not yet tested.

If you are
- on trunk, at/past revision 60012
- on fixes2.0, at/past revision 60013
then you can run it. (and it be nice if you do, please)

The test is in  components\lazdebuggers\lazdebuggerfplldb\test
TestFpLldb.lpi

Before you can run it you need
* CONFIG
copy and edit
  fpclist.txt.sample => fpclist.txt
  lldblist.txt.sample => lldblist.txt

Uncomment what you need. Edit the path to your fpc/lldb.
-You can ignore the version info.
-You can add/use one off (or leave away, which means both)
  bits=32
  bits=64
  bits=32,64
-For symbols=gw,gwset,gw3,gw4 you can use any flag that fpc recognizes for dwarf

-You can duplicate a section and extend it with (to pass extra param to fpc)
  opts=-O- -godwarfcpp
godwarfcpp is not fully supported

* DIRECTORIES
you may have to rename the folder testapps to lowercase
After you run tests, you should periodically delete any files in it, except for the "lib" folder, which must exist (as an empty folder)

You may create a "logs" folder.

If a file dialog opens, when you run the test, then it did not find the testapps/lib folder.

----------------------
Currently there is a known issue, with global variables from other units (other than the current paused line).

This leads to 61 fails in the "Scope" test. The test will list the number of fails at the end.

----------------------
Running the test may take some time. Between 10 and 30 minutes, depending on your system. Run it from a console, to see it is not stack (it prints dots to the console, from time to time)
« Last Edit: January 05, 2019, 06:24:20 pm by Martin_fr »

kcandrews

  • Jr. Member
  • **
  • Posts: 50
Re: New debugger for Mac based on lldb - "ignore exceptions" ineffective
« Reply #81 on: January 28, 2019, 04:27:47 am »
Hi Martin,

Following up from our late November conversation, I am still working on figuring out exception issues I encountered in my Mac OSX "big project" with the new LazDebuggerFpLldb 0.0 setup.  I am working with Lazarus 2.0.0RC3, FPC 3.04, X86_64-darwin-cocoa(alpha).

I note that you fixed incorrect class names which prepended: "2 digits at the start."  There is still something peculiar going on with exception class names for me -- apparently related to suffix characters appended to the end of the classnames.

Simple code from my project...

   if not assigned(Order)
   then
      raise ETradeException.Create('TTrade.GetSLPrice: No SL order!')
   else
      result := Order.Price;

In the IDE Options "Ignore these exceptions" list, I have added and checked the exception item "ETradeException".  When debugging, unexpectedly, I receive an exception dialog as a result of the "raise" in the code above.  This is true even when I uncheck "Notify on Exceptions" on the IDE Options dialog.  The interesting thing is that if I respond to the dialog saying that I want to "Ignore this exception type", that does work, but it also apparently is saving the exception with an additional suffix: "ETradeException\x10\v".  So when I now look at the revised "Ignore these exceptions" list, I see both the original "ETradeException" as well as the new one to be ignored: "ETradeException\x10\v".

Having no knowledge of the debugger internals, I don't know why the extra characters, but it appears they are causing a mismatch as the code tries to identify named exceptions.  Please let me know if I can explain better :-)

Thanks again for all your work on this!

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).
« Last Edit: January 28, 2019, 04:39:39 am by kcandrews »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #82 on: January 28, 2019, 04:58:13 am »
Can you try to get a log, as described in the first messages of this thread?
That would really help. Thanks.

I may have an idea... (next 2 or 3 days)
But in case.
« Last Edit: January 28, 2019, 05:03:15 am by Martin_fr »

kcandrews

  • Jr. Member
  • **
  • Posts: 50
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #83 on: January 28, 2019, 09:12:55 pm »
Martin,

I sent you a link to the 80 Mg file (because of the 250K forum limit).

Hope this helps!
Keith

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #84 on: January 29, 2019, 04:12:10 pm »
Ok, I think I got it.

Please test with rev 60239 (trunk / merge to fixes is pending)
Or apply the changes from
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas?root=lazarus&r1=60239&r2=60238&pathrev=60239

There is probably NOT going to be another RC.  So you need to apply the changes yourself for testing

kcandrews

  • Jr. Member
  • **
  • Posts: 50
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #85 on: January 29, 2019, 06:22:44 pm »
Martin,

Thanks so much!!  I applied your changes directly into the code in LibdbDebugger.pas, compiled and  rebuilt the package.

I know my log was probably big/complex enough to be a pain to search through, so I especially thank you for going through this.  Hopefully this will prevent similar exception name issues for others.

This seems to solve the Exception naming for me :-)

I'm doing more testing today...I am having instances of debug runs (without any breakpoints set) where things just hung and I had to actually kill and restart Lazarus.  As into, the application is a financial portfolio backtest system developed over many years (initially in Delphi and for the last 5 years in Lazarus).  So when I'm testing, I actually run tests on financial data analysis/technical indicators (stocks/futures/bonds) from 1935 to the current date.  The current test made it to 1980 but then hung.  (There are no issues like this without running under the lldb debugger and no issues when using gdb.)

I'll learn what I can from the laz.log but will probably need your help again, if you have time :-)

Keith

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #86 on: January 29, 2019, 06:47:59 pm »
I'm doing more testing today...I am having instances of debug runs (without any breakpoints set) where things just hung and I had to actually kill and restart Lazarus.

You could try to run the IDE in lldb. You need to build the IDE with -gw for this.
Open a terminal, and run (afaik)
Code: Pascal  [Select][+][-]
  1. lldb /path/to/lazarus/lazarus.app/Contents/MacOS/lazarus
Then enter r and return
and your IDE should run as normal. (after exit, you need to quit lldb: q)

That way you may get more info, should the IDE hang.
If lldb reports an error, then just enter: bt
and hopefully that gets a useful stack trace

If the IDE hangs, but lldb does not report, you should (IIRC) be able (in lldb / the terminal) to hit ctrl-c. You may have to select a diff thread after that. "threads list" and "t 1", "t 2", ...


If you run with --debug-log, delete the old logfile before each run. The IDE will keep appending....



I am not sure if you test RC3 or fixes branch.

There have been plenty of fixes since RC3. (including crashes in the debugger).
A list can be found here http://wiki.lazarus.freepascal.org/Lazarus_2.0_fixes_branch#Merged_revisions_for_2.0.0RC4 (note there likely will not be an RC4)


So it would be good to test on fixes branch. You can (most likely) download fixes, and replace some folders in your rc3, if you prefer. Folders needed to be copied:
components/fpdebug
components/lazdebuggers 
« Last Edit: January 29, 2019, 07:01:53 pm by Martin_fr »

kcandrews

  • Jr. Member
  • **
  • Posts: 50
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #87 on: January 29, 2019, 07:22:09 pm »
Thanks Martin.

Did as suggested compiling IDE with -gw...

So lldb said Lazarus "stopped":

Process 39997 stopped
* thread #14, stop reason = EXC_BAD_ACCESS (code=1, address=0x11d0c1000)
    frame #0: 0x000000010000cc44 Lazarus`SYSTEM_$$_DEFAULTANSI2UNICODEMOVE$PCHAR$WORD$UNICODESTRING$INT64 + 52
Lazarus`SYSTEM_$$_DEFAULTANSI2UNICODEMOVE$PCHAR$WORD$UNICODESTRING$INT64:
->  0x10000cc44 <+52>: movzbw (%rbx), %dx
    0x10000cc48 <+56>: movw   %dx, (%rcx)
    0x10000cc4b <+59>: addq   $0x1, %rbx
    0x10000cc4f <+63>: addq   $0x2, %rcx
Target 0: (Lazarus) stopped.

Here is the bt result:
(lldb) bt
* thread #14, stop reason = EXC_BAD_ACCESS (code=1, address=0x11d0c1000)
  * frame #0: 0x000000010000cc44 Lazarus`SYSTEM_$$_DEFAULTANSI2UNICODEMOVE$PCHAR$WORD$UNICODESTRING$INT64 + 52
    frame #1: 0x00000001000be445 Lazarus`CWSTRING_$$_ANSI2WIDEMOVE$PCHAR$WORD$WIDESTRING$INT64 + 197
    frame #2: 0x000000010000d05f Lazarus`fpc_ansistr_to_unicodestr + 111
    frame #3: 0x000000010000a92d Lazarus`SYSTEM_$$_ANSISTR_CONCAT_COMPLEX$RAWBYTESTRING$RAWBYTESTRING$RAWBYTESTRING$WORD + 133
    frame #4: 0x000000010000aa8c Lazarus`fpc_ansistr_concat + 220
    frame #5: 0x0000000100277ead Lazarus`DODEBUGLN(this=0x0000000103ff61c0, S="TTTTT data avail continue") at lazlogger.pas:730
    frame #6: 0x000000010013cc19 Lazarus`DEBUGLN(this=0x0000000103ff61c0, S="TTTTT data avail continue") at lazloggerbase.pas:897
    frame #7: 0x0000000100c69db8 Lazarus`EXECUTE(this=0x00000001134ec140) at debugprocess.pas:178
    frame #8: 0x00000001000d78c0 Lazarus`CLASSES_$$_THREADFUNC$POINTER$$INT64 + 272
    frame #9: 0x0000000100023f0c Lazarus`CTHREADS_$$_THREADMAIN$POINTER$$POINTER + 156
    frame #10: 0x00007fff79741661 libsystem_pthread.dylib`_pthread_body + 340
    frame #11: 0x00007fff7974150d libsystem_pthread.dylib`_pthread_start + 377
    frame #12: 0x00007fff79740bf9 libsystem_pthread.dylib`thread_start + 13
(lldb)

Not sure how to interpret this -- many years ago analyzed backtraces, but brain has lost this :-)

Thanks!


Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #88 on: January 29, 2019, 07:34:00 pm »
It seems that debugprocess (or something else) is launched as separate thread, so there is need for critical section when outputting text to stdout (or for processing strings). Possible solution is to create a critical section during initialization of the lazlogger unit and using it around TLazLoggerFile.DoDebugLn method.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: New debugger for Mac based on lldb (Call for testers)
« Reply #89 on: January 29, 2019, 08:22:36 pm »
LazLogger "transfers" the string to the main thread, which will write it to the logfile (TLazLoggerFileHandleMainThread).

Processing strings should be allowed within each thread.
So long as each thread uses its own strings (actually fpc has some provision for sharing strings, 2 threads can have separate references to the same string).

But there is indeed an issue.
FDebugIndent is a global var (a field of a global object). So all threads share the same reference. And that is not ok.

Please find the function:
TLazLoggerFile.CreateIndent
in
components\lazutils\lazlogger.pas
line 635

Comment out the entire function body. (or place an "exit" at the very start).
Lets see if that helps.
« Last Edit: January 29, 2019, 08:34:03 pm by Martin_fr »

 

TinyPortal © 2005-2018