From 964890f1a18064d2bfc816a5157f64068a20c388 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 23 Sep 2024 15:12:18 +0100 Subject: [PATCH] Stringify all the CONF_foo identifiers, for debugging. When dumping out the contents of a Conf, it's useful not to have to guess what the integer indices mean. By putting these identifiers in a separate array in its own library module, I should avoid them getting linked in to production binaries to take up space, as long as conf_id() is only called from inside debug() statements. And to enforce _that_, it isn't even declared in a header file unless you #define DEBUG. --- misc.h | 5 +++++ utils/CMakeLists.txt | 1 + utils/conf_debug.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 utils/conf_debug.c diff --git a/misc.h b/misc.h index 16b9b68e..3fc2e448 100644 --- a/misc.h +++ b/misc.h @@ -339,6 +339,11 @@ void debug_memdump(const void *buf, int len, bool L); #define debug(...) (debug_printf(__VA_ARGS__)) #define dmemdump(buf,len) (debug_memdump(buf, len, false)) #define dmemdumpl(buf,len) (debug_memdump(buf, len, true)) + +/* Functions used only for debugging, not declared unless + * defined(DEBUG) to avoid accidentally linking them in production */ +const char *conf_id(int key); + #else #define debug(...) ((void)0) #define dmemdump(buf,len) ((void)0) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 5851a62f..7accda5f 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -16,6 +16,7 @@ add_sources_from_current_dir(utils conf.c conf_data.c conf_dest.c + conf_debug.c conf_launchable.c ctrlparse.c ctrlset_normalise.c diff --git a/utils/conf_debug.c b/utils/conf_debug.c new file mode 100644 index 00000000..6f2f6c33 --- /dev/null +++ b/utils/conf_debug.c @@ -0,0 +1,15 @@ +#include "putty.h" + +#define CONF_OPTION(id, ...) "CONF_" #id, + +static const char *const conf_debug_identifiers[] = { + #include "conf.h" +}; + +const char *conf_id(int key) +{ + size_t i = key; + if (i < lenof(conf_debug_identifiers)) + return conf_debug_identifiers[i]; + return "CONF_!outofrange!"; +}