[SOLVED] Valgrind, Lazarus and Lion lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- caleb9 · 2011-09-28 10:10 Hello. I've found myself in need to use Valgrind on Lion for my Lazarus project. Unfortunately it doesn't work: Code: [Select]$ valgrind --tool=memcheck --leak-check=summary ./project1 valgrind: ./project1: cannot execute binary filewhere project1 is just an empty, dummy, default project created by Lazarus. The only things I've changed were Project Options -> Compiler Options / Linking where I toggled 'Generate Debugging Info For GDB' and 'Generate code for valgrind (-gv)', and in Code generation  I've set optimizations to Level 0. I also tried running it with 'open' which is the way to run programs from the terminal on Mac Code: [Select]$ valgrind --tool=memcheck --leak-check=summary --log- file=out.txt open project1.appand it actually executed the program but valgrind died before closing the form (I attached an output file). I'm on 10.7 Lion, using FPC 2.7.1 from SVN and Lazarus from SVN as well. I installed valgrind from macports (valgrind-devel @3.7.0-r12043 since 3.6.1 doesn't want to install, saying it's not supporting Lion). Here's bunch of info. The project1 executable is Code: [Select]$ file project1 project1: Mach-O executable i386 My Mac is Code: [Select]$ uname -a Darwin Mac-mini.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64 FPC Code: [Select]$ fpc -version [0.117] Free Pascal Compiler version 2.7.1 [2011/09/28] for i386 [0.117] Copyright (c) 1993-2011 by Florian Klaempfl and others [0.117] No source file name in command line [0.117] Compilation aborted Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled) Lazarus is 0.9.31 r32530 When compiling the empty project, fpc outputs Code: [Select]$ fpc  -MObjFPC -Scghi -g -gl -gv  -k-framework -kCarbon -k-framework -kOpenGL -k-dylib_file -k/System/Library/Frameworks/OpenG L.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Framework s/OpenGL.framework/Versions/A/Libraries/libGL.dylib -vewnhi -l -Filib/i386-darwin -Fu/Developer/lazarus/lcl/units/i386-darwin/carbon -Fu/Developer/lazarus/lcl/units/i386-darwin -Fu/Developer/lazarus/packager/units/i386-darwin -Fu. -FUlib/i386-darwin/ -dLCL -dLCLcarbon project1.lpr Hint: Start of reading config file /etc/fpc.cfg Hint: End of reading config file /etc/fpc.cfg Free Pascal Compiler version 2.7.1 [2011/09/28] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Darwin for i386 Compiling project1.lpr Assembling (pipe) lib/i386-darwin/project1.s Compiling resource lib/i386-darwin/project1.or Linking project1 ld: warning: -macosx_version_min not specificed, assuming 10.7 ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no- pic) not allowed in code signed PIE, but used in __start from /usr/lib/crt1.o. To fix this warning, don't compile with -mdynamic-no- pic or link with -Wl,-no_pie 22 lines compiled, 4.5 sec 2 hint(s) issued I tried valgrind with simple program in C and it seems to work. If anyone knows what can I do to use it with FPC, I'd be grateful for some hints :]. ---------------------------------------------------------------------- caleb9 · 2011-09-28 11:02 PS. I just installed valgrind-3.6.1 on Snow Leopard 10.6.8 and with FPC-2.4.4 there seems to be the same problem (although I tested it just for empty console program, not for Lazarus project)... ---------------------------------------------------------------------- caleb9 · 2011-09-28 11:10 PS 2 The C executable I successfully run through valgrind is different than the FPC one. Code: [Select]$ file a.out a.out: Mach-O 64-bit executable x86_64while as I noted earlier, the fpc executables are Code: [Select]$ file project1 project1: Mach-O executable i386if it can be of any relevance. ---------------------------------------------------------------------- Jonas Maebe · 2011-09-28 11:15 First of all, you must use the -gv command line option when compiling a program for use with Valgrind. When using an FPC 2.4.4-compiled binary you will still get an error (mentioning that Valgrind cannot deal with a custom PAGE_ZERO segment size), but with FPC 2.5.x/2.7.x it should work fine. I regularly use Valgrind on Mac OS X 10.6 with FPC-compiled programs and I've never seen the error message you are getting. I don't have 10.7. The "file" command simply tells you that the C binary is a 64 bit one and the FPC binary is a 32 bit one. Valgrind supports both. ---------------------------------------------------------------------- caleb9 · 2011-09-28 11:19 Yup I know, if you look at the compiler options I used for the project (my first post) the -gv is there... ---------------------------------------------------------------------- Jonas Maebe · 2011-09-28 11:29 Apparently the people from MacPorts have decided for some reason that their build of Valgrind should only support 64 bit applications (see e.g. http://stackoverflow.com/questions/6082808/run-valgrind- in-32-bit-mode-on-mac-10-6/6303692#6303692) I use the one from Fink and it works fine. You can also compile Valgrind yourself. ---------------------------------------------------------------------- caleb9 · 2011-09-28 11:36 Yes, compiling the C program with -m32 (32bit executable) causes the same error. Thanks! :] I'll try to compile valgrind myself now and report back. ---------------------------------------------------------------------- Jonas Maebe · 2011-09-28 11:40 You can also compile the FPC binary as 64 bit using "fpc -Px86_64". That won't work yet for Lazarus programs though due to its use of Carbon GUI functionality in the default Mac OS X widgetset. ---------------------------------------------------------------------- caleb9 · 2011-09-28 11:45 Great, it works. Installed valgrind straight from SVN. At first I also got the PAGE_ZERO error for unknown reason but after recompiling the executable again it all seems to work fine. I'll skip compiling with -Px86_64 since my main goal is to debug a Lazarus app, so I have to stick to 32 bits for now. Anyway, solved - thanks for help! ---------------------------------------------------------------------- caleb9 · 2011-09-28 12:17 Bleh, seems I was happy too soon, though it's a different problem now... Even the simplest Lazarus project crashes valgrind. The output tells me, among others that Code: [Select]--17978-- dSYM directory is missing; consider using --dsymutil=yes but when I used this option I get Code: [Select]dyld: could not load inserted library: /usr/local/lib/valgrind/vgpreload_core-x86-darwin.so Do you know if I need to rebuild Lazarus with some specific settings? ---------------------------------------------------------------------- Jonas Maebe · 2011-09-28 12:33 a) neither of those messages shows an actual crash b) the dSYM message is unlikely to be related to any crashing. Additionally, if you use that --dsymutil=yes option, you must make sure that you compiled the program with DWARF debug information (-gw). You can also avoid it by telling the compiler to generate a dSYM bundle (-gw -Xg) c) since you are using the latest svn version of Valgrind, consider that it may simply be buggy and try using a release version instead (and if that crashes, maybe it's simply a Valgrind bug related to Mac OS X 10.7; try the same under 10.6 and see whether that works and if so, file a bug against Valgrind). One thing you can try is to recompile the LCL with DWARF debug information. Since it's probably compiled using Stabs debug information without -gv, it contains some debug information that Valgrind cannot handle. I don't know whether it would cause it to crash though. ---------------------------------------------------------------------- caleb9 · 2011-09-28 12:53 Recompiling LCL with these settings doesn't fix it, but I managed to eliminate the dsym- warnings with your suggestions. The problem is I'm working on OS X 10.7 and the valgrind release (3.6.x) doesn't want to compile on it. But I'll try to see what does it say on 10.6. Update: valgrind 3.6.1 works fine on OS X 10.6 indeed, so maybe it is actually a bug in svn version. Anyway the case's closed for now I guess. Thanks again for help jmaebe. Yet another update: Seems valgrind-3.7.0 got fixed recently for OS X 10.7 (on SVN) - now I can run it with Lazarus applications seemingly without trouble.