Recent

Author Topic: HeapTrace Detection ??  (Read 598 times)

Josh

  • Hero Member
  • *****
  • Posts: 1194
HeapTrace Detection ??
« on: November 20, 2023, 02:43:05 pm »
Hi

I stumbled across an issue wher an old app is thinking heaptrace is active, so i done some test.

creating new project, placing a button on it, then in onclick i have
Code: [Select]
{$if declared(UseHeapTrace)}
  if UseHeapTrace then ShowMessage('Heaptrc is active')
  else showmessage('Heaptrc is used.');
  {$else}
  ShowMessage('No trace of Heaptrc.');
  {$endIf}   

if i create debug / release builds, debug mode has heaptrace turned on.

no matter which build mode i use, none are reporting heaptrace is active when i click button.

yet on one of my projects set to release, no heaptrace turned on in proj options and no-gh switch, it reports it active.

am i doing something stupid here...

currently on painkillers, so is very possible its a stupid me error.


Lazarus 2.2.7 (rev ada7a90f86) FPC 3.2.3 i386-win32-win32/win64
« Last Edit: November 20, 2023, 02:44:58 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6382
Re: HeapTrace Detection ??
« Reply #1 on: November 20, 2023, 05:13:44 pm »
In principle, I believe that declared() can also take a unit name as parameter:

Code: Pascal  [Select][+][-]
  1. {$macro on }
  2. uses
  3. //                              LogicAnalyzer; {$define ANALYZER__:= LogicAnalyzer }
  4. //                              LogicAnalyzer_Dynamic; {$define ANALYZER__:= LogicAnalyzer }
  5.                                 Analyzer_VcdCode; {$define ANALYZER__:= Analyzer_VcdCode }
  6.  
  7. {$if declared(LogicAnalyzer_Dynamic)    }
  8. var
  9.   logicAnalyzer: TLogicAnalyzer= nil;
  10. {$endif                                 }
  11.  

However yesterday, with v3.2.2, I started to find that erratic in a way I could not characterise which is why I added that macro with the uses statement rather than putting it in a slightly later conditional. But that variable declaration works as expected...

Edited to add: xref to https://forum.lazarus.freepascal.org/index.php/topic,65320.0.html

MarkMLl
« Last Edit: November 23, 2023, 05:00:17 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cpicanco

  • Hero Member
  • *****
  • Posts: 539
  • Programmer and Behavioral Scientist
    • Portfolio
Re: HeapTrace Detection ??
« Reply #2 on: November 21, 2023, 02:22:02 am »
I am using this to check heaptrace (when -gh option is checked) and dump it to a file:

Code: Pascal  [Select][+][-]
  1.   if FileExists('heaptrc.txt') then begin
  2.     DeleteFile('heaptrc.txt');
  3.   end;
  4.   {$IF Declared(heaptrc)}
  5.   SetHeapTraceOutput('heaptrc.txt');
  6.   {$ENDIF}  

Thaddy

  • Hero Member
  • *****
  • Posts: 13253
Re: HeapTrace Detection ??
« Reply #3 on: November 21, 2023, 02:29:34 pm »
It is also explained in the wiki years ago. I wrote that entry.
https://wiki.freepascal.org/heaptrc
Btw it was editted by someone else, who may have damaged the full information...
I checked just now and the information about detection is still OK.
Florian himself helped me with advice. Any other edits will be reverted.
« Last Edit: November 21, 2023, 02:38:21 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

Josh

  • Hero Member
  • *****
  • Posts: 1194
Re: HeapTrace Detection ??
« Reply #4 on: November 21, 2023, 03:01:45 pm »
Hi

Excuse still on strong painkillers.

What i was saying is currently on my test its not reliable.
as explained in my first post, in various build modes, including debug where i have -gh set its does not think heaptrc is active.
and on one of my old projects it thinks it is active even when build mode is set to release and no -gh switch is set.

It only showed up recently and is not fixed in stone, which makes it hard to pin down.

further tests it appears more likely to go awry if i do a clean and build in debug mode then it says its active, if i then set to release and run, now and again it willstill think heaptrc is set, i cant catagorically say this is this case but it seems more likely to happen.

ie the old project that was set to release but said heaptrc was active, i done a clean deleteall and rebuild (releae mode) then it was fine.

i noticed it when i compiled old project and moved to its run location and it failed with file not found and the file was a debug file that was written to in various location but only if heaptrc was active, in  a sub folder of the exe folder, which only exists in develop environment location.

what i am concerned about is if it is to do a clean build being done with debug mode, then a release build 'failing' this will have an impact on my compile and build many, as will have to do clean and delete all before running it.

Like i said I need to do more tests, to pin point; but my head is a bit fuzzy and euphoric with the meds.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018