Recent

Author Topic: Problems with Debugger on OSX  (Read 13946 times)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Problems with Debugger on OSX
« on: April 06, 2019, 09:51:56 pm »
Hi All.

When running application with Debug, it compiles ok with just one warning "Compile Project, Mode: Debug, CPU: x86_64, Target: MyStamps: Success, Hints: 1" and then after a wee delay fails with the attached “Access Violation” error.

I believe this occurs on all application I try and create, 32 or 64bit, Carbon or Cocoa.

Heres what I have ...

OS: OSX High Sierra 10.13.6
Lazarus: 2.0.0 (2019-03-07) - as reported by Help|About

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2


LLDB appears to be code signed ok ...

$ codesign -dv --verbose=4 /usr/bin/lldb
 
Executable=/usr/bin/lldb
Identifier=com.apple.lldb
Format=Mach-O thin (x86_64)
CodeDirectory v=20100 size=223 flags=0x0(none) hashes=3+2 location=embedded
Platform identifier=4
VersionPlatform=1
VersionMin=658688
VersionSDK=658688
Hash type=sha256 size=32
CandidateCDHash sha256=8784dbb260e938bbc83d3ab1adfdaa415900485e
Hash choices=sha256
Page size=4096
CDHash=8784dbb260e938bbc83d3ab1adfdaa415900485e
Signature size=4485
Authority=Software Signing
Authority=Apple Code Signing Certification Authority
Authority=Apple Root CA
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=1 size=64

Anyone have any ideas what I might (probably) be missing or where to look


Cheers guys
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #1 on: April 07, 2019, 01:36:01 am »
lldb is supplied by apple, when you install their developer tools, so yes it should be codesigned.

Unless you are logged in as root, it should ask you once for the password. A dialog should pop up (at least it does for me).


Unfortunately the screen shot does not help much. Can you generate, and attach a logfile?
Step for doing so: https://forum.lazarus.freepascal.org/index.php/topic,42869.0.html

It may be necessary that you have to recompile your IDE with debug settings
Menu: Tools > configure build lazarus
In the Options field add, if your IDE itself is 64 bit: -gw
if your IDE is 32bit: -gs

It may also be that you may have to run the IDE under lldb. I will know after looking at the log. If so I will provide detailed steps.

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Problems with Debugger on OSX
« Reply #2 on: April 07, 2019, 06:58:46 am »
Thanks martin_fr

I don't recall ever being prompted for the password - of course thats not to say it didn't a happen

Attached is the log you asked for

I tried the lazarus rebuild with -gs and all I got was a bunch of

Compile package FCL 1.0.1: Exit code 1, Errors: 11
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.
Error: assembler: error: unsupported directive '.stabs'. Hint: Use another type of debug info.

Thanks again
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #3 on: April 07, 2019, 02:29:11 pm »
Ok.
Unfortunately fpc misses a feature on Mac, that would allow to collect further info in the log file. (Not the reason of the crash, just making it a few extra steps to find out why it happens)

So you will need a few extra steps.

1) rebuild the IDE, this time with -gw  (even for 32bits)

2) start the IDE in lldb
Open a terminal, and run
Code: [Select]
lldb /path/to/lazarus/lazarus.app/Contents/MacOS/lazarusIn lldb enter:  r
and return

3) Use the IDE, when the crash happens the lldb in the terminal should print something like:
Code: [Select]
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:

in lldb enter (followed by return): bt

Copy the output and post it here (or copy to a file and attach)

Note that lldb may give data for the wrong thread, so you need to repeat the "bt" and add more data.
In lldb enter:  thread list

This will list a number of threads (starting at 0 or 1), for each of them do (replacing 1 by the thread number
thread select 1
bt

At least one, probably two of the results should contain some of the units names, of units used in the IDE.



I understand your IDE is 32 bit, and you compile your app for 64 bit?
While this should work, it is possible that the crash is related to this cross debug situation.

It would be good to have the data to fix this. But you might want to try and build your IDE for 64 bits (so that may give you other limitations, outside the debugger). It may then be able to debug your app.
Or you can debug your app compiled for 32 bit, and then later build for 64 bit.

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Problems with Debugger on OSX
« Reply #4 on: April 07, 2019, 09:58:26 pm »
Hi,

Ok, attached is the lldb output. I've include the output for all 5 threads that were listed, but only 1 looks relevant I'm guessing

I tried compiling for 32bit and the debug failed in the same way... "Access Violation". I haven't tried any of the steps you previously suggested, with this 32bit compile. Happy to do so if you think it worthwhile

I'm not sure I'm ready to attempt to build a 64bit IDE and deal with any loss of functionality, least not yet - this is my first gui app in over 20yrs and the learning curve is pretty steep as it is

Thanks for all the help
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #5 on: April 08, 2019, 12:53:11 am »
I had a first look at it.

The crash is probably a side effect. It seems that the debugger has problem reading the debug info from the app.

So in all likelihood, if it did not crash, it would start the app, but you could not inspect any data, because the debugger did not read the info what variable your app has.



Step by step:

1)  around line 1100
/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas
Code: Pascal  [Select][+][-]
  1.     FMemManager := Loader.MemManager;
  2.     FDwarfInfo := Loader.DwarfInfo;
  3.     Result := Loader.ReaderErrors;
  4.     Loader.Free;
  5.  
  6.     if FDwarfInfo.Image64Bit then
  7.       FPrettyPrinter := TFpPascalPrettyPrinter.Create(8)
  8.     else
  9.       FPrettyPrinter := TFpPascalPrettyPrinter.Create(4);
  10.     exit;
the line
Code: Pascal  [Select][+][-]
  1.     if FDwarfInfo.Image64Bit then
  2.  
should be
Code: Pascal  [Select][+][-]
  1.     if FDwarfInfo = nil then exit;
  2.     if FDwarfInfo.Image64Bit then
  3.  

I have to do some tests, if there will be further error (crash) after this.


THis leaves the question why the debug info is not read ....

Are you able to debug an empty project /form with just a button , and a button-click handler "caption:='test me';" ?

What settings did you do in your project?
Can you send a copy of the project.lpi  file? (Unless the next few question bring up an answer)

Is you debug type set to either "dwarf", "dwarf with sets" or "dwarf 3"
And you follow the settings in
http://wiki.lazarus.freepascal.org/Debugger_Setup

Do you use "external debug symbol" ?
If so, can you try with/without?
After you used it, there will be a folder projectname.DSYM => delete this folder after debugging (before switching off external info)



ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Problems with Debugger on OSX
« Reply #6 on: April 08, 2019, 04:42:17 am »
Hi

Quote
Step by step:

1)  around line 1100
/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas

I made the changes and rebuilt the IDE with no effect.

Quote
What settings did you do in your project?
Can you send a copy of the project.lpi  file? (Unless the next few question bring up an answer)

I've create a barebones project with your suggestions; entire project is at the attached Dropbox link

To keep things simple, I've compiled on 32bit only

Also on Dropbox is a PDF of screen dumps of IDE & Project settings

Quote
Is you debug type set to either "dwarf", "dwarf with sets" or "dwarf 3"
And you follow the settings in
http://wiki.lazarus.freepascal.org/Debugger_Setup

I believe so as best as I can figure out since the page describes GDB.

Quote
Do you use "external debug symbol" ?
If so, can you try with/without?
After you used it, there will be a folder projectname.DSYM => delete this folder after debugging (before switching off external info)

I'm going to have to plead ignorance on this one. I don't think I even know what one is :)

Cheers

File here because they're to big to upload ... https://www.dropbox.com/sh/ytkixv0rir29xlk/AACieRZ9x4yF0Edpd2a_MVOma?dl=0
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Problems with Debugger on OSX
« Reply #7 on: April 08, 2019, 04:48:34 am »
I believe so as best as I can figure out since the page describes GDB.

I suspect martin may have meant this wiki page - http://wiki.freepascal.org/Installing_Lazarus_on_MacOS_X
gdb can be made work under OSX but its not a simple process. LLdb is ....

Do check the formats you are using.

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

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #8 on: April 08, 2019, 06:06:47 pm »
Quote
Is you debug type set to either "dwarf", "dwarf with sets" or "dwarf 3"
And you follow the settings in
http://wiki.lazarus.freepascal.org/Debugger_Setup

I believe so as best as I can figure out since the page describes GDB.

I started updating the wiki, to point out the differences with LLDB. Or to mention were the same settings apply to LLDB.

There is also some work to be done in the IDE, where many labels refer to GDB, but setting often apply to both.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #9 on: April 08, 2019, 06:20:16 pm »
Quote
What settings did you do in your project?
Can you send a copy of the project.lpi  file? (Unless the next few question bring up an answer)

I've create a barebones project with your suggestions; entire project is at the attached Dropbox link
On a first glance, the settings seem ok.

Quote
To keep things simple, I've compiled on 32bit only
And were you able to run this in the debugger?
Set a breakpoint at "Label1.Caption:='That Tickles';" and see if it stops (when you click the button)?

Or does the debugger crash on this project too?

Quote
Quote
Do you use "external debug symbol" ?
If so, can you try with/without?
After you used it, there will be a folder projectname.DSYM => delete this folder after debugging (before switching off external info)

I'm going to have to plead ignorance on this one. I don't think I even know what one is :)
Menu: Project > Project Options
Page: Debugging

There is a checkbox: "Use external gdb debug symbol file"
(the caption is outdated, it is lldb too)

You can try if your project works, when you change this (i.e. it is likely off now, so you would switch it on)

If you have used it, and you go back to having it switched off:
In the project folder there will be a folder    project1.dSYM  (much like the project1.app folder). The name follows your project name, but it ends in .dSYM.
This folder is created (during compile) if the option is turned on. But it is never removed. SO if you switch the option off, please remove that folder (*.dSYM) by hand.


More later

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Problems with Debugger on OSX
« Reply #10 on: April 08, 2019, 10:31:35 pm »
Quote
And were you able to run this in the debugger?
Set a breakpoint at "Label1.Caption:='That Tickles';" and see if it stops (when you click the button)?

Or does the debugger crash on this project too?

Quote
There is a checkbox: "Use external gdb debug symbol file"
(the caption is outdated, it is lldb too)

You can try if your project works, when you change this (i.e. it is likely off now, so you would switch it on)

If you have used it, and you go back to having it switched off:
In the project folder there will be a folder    project1.dSYM  (much like the project1.app folder). The name follows your project name, but it ends in .dSYM.
This folder is created (during compile) if the option is turned on. But it is never removed. SO if you switch the option off, please remove that folder (*.dSYM) by hand.

Cool.. so I've just tried with and without the external symbol file, deleting the directory when the option is turned off. The project fails with the access violation in both cases. I've also run lazarus in lldb and attached is the result... looks like it failed somewhere else this time

Cheers
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #11 on: April 09, 2019, 08:51:54 pm »
Ok, the 2nd crash is already fixed in the fixes branch revision 60649  (and will be gone in 2.0.2)
The line is now:
Code: Pascal  [Select][+][-]
  1.   if (State = dsRun) and (FMemManager <> nil) then

The first crash should be addressed in  (also going to be in 2.0.2)
https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=60900

But that does not solve the main problem.
Both crashes are because the dwarf info was not loaded. And without that, there are no watches, no locals, no value-hints.... In other words the debugger will be useless.

60900 will also add a popup in that case. So at least there is feedback about the problem. (That is unless the user disables those warnings).

I added a try ... except. Just in case.

On top of that, I will be looking through the code, and may ask you to patch in a few "debugln" lines (log output), in order to try and locate were loading fails.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #12 on: April 09, 2019, 09:18:37 pm »
ok, unfortunately the next steps are going to be a bit of a guessing game....

Could you find the file components/fpdebug/fpdbgdwarfdataclasses.pas
Around line 2945
Code: Pascal  [Select][+][-]
  1. constructor TFpDwarfInfo.Create(ALoaderList: TDbgImageLoaderList);
  2. var
  3.   Section: TDwarfSection;
  4.   p: PDbgImageSection;
  5.   i: Integer;
  6. begin
  7.   inherited Create(ALoaderList);
  8.   FImage64Bit := ALoaderList.Image64Bit;
  9.   FCompilationUnits := TList.Create;
  10.   FImageBase := ALoaderList.ImageBase;
  11.  
  12.   SetLength(FFiles, ALoaderList.Count);
  13.   for i := 0 to ALoaderList.Count-1 do
  14.   begin
  15. debugln(['loaderlist ',i,' ',ALoaderList[i]<> nil]); //////////////////////////////
  16. debugln([ALoaderList[i].FileName, ' / ', ALoaderList[i].IsValid]);///////////////////////////////
  17.     FFiles[i].AddressMapList:=ALoaderList[i].AddressMapList;
  18.     for Section := Low(Section) to High(Section) do
  19.     begin
  20.       p := ALoaderList[i].Section[DWARF_SECTION_NAME[Section]];
  21.       if p = nil then Continue;
  22.       FFiles[i].Sections[Section].Section := Section;
  23.       FFiles[i].Sections[Section].RawData := p^.RawData;
  24.       FFiles[i].Sections[Section].Size := p^.Size;
  25.       FFiles[i].Sections[Section].VirtualAddress := p^.VirtualAddress;
  26.     end;
  27.     ALoaderList[i].CloseFileLoader;
  28.   end;
  29. end;
  30.  

Insert the 2 lines, that are marked ////
If possible also apply the try... except from the link in my previous post.

And then do the log again.
Thanks

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Problems with Debugger on OSX
« Reply #13 on: April 09, 2019, 11:43:08 pm »
Hi,

Quote
ok, unfortunately the next steps are going to be a bit of a guessing game....
I'm more than happy to continue to plug away

Quote
The first crash should be addressed in  (also going to be in 2.0.2)
https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&root=lazarus&revision=60900
Quote
If possible also apply the try... except from the link in my previous post

I couldn't figure out from your link to the revision exactly what I need to do and where (something else to add to me "to learn" list).. If you can tell me exactly where and what to change, more than happy to do so

I did however manage to add the debugln lines around line 2945 of components/fpdebug/fpdbgdwarfdataclasses.pas

Quote
Ok, the 2nd crash is already fixed in the fixes branch revision 60649  (and will be gone in 2.0.2)
The line is now:

Code: Pascal  [Select][+][-]
  1.   if (State = dsRun) and (FMemManager <> nil) then
  2.  


Ok, I assumed you meant around line 774 of components/fpdebug/fpdmemorytools.pas but when I added as suggested

Code: Pascal  [Select][+][-]
  1. function TFpDbgMemManager.GetCacheManager: TFpDbgMemCacheManagerBase;
  2. begin
  3.   If (State = dsRun) and (FMemManager <> nil) then
  4.     SetCacheManager(TFpDbgMemCacheManagerBase.Create);
  5.   Result := FCacheManager;
  6. end;
  7.  

... the compile failed with

Quote
fpdmemorytools.pas(775,7) Error: Identifier not found "State"
fpdmemorytools.pas(775,15) Error: Identifier not found "dsRun"
fpdmemorytools.pas(775,27) Error: Identifier not found "FMemManager"

so I'm guessing its a different file?

There is no difference in the lldb output (because theres no change to fpdmemorytools.pas, I presume)

Cheers

OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Problems with Debugger on OSX
« Reply #14 on: April 10, 2019, 12:04:45 am »
As for the link, click on "text changed" and it gets you here: https://svn.freepascal.org/cgi-bin/viewvc.cgi/branches/fixes_2_0/components/lazdebuggers/lazdebuggerfplldb/fplldbdebugger.pas?root=lazarus&r1=60900&r2=60899&pathrev=60900

You can apply it line by line. (you only need the try except part, line 300-350, making sure any exception will be known)
Or you can download the "patch" (link at top) and then something like
  patch -p2 lazarus_inst_dir < patch
I am not sure it may be -p1.




As for the other line (it is the  2nd line in the stack trace)
components\lazdebuggers\lazdebuggerfplldb\fplldbdebugger.pas
line 1120 (yours may differ +/-50)

Code: Pascal  [Select][+][-]
  1. procedure TFpLldbDebugger.DoState(const OldState: TDBGState);
  2. ....
  3.       FWatchEvalList.Clear;
  4.     end;
  5.   end;
  6.   if (State = dsRun) and (FMemManager <> nil) then
  7.     TFpLldbDbgMemCacheManagerSimple(FMemManager.CacheManager).Clear;
  8. end;
  9.  
Above already contains the changed line.
After "  if (State = dsRun) and (FMemManager <> nil) then"
before "  if (State = dsRun) then"


Again, dont worry about that line. If you crash there the problem has happened way before.
« Last Edit: April 10, 2019, 12:07:43 am by Martin_fr »

 

TinyPortal © 2005-2018