Recent

Author Topic: Heaptrc and MacOS  (Read 6914 times)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Heaptrc and MacOS
« on: May 01, 2019, 10:49:05 pm »
Heres what I have

OS: OSX High Sierra 10.13.6
Lazarus: 2.0.2 rev.61074

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


I'm trying to use heaptrc on my application to identify memory leaks. I've done what heaptrc and leak view wiki pages says ..

Quote
To enable this in your Lazarus project: go to Project Options/Linking and in the Debugging section enable Use Heaptrc unit (check for mem-leaks) (-gh)
To get meaningful heaptrc results with descriptions to your code lines and not just assembler addresses, go to Tools/Options/Debugger/general and set a debugger.

... but I'm not getting any meaningful descriptions of the code lines, just the assembler addresses ... The trace file , truncated for the sake of brevity...

Quote
Heap dump by heaptrc unit
1578 memory blocks allocated : 2098562/2101984
1577 memory blocks freed     : 2098442/2101864
1 unfreed memory blocks : 120
True heap size : 950272 (96 used in System startup)
True free heap : 949888
Should be : 949928
Call trace for block $0000000100B59500 size 120
study:Contents andy$ cat ~/Desktop/memleak.trc
/mnt/NAS/Documents/Andy/Pascal/src/MemLeak/project1.app/Contents/MacOS/project1
Heap dump by heaptrc unit
1278 memory blocks allocated : 2085956/2088320
1265 memory blocks freed     : 2085293/2087592
13 unfreed memory blocks : 663
True heap size : 1015808 (96 used in System startup)
True free heap : 1012896
Should be : 1013320
Call trace for block $0000000105991680 size 27
Call trace for block $00000001059915C0 size 26 ...
Call trace for block $00000001059885A0 size 256
  $0000000100152168
  $0000000100152072
  $0000000100151EBB
  $0000000100149FE1
  $000000010002FA66
  $000000010002F90B
  $00000001000329D5 ...

My basic program to reproduce the problem.

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses {$IFDEF UNIX} {$IFDEF UseCThreads}
  6.   cthreads, {$ENDIF} {$ENDIF}
  7.   Interfaces, // this includes the LCL widgetset
  8.   Forms,
  9.   Classes,
  10.   Unit1,
  11.   OSUtils,
  12.   SysUtils { you can add units after this };
  13.  
  14. {$R *.res}
  15.  
  16.  
  17. var
  18.   htrc: string;
  19.   i: integer;
  20.   leaky: TStringList;
  21.  
  22. begin
  23.  
  24.   htrc := GetUserDir + '/Desktop/memleak.trc';
  25.   if FileExists(htrc) then
  26.     DeleteFile(htrc);
  27.   SetHeapTraceOutput(htrc);
  28.  
  29.   RequireDerivedFormResource := True;
  30.   Application.Scaled := True;
  31.   Application.Initialize;
  32.   Application.CreateForm(TForm1, Form1);
  33.  
  34.   leaky := TStringList.Create;
  35.   for i := 0 to 10 do
  36.     leaky.Add(IntToStr(i));
  37.  
  38.   Application.Run;
  39. end.
  40.  

The button on th form simply calls Close to terminate the program.

Can anyone throw any light on what I might be missing, doing wrong or should try?

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: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #1 on: May 01, 2019, 11:42:50 pm »

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #2 on: May 02, 2019, 12:58:17 am »
Thanks
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: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #3 on: May 02, 2019, 03:12:09 am »
There may be another option. But it requires svn trunk (and will not be merged to fixes)
I have not tested it on Mac yet, but it should be ok.

In the View menu is an entry "Leaks and traces" (should be there, if not install package LeakView)
You can paste your leak there. You paste the data that only has addresses, and misses the lines/filenames.

It has a "Resolve" button. Since revision 61105 this uses FpDebug (before that it used the fpc code, that does not support cocoa).
FpDebug has support for 64 bit cocoa.

The resolve button opens a file dialog. Select the app, that produced the leak (Probably need to select the bundle, but if that doesnt work then select the exe in Contents/MacOS). The app must be compiled with debug info, otherwise it will not work.
The leak view should now look up each address, and resolve it.

I do hope it works....

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #4 on: May 02, 2019, 01:05:09 pm »
Thanks.

I'm still trying to get my head around svn. currently I have 61074M according to Help|About.

If I want to get 61105, do I just do an "svn update" ???
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: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #5 on: May 02, 2019, 01:30:08 pm »
The "M" at the end means you have local modifications.

You can do an
  svn info
to see the current svn url.
It be something like
  https://svn.freepascal.org/svn/fpc/........
either branches/fixes...   (or tag...)
or trunk

If it not trunk, you can do
  svn switch https://svn.freepascal.org/svn/fpc/trunk
or
  svn switch ^/trunk

I use a frontend on windows, so I had to look up the syntax myself.
If you want to keep fixes, and have trunk, then check it out into a new folder
  svn checkout https://svn.freepascal.org/svn/fpc/trunk folder_for_trunk

After the switch, you should already be up to date, but you can do "svn up"

  svn log | head - n 20
should show you the log entries for the last revisions. Depending how many new revisions were added since, you may see 61105 in the list.
(While you are on fixes branch, svn log will not show this)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #6 on: May 02, 2019, 10:46:23 pm »
Hi,

When you say

... it requires svn trunk (and will not be merged to fixes)

With my limited knowledge of svn, I thought branches (fixes) were merged into trunk, not trunk into fixes but your comment suggest otherwise.

Does this mean if I take trunk, that I can't benefit from fixes on that trunk?

Anyway, I've done this...

Quote
cd /Developer/lazarus/
svn info
svn switch ^/trunk
svn up

Updating '.':
Skipped 'lcl' -- Node remains in conflict
Skipped 'components' -- Node remains in conflict
Skipped 'ide' -- Node remains in conflict
At revision 61108.
Summary of conflicts:
  Skipped paths: 3

Rebuilt and now Help|About shows 61074:61108MS

I've done a Clean & Rebuild of my application, run with debug Ok. But when I try the Resolve" as you suggest

(a) using the executable, nothing appears to happen
(b) using the app bundle, I get an "Out of Memory" error

For what its worth, I've attached a Laz debug log for (b). I won't upload both, they're too big.

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: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #7 on: May 02, 2019, 11:08:01 pm »
Quote
Skipped 'lcl' -- Node remains in conflict

do an
svn -R revert .
svn up .

If you still get an error on any folder, then delete that folder, e.g.: rm -rf lcl
svn up .
will restore the folder.

If you made any changes to the Lazarus sources that you want to keep: Save them before, and re-apply after.

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #8 on: May 02, 2019, 11:42:03 pm »
Cool. so now I have 2.0.3 61008S according to Help|About.

I still get the same results when trying to "Resolve". this time though I used the basic program I mentioned at the start rather than the main app I'm writing so the logs are much smaller

All attached

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: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #9 on: May 03, 2019, 12:10:43 am »
I'll look into it.... In a bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #10 on: May 03, 2019, 08:47:57 pm »
Ok, I just did a test run. It worked for me.

Lazarus build 64bit for cocoa

Project with leak, build 64bit for cocoa
Project is a new application, empty form, with an FormCreate event:
  TObject.Create;

So that leaks one TObject.

I copied the trace, and resolved it. No errors, and unit-names/lines were added.
I used the app bundle for the resolve button.

Just one note:
The trace begins in customform, which is the caller of FormCreate. So effectively it lacks the top line. This can happen, if the leaking code that was called is optimized by fpc.
If that happens, it can not be helped. At least not if the code (like TObject.Create (or actually TObject.NewInstance)) is in the rtl (or fpc packages. Unless you like to build your own fpc.



Please check in the file  components\leakview\leakinfo.pas
Around line 870
There should be a nested
    procedure LoadDwarf;

If not, then your "svn switch" did not work. The output of "svn info" should also tell that.

If you have that LoadDwarf in that file, see if you can test with an empty form, the way I did.

Also if you have the LoadDwarf, then try running the IDE in lldb, get the out of mem, and do a "bt" in lldb.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #11 on: May 05, 2019, 08:14:57 pm »
Cool. so now I have 2.0.3 61008S according to Help|About.

2.0.3 is still fixes.

Trunk is 2.1 (or 2.1.0)

that means the svn switch did not work.

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Heaptrc and MacOS
« Reply #12 on: May 05, 2019, 10:54:25 pm »
Thanks,

I've tried a few things to get to 2.1. The last, and my current state, is a fresh install of 2.0.2, followed by

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

study:lazarus andy$ svn info
Path: .
Working Copy Root Path: /Developer/lazarus
URL: https://svn.freepascal.org/svn/fpc/trunk
Relative URL: ^/trunk
Repository Root: https://svn.freepascal.org/svn/fpc
Repository UUID: 3ad0048d-3df7-0310-abae-a5850022a9f2
Revision: 42002
Node Kind: directory
Schedule: normal
Last Changed Author: pierre
Last Changed Rev: 41983
Last Changed Date: 2019-05-05 00:45:02 +1200 (Sun, 05 May 2019)

and now it showing 2.0.2 r42002M  :( and still now no sign of this


Please check in the file  components\leakview\leakinfo.pas
Around line 870
There should be a nested
    procedure LoadDwarf;


I've tried this twice What have I done wrong?

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 #13 on: May 05, 2019, 11:35:23 pm »
I realised where I might have gone with my earlier attempts... point at svn/fpc rather than fpc/lazarus. So I did a fresh 2.0.2 install, followed by

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

study:lazarus andy$ svn info
Path: .
Working Copy Root Path: /Developer/lazarus
URL: https://svn.freepascal.org/svn/lazarus/trunk
Relative URL: ^/trunk
Repository Root: https://svn.freepascal.org/svn/lazarus
Repository UUID: 4005530d-fff6-0310-9dd1-cebe43e6787f
Revision: 61162
Node Kind: directory
Schedule: normal
Last Changed Author: dmitry
Last Changed Rev: 61162
Last Changed Date: 2019-05-06 08:42:10 +1200 (Mon, 06 May 2019)

and now its showing 2.0.2 r61162M, still no sign of 2.1 or any nested procedure LoadDwarf around line 870 of components\leakview\leakinfo.pas
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: 9908
  • Debugger - SynEdit - and more
    • wiki
Re: Heaptrc and MacOS
« Reply #14 on: May 05, 2019, 11:39:21 pm »
Argh, now I see it. My fault...

Code: Pascal  [Select][+][-]
  1. svn co https://svn.freepascal.org/svn/fpc/trunk .

When I copied that I must have been in the wrong folder.

That is the url to get the svn version of freepascal. You neither need nor want that.... Sorry.




what you want is https://svn.freepascal.org/svn/lazarus/trunk

Create a new empty folder:
Code: [Select]
mkdir lazarus_2_1
cd lazarus_2_1
svn co https://svn.freepascal.org/svn/lazarus/trunk .
make bigide LCL_PLATFORM=carbon CPU_TARGET=i386

The make will take a while. At the end you should have a lazarus file in that folder. And be able to start the app bundle that is in the folder.

also in that folder create a file lazarus.cfg with the content
--primary-config-path=/home/wherever/path
The path to an empty folder, where you want the config to go.


 

TinyPortal © 2005-2018