Library to trace allocation function calls.
Memtrace is a C library to trace allocation function calls by printing them to stderr.
The calls are printed out in the format of "<source_file>:<line>: <function_name>(<args>...)[: <return_value>]".
Include memtrace3.h in source files that you want to debug.
It is not recommended to include memtrace3.h in any header files.
#include <memtrace3.h>
#include <stdlib.h>
int main() {
void* ptr = malloc(64);
free(ptr);
}The target binary must be linked with the memtrace3 library.
cc main.c -lmemtrace3Possible output:
main.c:5: malloc(64): 0x47c2a0
main.c:6: free(0x47c2a0)Memtrace should purely be used for debugging purposes.
To make sure that the end user, that is manually building and installing your software, doesn't need to download and
install Memtrace themselves, you should wrap the directive where you include memtrace3.h inside a preprocessor if
block, which should only be entered when compiling debug builds of your software.
#ifndef NDEBUG
#include <memtrace3.h>
#endifFor more information visit the extensive documentation.
Download the source code (by cloning the repository), build the library and install it.
git clone -b v3.0.0 -o memtrace3 https://github.com/mfederczuk/memtrace.git &&
cd memtrace3 &&
make &&
sudo make installRead through the Contribution Guidelines if you want to contribute to this project.
Memtrace is licensed under both the Mozilla Public License 2.0 AND the
Apache License 2.0.
For more information about copying and licensing, see the COPYING.txt file.