Recent

Author Topic: HeapTrc not showing line numbers  (Read 4015 times)

TRon

  • Hero Member
  • *****
  • Posts: 2790
Re: HeapTrc not showing line numbers
« Reply #15 on: April 27, 2024, 03:11:18 am »
No mention of line 6. Starts from the method that called the leaking method, not the leak !
Yeah, I mentioned that some time ago as well in combination with Lazarus.

Common reaction was: you have to learn how to read the trace even if that leads to dark obscure places. There is practically no use for heaptrace on linux except for knowing that there is a leak and that it is somewhere in the neighbourhood of the displayed trace (but in practice it can be buried anywhere)

:shrugs:

dbannon

  • Hero Member
  • *****
  • Posts: 2858
    • tomboy-ng, a rewrite of the classic Tomboy
Re: HeapTrc not showing line numbers
« Reply #16 on: April 27, 2024, 04:35:52 am »
Yes TRon, well summed up.

I have confirmed, even with a March 2024 FPC-Fixes, no line numbers. (Intel based Monterey).

To be quite clear, on Mac, heaptrc is useful to tell you you have a leak, but does not tell you where.  Lets not go off chasing this particular wild goose again.

This is almost certainly a bug in the FPC / heaptce tool chain, I totally reject Thaddy's suggestion that we have discovered a flaw in Unix ! (I think he must have been joking...)

JdeHaan, if you can get your code to compile on Linux (or even Windows) debug there. VirtualBox perhaps ? Otherwise, it might be a case of gradually commenting out sections of code until the leak goes away (or reduces), messy indeed. My 25K line project does not have any leaks, obviously I don't use all of LCL but some of it, so as a starting point, assume the leaks are in your own code. Sorry

I do all my development on Linux, its so much easy to debug there. (Join us, do not be afraid....)

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

JdeHaan

  • Full Member
  • ***
  • Posts: 132
Re: HeapTrc not showing line numbers
« Reply #17 on: April 27, 2024, 03:51:44 pm »
@Davo, I used your example, with really the latest trunk (1 minute ago) for MacOs. I get this result:

Code: Text  [Select][+][-]
  1. 1 memory blocks allocated : 16/16
  2. 0 memory blocks freed     : 0/0
  3. 1 unfreed memory blocks : 16
  4. True heap size : 360448 (96 used in System startup)
  5. True free heap : 360128
  6. Should be : 360144
  7. Call trace for block $0000000108B24100 size 16
  8.   $000000010890D4D9
  9.   $000000010890D4E9
  10.   $000000010890D52E
  11.   $0000000108930B9C
  12.   $00007FF8178E1366
  13.  

So, just 1 reporting trace, instead of your 3 traces...

I get your point on Linux, but I'm using Mac already for many years, and not ready to move to a different platform...
However, indeed let's close the topic for now.

« Last Edit: April 27, 2024, 03:55:25 pm by JdeHaan »

jamie

  • Hero Member
  • *****
  • Posts: 6302
Re: HeapTrc not showing line numbers
« Reply #18 on: April 27, 2024, 09:52:52 pm »
has anyone tried using an external debug file?

I am sure the heaptrc must use something to reference by, maybe the MAC os is somehow not working the same way with the debug file attached to the bin file.
The only true wisdom is knowing you know nothing

dbannon

  • Hero Member
  • *****
  • Posts: 2858
    • tomboy-ng, a rewrite of the classic Tomboy
Re: HeapTrc not showing line numbers
« Reply #19 on: April 28, 2024, 03:18:33 am »
From memory, Jamie, back in 2017, I was trying to track down a lean in Carbon's System Tray, then I was using gdb and the issue was that the compiler just did not put that information in there.  But today, of course, its lldb, Cocoa etc, so maybe ? Probably worth trying but I don't know how to do it !

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

jamie

  • Hero Member
  • *****
  • Posts: 6302
Re: HeapTrc not showing line numbers
« Reply #20 on: April 28, 2024, 12:49:18 pm »
I don't know a lot of MAC OS but I believe items are not bound together like they are in other OS's, for example Windows.

 If you go into the debugging options in your project from lazarus, you can checkmark the option to use external file.

do a build all..
The only true wisdom is knowing you know nothing

JdeHaan

  • Full Member
  • ***
  • Posts: 132
Re: HeapTrc not showing line numbers
« Reply #21 on: April 28, 2024, 03:25:32 pm »
That's it! Thanks Jamie!

Result of the example:

Code: Pascal  [Select][+][-]
  1. program memleak;
  2.  
  3. {$mode objfpc}
  4.  
  5. var a:TObject;
  6.  
  7. procedure DoIt3;
  8. begin
  9.   a:=TObject.Create;
  10. end;
  11.  
  12.  
  13. procedure DoIt2;
  14. begin
  15.   DoIt3;
  16. end;
  17.  
  18. procedure DoIt;
  19. begin
  20.     DoIt2;
  21. end;
  22.  
  23. begin
  24.     DoIt;
  25. end.
  26.  

is now:

Code: Text  [Select][+][-]
  1. 1 memory blocks allocated : 16/16
  2. 0 memory blocks freed     : 0/0
  3. 1 unfreed memory blocks : 16
  4. True heap size : 360448 (96 used in System startup)
  5. True free heap : 360128
  6. Should be : 360144
  7. Call trace for block $000000010A2FE100 size 16
  8.   $000000010A15E909 line 15 of memleak.lpr
  9.   $000000010A15E919 line 20 of memleak.lpr
  10.   $000000010A15E95E line 24 of memleak.lpr
  11.   $000000010A16736C
  12.   $00007FF8178E1366
  13.  

TRon

  • Hero Member
  • *****
  • Posts: 2790
Re: HeapTrc not showing line numbers
« Reply #22 on: April 29, 2024, 11:13:38 am »
That's it! Thanks Jamie!
Really ?

Are you able to sum up what settings/circumstances you used to get that working because this (macos specific) topic seem to be a re-occurring one (and one that should be mentioned in the wiki).

TIA

JdeHaan

  • Full Member
  • ***
  • Posts: 132
Re: HeapTrc not showing line numbers
« Reply #23 on: April 29, 2024, 11:58:25 am »
Sure, I attached a screenshot of my debugging settings.

Compilation and linking:
- Optimization level 0 or 1 (2, 3, 4 don't provide line numbers)

Debugging:
- Display line numbers (-gl)
- Use external debug symbols file (-Xg)
- Use heaptrc unit (-gh)


On MacOs Sonoma 14.4.1, with FPC trunk
« Last Edit: April 29, 2024, 12:00:44 pm by JdeHaan »

dbannon

  • Hero Member
  • *****
  • Posts: 2858
    • tomboy-ng, a rewrite of the classic Tomboy
Re: HeapTrc not showing line numbers
« Reply #24 on: April 29, 2024, 12:27:51 pm »
Wow, thats something of a breakthrough !

I am away from home for a couple of weeks, don't have access to my Mac. So cannot test and write something up on the Macos wiki page. Anyone else ?

Seriously, thanks JdeHaan and Jamie !

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

 

TinyPortal © 2005-2018