1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 01:18:00 +00:00

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.
This commit is contained in:
Simon Tatham 2024-09-23 15:12:18 +01:00
parent 31ab5b8e30
commit 964890f1a1
3 changed files with 21 additions and 0 deletions

5
misc.h
View File

@ -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)

View File

@ -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

15
utils/conf_debug.c Normal file
View File

@ -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!";
}