mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Dave Hinton's debugging patch.
[originally from svn r1079]
This commit is contained in:
parent
b7844a20af
commit
ea2e1dd9ae
49
misc.c
49
misc.c
@ -303,10 +303,8 @@ void safefree(void *ptr) {
|
||||
static FILE *debug_fp = NULL;
|
||||
static int debug_got_console = 0;
|
||||
|
||||
void dprintf(char *fmt, ...) {
|
||||
char buf[2048];
|
||||
static void dputs (char *buf) {
|
||||
DWORD dw;
|
||||
va_list ap;
|
||||
|
||||
if (!debug_got_console) {
|
||||
AllocConsole();
|
||||
@ -316,11 +314,50 @@ void dprintf(char *fmt, ...) {
|
||||
debug_fp = fopen("debug.log", "w");
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(buf, fmt, ap);
|
||||
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
|
||||
fputs(buf, debug_fp);
|
||||
fflush(debug_fp);
|
||||
}
|
||||
|
||||
|
||||
void dprintf(char *fmt, ...) {
|
||||
char buf[2048];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(buf, fmt, ap);
|
||||
dputs (buf);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void debug_memdump (void *buf, int len, int L) {
|
||||
int i;
|
||||
unsigned char *p = buf;
|
||||
if (L) {
|
||||
int delta;
|
||||
dprintf ("\t%d (0x%x) bytes:\n", len, len);
|
||||
delta = 15 & (int) p;
|
||||
p -= delta;
|
||||
len += delta;
|
||||
}
|
||||
for (; 0 < len; p += 16, len -= 16) {
|
||||
dputs ("\t");
|
||||
if (L) dprintf ("%p: ", p);
|
||||
for (i = 0; i < 16 && i < len; ++i) {
|
||||
if (&p[i] < (unsigned char *) buf) {
|
||||
dputs (" "); /* 3 spaces */
|
||||
} else {
|
||||
dprintf (
|
||||
"%c%02.2x",
|
||||
&p[i] != (unsigned char *) buf && i % 4 ? '.' : ' ',
|
||||
p[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
dputs ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* def DEBUG */
|
||||
|
||||
|
38
misc.h
Normal file
38
misc.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef PUTTY_MISC_H
|
||||
#define PUTTY_MISC_H
|
||||
|
||||
#include "puttymem.h"
|
||||
|
||||
|
||||
/*
|
||||
* Debugging functions.
|
||||
*
|
||||
* Output goes to debug.log
|
||||
*
|
||||
* debug(()) (note the double brackets) is like printf().
|
||||
*
|
||||
* dmemdump() and dmemdumpl() both do memory dumps. The difference
|
||||
* is that dmemdumpl() is more suited for when where the memory is is
|
||||
* important (say because you'll be recording pointer values later
|
||||
* on). dmemdump() is more concise.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
void dprintf(char *fmt, ...);
|
||||
void debug_memdump (void *buf, int len, int L);
|
||||
#define debug(x) (dprintf x)
|
||||
#define dmemdump(buf,len) debug_memdump (buf, len, 0);
|
||||
#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
|
||||
#else
|
||||
#define debug(x)
|
||||
#define dmemdump(buf,len)
|
||||
#define dmemdumpl(buf,len)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef lenof
|
||||
#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
8
putty.h
8
putty.h
@ -425,7 +425,7 @@ void random_get_savedata(void **data, int *len);
|
||||
* Exports from misc.c.
|
||||
*/
|
||||
|
||||
#include "puttymem.h"
|
||||
#include "misc.h"
|
||||
|
||||
/*
|
||||
* Exports from version.c.
|
||||
@ -459,11 +459,5 @@ void crypto_wrapup();
|
||||
void agent_query(void *in, int inlen, void **out, int *outlen);
|
||||
int agent_exists(void);
|
||||
|
||||
#ifdef DEBUG
|
||||
void dprintf(char *fmt, ...);
|
||||
#define debug(x) (dprintf x)
|
||||
#else
|
||||
#define debug(x)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
13
puttymem.h
13
puttymem.h
@ -5,6 +5,10 @@
|
||||
#ifndef PUTTY_PUTTYMEM_H
|
||||
#define PUTTY_PUTTYMEM_H
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <string.h> /* for memcpy() */
|
||||
|
||||
|
||||
/* #define MALLOC_LOG do this if you suspect putty of leaking memory */
|
||||
#ifdef MALLOC_LOG
|
||||
#define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
|
||||
@ -21,4 +25,13 @@ void *safemalloc(size_t);
|
||||
void *saferealloc(void *, size_t);
|
||||
void safefree(void *);
|
||||
|
||||
|
||||
/* smalloc a thing */
|
||||
#define smalloca(type) ((type *) smalloc (sizeof (type)))
|
||||
/* smalloc a copy of a thing */
|
||||
#define smallocc(ptr) memcpy (smalloc (sizeof (*ptr)), ptr, sizeof (*ptr))
|
||||
/* smalloc n things */
|
||||
#define smallocn(n,type) ((type *) smalloc ((n) * sizeof (type)))
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user