Recent

Author Topic: Heaptrc and MacOS  (Read 1798 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5524
    • wiki
Re: Heaptrc and MacOS
« Reply #15 on: May 05, 2019, 11:41:42 pm »
Ups, overlapped replies.

The svn info says you should have the right data.

You did that in a new empty folder?

Can you start from console
lazarus.app/Contents/MacOS/lazarus
?

In that folder
Code: Pascal  [Select]
  1. grep -i LoadDwarf components\leakview\leakinfo.pas

VTwin

  • Hero Member
  • *****
  • Posts: 742
  • Former Turbo Pascal 3 user
Re: Heaptrc and MacOS
« Reply #16 on: May 05, 2019, 11:42:48 pm »
Martin_fr is much more informed than I, and has steered you in the correct direction. I am running Cocoa trunk, currently at 2.1.0 61159M using svn up, so might be able to help.

The fixes branch is always behind the trunk, and I have resorted to trunk to get the latest Cocoa fixes.

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

macOS 10.11.6: Lazarus 2.1.0 svn 61741M (64 bit Cocoa trunk)
Ubuntu 18.04.3: Lazarus 2.0.4 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.4 (64 bit on VBox)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #17 on: May 06, 2019, 01:04:39 am »
Martin_fr is much more informed than I, and has steered you in the correct direction. I am running Cocoa trunk, currently at 2.1.0 61159M using svn up, so might be able to help.

The fixes branch is always behind the trunk, and I have resorted to trunk to get the latest Cocoa fixes.

Thanks, but I don't seem to be having too much luck getting 2.1.0 r61162 running (see next post)
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

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #18 on: May 06, 2019, 01:24:11 am »
Ups, overlapped replies.

No problem. I started redoing the install as you were replying :) What I've done... Completely deleted the Lazarus install then ...

 
Quote
svn co https://svn.freepascal.org/svn/lazarus/trunk .
make bigide LCL_PLATFORM=carbon CPU_TARGET=i386

Though it completed without errors, I did get a bunch of warnings like this ..

Quote
ld: warning: text-based stub file /System/Library/Frameworks//Foundation.framework/Foundation.tbd and library file /System/Library/Frameworks//Foundation.framework/Foundation are out of sync. Falling back to library file for linking.

I created a basic project as you suggested ..

Code: Pascal  [Select]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, Unit1
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17.   Application.Scaled:=True;
  18.   Application.Initialize;
  19.   Application.CreateForm(TForm1, Form1);
  20.   Application.Run;
  21. end.
  22.  
  23.  
  24. unit Unit1;
  25.  
  26. {$mode objfpc}{$H+}
  27.  
  28. interface
  29.  
  30. uses
  31.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  32.  
  33. type
  34.  
  35.   { TForm1 }
  36.  
  37.   TForm1 = class(TForm)
  38.     procedure FormCreate(Sender: TObject);
  39.   private
  40.  
  41.   public
  42.  
  43.   end;
  44.  
  45. var
  46.   Form1: TForm1;
  47.  
  48. implementation
  49.  
  50. {$R *.lfm}
  51.  
  52. { TForm1 }
  53.  
  54. procedure TForm1.FormCreate(Sender: TObject);
  55. begin
  56.     TObject.Create;
  57. end;
  58.  
  59. end.  
  60.  

But the build "errored"  with a bunch of these ..

Quote
Error: ld: warning: text-based stub file /System/Library/Frameworks//OpenGL.framework/OpenGL.tbd and library file /System/Library/Frameworks//OpenGL.framework/OpenGL are out of sync. Falling back to library file for linking.

That said, it does run!, but with no trc file that I can find. So I added SetHeapTraceOutput ...

Code: Pascal  [Select]
  1.  
  2.   SetHeapTraceOutput('/Users/andy/Desktop/memleak.trc');
  3.   TObject.Create;    
  4.  

But the compile fails "unit1.pas(33,3) Error: Identifier not found "SetHeapTraceOutput"

I thought SetHeapTraceOutput was part of the Heaptrc unit automatically included when building with -gh, which it is ...

Quote
/usr/local/bin/fpc
-MObjFPC
-Scaghi
-CirotR
-gw2
-gl
-gh
-gt
-k-framework
-kCocoa
-l
-vewnhibq
-Filib/x86_64-darwin
-Fu/Developer/lazarus/lcl/units/x86_64-darwin/cocoa
-Fu/Developer/lazarus/lcl/units/x86_64-darwin
-Fu/Developer/lazarus/components/lazutils/lib/x86_64-darwin
-Fu/Developer/lazarus/packager/units/x86_64-darwin
-Fu.
-FUlib/x86_64-darwin
-FE.
-oproject1
-dLCL
-dLCLcocoa

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: 5524
    • wiki
Re: Heaptrc and MacOS
« Reply #19 on: May 06, 2019, 01:42:23 am »
the best way to get the heaptrc output is to run your app with a console.

Either use the option in the global debugger settings, to enable the debugger to launch a terminal.

Or compile your app, then run it outside the IDE from a terminal, and the log goes to console.

Or use the environment: https://www.freepascal.org/docs-html/rtl/heaptrc/environment.html
(I haven't tried that last one, not for the logfile at least)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #20 on: May 06, 2019, 01:46:42 am »
Thanks Martin_f, I was just playing around and about to reply when you posted.

I've moved the SetHeapTraceOutput to the program file rather than the forms unit and things are looking a lot more as expected.. I'll have a play with the other options you suggest.

Any idea what these are all  about ...

Quote
ld: warning: text-based stub file /System/Library/Frameworks//Foundation.framework/Foundation.tbd and library file /System/Library/Frameworks//Foundation.framework/Foundation are out of sync. Falling back to library file for linking.
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: 5524
    • wiki
Re: Heaptrc and MacOS
« Reply #21 on: May 06, 2019, 01:48:59 am »
You can google the ld warning. It seem to relate to apple tools...

My guess: You did build for carbon
  make bigide LCL_PLATFORM=carbon CPU_TARGET=i386

Maybe those are outdated? (on the  side of apple)
The google responses give a lot of different tips, which all seem to work for some people and not for others

With lazarus trunk, you also have all the latest cocoa fixes.
So maybe
make bigide LCL_PLATFORM=cocoa CPU_TARGET=x86_64

You can always create a 2nd folder for a 2nd lazarus (just make sure you do the lazarus.cfg for separate configs)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #22 on: May 06, 2019, 10:04:07 pm »
You can google the ld warning. It seem to relate to apple tools...

My guess: You did build for carbon
  make bigide LCL_PLATFORM=carbon CPU_TARGET=i386

Maybe those are outdated? (on the  side of apple)
The google responses give a lot of different tips, which all seem to work for some people and not for others

With lazarus trunk, you also have all the latest cocoa fixes.
So maybe
make bigide LCL_PLATFORM=cocoa CPU_TARGET=x86_64

You can always create a 2nd folder for a 2nd lazarus (just make sure you do the lazarus.cfg for separate configs)


Thanks. that gives me something to work on

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

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #23 on: May 07, 2019, 03:08:18 am »
I posted this over on another board, but the feedback seems to be that it shouldn't be a memory leak.

https://forum.lazarus.freepascal.org/index.php/topic,45312.0.html

Am I mis-using or mis-reading the heap trc output
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: 5524
    • wiki
Re: Heaptrc and MacOS
« Reply #24 on: May 07, 2019, 01:46:55 pm »
Ah, it looks like you got the "resolve" function working ;)

VTwin

  • Hero Member
  • *****
  • Posts: 742
  • Former Turbo Pascal 3 user
Re: Heaptrc and MacOS
« Reply #25 on: May 07, 2019, 06:14:44 pm »
I install Cocoa trunk something like this:

Code: Pascal  [Select]
  1. cd /Developer
  2. mkdir laz_trunk
  3. cd laz_trunk
  4. svn checkout https://svn.freepascal.org/svn/lazarus/trunk
  5. make clean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64
  6. open lazarus.app --args "--pcp=~/.laz_trunk"
[/code]

Then update like this:

Code: Pascal  [Select]
  1. cd /Developer/laz_trunk
  2. svn update
  3. make clean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64
  4. open lazarus.app --args "--pcp=~/.laz_trunk"

You need follow that by installing the debugger package.  I am at 2.1.0 r61174M.
« Last Edit: May 07, 2019, 06:25:02 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.11.6: Lazarus 2.1.0 svn 61741M (64 bit Cocoa trunk)
Ubuntu 18.04.3: Lazarus 2.0.4 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.4 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5524
    • wiki
Re: Heaptrc and MacOS
« Reply #26 on: May 07, 2019, 06:23:17 pm »
I think "make bigide ...." has the packages already installed. But now that you are done, that does not matter.

you can put the --pcp=.... (without quotes) into a file called lazarus.cfg in the laz_trunk directory.
But you need to replace the ~ by /home/....

This file is read line by line. Each line (if not starting with # for comment) is taken as one command line arg. (But no shell expansion for ~)

You can verify the effect under menu: View > IDE internals > About IDE
It shows the current used pcp.

VTwin

  • Hero Member
  • *****
  • Posts: 742
  • Former Turbo Pascal 3 user
Re: Heaptrc and MacOS
« Reply #27 on: May 07, 2019, 06:32:26 pm »
I think "make bigide ...." has the packages already installed. But now that you are done, that does not matter.

you can put the --pcp=.... (without quotes) into a file called lazarus.cfg in the laz_trunk directory.
But you need to replace the ~ by /home/....

This file is read line by line. Each line (if not starting with # for comment) is taken as one command line arg. (But no shell expansion for ~)

You can verify the effect under menu: View > IDE internals > About IDE
It shows the current used pcp.

Many thanks for the tips. I'll check if the packages include "lazdebuggerfplldb.lpk". That would save me the extra compile. :)
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.11.6: Lazarus 2.1.0 svn 61741M (64 bit Cocoa trunk)
Ubuntu 18.04.3: Lazarus 2.0.4 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.4 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5524
    • wiki
Re: Heaptrc and MacOS
« Reply #28 on: May 07, 2019, 07:08:16 pm »
Also once you have the IDE build, you can rebuild it from the Tools menu. (you may have to set the target cocoa/x86_64 ; not sure)

Even after an svn up.

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #29 on: May 07, 2019, 10:33:43 pm »
Ah, it looks like you got the "resolve" function working ;)

Did I not say :(.. apologies, my bad - Yes I got it working, many thanks to you.

I managed to get x86_64 IDE up and running as well without any issues. But I'm still getting the same to problems

Quote
Error: ld: warning: text-based stub file /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE.tbd and library file /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE are out of sync. Falling back to library file for linking.

This one I've decided to live with, at least for now.

Its the heaptrc that I can't get a grip on. Things like this (another I've found since I posted my other thread on the subject)

Code: Pascal  [Select]
  1. var
  2.   MyForm: TMatchedStampsForm;
  3. ...
  4. begin
  5.  
  6.   MyForm := TMatchedStampsForm.Create(Self);
  7. ...
  8.   MyForm.ShowModal;
  9.   FreeAndNil(MyForm);                            
  10. ...

.. and why the MyForm.ShowModal shows up in the attached heaptrc output. (its line 1775 in the src.). I've learned about the un-necessary use of FreeAndNil.. just haven't changed it yet )

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