diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-04-19 22:13:44 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-04-19 22:13:44 +0200 |
commit | fef4d6ff2ad9f48e6dccde0f061453e6a3ac624e (patch) | |
tree | c21dfcf8e7c8895a94e1c72cb9588c94794656b1 /src/glibc.md | |
parent | 43e402ba2320ced7972d33c9442b2745afe230f6 (diff) | |
download | notes-fef4d6ff2ad9f48e6dccde0f061453e6a3ac624e.tar.gz notes-fef4d6ff2ad9f48e6dccde0f061453e6a3ac624e.zip |
added new hierarchy
Diffstat (limited to 'src/glibc.md')
-rw-r--r-- | src/glibc.md | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/glibc.md b/src/glibc.md deleted file mode 100644 index 2b2ab34..0000000 --- a/src/glibc.md +++ /dev/null @@ -1,47 +0,0 @@ -# glibc - -## malloc tracer [`mtrace(3)`][mtrace] -Trace memory allocation and de-allocation to detect memory leaks. -Need to call `mtrace(3)` to install the tracing hooks. - -If we can't modify the binary to call `mtrace` we can create a small shared -library and pre-load it. -```c -// libmtrace.c -#include <mcheck.h> -__attribute__((constructor)) static void init_mtrace() { mtrace(); } -``` - -Compile as: -```bash -gcc -shared -fPIC -o libmtrace.so libmtrace.c -``` - -To generate the trace file run: -```bash -export MALLOC_TRACE=<file> -LD_PRELOAD=./libmtrace.so <binary> -``` -**Note**: If `MALLOC_TRACE` is not set `mtrace` won't install tracing hooks. - -To get the results of the trace file: -```bash -mtrace <binary> $MALLOC_TRACE -``` - -## malloc check [`mallopt(3)`][mallopt] -Configure action when glibc detects memory error. - -```bash -export MALLOC_CHECK_=<N> -``` - -Useful values: -```markdown -1 print detailed error & continue -3 print detailed error + stack trace + memory mappings & abort -7 print simple error message + stack trace + memory mappings & abort -``` - -[mtrace]: http://man7.org/linux/man-pages/man3/mtrace.3.html -[mallopt]: http://man7.org/linux/man-pages/man3/mallopt.3.html |