From: Simon Glass <sjg@chromium.org>
When tracking down heap-registry overflows it is useful to see how
many entries are currently tracked, so the limit can be compared at
a glance.
Expose malloc_mcheck_count() as a public accessor over the existing
mcheck_chunk_count variable, and print its value with the 'malloc info'
command when CONFIG_MCHECK_HEAP_PROTECTION is enabled.
Extend cmd_test_malloc_info() to check the extra line when the feature
is on.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
cmd/malloc.c | 2 ++
common/dlmalloc.c | 5 +++++
include/malloc.h | 2 ++
test/cmd/malloc.c | 2 ++
4 files changed, 11 insertions(+)
@@ -27,6 +27,8 @@ static int do_malloc_info(struct cmd_tbl *cmdtp, int flag, int argc,
printf("malloc count = %lu\n", info.malloc_count);
printf("free count = %lu\n", info.free_count);
printf("realloc count = %lu\n", info.realloc_count);
+ if (IS_ENABLED(CONFIG_MCHECK_HEAP_PROTECTION))
+ printf("mcheck count = %zu\n", malloc_mcheck_count());
return 0;
}
@@ -6015,6 +6015,11 @@ bool malloc_mcheck_overflow(void)
return mcheck_registry_full;
}
+size_t malloc_mcheck_count(void)
+{
+ return mcheck_chunk_count;
+}
+
static const char *mcheck_caller(void)
{
#if CONFIG_IS_ENABLED(MCHECK_BACKTRACE)
@@ -875,8 +875,10 @@ static inline bool malloc_backtrace_is_active(bool *skipp, bool *busyp)
*/
#if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION)
bool malloc_mcheck_overflow(void);
+size_t malloc_mcheck_count(void);
#else
static inline bool malloc_mcheck_overflow(void) { return false; }
+static inline size_t malloc_mcheck_count(void) { return 0; }
#endif
/**
@@ -28,6 +28,8 @@ static int cmd_test_malloc_info(struct unit_test_state *uts)
ut_assert_nextlinen("malloc count = ");
ut_assert_nextlinen("free count = ");
ut_assert_nextlinen("realloc count = ");
+ if (IS_ENABLED(CONFIG_MCHECK_HEAP_PROTECTION))
+ ut_assert_nextlinen("mcheck count = ");
ut_assert_console_end();
return 0;