Recent

Author Topic: [SOLVED]How to modify HeapTrc?  (Read 2252 times)

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
[SOLVED]How to modify HeapTrc?
« on: December 10, 2018, 06:57:20 am »
I've changed \lazarus\components\codetools\MemCheck.pas, but it hasn't any result. I've tried to rebuild IDE, but no result either.

What I need:
1) I don't want it to write anything to file, if no memory leaks occurred, in order to avoid flooding log file.
2) I want to add some additional info to it, such as date and time, when memory leak occurred, in order to sync it with crash dump log.
3) Ideally, I want to dump both memory leaks and crash dumps to same file. File is opened during whole life time of program, that causes error, when I try to open it again for crash dump.
« Last Edit: December 10, 2018, 12:41:24 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: How to modify HeapTrc?
« Reply #1 on: December 10, 2018, 09:28:08 am »
I've found, that HeapTrc unit is actually HeapTrc.pp from Rtl. I've changed it, rebuilt IDE with full cleanup, that should have caused Rtl to be rebuilt too. No result anyway. So, how can I change it's behavior?
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: How to modify HeapTrc?
« Reply #2 on: December 10, 2018, 09:49:15 am »
RTL is FreePascal, not Lazarus, that's why rebuilding the IDE didn't help. I don't have much experience with rebuilding the compiler, but you'll probably find a few makefiles there and can restrict your recompilation to a part of it.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: How to modify HeapTrc?
« Reply #3 on: December 10, 2018, 10:47:13 am »
Even after rebuilding Rtl via Make Lazarus still doesn't see my changes.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: How to modify HeapTrc?
« Reply #4 on: December 10, 2018, 11:51:37 am »
Ok. I realized, what was wrong. I was compiling my project for Win32 target, while changes were made for Win64 Rtl only. And also all files were put into pp directory and I needed to copy files from there manually. Everything works now. Problem is - I can't figure out, how can I cross compile Rtl for Win32. Can anyone help me with this? No matter, what I do, only x86_x64-win64 directory in made, when I execute "make install".

When I run "make -C win32", it enters right folder, but then tells me, that x86_64-win32 target isn't supported, that is obviously wrong target and I don't know, how to change it to right one, i.e. i386-win32.
« Last Edit: December 10, 2018, 12:04:44 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: [SOLVED]How to modify HeapTrc?
« Reply #5 on: December 10, 2018, 12:45:55 pm »
Ok. I've done it. For Win32 I needed to run "make CPU_TARGET=i386 OS_TARGET=win32". Everything works now.

Last question. How can I remove all debug info, except line numbers? Docs say, that I need to specify -gl to have line numbers only. But when I do it, my program seems to still have all debug info, i.e. it's size is around 22Mb. I used -Xg to use external GDB symbol file and my program has 3Mb size now, so debug info seems to go away, but is it right way to remove debug info from program?
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: [SOLVED]How to modify HeapTrc?
« Reply #6 on: December 10, 2018, 03:07:27 pm »
Yes, if you want to have a lean executable but still be able to debug comfortably.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: [SOLVED]How to modify HeapTrc?
« Reply #7 on: December 11, 2018, 06:33:10 am »
Yes, if you want to have a lean executable but still be able to debug comfortably.
I just don't see "Line numbers only" option. As I remember, old Borland products had one, cuz, as I know, this feature is PE files' built-in one. But all of a sudden I can't enable this option without enabling whole debug info in Lazarus. Problem is - if program doesn't find GDB file near it, line numbers also disappear. What I need - is to make dealing with stack traces in crash reports easier, but without publishing whole debug information. Without any debug info I'll need to mess with map files. And line numbers would be enough to find, where crash and/or memory leak happened.

And debug info has around 45Mb size and that's double size of whole distributive, that has both 32bit and 64bit versions of program. I don't even talk, that it's not secure to distribute program with whole debug info.
« Last Edit: December 11, 2018, 07:23:15 am by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: [SOLVED]How to modify HeapTrc?
« Reply #8 on: December 11, 2018, 10:06:50 am »
1) I don't want it to write anything to file, if no memory leaks occurred, in order to avoid flooding log file.
http://wiki.freepascal.org/heaptrc#Show_report_only_on_leak

2) I want to add some additional info to it, such as date and time, when memory leak occurred, in order to sync it with crash dump log.
http://forum.lazarus.freepascal.org/index.php/topic,43428.msg304208.html#msg304208
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: [SOLVED]How to modify HeapTrc?
« Reply #9 on: December 11, 2018, 10:54:53 am »
Re 1) he specified he didn't want it to write "anything" to the file; even with GlobalSkipIfNoLeaks set, the process filename is dumped once into the log on each run.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: [SOLVED]How to modify HeapTrc?
« Reply #10 on: December 11, 2018, 01:45:04 pm »
1) I don't want it to write anything to file, if no memory leaks occurred, in order to avoid flooding log file.
http://wiki.freepascal.org/heaptrc#Show_report_only_on_leak

2) I want to add some additional info to it, such as date and time, when memory leak occurred, in order to sync it with crash dump log.
http://forum.lazarus.freepascal.org/index.php/topic,43428.msg304208.html#msg304208
Yeah, as it has been already said, SetHeapTraceOutput has hardcoded command line dump to log file. Why not just CmdLine, but summ of ParamStr? I don't know, it's a mystery.

And I've achieved all 3 goals via modifying HeapTrc.pp. Only problems: 1) I can't use SysUtils there, as it causes crash. HeapTrc.pp should be first unit to initialize, I guess, so I had to pass Date and Time to it as string. 2) Too many things have to be changed to open memory leak log file, only when HeapTrc needs to dump something to it. So I decided to simply move UseOwnFile and OwnFile itself to interface section, so my program is able to write something to it, i.e. my crash dumps. So now I have both memory leaks and crash dumps in single log file, i.e. I don't even need to bother about syncing them. Crutch? Yeah, but I'm too lazy now to rewrite whole HeapTrc.pp from scratch to make everything work, as I want.

But my current question - how to remove all debug information, except line numbers? I don't want to mess with map file in order to find, where memory leak or crash has happened, but I also don't want to provide 45Mb of GDB debug files with my program.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9870
  • Debugger - SynEdit - and more
    • wiki
Re: [SOLVED]How to modify HeapTrc?
« Reply #11 on: December 11, 2018, 02:18:43 pm »
Quote from: Mr.Madguy
I just don't see "Line numbers only" option.
The option is -gl
There seems to be a bug in the project options, you can only set the checkbox if you turn on the entire debug info.
Simply go to "Custom Options" and enter it there.

Afaik you can do -gw- -gl But you have to test this.


Quote from: Mr.Madguy
And debug info has around 45Mb size and that's double size of whole distributive, that has both 32bit and 64bit versions of program. I don't even talk, that it's not secure to distribute program with whole debug info.
You do not need to. The IDE has "view leaks and traces" in the View menu.

- Compile your app, with as much debug info as you want. (Only line info is ok, but more does not matter)
- Keep a copy of that file.
- Use "strip.exe" to get rid of all debug info on the copy you want to distribute

If the user gets a leak or crash, they get a stackdump with addresses only.
When you receive this you can paste it into the leak viewer. Then you press the "resolve" button.
Now you can select an exe with debug info. Obviously you must choose the one you kept, the one that matches 100% the version of the user. (I.e. what it was before strip)

The leak view will resolve each line, and display the location.
You can double click to navigate.

Please test this, before you relay on it.


Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: [SOLVED]How to modify HeapTrc?
« Reply #12 on: December 11, 2018, 04:18:04 pm »
The option is -gl
There seems to be a bug in the project options, you can only set the checkbox if you turn on the entire debug info.
Simply go to "Custom Options" and enter it there.

Afaik you can do -gw- -gl But you have to test this.
I know this and have already tried it, but even when I do it, exe size is still 20Mb, i.e. full debug info seems to be there anyway.
You do not need to. The IDE has "view leaks and traces" in the View menu.

- Compile your app, with as much debug info as you want. (Only line info is ok, but more does not matter)
- Keep a copy of that file.
- Use "strip.exe" to get rid of all debug info on the copy you want to distribute

If the user gets a leak or crash, they get a stackdump with addresses only.
When you receive this you can paste it into the leak viewer. Then you press the "resolve" button.
Now you can select an exe with debug info. Obviously you must choose the one you kept, the one that matches 100% the version of the user. (I.e. what it was before strip)

The leak view will resolve each line, and display the location.
You can double click to navigate.

Please test this, before you relay on it.
Ok, thx. Does it work with external symbol files? I'll try it tomorrow.
« Last Edit: December 11, 2018, 04:27:04 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

 

TinyPortal © 2005-2018