Using mpatrol under Code::Blocks
Code::Blocks is an IDE with Mingw32, it comes with gcc compiler verion 3.4.4 as of Code::Blocks v1.0RC2.
The mpatrol library is a powerful debugging tool that attempts to diagnose run-time errors that are caused by the wrong use of dynamically allocated memory. It acts as a malloc() debugger for debugging dynamic memory allocations, although it can also trace and profile calls to malloc() and free() too.
We will start with downloading Code::Blocks from the website. This is an open-source project, so don't hesitate to grab a copy. Create a simple Win32 GUI application and make sure that it runs. This way we can be sure that the Code::Blocks installation is good.
Next, download mpatrol from mingw-SWiK website. The website mentioned contains information to projects related to or ported to MingW. Extract to a convenient location. Note that it is a bz2 file so you need a program that knows how to manipulate files of this type. A good candidate would be 7-zip.
If you are like most programmers, you may have different compilers that comes with "make". So, to make things simple, we will create a simple batch file to only include directories specially for Code::Blocks, see the snippet below:
path=C:\Windows\system32;C:\Program Files\CodeBlocks\bin
cmd.exe
Save this as codeblocks.bat.
Run this batch file and from the console(command prompt), change directory to\build\mingw32. Then run make. If all goes well then you should have compiled the library correctly.
Here is a sample Code::Blocks project file with the source.
Note that in test1.cbp, I have hardcoded the location of mpatrol source directory as well as the library files.
Hope this document helps anyone in getting mpatrol to work under Windows+Mingw32+Code::Blocks.
The mpatrol library is a powerful debugging tool that attempts to diagnose run-time errors that are caused by the wrong use of dynamically allocated memory. It acts as a malloc() debugger for debugging dynamic memory allocations, although it can also trace and profile calls to malloc() and free() too.
We will start with downloading Code::Blocks from the website. This is an open-source project, so don't hesitate to grab a copy. Create a simple Win32 GUI application and make sure that it runs. This way we can be sure that the Code::Blocks installation is good.
Next, download mpatrol from mingw-SWiK website. The website mentioned contains information to projects related to or ported to MingW. Extract to a convenient location. Note that it is a bz2 file so you need a program that knows how to manipulate files of this type. A good candidate would be 7-zip.
If you are like most programmers, you may have different compilers that comes with "make". So, to make things simple, we will create a simple batch file to only include directories specially for Code::Blocks, see the snippet below:
path=C:\Windows\system32;C:\Program Files\CodeBlocks\bin
cmd.exe
Save this as codeblocks.bat.
Run this batch file and from the console(command prompt), change directory to
Here is a sample Code::Blocks project file with the source.
--test1.cbp starts here, don't include this in when doing copy/paste
<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_project_file>
<CodeBlocks_project_file>
<FileVersion major="1" minor="1"/>
<Project>
<Option title="test1"/>
<Option makefile="Makefile"/>
<Option makefile_is_custom="0"/>
<Option compiler="0"/>
<Build>
<Target title="mpatrol">
<Option output="obj\mpatrol\test1.exe"/>
<Option working_dir="."/>
<Option object_output="obj\mpatrol"/>
<Option deps_output=".deps"/>
<Option type="1"/>
<Option compiler="0"/>
<Option projectResourceIncludeDirsRelation="1"/>
<Compiler>
<Add option="-g"/>
<Add option="-mconsole"/>
<Add directory="D:\Software\Language\c\mpatrol\src"/>
</Compiler>
<Linker>
<Add library="mpatrol"/>
<Add library="bfd"/>
<Add library="iberty"/>
<Add library="imagehlp"/>
<Add directory="D:\Software\Language\c\mpatrol\build\mingw32"/>
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-g"/>
</Compiler>
<Unit filename="test1.c">
<Option compilerVar="CC"/>
<Option target="mpatrol"/>
</Unit>
</Project>
</CodeBlocks_project_file>
--test1.cbp ends here, don't include this in when doing copy/paste
//begin - test1.c
#include "mpatrol.h"
int main(void)
{
char *p;
if (p = (char *) malloc(16))
//fixed by yoyong
// orig : free(p + 1);
free(p);
return EXIT_SUCCESS;
}
//end - test1.c
Note that in test1.cbp, I have hardcoded the location of mpatrol source directory as well as the library files.
Hope this document helps anyone in getting mpatrol to work under Windows+Mingw32+Code::Blocks.
