From 5c87616d96cb1533ed3392d9257b75f10b30e304 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Tue, 11 Feb 2025 11:31:44 +0100 Subject: [PATCH] util: Add dump_debug_control_string to dump debug_control Signed-off-by: Danylo Piliaiev Part-of: --- src/util/u_debug.c | 36 ++++++++++++++++++++++++++++++++++++ src/util/u_debug.h | 5 +++++ 2 files changed, 41 insertions(+) diff --git a/src/util/u_debug.c b/src/util/u_debug.c index f14a260622c..96f7ccaaeb0 100644 --- a/src/util/u_debug.c +++ b/src/util/u_debug.c @@ -501,3 +501,39 @@ comma_separated_list_contains(const char *list, const char *s) return false; } + +void +dump_debug_control_string(char *output, + size_t max_size, + const struct debug_control *control, + uint64_t flags) +{ + size_t pos = 0; + int ret; + bool first = true; + + for (const struct debug_control *c = control; c->string != NULL; c++) { + if (!(flags & c->flag)) + continue; + ret = snprintf(output + pos, max_size - pos, + first ? "%s" : "|%s", c->string); + if (ret < 0 || ret >= max_size - pos) { + output[max_size-3] = output[max_size-2] = '.'; + output[max_size-1] = '\0'; + return; + } + + pos += ret; + first = false; + flags &= ~(c->flag); + } + + if (flags) { + ret = snprintf(output + pos, max_size - pos, + first ? "0x%" PRIx64 : "|0x%" PRIx64, flags); + if (ret < 0 || ret >= max_size - pos) { + output[max_size-3] = output[max_size-2] = '.'; + output[max_size-1] = '\0'; + } + } +} diff --git a/src/util/u_debug.h b/src/util/u_debug.h index ff10e3bacda..50b45f51a5f 100644 --- a/src/util/u_debug.h +++ b/src/util/u_debug.h @@ -341,6 +341,11 @@ parse_enable_string(const char *debug, uint64_t default_value, const struct debug_control *control); +void +dump_debug_control_string(char *output, + size_t max_size, + const struct debug_control *control, + uint64_t flags); bool comma_separated_list_contains(const char *list, const char *s);