Use a per-thread buffer and write(2) for debug traces.

Removed debug_dumpstr.
This commit is contained in:
Alexandre Julliard 2000-01-29 19:46:50 +00:00
parent 6a9f1906a5
commit 8bc1d837d2
5 changed files with 76 additions and 61 deletions

View File

@ -15,11 +15,10 @@
#include "builtin16.h"
#include "task.h"
#include "syslevel.h"
#include "debugstr.h"
#include "debugtools.h"
#include "main.h"
DEFAULT_DEBUG_CHANNEL(relay)
DEFAULT_DEBUG_CHANNEL(relay);
/***********************************************************************
* RELAY_Init
@ -143,20 +142,14 @@ void RELAY_DebugCallFrom16( CONTEXT86 *context )
DPRINTF( "0x%08x", *(int *)args16 );
args16 += 4;
break;
case 't':
DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
if (HIWORD(*(SEGPTR *)args16))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
args16 += 4;
break;
case 'p':
DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
args16 += 4;
break;
case 't':
case 'T':
DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
if (HIWORD( *(SEGPTR *)args16 ))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )) );
args16 += 4;
break;
}
@ -199,9 +192,8 @@ void RELAY_DebugCallFrom16( CONTEXT86 *context )
break;
case 't':
args16 -= 4;
DPRINTF( "0x%08x", *(int *)args16 );
if (HIWORD(*(SEGPTR *)args16))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
DPRINTF( "0x%08x %s", *(int *)args16,
debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
break;
case 'p':
args16 -= 4;
@ -209,9 +201,8 @@ void RELAY_DebugCallFrom16( CONTEXT86 *context )
break;
case 'T':
args16 -= 4;
DPRINTF( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
if (HIWORD( *(SEGPTR *)args16 ))
debug_dumpstr( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 ));
DPRINTF( "%04x:%04x %s", *(WORD *)(args16+2), *(WORD *)args16,
debugres_a( (LPSTR)PTR_SEG_TO_LIN(*(SEGPTR *)args16 )));
break;
}
args++;

View File

@ -4,12 +4,15 @@
#ifdef __WINE__ /* Debugging interface is internal to Wine */
#include <stdarg.h>
#include <stdio.h>
#include "config.h"
#include "debugstr.h"
#include "windef.h"
#define DEBUG_RUNTIME
struct _GUID;
/* Internal definitions (do not use these directly) */
enum __DEBUG_CLASS { __DBCL_FIXME, __DBCL_ERR, __DBCL_WARN, __DBCL_TRACE, __DBCL_COUNT };
@ -36,6 +39,25 @@ extern const char * const debug_ch_name[];
/* Exported definitions and macros */
/* These function return a printable version of a string, including
quotes. The string will be valid for some time, but not indefinitely
as strings are re-used. */
extern LPSTR debugstr_an (LPCSTR s, int n);
extern LPSTR debugstr_a (LPCSTR s);
extern LPSTR debugstr_wn (LPCWSTR s, int n);
extern LPSTR debugstr_w (LPCWSTR s);
extern LPSTR debugres_a (LPCSTR res);
extern LPSTR debugres_w (LPCWSTR res);
extern LPSTR debugstr_guid( const struct _GUID *id );
extern LPSTR debugstr_hex_dump (const void *ptr, int len);
extern int dbg_vprintf( const char *format, va_list args );
#ifdef __GNUC__
extern int dbg_printf(const char *format, ...) __attribute__((format (printf,1,2)));
#else
extern int dbg_printf(const char *format, ...);
#endif
/* use configure to allow user to compile out debugging messages */
#ifndef NO_TRACE_MSGS
#define TRACE __DPRINTF(__DBCL_TRACE,*DBCH_DEFAULT)

View File

@ -94,10 +94,11 @@ typedef struct _TEB
int socket; /* --3 204 Socket for server communication */
void *buffer; /* --3 208 Buffer shared with server */
int buffer_size; /* --3 20c Size of server buffer */
void *debug_info; /* --3 210 Info for debugstr functions */
/* here is plenty space for wine specific fields (don't forget to change pad6!!) */
/* the following are nt specific fields */
DWORD pad6[634]; /* --n 210 */
DWORD pad6[633]; /* --n 214 */
UNICODE_STRING StaticUnicodeString; /* -2- bf8 used by advapi32 */
USHORT StaticUnicodeBuffer[261]; /* -2- c00 used by advapi32 */
DWORD pad7; /* --n e0c */

View File

@ -1,29 +1,45 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include "debugstr.h"
#include "debugtools.h"
#include "wtypes.h"
#include "xmalloc.h"
#include "thread.h"
/* ---------------------------------------------------------------------- */
#define SAVE_STRING_COUNT 50
static void *strings[SAVE_STRING_COUNT];
static int nextstring;
struct debug_info
{
char *str_pos; /* current position in strings buffer */
char *out_pos; /* current position in output buffer */
char strings[500]; /* buffer for temporary strings */
char output[500]; /* current output line */
};
static inline struct debug_info *get_info(void)
{
struct debug_info *info = NtCurrentTeb()->debug_info;
if (!info)
{
NtCurrentTeb()->debug_info = info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
info->str_pos = info->strings;
info->out_pos = info->output;
}
return info;
}
/* ---------------------------------------------------------------------- */
static void *
gimme1 (int n)
{
void *res;
if (strings[nextstring]) free (strings[nextstring]);
res = strings[nextstring] = xmalloc (n);
if (++nextstring == SAVE_STRING_COUNT) nextstring = 0;
struct debug_info *info = get_info();
char *res = info->str_pos;
if (res + n >= &info->strings[sizeof(info->strings)]) res = info->strings;
info->str_pos = res + n;
return res;
}
@ -176,39 +192,23 @@ LPSTR debugstr_guid( const GUID *id )
/* ---------------------------------------------------------------------- */
void debug_dumpstr (LPCSTR s)
int dbg_vprintf( const char *format, va_list args )
{
fputc ('"', stderr);
while (*s)
{
switch (*s)
{
case '\\':
case '"':
fputc ('\\', stderr);
fputc (*s, stderr);
break;
case '\n':
fputc ('\\', stderr);
fputc ('n', stderr);
break;
case '\r':
fputc ('\\', stderr);
fputc ('r', stderr);
break;
case '\t':
fputc ('\\', stderr);
fputc ('t', stderr);
break;
default:
if (*s<' ')
fprintf (stderr, "\\0x%02x", *s);
struct debug_info *info = get_info();
int ret = vsprintf( info->out_pos, format, args );
char *p = strrchr( info->out_pos, '\n' );
if (!p) info->out_pos += ret;
else
fputc (*s, stderr);
{
char *pos = info->output;
p++;
write( 2, pos, p - pos );
/* move beginning of next line to start of buffer */
while ((*pos = *p++)) pos++;
info->out_pos = pos;
}
s++;
}
fputc ('"', stderr);
return ret;
}
/* ---------------------------------------------------------------------- */
@ -219,7 +219,7 @@ int dbg_printf(const char *format, ...)
va_list valist;
va_start(valist, format);
ret = vfprintf(stderr, format, valist);
ret = dbg_vprintf( format, valist);
va_end(valist);
return ret;
}

View File

@ -165,6 +165,7 @@ void CALLBACK THREAD_FreeTEB( ULONG_PTR arg )
SELECTOR_FreeBlock( teb->teb_sel, 1 );
close( teb->socket );
if (teb->buffer) munmap( teb->buffer, teb->buffer_size );
if (teb->debug_info) HeapFree( GetProcessHeap(), 0, teb->debug_info );
VirtualFree( teb->stack_base, 0, MEM_RELEASE );
VirtualFree( teb, 0, MEM_FREE );
}