Web lists-archives.org

Re: [Mingw-users] Best memory checker




--- Dan Osborne <dan.osborne@xxxxxxxxxxxxxxxxx> wrote:

> Does anybody out there use a memory checker on windows? [...]

I've used mpatrol with mingw gcc and libraries in the Dev-C++ IDE.  And
the resulting application executable runs outside of Dev-C++ as well.

In my application I used Dev-C++ because I wanted a convenient way to
easily use wxWidegets, which is said to be a rather portable GUI system
and which is available as a DevPak
(wxWidgets-2.6.1-gcc3.4.2-1spec.DevPak) for gcc 3.4.2 and Dev-C++.  But
I suppose that multithreading must be needed for the wxWidgets DevPak
because in creating the project in Dev-C++ the parameter -mthreads is
set automatically for both the C and C++ compiler as well as the
linker.

And when I downloaded and installed the mpatrol binaries from the mingw
download site and linked to them, I got various kinds of crashes when I
executed the application.  (I tried linking to both libmpatrol.a as
well as mpatrol.dll.)  But when I installed the mingw mpatrol source
package and modified the Makefile in build\mingw32 so that all the
compiler and shared-library linker commands had the -mthreads parameter
and linked my executable to the resulting library, mpatrol seemed to
work just fine.  (Note that this mingw-specific installation
information is omitted and left somewhat vague in the mpatrol
documentation.)  I also tried rebuilding mpatrol using the original
Makefile and verified that indeed the application does crash even when
using the build (without -mthreads) from the downloaded source (as
distinguished from using the downloaded binaries).

To add -mthreads to the compiler commands in the Makefile, simply add
-mthreads to the end of the "OFLAGS =" statement; and to add -mthreads
to the link commands for the shared libraries, simply replace all
occurrences of "-shared" with "-shared -mthreads".  Then execute "make"
(or "make -f Makefile.threads.txt" in my case) in a bash shell, which
in my case was a cygwin bash, but I guess an msys bash would probably
work just as well.  I simply left the headers in the src directory and
the mpatrol libraries in the build\mingw32 directory, but of course, I
had to point the compiler and the linker to these directories as
appropriate.  As I recall, I then linked to the resulting libmpatrol.a
and I think, if I recall correctly, the linker parameters
"-Wl,--allow-multiple-definition" and "-limagehlp -lbfd -liberty" (the
order of parameters matters!) were also needed.  I wasn't able to get
the executable linked to mpatrol.dll to work properly, but this seemed
unimportant since I wouldn't expect to be using several mpatrol-linked
executables at one time, say, in separate processes.

As for the usefulness of mpatrol for memory debugging, I'll say this:

1) I haven't tried it out extensively.  I only got a small test case
and then my wxWidget-based application to run satisfactorily and didn't
try much else.  Much of the symbolic information for wxWidget calls to
"malloc" & "free", etc., (which might actually be "new" and "delete")
was absent in the output, but my application, which I compiled with -g3
-O0, provided the appropriate symbolic information for my "new" and
"delete" calls.  (I think mpatrol must translate these to "malloc" and
"free", at least for classification purposes.)

2) The package seems to be well thought of and seems to have been very
well designed and developed, but it is primarily for debugging heap
memory problems and uses of standard C memory-oriented library
functions (apparently, 10 of them, including memcpy()) and does not do
any memory checking for static and local (automatic, stack) variables. 
In particular, it does no checks for memory overruns of _local_ or
static arrays.

3) The documentation is pretty good and substantial, but I sometimes
found it a bit abstract and ambiguous in places, particularly when I
wanted to know exactly what mpatrol is supposed to do.

4) mpatrol is said to be pretty portable, but it is said to take a bit
more study to get it to work properly than does Purify.

5) After studying a number of online discussions about mpatrol and
other debugging packages (especially those listed by Wikipedia), I came
to the conclusion that mpatrol is probably the best bet for someone
with a limited budget; it is "free", open-source software.  But other
techniques or facilities might be needed for testing uses of static and
local memory.  I seem to recall that there is a bounds-checker patch
somewhere for gcc.  According to the mpatrol documentation GNU Checker
does some memory checking, particularly stack checking, that mpatrol
does not do.  (Search the mpatrol documentation for "Checker" for
specifics.)

Richard Haney


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users