Skip to content

Commit fceccde

Browse files
committed
helper/log: Fix build using _DEBUG_FREE_SPACE_
The glibc API 'mallinfo' is deprecated and the new 'mallinfo2' should be used from glibc 2.33 (2021-02-01). Throw an error when '--enable-malloc-logging' is used on systems that compile without glibc. Detect the glibc version and, for backward compatibility, define 'mallinfo2' as the old 'mallinfo'. Define a macro for the format of 'fordblks'. Change-Id: I68bff7b1b58f0ec2669db0b911f19c1c5a26ed30 Reported-by: Steven J. Hill <[email protected]> Signed-off-by: Antonio Borneo <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8589 Tested-by: jenkins
1 parent 8038e2f commit fceccde

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/helper/log.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@
3030
#else
3131
#error "malloc.h is required to use --enable-malloc-logging"
3232
#endif
33+
34+
#ifdef __GLIBC__
35+
#if __GLIBC_PREREQ(2, 33)
36+
#define FORDBLKS_FORMAT " %zu"
37+
#else
38+
/* glibc older than 2.33 (2021-02-01) use mallinfo(). Overwrite it */
39+
#define mallinfo2 mallinfo
40+
#define FORDBLKS_FORMAT " %d"
41+
#endif
42+
#else
43+
#error "GNU glibc is required to use --enable-malloc-logging"
44+
#endif
3345
#endif
3446

3547
int debug_level = LOG_LVL_INFO;
@@ -105,12 +117,11 @@ static void log_puts(enum log_levels level,
105117
/* print with count and time information */
106118
int64_t t = timeval_ms() - start;
107119
#ifdef _DEBUG_FREE_SPACE_
108-
struct mallinfo info;
109-
info = mallinfo();
120+
struct mallinfo2 info = mallinfo2();
110121
#endif
111122
fprintf(log_output, "%s%d %" PRId64 " %s:%d %s()"
112123
#ifdef _DEBUG_FREE_SPACE_
113-
" %d"
124+
FORDBLKS_FORMAT
114125
#endif
115126
": %s", log_strings[level + 1], count, t, file, line, function,
116127
#ifdef _DEBUG_FREE_SPACE_

0 commit comments

Comments
 (0)