Recent

Author Topic: Using heaptrc and lineinfo  (Read 5888 times)

VKB

  • Newbie
  • Posts: 2
Using heaptrc and lineinfo
« on: May 28, 2014, 01:43:25 pm »
Hello, All.

I need get information about exact place of memory leak.

I create new simple console program
Code: [Select]
program heap;

var
  a, b: pointer;

begin
  getmem(a,100);
  getmem(b,200);
  freemem(b);
  //freemem(a);
end.     
I have Lasarus 1.2.0 win32 with default setting. I check "-gh" in project parameters ("-gl" already was checked), "-Xs" and "-Xg" I do not touch (both is disabled by default). The Lasarus creates heap.exe with size 86817 bytes.

The heap.exe writes
Code: [Select]
    Heap dump by heaptrc unit
    2 memory blocks allocated : 300/304
    1 memory blocks freed     : 200/200
    1 unfreed memory blocks : 100
    True heap size : 131072 (128 used in System startup)
    True free heap : 130768
    Should be : 130776
    Call trace for block $00096348 size 100
      $00407DC1
      $554C4C41
      $53524553
      $464F5250
      $3D454C49
      $445C3A43
      $6D75636F
      $73746E65
I asked in russian forum http://freepascal.ru/forum/viewtopic.php?p=81397#p81397, but did not get answer.

Can anybody explain how can I get worked example, which output module and line numbers where memory leak happens?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Using heaptrc and lineinfo
« Reply #1 on: May 28, 2014, 01:58:53 pm »
use the leakview package http://wiki.freepascal.org/leakview
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Using heaptrc and lineinfo
« Reply #2 on: May 28, 2014, 02:08:53 pm »
I presume for programs such as yours that use only system routines, that you will need to rebuild the RTL to include debug information. The fpc RTL that is installed by default with Lazarus does not include any RTL debug information (it would make the download much bigger, compilation slower, and most do not need or want it).
You also need to turn off optimizations and smart linking in the compilation options (but I expect you know that).

VKB

  • Newbie
  • Posts: 2
Re: Using heaptrc and lineinfo
« Reply #3 on: May 28, 2014, 02:56:42 pm »
2 taazz
Leakview is not a package. Lieakview is a tool. It only can interpret output of heapdump. If heapdump is not output the line information then leakview could not show it.
2 howardpc
Yes, I turn off optimization and do not use smart linking (leave unchecked -CX and -XX). How can I recompile RTL with debug info?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Using heaptrc and lineinfo
« Reply #4 on: May 28, 2014, 07:28:04 pm »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9864
  • Debugger - SynEdit - and more
    • wiki
Re: Using heaptrc and lineinfo
« Reply #5 on: May 29, 2014, 12:30:41 am »
Best if you attach the sample project with lpi, so we have all the settings.

Reading your description, I would have expected to see file names and line numbers on the trace (no need to recompile the RTL / it should show your file)

That is, only the first line should have a filename and line, showing your "getmem" call.
Since it is in the main program body the calling frames are fpc generated stuff...

Sometimes heaptrc ( -gh ) has a problem. actually the line dumper ( -gl ) has.
Then you can try to paste the output with the numbers, into the IDE' leakview (tools menu), and press the resolve button and select your exe.

You may also try -gs instead of -gw
I remember, I had issues with -gw together with -gh in some versions of fpc. But not sure which.

 

TinyPortal © 2005-2018