mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00:00
3396c97da9
Now that the new CMake build system is encouraging us to lay out the code like a set of libraries, it seems like a good idea to make them look more _like_ libraries, by putting things into separate modules as far as possible. This fixes several previous annoyances in which you had to link against some object in order to get a function you needed, but that object also contained other functions you didn't need which included link-time symbol references you didn't want to have to deal with. The usual offender was subsidiary supporting programs including misc.c for some innocuous function and then finding they had to deal with the requirements of buildinfo(). This big reorganisation introduces three new subdirectories called 'utils', one at the top level and one in each platform subdir. In each case, the directory contains basically the same files that were previously placed in the 'utils' build-time library, except that the ones that were extremely miscellaneous (misc.c, utils.c, uxmisc.c, winmisc.c, winmiscs.c, winutils.c) have been split up into much smaller pieces.
57 lines
1.4 KiB
C
57 lines
1.4 KiB
C
/*
|
|
* Debugging routines used by the debug() macros, at least if you
|
|
* compiled with -DDEBUG (aka the PUTTY_DEBUG cmake option) so that
|
|
* those macros don't optimise down to nothing.
|
|
*/
|
|
|
|
#include "defs.h"
|
|
#include "misc.h"
|
|
#include "utils/utils.h"
|
|
|
|
void debug_printf(const char *fmt, ...)
|
|
{
|
|
char *buf;
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
buf = dupvprintf(fmt, ap);
|
|
dputs(buf);
|
|
sfree(buf);
|
|
va_end(ap);
|
|
}
|
|
|
|
void debug_memdump(const void *buf, int len, bool L)
|
|
{
|
|
int i;
|
|
const unsigned char *p = buf;
|
|
char foo[17];
|
|
if (L) {
|
|
int delta;
|
|
debug_printf("\t%d (0x%x) bytes:\n", len, len);
|
|
delta = 15 & (uintptr_t)p;
|
|
p -= delta;
|
|
len += delta;
|
|
}
|
|
for (; 0 < len; p += 16, len -= 16) {
|
|
dputs(" ");
|
|
if (L)
|
|
debug_printf("%p: ", p);
|
|
strcpy(foo, "................"); /* sixteen dots */
|
|
for (i = 0; i < 16 && i < len; ++i) {
|
|
if (&p[i] < (unsigned char *) buf) {
|
|
dputs(" "); /* 3 spaces */
|
|
foo[i] = ' ';
|
|
} else {
|
|
debug_printf("%c%2.2x",
|
|
&p[i] != (unsigned char *) buf
|
|
&& i % 4 ? '.' : ' ', p[i]
|
|
);
|
|
if (p[i] >= ' ' && p[i] <= '~')
|
|
foo[i] = (char) p[i];
|
|
}
|
|
}
|
|
foo[i] = '\0';
|
|
debug_printf("%*s%s\n", (16 - i) * 3 + 2, "", foo);
|
|
}
|
|
}
|