Added wine_dbg_sprintf function that allocates a temporary buffer in

the per-thread strings area.
Added inline functions to format POINT, SIZE and RECT structures.
This commit is contained in:
Alexandre Julliard 2003-01-03 03:12:58 +00:00
parent dfa6b127c2
commit 78ff6763ed
4 changed files with 74 additions and 57 deletions

View File

@ -247,27 +247,17 @@ static const char *NTDLL_dbgstr_wn( const WCHAR *src, int n )
}
/***********************************************************************
* NTDLL_dbgstr_guid
* NTDLL_dbg_vsprintf
*/
static const char *NTDLL_dbgstr_guid( const GUID *id )
static const char *NTDLL_dbg_vsprintf( const char *format, va_list args )
{
char *str;
static const int max_size = 200;
if (!id) return "(null)";
if (!HIWORD(id))
{
str = gimme1(12);
sprintf( str, "<guid-0x%04x>", LOWORD(id) );
}
else
{
str = gimme1(40);
sprintf( str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
id->Data1, id->Data2, id->Data3,
id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
}
return str;
char *res = gimme1( max_size );
int len = vsnprintf( res, max_size, format, args );
if (len == -1 || len >= max_size) res[max_size-1] = 0;
else release( res + len + 1 );
return res;
}
/***********************************************************************
@ -310,14 +300,14 @@ static int NTDLL_dbg_vprintf( const char *format, va_list args )
/***********************************************************************
* NTDLL_dbg_vlog
*/
static int NTDLL_dbg_vlog( int cls, const char *channel,
static int NTDLL_dbg_vlog( unsigned int cls, const char *channel,
const char *function, const char *format, va_list args )
{
static const char *classes[] = { "fixme", "err", "warn", "trace" };
int ret = 0;
if (TRACE_ON(tid))
ret = wine_dbg_printf( "%08lx:", (DWORD)NtCurrentTeb()->tid );
ret = wine_dbg_printf( "%08lx:", NtCurrentTeb()->tid );
if (cls < sizeof(classes)/sizeof(classes[0]))
ret += wine_dbg_printf( "%s:%s:%s ", classes[cls], channel + 1, function );
if (format)
@ -332,7 +322,7 @@ DECL_GLOBAL_CONSTRUCTOR(debug_init)
{
__wine_dbgstr_an = NTDLL_dbgstr_an;
__wine_dbgstr_wn = NTDLL_dbgstr_wn;
__wine_dbgstr_guid = NTDLL_dbgstr_guid;
__wine_dbg_vsprintf = NTDLL_dbg_vsprintf;
__wine_dbg_vprintf = NTDLL_dbg_vprintf;
__wine_dbg_vlog = NTDLL_dbg_vlog;
}

View File

@ -23,6 +23,9 @@
#include <stdarg.h>
#include "windef.h"
#ifndef GUID_DEFINED
#include "guiddef.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -108,16 +111,44 @@ enum __WINE_DEBUG_CLASS {
/* 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 const char *wine_dbgstr_guid( const struct _GUID *id );
extern const char *wine_dbgstr_an( const char * s, int n );
extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
extern const char *wine_dbgstr_a( const char *s );
extern const char *wine_dbgstr_w( const WCHAR *s );
extern const char *wine_dbg_sprintf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
extern int wine_dbg_printf( const char *format, ... ) __WINE_PRINTF_ATTR(1,2);
extern int wine_dbg_log( int cls, const char *ch, const char *func,
extern int wine_dbg_log( unsigned int cls, const char *ch, const char *func,
const char *format, ... ) __WINE_PRINTF_ATTR(4,5);
static inline const char *wine_dbgstr_guid( const GUID *id )
{
if (!id) return "(null)";
if (!((int)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04x>", (int)id & 0xffff );
return wine_dbg_sprintf( "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
id->Data1, id->Data2, id->Data3,
id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
}
static inline const char *wine_dbgstr_point( const POINT *pt )
{
if (!pt) return "(null)";
return wine_dbg_sprintf( "(%ld,%ld)", pt->x, pt->y );
}
static inline const char *wine_dbgstr_size( const SIZE *size )
{
if (!size) return "(null)";
return wine_dbg_sprintf( "(%ld,%ld)", size->cx, size->cy );
}
static inline const char *wine_dbgstr_rect( const RECT *rect )
{
if (!rect) return "(null)";
return wine_dbg_sprintf( "(%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
}
#define WINE_TRACE __WINE_DPRINTF(_TRACE,__wine_dbch___default)
#define WINE_TRACE_(ch) __WINE_DPRINTF(_TRACE,__wine_dbch_##ch)
#define WINE_TRACE_ON(ch) __WINE_GET_DEBUGGING(_TRACE,__wine_dbch_##ch)

View File

@ -50,9 +50,9 @@ extern WCHAR **__wine_main_wargv;
extern const char * (*__wine_dbgstr_an)( const char * s, int n );
extern const char * (*__wine_dbgstr_wn)( const WCHAR *s, int n );
extern const char * (*__wine_dbgstr_guid)( const struct _GUID *id );
extern const char * (*__wine_dbg_vsprintf)( const char *format, va_list args );
extern int (*__wine_dbg_vprintf)( const char *format, va_list args );
extern int (*__wine_dbg_vlog)( int cls, const char *channel,
extern int (*__wine_dbg_vlog)( unsigned int cls, const char *channel,
const char *function, const char *format, va_list args );
extern void wine_dbg_add_option( const char *name, unsigned char set, unsigned char clear );

View File

@ -205,8 +205,21 @@ int wine_dbg_printf( const char *format, ... )
}
/* varargs wrapper for __wine_dbg_vsprintf */
const char *wine_dbg_sprintf( const char *format, ... )
{
const char *ret;
va_list valist;
va_start(valist, format);
ret = __wine_dbg_vsprintf( format, valist );
va_end(valist);
return ret;
}
/* varargs wrapper for __wine_dbg_vlog */
int wine_dbg_log( int cls, const char *channel, const char *func, const char *format, ... )
int wine_dbg_log( unsigned int cls, const char *channel, const char *func, const char *format, ... )
{
int ret;
va_list valist;
@ -335,28 +348,16 @@ static const char *default_dbgstr_wn( const WCHAR *str, int n )
}
/* default implementation of wine_dbgstr_guid */
static const char *default_dbgstr_guid( const struct _GUID *id )
/* default implementation of wine_dbg_vsprintf */
static const char *default_dbg_vsprintf( const char *format, va_list args )
{
char *str;
static const int max_size = 200;
if (!id) return "(null)";
if (!((int)id >> 16))
{
str = get_tmp_space( 12 );
sprintf( str, "<guid-0x%04x>", (int)id & 0xffff );
char *res = get_tmp_space( max_size );
int len = vsnprintf( res, max_size, format, args );
if (len == -1 || len >= max_size) res[max_size-1] = 0;
return res;
}
else
{
str = get_tmp_space( 40 );
sprintf( str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
id->Data1, id->Data2, id->Data3,
id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
}
return str;
}
/* default implementation of wine_dbg_vprintf */
static int default_dbg_vprintf( const char *format, va_list args )
@ -366,7 +367,7 @@ static int default_dbg_vprintf( const char *format, va_list args )
/* default implementation of wine_dbg_vlog */
static int default_dbg_vlog( int cls, const char *channel, const char *func,
static int default_dbg_vlog( unsigned int cls, const char *channel, const char *func,
const char *format, va_list args )
{
int ret = 0;
@ -383,18 +384,13 @@ static int default_dbg_vlog( int cls, const char *channel, const char *func,
const char * (*__wine_dbgstr_an)( const char * s, int n ) = default_dbgstr_an;
const char * (*__wine_dbgstr_wn)( const WCHAR *s, int n ) = default_dbgstr_wn;
const char * (*__wine_dbgstr_guid)( const struct _GUID *id ) = default_dbgstr_guid;
const char * (*__wine_dbg_vsprintf)( const char *format, va_list args ) = default_dbg_vsprintf;
int (*__wine_dbg_vprintf)( const char *format, va_list args ) = default_dbg_vprintf;
int (*__wine_dbg_vlog)( int cls, const char *channel, const char *function,
int (*__wine_dbg_vlog)( unsigned int cls, const char *channel, const char *function,
const char *format, va_list args ) = default_dbg_vlog;
/* wrappers to use the function pointers */
const char *wine_dbgstr_guid( const struct _GUID *id )
{
return __wine_dbgstr_guid(id);
}
const char *wine_dbgstr_an( const char * s, int n )
{
return __wine_dbgstr_an(s, n);