forked from auracaster/openocd
configure.ac: Detect mallinfo automatically
Previously, configure.ac only checked whether glibc was available, but other C runtime libraries like Newlib have mallinfo too. This is a first step to remove configuration option --enable-malloc-logging and replace it with a debug level configurable at runtime. Change-Id: If30fc98a84158459e222fddf08043f46d6fa4112 Signed-off-by: R. Diez <rdiez-2006@rd10.de> Reviewed-on: https://review.openocd.org/c/openocd/+/9394 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
This commit is contained in:
+14
-18
@@ -25,23 +25,7 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#error "malloc.h is required to use --enable-malloc-logging"
|
||||
#endif
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#if __GLIBC_PREREQ(2, 33)
|
||||
#define FORDBLKS_FORMAT " %zu"
|
||||
#else
|
||||
/* glibc older than 2.33 (2021-02-01) use mallinfo(). Overwrite it */
|
||||
#define mallinfo2 mallinfo
|
||||
#define FORDBLKS_FORMAT " %d"
|
||||
#endif
|
||||
#else
|
||||
#error "GNU glibc is required to use --enable-malloc-logging"
|
||||
#endif
|
||||
#include <malloc.h> // For mallinfo/mallinfo2.
|
||||
#endif
|
||||
|
||||
int debug_level = LOG_LVL_INFO;
|
||||
@@ -118,11 +102,23 @@ static void log_puts(enum log_levels level,
|
||||
/* print with count and time information */
|
||||
int64_t t = timeval_ms() - start;
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
#ifdef HAVE_MALLINFO2
|
||||
struct mallinfo2 info = mallinfo2();
|
||||
#elif defined(HAVE_MALLINFO)
|
||||
struct mallinfo info = mallinfo();
|
||||
#else
|
||||
#error "Configuration error: Neither mallinfo() nor mallinfo2() are available."
|
||||
#endif
|
||||
#endif
|
||||
fprintf(log_output, "%s%d %" PRId64 " %s:%d %s()"
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
FORDBLKS_FORMAT
|
||||
#ifdef HAVE_MALLINFO2
|
||||
" %zu"
|
||||
#elif defined(HAVE_MALLINFO)
|
||||
" %d"
|
||||
#else
|
||||
#error "Configuration error: Neither mallinfo() nor mallinfo2() are available."
|
||||
#endif
|
||||
#endif
|
||||
": %s", log_strings[level + 1], count, t, file, line, function,
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
|
||||
Reference in New Issue
Block a user