From 88bac632954a72e5a04a176efc2760230a3bb09d Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 3 Feb 2010 02:45:32 +0000 Subject: [PATCH] 2010-02-03 03:45 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/vm/hvm.c * harbour/src/vm/itemapi.c * harbour/src/rtl/errapi.c * harbour/contrib/xhb/cstructc.c * changed HB_TRACE_STEALTH() to HB_TRACE() * harbour/include/hbtrace.h * harbour/include/hbstack.h * harbour/src/vm/estack.c * harbour/src/nortl/nortl.c + added hb_traceset() and hb_traceinfo() * harbour/include/hbtrace.h * harbour/src/common/hbtrace.c * use hb_traceset()/hb_traceinfo() instead of hb_tr_file_, hb_tr_line_, hb_tr_level_ - removed hb_tr_file_, hb_tr_line_, hb_tr_level_ + added hb_tr_stealth() function and modified HB_TRACE_STEALTH() macro to not touch any of hb_tr_*_ global variables + added HB_TR_FM macro which can be used to infrom FM statistic module that it should take filename and line number from hb_tr_*_ global variables * harbour/src/vm/fm.c - removed dummy code with HB_TR_LEVEL setting - HB_TR_LEVEL is always defined by hbtrace.h * use hb_traceset()/hb_traceinfo() instead of hb_tr_file_, hb_tr_line_, hb_tr_level_ * respect HB_TR_FM * harbour/src/rtl/gttrm/gttrm.c * formatting * harbour/src/vm/itemapi.c * harbour/src/vm/extend.c * harbour/src/rtl/descend.c * harbour/src/rtl/hbgtcore.c * harbour/src/rtl/mtran.c * harbour/src/rtl/samples.c * harbour/src/common/hbstr.c * harbour/src/common/hbdate.c ! fixed possible GPF traps in HB_TRACE() messages caused by %s used for not \0 terminated strings or uninitialized buffers --- harbour/ChangeLog | 45 ++++++++++++++++++++++++++++++++++ harbour/contrib/xhb/cstructc.c | 4 +-- harbour/include/hbstack.h | 1 + harbour/include/hbtrace.h | 26 ++++++++++++-------- harbour/src/common/hbdate.c | 6 ++--- harbour/src/common/hbstr.c | 24 +++++++++--------- harbour/src/common/hbtrace.c | 39 ++++++++++++++++++++--------- harbour/src/nortl/nortl.c | 19 ++++++++++++++ harbour/src/rtl/descend.c | 2 +- harbour/src/rtl/errapi.c | 2 +- harbour/src/rtl/gttrm/gttrm.c | 8 +++--- harbour/src/rtl/hbgtcore.c | 2 +- harbour/src/rtl/mtran.c | 2 +- harbour/src/rtl/samples.c | 2 +- harbour/src/vm/estack.c | 23 +++++++++++++++++ harbour/src/vm/extend.c | 12 ++++----- harbour/src/vm/fm.c | 30 +++++++++++++++-------- harbour/src/vm/hvm.c | 2 +- harbour/src/vm/itemapi.c | 30 +++++++++++------------ 19 files changed, 200 insertions(+), 79 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5d3f2b43d8..b9cdc01340 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,51 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-02-03 03:45 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/vm/hvm.c + * harbour/src/vm/itemapi.c + * harbour/src/rtl/errapi.c + * harbour/contrib/xhb/cstructc.c + * changed HB_TRACE_STEALTH() to HB_TRACE() + + * harbour/include/hbtrace.h + * harbour/include/hbstack.h + * harbour/src/vm/estack.c + * harbour/src/nortl/nortl.c + + added hb_traceset() and hb_traceinfo() + + * harbour/include/hbtrace.h + * harbour/src/common/hbtrace.c + * use hb_traceset()/hb_traceinfo() instead of hb_tr_file_, hb_tr_line_, + hb_tr_level_ + - removed hb_tr_file_, hb_tr_line_, hb_tr_level_ + + added hb_tr_stealth() function and modified HB_TRACE_STEALTH() + macro to not touch any of hb_tr_*_ global variables + + added HB_TR_FM macro which can be used to infrom FM statistic + module that it should take filename and line number from hb_tr_*_ + global variables + + * harbour/src/vm/fm.c + - removed dummy code with HB_TR_LEVEL setting - HB_TR_LEVEL is + always defined by hbtrace.h + * use hb_traceset()/hb_traceinfo() instead of hb_tr_file_, hb_tr_line_, + hb_tr_level_ + * respect HB_TR_FM + + * harbour/src/rtl/gttrm/gttrm.c + * formatting + + * harbour/src/vm/itemapi.c + * harbour/src/vm/extend.c + * harbour/src/rtl/descend.c + * harbour/src/rtl/hbgtcore.c + * harbour/src/rtl/mtran.c + * harbour/src/rtl/samples.c + * harbour/src/common/hbstr.c + * harbour/src/common/hbdate.c + ! fixed possible GPF traps in HB_TRACE() messages caused by %s used + for not \0 terminated strings or uninitialized buffers + 2010-02-02 16:24 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbide/hbide.hbp * contrib/hbide/hbide.prg diff --git a/harbour/contrib/xhb/cstructc.c b/harbour/contrib/xhb/cstructc.c index 6c5441e4b6..f318dd2b45 100644 --- a/harbour/contrib/xhb/cstructc.c +++ b/harbour/contrib/xhb/cstructc.c @@ -63,7 +63,7 @@ static PHB_ITEM hb_itemPutCRaw( PHB_ITEM pItem, const char * szText, HB_SIZE ulLen ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemPutCRaw(%p, %s, %lu)", pItem, szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCRaw(%p, %s, %lu)", pItem, szText, ulLen)); if( pItem ) { @@ -92,7 +92,7 @@ static PHB_ITEM hb_itemPutCRaw( PHB_ITEM pItem, const char * szText, HB_SIZE ulL #endif static PHB_ITEM hb_itemPutCRawStatic( PHB_ITEM pItem, const char * szText, HB_SIZE ulLen ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemPutCRawStatic(%p, %s, %lu)", pItem, szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCRawStatic(%p, %s, %lu)", pItem, szText, ulLen)); if( pItem ) { diff --git a/harbour/include/hbstack.h b/harbour/include/hbstack.h index 327183ede8..065ddc4b85 100644 --- a/harbour/include/hbstack.h +++ b/harbour/include/hbstack.h @@ -185,6 +185,7 @@ typedef struct int iDynH; /* number of dynamic symbol handles */ void * pStackLst; /* this stack entry in stack linked list */ HB_IOERRORS IOErrors; /* MT safe buffer for IO errors */ + HB_TRACEINFO traceInfo; /* MT safe buffer for HB_TRACE data */ char * pDirBuffer; /* MT safe buffer for hb_fsCurDir() results */ void * allocator; /* memory manager global struct pointer */ #endif diff --git a/harbour/include/hbtrace.h b/harbour/include/hbtrace.h index d57a06e216..450ea026a9 100644 --- a/harbour/include/hbtrace.h +++ b/harbour/include/hbtrace.h @@ -68,6 +68,8 @@ HB_EXTERN_BEGIN #define HB_TR_DEBUG 5 #define HB_TR_LAST 6 +#define HB_TR_FM 10 + /* * Default tracing level. */ @@ -112,9 +114,7 @@ HB_EXTERN_BEGIN { \ if( hb_tr_level() >= l ) \ { \ - hb_tr_file_ = __FILE__; \ - hb_tr_line_ = __LINE__; \ - hb_tr_level_ = l; \ + hb_traceset( l, __FILE__, __LINE__, NULL ); \ hb_tr_trace x ; \ } \ } while( 0 ) @@ -165,10 +165,7 @@ HB_EXTERN_BEGIN #define HB_ECHO_STEALTH( l, x ) do \ { \ if( hb_tr_level() >= l ) \ - { \ - hb_tr_level_ = l; \ - hb_tr_trace x ; \ - } \ + hb_tr_stealth x ; \ } while( 0 ) #if HB_TR_LEVEL >= HB_TR_DEBUG @@ -212,16 +209,25 @@ HB_EXTERN_BEGIN */ #define HB_TRACE_STEALTH(l, x) HB_ECHO_STEALTH_##l(x) +typedef struct +{ + const char * file; + const char * proc; + int line; + int level; +} +HB_TRACEINFO, * PHB_TRACEINFO; + extern HB_EXPORT int hb_tracestate( int new_state ); extern HB_EXPORT int hb_tracelevel( int new_level ); extern HB_EXPORT void hb_tracelog( int level, const char * file, int line, const char * proc, const char * fmt, ... ) HB_PRINTF_FORMAT( 5, 6 ); -extern HB_EXPORT const char * hb_tr_file_; -extern HB_EXPORT int hb_tr_line_; -extern HB_EXPORT int hb_tr_level_; +extern HB_EXPORT void hb_traceset( int level, const char * file, int line, const char * proc ); +extern HB_EXPORT PHB_TRACEINFO hb_traceinfo( void ); extern HB_EXPORT int hb_tr_level( void ); extern HB_EXPORT void hb_tr_trace( const char * fmt, ... ) HB_PRINTF_FORMAT( 1, 2 ); +extern HB_EXPORT void hb_tr_stealth( const char * fmt, ... ) HB_PRINTF_FORMAT( 1, 2 ); HB_EXTERN_END diff --git a/harbour/src/common/hbdate.c b/harbour/src/common/hbdate.c index 4b23a87733..831fbd0506 100644 --- a/harbour/src/common/hbdate.c +++ b/harbour/src/common/hbdate.c @@ -295,7 +295,7 @@ void hb_dateStrPut( char * szDate, int iYear, int iMonth, int iDay ) void hb_dateStrGet( const char * szDate, int * piYear, int * piMonth, int * piDay ) { - HB_TRACE(HB_TR_DEBUG, ("hb_dateStrGet(%s, %p, %p, %p)", szDate, piYear, piMonth, piDay)); + HB_TRACE(HB_TR_DEBUG, ("hb_dateStrGet(%.8s, %p, %p, %p)", szDate, piYear, piMonth, piDay)); #if defined( HB_CLP_STRICT ) || 1 if( szDate ) @@ -355,7 +355,7 @@ long hb_dateEncStr( const char * szDate ) { int iYear, iMonth, iDay; - HB_TRACE(HB_TR_DEBUG, ("hb_dateEncStr(%s)", szDate)); + HB_TRACE(HB_TR_DEBUG, ("hb_dateEncStr(%.8s)", szDate)); hb_dateStrGet( szDate, &iYear, &iMonth, &iDay ); @@ -573,7 +573,7 @@ void hb_timeStrRawGet( const char * szTime, int * piHour, int * piMinutes, int * piSeconds, int * piMSec ) { - HB_TRACE(HB_TR_DEBUG, ("hb_timeStrRawGet(%s, %p, %p, %p, %p)", szTime, piHour, piMinutes, piSeconds, piMSec)); + HB_TRACE(HB_TR_DEBUG, ("hb_timeStrRawGet(%.10s, %p, %p, %p, %p)", szTime, piHour, piMinutes, piSeconds, piMSec)); *piHour = *piMinutes = *piSeconds = *piMSec = 0; diff --git a/harbour/src/common/hbstr.c b/harbour/src/common/hbstr.c index fd3573f5d7..6b699b96f5 100644 --- a/harbour/src/common/hbstr.c +++ b/harbour/src/common/hbstr.c @@ -171,7 +171,7 @@ char * hb_strndup( const char * pszText, HB_SIZE ulLen ) char * pszDup; HB_SIZE ul; - HB_TRACE(HB_TR_DEBUG, ("hb_strndup(%s, %ld)", pszText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strndup(%.*s, %ld)", ( int ) ulLen, pszText, ulLen)); ul = 0; pszDup = ( char * ) pszText; @@ -189,7 +189,7 @@ HB_SIZE hb_strnlen( const char * pszText, HB_SIZE ulLen ) { HB_SIZE ul = 0; - HB_TRACE(HB_TR_DEBUG, ("hb_strnlen(%s, %ld)", pszText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strnlen(%.*s, %ld)", ( int ) ulLen, pszText, ulLen)); while( ulLen-- && *pszText++ ) ++ul; @@ -267,7 +267,7 @@ int hb_strnicmp( const char * s1, const char * s2, HB_SIZE count ) HB_SIZE ulCount; int rc = 0; - HB_TRACE(HB_TR_DEBUG, ("hb_strnicmp(%s, %s, %lu)", s1, s2, count)); + HB_TRACE(HB_TR_DEBUG, ("hb_strnicmp(%.*s, %s, %lu)", ( int ) count, s1, s2, count)); for( ulCount = 0; ulCount < count; ulCount++ ) { @@ -708,7 +708,7 @@ HB_BOOL hb_compStrToNum( const char* szNum, HB_SIZE ulLen, HB_LONG * plVal, doub HB_BOOL hb_valStrnToNum( const char* szNum, HB_SIZE ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ) { - HB_TRACE(HB_TR_DEBUG, ("hb_valStrToNum( %s, %lu, %p, %p, %p, %p)", szNum, ulLen, plVal, pdVal, piDec, piWidth )); + HB_TRACE(HB_TR_DEBUG, ("hb_valStrnToNum( %s, %lu, %p, %p, %p, %p)", szNum, ulLen, plVal, pdVal, piDec, piWidth )); return hb_str2number( HB_FALSE, szNum, ulLen, plVal, pdVal, piDec, piWidth ); } @@ -720,7 +720,7 @@ HB_BOOL hb_strToNum( const char* szNum, HB_LONG * plVal, double * pdVal ) HB_BOOL hb_strnToNum( const char* szNum, HB_SIZE ulLen, HB_LONG * plVal, double * pdVal ) { - HB_TRACE(HB_TR_DEBUG, ("hb_strToNum(%s, %lu, %p, %p)", szNum, ulLen, plVal, pdVal )); + HB_TRACE(HB_TR_DEBUG, ("hb_strnToNum(%.*s, %lu, %p, %p)", ( int ) ulLen, szNum, ulLen, plVal, pdVal )); return hb_str2number( HB_FALSE, szNum, ulLen, plVal, pdVal, NULL, NULL ); } @@ -730,7 +730,7 @@ double hb_strVal( const char * szText, HB_SIZE ulLen ) HB_LONG lVal; double dVal; - HB_TRACE(HB_TR_DEBUG, ("hb_strVal(%s, %lu)", szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strVal(%.*s, %lu)", ( int ) ulLen, szText, ulLen)); if( ! hb_str2number( HB_FALSE, szText, ulLen, &lVal, &dVal, NULL, NULL ) ) dVal = ( double ) lVal; @@ -797,7 +797,7 @@ char * hb_strncpy( char * pDest, const char * pSource, HB_SIZE ulLen ) { char * pBuf = pDest; - HB_TRACE(HB_TR_DEBUG, ("hb_strncpy(%p, %s, %lu)", pDest, pSource, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strncpy(%p, %.*s, %lu)", pDest, ( int ) ulLen, pSource, ulLen)); pDest[ ulLen ] = '\0'; @@ -816,7 +816,7 @@ char * hb_strncat( char * pDest, const char * pSource, HB_SIZE ulLen ) { char * pBuf = pDest; - HB_TRACE(HB_TR_DEBUG, ("hb_strncat(%p, %s, %lu)", pDest, pSource, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strncat(%p, %.*s, %lu)", pDest, ( int ) ulLen, pSource, ulLen)); pDest[ ulLen ] = '\0'; @@ -843,7 +843,7 @@ char * hb_strncpyLower( char * pDest, const char * pSource, HB_SIZE ulLen ) { char * pBuf = pDest; - HB_TRACE(HB_TR_DEBUG, ("hb_strncpyLower(%p, %s, %lu)", pDest, pSource, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strncpyLower(%p, %.*s, %lu)", pDest, ( int ) ulLen, pSource, ulLen)); pDest[ ulLen ] = '\0'; @@ -867,7 +867,7 @@ char * hb_strncpyUpper( char * pDest, const char * pSource, HB_SIZE ulLen ) { char * pBuf = pDest; - HB_TRACE(HB_TR_DEBUG, ("hb_strncpyUpper(%p, %s, %lu)", pDest, pSource, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strncpyUpper(%p, %.*s, %lu)", pDest, ( int ) ulLen, pSource, ulLen)); pDest[ ulLen ] = '\0'; @@ -892,7 +892,7 @@ char * hb_strncpyUpperTrim( char * pDest, const char * pSource, HB_SIZE ulLen ) char * pBuf = pDest; HB_SIZE ulSLen; - HB_TRACE(HB_TR_DEBUG, ("hb_strncpyUpperTrim(%p, %s, %lu)", pDest, pSource, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strncpyUpperTrim(%p, %.*s, %lu)", pDest, ( int ) ulLen, pSource, ulLen)); ulSLen = 0; while( ulSLen < ulLen && pSource[ ulSLen ] ) @@ -924,7 +924,7 @@ char * hb_strncpyTrim( char * pDest, const char * pSource, HB_SIZE ulLen ) char * pBuf = pDest; HB_SIZE ulSLen; - HB_TRACE(HB_TR_DEBUG, ("hb_strncpyTrim(%p, %s, %lu)", pDest, pSource, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strncpyTrim(%p, %.*s, %lu)", pDest, ( int ) ulLen, pSource, ulLen)); ulSLen = 0; while( ulSLen < ulLen && pSource[ ulSLen ] ) diff --git a/harbour/src/common/hbtrace.c b/harbour/src/common/hbtrace.c index ab6c98b35e..dc18a8ce85 100644 --- a/harbour/src/common/hbtrace.c +++ b/harbour/src/common/hbtrace.c @@ -193,10 +193,16 @@ static void hb_tracelog_( int level, const char * file, int line, const char * p * * foo/bar/baz.c */ - while( *file == '.' || *file == '/' || *file == '\\' ) - file++; + if( file ) + { + while( *file == '.' || *file == '/' || *file == '\\' ) + file++; + } + else + file = ""; - pszLevel = level < 0 ? "(\?\?\?)" : s_slevel[ level ]; + pszLevel = ( level >= HB_TR_ALWAYS && level <= HB_TR_LAST ) ? + s_slevel[ level ] : "(\?\?\?)"; /* * Print file and line. @@ -270,10 +276,6 @@ void hb_tracelog( int level, const char * file, int line, const char * proc, } } -const char * hb_tr_file_ = ""; -int hb_tr_line_ = 0; -int hb_tr_level_ = 0; - void hb_tr_trace( const char * fmt, ... ) { /* @@ -281,23 +283,38 @@ void hb_tr_trace( const char * fmt, ... ) */ if( s_enabled ) { + PHB_TRACEINFO pTrace = hb_traceinfo(); + va_list ap; va_start( ap, fmt ); - hb_tracelog_( hb_tr_level_, hb_tr_file_, hb_tr_line_, NULL, fmt, ap ); + hb_tracelog_( pTrace->level, pTrace->file, pTrace->line, pTrace->proc, fmt, ap ); va_end( ap ); /* * Reset file and line. */ - hb_tr_level_ = -1; + pTrace->level = -1; /* NOTE: resetting file name/line number will cause that we will unable * to report the location of code that allocated unreleased memory blocks * See hb_xalloc/hb_xgrab in src/vm/fm.c */ if( hb_tr_level() < HB_TR_DEBUG ) { - hb_tr_file_ = ""; - hb_tr_line_ = -1; + pTrace->file = ""; + pTrace->line = -1; } } } + +void hb_tr_stealth( const char * fmt, ... ) +{ + if( s_enabled ) + { + PHB_TRACEINFO pTrace = hb_traceinfo(); + + va_list ap; + va_start( ap, fmt ); + hb_tracelog_( pTrace->level, pTrace->file, pTrace->line, pTrace->proc, fmt, ap ); + va_end( ap ); + } +} diff --git a/harbour/src/nortl/nortl.c b/harbour/src/nortl/nortl.c index f2211508dc..79238c278b 100644 --- a/harbour/src/nortl/nortl.c +++ b/harbour/src/nortl/nortl.c @@ -386,6 +386,24 @@ const char * hb_osDecodeCP( const char * szName, char ** pszFree, ULONG * pulSiz return szName; } + +/* HB_TRACE */ +static HB_TRACEINFO s_traceInfo; + +void hb_traceset( int level, const char * file, int line, const char * proc ) +{ + s_traceInfo.level = level; + s_traceInfo.file = file; + s_traceInfo.line = line; + s_traceInfo.proc = proc; +} + +PHB_TRACEINFO hb_traceinfo( void ) +{ + return &s_traceInfo; +} + + /* VM */ void hb_vmLock( void ) {} @@ -397,6 +415,7 @@ void hb_fsSetIOError( HB_BOOL fResult, USHORT uiOperation ) HB_SYMBOL_UNUSED( uiOperation ); } + /* file name conversion */ static int s_iFileCase = HB_SET_CASE_MIXED; diff --git a/harbour/src/rtl/descend.c b/harbour/src/rtl/descend.c index 3894d5d071..35d5f21970 100644 --- a/harbour/src/rtl/descend.c +++ b/harbour/src/rtl/descend.c @@ -55,7 +55,7 @@ void hb_strDescend( char * szStringTo, const char * szStringFrom, HB_SIZE ulLen ) { - HB_TRACE(HB_TR_DEBUG, ("hb_strDescend(%s, %s, %lu)", szStringTo, szStringFrom, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_strDescend(%p, %s, %lu)", szStringTo, szStringFrom, ulLen)); if( ulLen == 1 && szStringFrom[ 0 ] == '\0' ) szStringTo[ 0 ] = '\0'; diff --git a/harbour/src/rtl/errapi.c b/harbour/src/rtl/errapi.c index ac6b09ac6e..ff8c3cc871 100644 --- a/harbour/src/rtl/errapi.c +++ b/harbour/src/rtl/errapi.c @@ -986,7 +986,7 @@ PHB_ITEM hb_errRT_SubstParams( const char * szSubSystem, HB_ERRCODE errGenCode, PHB_ITEM pError; PHB_ITEM pArray; - HB_TRACE_STEALTH( HB_TR_DEBUG, ( "hb_errRT_SubstParams()") ); + HB_TRACE( HB_TR_DEBUG, ( "hb_errRT_SubstParams()") ); pError = hb_errRT_New_Subst( ES_ERROR, szSubSystem ? szSubSystem : HB_ERR_SS_BASE, errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE ); diff --git a/harbour/src/rtl/gttrm/gttrm.c b/harbour/src/rtl/gttrm/gttrm.c index aedd4b637d..831ce7e7d7 100644 --- a/harbour/src/rtl/gttrm/gttrm.c +++ b/harbour/src/rtl/gttrm/gttrm.c @@ -1739,9 +1739,9 @@ static void hb_gt_trm_XtermSetAttributes( PHB_GTTRM pTerm, int iAttr ) * BSD console */ static HB_BOOL hb_gt_trm_BsdGetCursorPos( PHB_GTTRM pTerm, int * iRow, int * iCol, - const char * szPost ) + const char * szPost ) { - HB_TRACE(HB_TR_DEBUG, ("hb_gt_trm_BsdGetCursorPos(%p,%p,%p,%p)", pTerm, iRow, iCol, szPost)); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_trm_BsdGetCursorPos(%p,%p,%p,%s)", pTerm, iRow, iCol, szPost)); HB_SYMBOL_UNUSED( szPost ); @@ -1830,9 +1830,9 @@ static void hb_gt_trm_AnsiSetTermMode( PHB_GTTRM pTerm, int iAM ) } static HB_BOOL hb_gt_trm_AnsiGetCursorPos( PHB_GTTRM pTerm, int * iRow, int * iCol, - const char * szPost ) + const char * szPost ) { - HB_TRACE(HB_TR_DEBUG, ("hb_gt_trm_AnsiGetCursorPos(%p,%p,%p,%p)", pTerm, iRow, iCol, szPost)); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_trm_AnsiGetCursorPos(%p,%p,%p,%s)", pTerm, iRow, iCol, szPost)); if( pTerm->fPosAnswer ) { diff --git a/harbour/src/rtl/hbgtcore.c b/harbour/src/rtl/hbgtcore.c index 4d9c1ddd14..ea9ede5f31 100644 --- a/harbour/src/rtl/hbgtcore.c +++ b/harbour/src/rtl/hbgtcore.c @@ -505,7 +505,7 @@ static void hb_gt_def_ColorsToString( PHB_GT pGT, int * pColors, int iColorCount { int iColorIndex, iPos; - HB_TRACE(HB_TR_DEBUG, ("hb_gt_def_ColorsToString(%p,%p,%d,%s,%d)", pGT, pColors, iColorCount, pszColorString, iBufSize)); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_def_ColorsToString(%p,%p,%d,%p,%d)", pGT, pColors, iColorCount, pszColorString, iBufSize)); HB_SYMBOL_UNUSED( pGT ); diff --git a/harbour/src/rtl/mtran.c b/harbour/src/rtl/mtran.c index 6f92f120fa..2eee2dd60f 100644 --- a/harbour/src/rtl/mtran.c +++ b/harbour/src/rtl/mtran.c @@ -60,7 +60,7 @@ static char * hb_strMemotran( char * pszResult, HB_SIZE * ulResultLen, const cha HB_SIZE ulStringPos = 0; HB_SIZE ulResultPos = 0; - HB_TRACE(HB_TR_DEBUG, ("hb_strMemotran(%s, %p, %s, %lu, %x, %x)", pszResult, ulResultLen, pszString, ulStringLen, cHardcr, cSoftcr)); + HB_TRACE(HB_TR_DEBUG, ("hb_strMemotran(%p, %p, %s, %lu, %x, %x)", pszResult, ulResultLen, pszString, ulStringLen, cHardcr, cSoftcr)); while( ulStringPos < ulStringLen ) { diff --git a/harbour/src/rtl/samples.c b/harbour/src/rtl/samples.c index 5b233fa5a3..c02c99b3f3 100644 --- a/harbour/src/rtl/samples.c +++ b/harbour/src/rtl/samples.c @@ -58,7 +58,7 @@ static char * hb_SecToTimeStr( char * pszTime, ULONG ulTime ) { int iValue; - HB_TRACE(HB_TR_DEBUG, ("hb_SecToTimeStr(%s, %lu)", pszTime, ulTime)); + HB_TRACE(HB_TR_DEBUG, ("hb_SecToTimeStr(%p, %lu)", pszTime, ulTime)); iValue = ( int ) ( ( ulTime / 3600 ) % 24 ); pszTime[ 0 ] = ( char ) ( iValue / 10 ) + '0'; diff --git a/harbour/src/vm/estack.c b/harbour/src/vm/estack.c index e07f4a2358..548a01b918 100644 --- a/harbour/src/vm/estack.c +++ b/harbour/src/vm/estack.c @@ -149,6 +149,7 @@ static char s_szDirBuffer[ HB_PATH_MAX ]; static HB_IOERRORS s_IOErrors; +static HB_TRACEINFO s_traceInfo; /* ------------------------------- */ @@ -1334,3 +1335,25 @@ void hb_stackUpdateAllocator( void * pStackId, PHB_ALLOCUPDT_FUNC pFunc, int iCo HB_SYMBOL_UNUSED( iCount ); #endif } + +PHB_TRACEINFO hb_traceinfo( void ) +{ +#if defined( HB_MT_VM ) + if( hb_stack_ready() ) + { + HB_STACK_TLS_PRELOAD + return &hb_stack.traceInfo; + } +#endif + return &s_traceInfo; +} + +void hb_traceset( int level, const char * file, int line, const char * proc ) +{ + PHB_TRACEINFO pTrace = hb_traceinfo(); + + pTrace->level = level; + pTrace->file = file; + pTrace->line = line; + pTrace->proc = proc; +} diff --git a/harbour/src/vm/extend.c b/harbour/src/vm/extend.c index 1d55ca058b..946c7da4f5 100644 --- a/harbour/src/vm/extend.c +++ b/harbour/src/vm/extend.c @@ -1359,7 +1359,7 @@ void hb_retclen( const char * szText, HB_SIZE ulLen ) { HB_STACK_TLS_PRELOAD - HB_TRACE(HB_TR_DEBUG, ("hb_retclen(%s, %lu)", szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_retclen(%.*s, %lu)", ( int ) ulLen, szText, ulLen)); hb_itemPutCL( hb_stackReturnItem(), szText, ulLen ); } @@ -1369,7 +1369,7 @@ void hb_retclen_buffer( char * szText, HB_SIZE ulLen ) { HB_STACK_TLS_PRELOAD - HB_TRACE(HB_TR_DEBUG, ("hb_retclen_buffer(%s, %lu)", szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_retclen_buffer(%.*s, %lu)", ( int ) ulLen, szText, ulLen)); hb_itemPutCLPtr( hb_stackReturnItem(), szText, ulLen ); } @@ -1624,7 +1624,7 @@ int hb_storclen( const char * szText, HB_SIZE ulLen, int iParam ) { HB_STACK_TLS_PRELOAD - HB_TRACE(HB_TR_DEBUG, ("hb_storclen(%s, %lu, %d)", szText, ulLen, iParam)); + HB_TRACE(HB_TR_DEBUG, ("hb_storclen(%.*s, %lu, %d)", ( int ) ulLen, szText, ulLen, iParam)); if( iParam == -1 ) { @@ -1649,7 +1649,7 @@ int hb_storclen_buffer( char * szText, HB_SIZE ulLen, int iParam ) { HB_STACK_TLS_PRELOAD - HB_TRACE(HB_TR_DEBUG, ("hb_storclen_buffer(%s, %lu, %d)", szText, ulLen, iParam)); + HB_TRACE(HB_TR_DEBUG, ("hb_storclen_buffer(%.*s, %lu, %d)", ( int ) ulLen, szText, ulLen, iParam)); if( iParam == -1 ) { @@ -2015,7 +2015,7 @@ int hb_storvclen( const char * szText, HB_SIZE ulLen, int iParam, ... ) { HB_STACK_TLS_PRELOAD - HB_TRACE(HB_TR_DEBUG, ("hb_storvclen(%s, %lu, %d, ...)", szText, ulLen, iParam)); + HB_TRACE(HB_TR_DEBUG, ("hb_storvclen(%.*s, %lu, %d, ...)", ( int ) ulLen, szText, ulLen, iParam)); if( iParam >= -1 && iParam <= hb_pcount() ) { @@ -2048,7 +2048,7 @@ int hb_storvclen_buffer( char * szText, HB_SIZE ulLen, int iParam, ... ) { HB_STACK_TLS_PRELOAD - HB_TRACE(HB_TR_DEBUG, ("hb_storvclen_buffer(%s, %lu, %d, ...)", szText, ulLen, iParam)); + HB_TRACE(HB_TR_DEBUG, ("hb_storvclen_buffer(%.*s, %lu, %d, ...)", ( int ) ulLen, szText, ulLen, iParam)); if( iParam >= -1 && iParam <= hb_pcount() ) { diff --git a/harbour/src/vm/fm.c b/harbour/src/vm/fm.c index 67aef4365d..5c7c6241bf 100644 --- a/harbour/src/vm/fm.c +++ b/harbour/src/vm/fm.c @@ -256,10 +256,6 @@ # undef HB_PARANOID_MEM_CHECK #endif -#if defined( HB_FM_STATISTICS ) && !defined( HB_TR_LEVEL ) -# define HB_TR_LEVEL HB_TR_ERROR -#endif - #ifdef HB_FM_NEED_INIT static HB_BOOL s_fInitedFM = HB_FALSE; #endif @@ -588,6 +584,8 @@ void * hb_xalloc( ULONG ulSize ) /* allocates fixed memory, returns NULL if( s_fStatistic ) { + PHB_TRACEINFO pTrace; + HB_FM_LOCK if( ! s_pFirstBlock ) @@ -607,15 +605,20 @@ void * hb_xalloc( ULONG ulSize ) /* allocates fixed memory, returns NULL HB_FM_SETSIG( HB_MEM_PTR( pMem ), ulSize ); pMem->ulSize = ulSize; /* size of the memory block */ - if( hb_tr_level() >= HB_TR_DEBUG ) + pTrace = hb_traceinfo(); + if( hb_tr_level() >= HB_TR_DEBUG || pTrace->level == HB_TR_FM ) { /* NOTE: PRG line number/procname is not very useful during hunting * for memory leaks - this is why we are using the previously stored * function/line info - this is a location of code that called * hb_xalloc/hb_xgrab */ - pMem->uiProcLine = hb_tr_line_; /* C line number */ - hb_strncpy( pMem->szProcName, hb_tr_file_, sizeof( pMem->szProcName ) - 1 ); + pMem->uiProcLine = pTrace->line; /* C line number */ + if( pTrace->file ) + hb_strncpy( pMem->szProcName, pTrace->file, sizeof( pMem->szProcName ) - 1 ); + else + pMem->szProcName[ 0 ] = '\0'; + pTrace->level = -1; } else { @@ -667,6 +670,8 @@ void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on fail if( s_fStatistic ) { + PHB_TRACEINFO pTrace; + HB_FM_LOCK if( ! s_pFirstBlock ) @@ -686,15 +691,20 @@ void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on fail HB_FM_SETSIG( HB_MEM_PTR( pMem ), ulSize ); pMem->ulSize = ulSize; /* size of the memory block */ - if( hb_tr_level() >= HB_TR_DEBUG ) + pTrace = hb_traceinfo(); + if( hb_tr_level() >= HB_TR_DEBUG || pTrace->level == HB_TR_FM ) { /* NOTE: PRG line number/procname is not very useful during hunting * for memory leaks - this is why we are using the previously stored * function/line info - this is a location of code that called * hb_xalloc/hb_xgrab */ - pMem->uiProcLine = hb_tr_line_; /* C line number */ - hb_strncpy( pMem->szProcName, hb_tr_file_, sizeof( pMem->szProcName ) - 1 ); + pMem->uiProcLine = pTrace->line; /* C line number */ + if( pTrace->file ) + hb_strncpy( pMem->szProcName, pTrace->file, sizeof( pMem->szProcName ) - 1 ); + else + pMem->szProcName[ 0 ] = '\0'; + pTrace->level = -1; } else { diff --git a/harbour/src/vm/hvm.c b/harbour/src/vm/hvm.c index 8bed9efbb1..11f8139879 100644 --- a/harbour/src/vm/hvm.c +++ b/harbour/src/vm/hvm.c @@ -7088,7 +7088,7 @@ void hb_vmPopState( void ) { HB_STACK_TLS_PRELOAD - HB_TRACE_STEALTH( HB_TR_DEBUG, ( "hb_vmPopState()" ) ); + HB_TRACE( HB_TR_DEBUG, ( "hb_vmPopState()" ) ); hb_stackPopReturn(); } diff --git a/harbour/src/vm/itemapi.c b/harbour/src/vm/itemapi.c index 9eb167b815..104df82d13 100644 --- a/harbour/src/vm/itemapi.c +++ b/harbour/src/vm/itemapi.c @@ -247,7 +247,7 @@ PHB_ITEM hb_itemPutCL( PHB_ITEM pItem, const char * szText, HB_SIZE ulLen ) { HB_SIZE ulAlloc; - HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCL(%p, %s, %lu)", pItem, szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCL(%p, %.*s, %lu)", pItem, ( int ) ulLen, szText, ulLen)); if( ulLen > 1 ) { @@ -312,7 +312,7 @@ PHB_ITEM hb_itemPutCConst( PHB_ITEM pItem, const char * szText ) PHB_ITEM hb_itemPutCLConst( PHB_ITEM pItem, const char * szText, HB_SIZE ulLen ) { - HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCConst(%p, %s, %lu)", pItem, szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCLConst(%p, %.*s, %lu)", pItem, ( int ) ulLen, szText, ulLen)); if( pItem ) { @@ -379,7 +379,7 @@ PHB_ITEM hb_itemPutCPtr( PHB_ITEM pItem, char * szText ) PHB_ITEM hb_itemPutCLPtr( PHB_ITEM pItem, char * szText, HB_SIZE ulLen ) { - HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCLPtr(%p, %s, %lu)", pItem, szText, ulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutCLPtr(%p, %.*s, %lu)", pItem, ( int ) ulLen, szText, ulLen)); if( pItem ) { @@ -499,7 +499,7 @@ HB_BOOL hb_itemFreeC( char * szText ) char * hb_itemGetDS( PHB_ITEM pItem, char * szDate ) { - HB_TRACE(HB_TR_DEBUG, ("hb_itemGetDS(%p, %s)", pItem, szDate)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemGetDS(%p, %p)", pItem, szDate)); if( pItem && HB_IS_DATETIME( pItem ) ) return hb_dateDecStr( szDate, pItem->item.asDateTime.julian ); @@ -746,7 +746,7 @@ PHB_ITEM hb_itemReturn( PHB_ITEM pItem ) PHB_ITEM hb_itemReturnForward( PHB_ITEM pItem ) { - HB_TRACE_STEALTH( HB_TR_DEBUG, ("hb_itemReturnForward(%p)", pItem ) ); + HB_TRACE( HB_TR_DEBUG, ("hb_itemReturnForward(%p)", pItem ) ); if( pItem ) { @@ -759,7 +759,7 @@ PHB_ITEM hb_itemReturnForward( PHB_ITEM pItem ) void hb_itemReturnRelease( PHB_ITEM pItem ) { - HB_TRACE_STEALTH( HB_TR_DEBUG, ("hb_itemReturnRelease(%p)", pItem ) ); + HB_TRACE( HB_TR_DEBUG, ("hb_itemReturnRelease(%p)", pItem ) ); if( pItem ) { @@ -772,7 +772,7 @@ void hb_itemReturnRelease( PHB_ITEM pItem ) PHB_ITEM hb_itemPutDS( PHB_ITEM pItem, const char * szDate ) { - HB_TRACE(HB_TR_DEBUG, ("hb_itemPutDS(%p, %s)", pItem, szDate)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutDS(%p, %.8s)", pItem, szDate)); if( pItem ) { @@ -1094,7 +1094,7 @@ PHB_ITEM hb_itemPutNDLen( PHB_ITEM pItem, double dNumber, int iWidth, int iDec ) PHB_ITEM hb_itemPutNDDec( PHB_ITEM pItem, double dNumber, int iDec ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemPutNDDec(%p, %lf, %i)", pItem, dNumber, iDec)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPutNDDec(%p, %lf, %i)", pItem, dNumber, iDec)); if( pItem ) { @@ -1932,7 +1932,7 @@ PHB_ITEM hb_itemUnRefRefer( PHB_ITEM pItem ) PHB_ITEM hb_itemReSizeString( PHB_ITEM pItem, HB_SIZE ulSize ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemReSizeString(%p,%lu)", pItem, ulSize)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemReSizeString(%p,%lu)", pItem, ulSize)); if( pItem->item.asString.allocated == 0 ) { @@ -1965,7 +1965,7 @@ PHB_ITEM hb_itemReSizeString( PHB_ITEM pItem, HB_SIZE ulSize ) PHB_ITEM hb_itemUnShareString( PHB_ITEM pItem ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemUnShareString(%p)", pItem)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemUnShareString(%p)", pItem)); if( pItem->item.asString.allocated == 0 || hb_xRefCount( pItem->item.asString.value ) > 1 ) @@ -1989,7 +1989,7 @@ PHB_ITEM hb_itemUnShareString( PHB_ITEM pItem ) PHB_ITEM hb_itemUnShare( PHB_ITEM pItem ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemUnShare(%p)", pItem)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemUnShare(%p)", pItem)); if( HB_IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); @@ -2002,7 +2002,7 @@ PHB_ITEM hb_itemUnShare( PHB_ITEM pItem ) HB_BOOL hb_itemGetWriteCL( PHB_ITEM pItem, char ** pszValue, HB_SIZE * pulLen ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemGetWriteCL(%p,%p,%p)", pItem, pszValue, pulLen)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemGetWriteCL(%p,%p,%p)", pItem, pszValue, pulLen)); if( pItem ) { @@ -2024,7 +2024,7 @@ HB_BOOL hb_itemGetWriteCL( PHB_ITEM pItem, char ** pszValue, HB_SIZE * pulLen ) /* clone the given item */ PHB_ITEM hb_itemClone( PHB_ITEM pItem ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemClone(%p)", pItem)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemClone(%p)", pItem)); if( HB_IS_ARRAY( pItem ) ) return hb_arrayClone( pItem ); @@ -2038,7 +2038,7 @@ PHB_ITEM hb_itemClone( PHB_ITEM pItem ) PHB_ITEM hb_itemCloneTo( PHB_ITEM pDest, PHB_ITEM pSource ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemCloneTo(%p,%p)", pDest, pSource)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemCloneTo(%p,%p)", pDest, pSource)); if( HB_IS_ARRAY( pSource ) ) return hb_arrayCloneTo( pDest, pSource ); @@ -2625,7 +2625,7 @@ char * hb_itemString( PHB_ITEM pItem, HB_SIZE * ulLen, HB_BOOL * bFreeReq ) char * hb_itemPadConv( PHB_ITEM pItem, HB_SIZE * pulSize, HB_BOOL * bFreeReq ) { - HB_TRACE_STEALTH(HB_TR_DEBUG, ("hb_itemPadConv(%p, %p, %p)", pItem, pulSize, bFreeReq)); + HB_TRACE(HB_TR_DEBUG, ("hb_itemPadConv(%p, %p, %p)", pItem, pulSize, bFreeReq)); if( pItem ) {