Recent

Author Topic: How am I supposed to read HeapTrc/Leakview output?  (Read 2804 times)

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
How am I supposed to read HeapTrc/Leakview output?
« on: January 27, 2022, 01:21:01 pm »
Seens I missed to properly destroy something somewhere. In debug mode, at the end of my program, I get a list of addresses and a hint that my program has eaten some bytes (see Screenshot).

I read the docs here https://wiki.freepascal.org/leakview and here https://wiki.freepascal.org/heaptrc but found no information how these numbers need to be interpreted, and what they point to. I see a call to "Execute", which belongs to a TTask and is fairly long, and calls numerous subroutines. I already suspected that one of those may contain the bug, but at first glance everything seems to be fine, everything what is created is freed properly. Getting somewhat closer to where the problem is would be greatly appreciated.

And more infos available how I am supposed to use this table? Can I find out which type the offending object has been, or where it was created?

Thnx, Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #1 on: January 27, 2022, 01:31:55 pm »
I see a call to "Execute", which belongs to a TTask and is fairly long, and calls numerous subroutines. I already suspected that one of those may contain the bug, but at first glance everything seems to be fine, everything what is created is freed properly.
Thnx, Armin.
Take a second glance.
heaptrc gives you the starting point (caller) where the issue originated from.
you can be 99.99999% sure that there is an unfreed object (or pointer) somewhere there

When i start writing a program, usually i use an additional log-file, which gets written to in each constructor and destructor of every class i use
(e.g. log-entry might look like: "2022-01-27 13:31:06: Unit MyUnit1: Line 161 - TMyClass created" (or free'ed))
If heaptrc throws me a memory-leak i just have to check the logfile and count the "create"'s against the "free"'s
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #2 on: January 27, 2022, 04:45:59 pm »
I searched for hours now, found no problem. I suspect, the problem might be somewhere else, it is a multitasking app ...

- What do the lines with no line numbers mean?
- the block address ... is this any way related to variable addresses which I can see when inspecting code with the debugger?

I need any hint what is in that block ...

Armin.
« Last Edit: January 27, 2022, 04:47:58 pm by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #3 on: January 27, 2022, 05:26:00 pm »
It is likely that those are just stale pointers. My guess is "use after free".
« Last Edit: January 27, 2022, 05:29:28 pm by Thaddy »
Specialize a type, not a var.

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #4 on: January 27, 2022, 05:33:56 pm »
I see a lot of BAADFOOD……
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #5 on: January 27, 2022, 05:38:37 pm »
Maybe https://forum.lazarus.freepascal.org/index.php/topic,57840.msg430465.html#msg430465 (last section of that post)

From the image, only top 4 frame are in your app. And some may be in packages... If they are in packages, make sure they are compiled with debug info. And the same debug info for all of them, as well as the same that is used for the project itself. (ideally everything DWARF)

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #6 on: January 28, 2022, 09:15:56 am »
Windows

The 16 8 bytes (heaptrc.pp tracesize := 16) addresses are the return (call ?) addresses of the calling code in 32bit cpu mode when compiled in a reasonably standard way (O1).

The addresses starting with $FF are likely to be addresses in the operating system (in windows 64 they start with $7FF...).

BAADF00D are 32 bit filler initialized, probably by windows or the OS, and indicate that the slots where not used.

What are the instructions of at line 1661 of fileobserverunit.pas ?


Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #7 on: January 28, 2022, 09:46:47 am »
https://en.wikipedia.org/wiki/Magic_number_(programming)
Quote
BAADF00D
"Bad food", Used by Microsoft's debug HeapAlloc() to mark uninitialized allocated heap memory[23]
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #8 on: January 31, 2022, 04:26:27 pm »
Maybe https://forum.lazarus.freepascal.org/index.php/topic,57840.msg430465.html#msg430465 (last section of that post)

From the image, only top 4 frame are in your app. And some may be in packages... If they are in packages, make sure they are compiled with debug info. And the same debug info for all of them, as well as the same that is used for the project itself. (ideally everything DWARF)

Didn't help.

There is an old omission that catches up with me again: how to integrate a debuggable version of the FCL into a Lazarus project with tolerable effort, so that the FCL is automatically recompiled when switching between "debug" and "release" configuration?

I found so far only a vague instruction (https://wiki.lazarus.freepascal.org/Lazarus_FAQ#How_can_I_debug_FCL_components_from_packages_with_Lazarus) how to do this for Linux, I use Windows.

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: How am I supposed to read HeapTrc/Leakview output?
« Reply #9 on: January 31, 2022, 04:44:22 pm »
There is an old omission that catches up with me again: how to integrate a debuggable version of the FCL into a Lazarus project with tolerable effort, so that the FCL is automatically recompiled when switching between "debug" and "release" configuration?

Don't automatically recompile the FCL, that is only asking for trouble sooner or later.

In general you can do this:
  • build the same FPC version as your release once from source with OPT=-glw2 RELEASE=1 and do a make install to some separate location
  • copy the units/<cpu>-<os> folder from the new installation to your main installation as units/<cpu>-<os>-debug
  • (remove the new installation)
  • edit the fpc.cfg and where the units/$fpctarget is mentioned encase that with the following
Code: [Select]
#ifdef DEBUG_FCL
<paths to $fpctarget-debug>
#else
<paths to $fpctarget>
#endif
  • when you need to debug into the FCL define DEBUG_FCL in your project options and compile (might lead to recompilation of the LCL however despite that not being necessary)

Note: I have not tested this, but from my general understanding of both the compiler and Lazarus it should work this way.[/list]

 

TinyPortal © 2005-2018