New version of log-malloc2 provides new helpful functions and scripts that make backtrace printing and analyzing easy and convenient.
log-malloc2_util.h provides few fully inlined functions:
- Pre-initializes backtrace() function, to avoid any later memory allocations. Use of this function is optional, but it’s good to use it on program start if you want to generate backtrace in SIGSEGV signal handler (memory allocations in SIGSEGV should be avoided if possible).
2. ssize_t log_malloc_backtrace(int fd)
- Prints current backtrace to given file descriptor, including process memory map (/proc/self/maps) to make backtrace symbol conversion easier (this is needed because of ASLR).
- Generated output can be directly pasted to backtrace2line script, that will convert it to human readable stack trace (ASLR is supported).
Because both functions are inlined, it is not needed to link program against log-malloc2 library, and this makes it also bit easier to use it in segfault (SIGSEGV) signal handler.