Problem using heaptrc! :-( lazarus / 12-Debugger ---------------------------------------------------------------------- nyrell · 2008-08-22 06:23 Hi, I suspect I have some memory problems in the program I'm working on. I just learnet about the heaptrc unit, and tried to use that to track down the problems. Heaptrc says that there are indeed memory leaks, but for some reason it only gives references to "line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S", which is a file that doesn't exist on my system. So, I read more about heaptrc and checked out the example heapex that I found on this page: http://community.freepascal.org:10000/docs- html/rtl/heaptrc/usage.html If I build heapex.pas like this:  fpc -oheapex -gl heapex.pas This works fine and I get a nice output that tells me in which file the problem is: QuoteWrong size : 128 allocated 64 freed   $00000000004156A7   $0000000000400287 line 26 of heapex.pas   $0000000000400178 Call trace for block $00007F79A06CF5A0 size 128   $0000000000400270 line 25 of heapex.pas   $0000000000400178   $00007FFFA86DBAB0   $00007FFFA86DBAB0   $00007FFFA86DBAB0   $00007FFFA86DBAB0   $00007FFFA86DBAB0   Next I tried to create a new lazarus project and compile heapex through that, to see what will happen. So I created a new Lazarus application with no units, and put the code of heapex.pas in heapex.lpr. Heapex.lpr is identical to heapex.pas except that it start like this: Quoteprogram heapex; {$mode objfpc}{$H+} uses   heaptrc,   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Interfaces, // this includes the LCL widgetset   Forms;   { you can add units after this } ... When I compile this from within lazarus and run the resulting file I get the following output: QuoteMarked memory at $00007FAF89F045A0 invalid Wrong size : 128 allocated 64 freed   $0000000000482E67 line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S   $000000000046DA47 line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S   $000000000046D8C1 Call trace for block $00007FAF89F045A0 size 128   $000000000046DA30 line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S   $000000000046D8C1   $00007FFF91F0F210   $00007FFF91F0F210   $00007FFF91F0F210   $00007FFF91F0F210   $00007FFF91F0F210   The very same references to line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S that I got when I tried to use heaptrc on my own program. Why is this? The command line that lazarus uses to build the program looks like this: Quote/usr/local/bin/ppcx64  -S2cgi -gl -vewnh -Fu/usr/local/lazarus/0.9.24/lcl/units/x86_64-linux/ -Fu/usr/local/lazarus/0.9.24/lcl/units/x86_64-linux/gtk/ -Fu/usr/local/lazarus/0.9.24/packager/units/x86_64-linux/ -Fu. -oheapex -dLCL -dLCLgtk heapex.lpr I have tried to use various different compiler switches, switching between ppcx64 to fpc, but I don't get it to work. Finally I tried to remove the extra units in heap.lpr to make heap.lpr identical with heap.pas. Then it suddenly works, and I get the following output: QuoteMarked memory at $00007F05C8FA35A0 invalid Wrong size : 128 allocated 64 freed   $00000000004156A7   $0000000000400287 line 35 of heapex.lpr   $0000000000400178 Call trace for block $00007F05C8FA35A0 size 128   $0000000000400270 line 34 of heapex.lpr   $0000000000400178   $00007FFFF6BAAF90   $00007FFFF6BAAF90   $00007FFFF6BAAF90   $00007FFFF6BAAF90   $00007FFFF6BAAF90   So can anyone explain this to me? Is heaptrc only usable with simple command line programs? Why does it stop working when I add the units Interfaces and Forms? Am I doing something wrong? Any help *much* appreciated! Best regards, Mattias ---------------------------------------------------------------------- Leledumbo · 2008-08-22 09:19 from here, did you notice: QuoteIf lines without filename/line-number occur, this means there is a unit which has no debug info included. Try recompiling LCL with -glh switch. ---------------------------------------------------------------------- nyrell · 2008-08-22 17:36 Quote from: "Leledumbo"from here, did you notice: QuoteIf lines without filename/line-number occur, this means there is a unit which has no debug info included. Try recompiling LCL with -glh switch. Umm, yes I did notice that but it seems that I misinterpreted it. I thought it meant that only those units were the errors occured needed to be compiled with -glh, not all used units. But anyway, I did what you sugested and tried to recompile the LCL with the -glh switch, but I still have not solved the problem. It should be enough to add the "-glh" in the textbox "Options:" in Tools->Configure "Build Lazarus", right? Like this: http://nyrell.se/webkatalog/lazarus/lazarus_build_settings.png As far as I can tell the LCL recompiled OK. The compile command used was as below, and the -glh switch was added successfully: Quote/usr/local/bin/ppcx64 -gl -dgtk1 -Fu../../units/x86_64-linux -Fu. -Fu/usr/local/lib/fpc/2.2.0/units/x86_64-linux/rtl -Fu/usr/local/lib/fpc/2.2.0/units/x86_64-linux/gtk -Fu/usr/local/lib/fpc/2.2.0/units/x86_64-linux/x11 -Fu/usr/local/lib/fpc/2.2.0/units/x86_64-linux/opengl -FE. -FU../../units/x86_64-linux/gtk -Cg -Fl/usr/lib/gcc/x86_64-linux- gnu/4.2.3 -Flinclude -Fl/etc/ld.so.conf.d/*.conf -glh -dx86_64 interfaces.pp Here is the complete output from the recompile: http://nyrell.se/webkatalog/lazarus/recompile_of_LCL.txt When I compile the heapex program, and run the resulting file I get this result: QuoteMarked memory at $00007F1F947095A0 invalid Wrong size : 128 allocated 64 freed   $0000000000482E67 line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S   $000000000046DA47 line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S   $000000000046D8C1 Call trace for block $00007F1F947095A0 size 128   $000000000046DA30 line 26 of /build/buildd/glibc-2.7/build- tree/amd64-libc/csucrti.S   $000000000046D8C1   $00007FFF9C7125C0   $00007FFF9C7125C0   $00007FFF9C7125C0   $00007FFF9C7125C0   $00007FFF9C7125C0 So this is not much of an improvement. I get one more row with line numbers, but they all still refer to the strange "csucrti.S" file. What am I doing wrong? ---------------------------------------------------------------------- nyrell · 2008-08-22 17:41 Oh, and by the way, I also tried to recompile everything in "Build Lazarus" with the -glh switch, but it didn't make any difference. I also notice that if I run the heapex program from within lazarus I now get a small white text window for the output. I don't know why that appeared now and not before, but maybe it is because I'm running as root or something? Update: I noticed now that the text window was caused by the -WG (Win32 GUI application) switch. Still no luck with heaptrc though... ---------------------------------------------------------------------- Bart · 2008-08-24 14:48 Do you use a precompiled fpc version or did you build fpc yourself? My fpc on windows (the 2.2.0 package that comes with stable lazarus) mentions files in folders i do not have (when I build lazarus from svn), but I guess those names are somehow "built in" in the debug info when fpc was built (by whomever built the windows version). Bart ---------------------------------------------------------------------- nyrell · 2008-08-24 19:10 I'm running the version that came with Kubuntu 8.04: Lazarus 0.9.24-0-5 I did rebuild everything from the tools menu with the switch -glh though, and that didn't make any difference. Still, isn't it strange that the error only occurs when I add the extra units? The memory leak itself occurs in the exact same location as when I don't add those units. ---------------------------------------------------------------------- nyrell · 2008-08-25 06:49 I tried to move the project to a windows computer and compile it with lazarus for windows (still 0.9.24), and now the heaptrc worked! Quotec:\Develop\heapex\heapex.exe Marked memory at $0015B9E8 invalid Wrong size : 128 allocated 64 freed   $0040AB08  FREEMEM,  line 263 of C:/temp/lazbuild/fpc- patched/rtl/inc/heap.inc   $0040261E  main,  line 34 of heapex.lpr   $0040DFFB  EXE_ENTRY,  line 383 of system.pp Call trace for block $0015B9E8 size 128   $0040260F  main,  line 32 of heapex.lpr   $0040DFFB  EXE_ENTRY,  line 383 of system.pp I tried it for my own program too, and it seemed to work fine there too. Still, it would be nice to get heaptrc working in linux too. So if anyone has any ideas please tell me... ---------------------------------------------------------------------- Almindor · 2008-08-25 09:22 Heaptrace works fine in linux but I think there was a bug in older fpc version which caused those results. I'm just guessing from memory here tho, I remember getting something like that myself. Try updating to fpc 2.2.2 and see what you get (don't forget you need to have lazarus compiled with fpc 2.2.2 too then). ---------------------------------------------------------------------- nyrell · 2008-09-15 05:56 Quote from: "Almindor2"Heaptrace works fine in linux but I think there was a bug in older fpc version which caused those results. I'm just guessing from memory here tho, I remember getting something like that myself. Try updating to fpc 2.2.2 and see what you get (don't forget you need to have lazarus compiled with fpc 2.2.2 too then). Thanks! I did a quick try to switch to fpc 2.2.2 but I ran into some compile problems, so I gave up for the moment. I'm under a very tight deadline with the project I'm working on right now, so at the moment I have to be satisfied with being able to run heaptrc in windows. But I will get back to this issue later on when time allows. I also managed to find the problem that made me want to run heaptrc in the first place. It was a very strange crash bug that occured in a non-deterministic way. In the end I tracked it down to the GTK1 theme I installed at the same time as Lazarus. I removed the theme and the crash bug disappeared. I will make a more detailed post on this bug later on too. ---------------------------------------------------------------------- lorincka · 2008-09-18 11:28 If you want to build fpc 2.2.2 under linux ubuntu 8.04 you must pass make parameter GDBLIBDIR=/usr/lib/, and also FPC=/usr/lib/fpc/2.2.0/ppcx64 if you are on 64 bit platform. If you only need to build version 2.2.0 with debug infos you can still find sources and makefile here: http://cyberside.dontexist.org/files/devel/pascal/freepascal/2.2.0/ About the way to make lazarus use new compiler and units, we disscussed about it here: http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file;=viewto pic&t;=5713 This way it works. I don't know if there are better solutions. I hope it helps!