Recent

Author Topic: Line numbers for heaptrc  (Read 3777 times)

ChrisR

  • Full Member
  • ***
  • Posts: 247
Line numbers for heaptrc
« on: October 02, 2018, 05:06:28 pm »
With the rapid progress of Cocoa, I am doing more development on MacOS. One feature I like with Windows is that the heaptrc reports the line number that generated a leak. However, even though I set the Project Options/Debugging options to generate line numbers and use Heaptrc, when I test a project in MacOS I do not get line numbers for the leak. Consider the code:

procedure TForm1.LeakBtnClick(Sender: TObject);
var
  PascalFiles: TStringList;
begin
  PascalFiles := TStringList.Create;
end;

When I run this on MacOS, the leak is reported, but it misses line number

Heap dump by heaptrc unit
1813 memory blocks allocated : 2107894/2112200
1812 memory blocks freed     : 2107774/2112080
1 unfreed memory blocks : 120
True heap size : 884736 (32 used in System startup)
True free heap : 884416
Should be : 884456
Call trace for block $00000001009F4500 size 120
  $00000001001D1460
  $000000010026981A
  $0000000100269FDF
  $0000000100269722
  $0000000100012A43
  $00000001001C34D6
  $00000001001AF7B8
  $00000001001AF8C3

In contrast, Windows includes "line 37 of unit1.pas"

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: Line numbers for heaptrc
« Reply #1 on: October 02, 2018, 07:25:31 pm »
Compile you project (and optionally fpc) with -gl -O- (At least this helps on windows).
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Line numbers for heaptrc
« Reply #2 on: October 02, 2018, 09:00:42 pm »
@Pascal,
  Thanks for the suggestion, but it does not help. I think this is the minimal project:

Code: Pascal  [Select][+][-]
  1. program leak;
  2. uses
  3.  Classes;
  4. var
  5.   PascalFiles: TStringList;
  6. begin
  7.   PascalFiles := TStringList.Create;
  8. end.

On MacOS if I compile with
 $ fpc -g -gl -gh -O- -gh leak.pas
I get

$ ./leak
Heap dump by heaptrc unit
22 memory blocks allocated : 2176/2176
21 memory blocks freed     : 2056/2056
1 unfreed memory blocks : 120
True heap size : 655360 (32 used in System startup)
True free heap : 655040
Should be : 655080
Call trace for block $00000001001EE300 size 120

The [leakview][http://wiki.freepascal.org/leakview] does not show anything more.

This [2017 stackoverflow][https://stackoverflow.com/questions/47660310/unable-to-generate-line-numbers-in-fpc-debugging-output] question also suggests heaptrc does not provide line numbers with MacOS. One of the commenters suggests if requires ppc32 architecture on macOS. I guess this might refer to PowerPC, as targeting either 32-bit i386 or 64-bit x86_64 had no influence.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Line numbers for heaptrc
« Reply #3 on: October 02, 2018, 09:12:50 pm »
Does FPC for Mac OS support DWARF 2 debug information? Try to add -gw2 at the command line options.

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Line numbers for heaptrc
« Reply #4 on: October 02, 2018, 10:24:30 pm »
$ fpc -gl -gh -O- -gh -gw2 leak.pas

generates the same output - still no line numbers, as does -gw, -gs, -gw3

TRon

  • Hero Member
  • *****
  • Posts: 2511
Re: Line numbers for heaptrc
« Reply #5 on: October 03, 2018, 02:06:16 am »
no guarantees but try FPC trunk. See also mantis 32775

 

TinyPortal © 2005-2018