summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2011-11-22 09:34:46 +0100
committerStephan Bergmann <sbergman@redhat.com>2011-11-22 09:41:47 +0100
commit70a6b9ffbd676a1384433a86205d2cd4f2d4f4b1 (patch)
treeffb31ef817b5f2037cf7c332da422b9179d613d5 /tools
parentf2972242673cc9608960e9ca70e82766be5275e3 (diff)
New sal/log.h obsoletes osl/diagnose.h and tools/debug.hxx.
* New SAL_INFO..., SAL_WARN... macros. * New SAL_STREAM supersedes OSL_FORMAT. * oustringostreaminserter.hxx moved from unotest to rtl (and always UTF-8 now). * TODO to enable GCC __attribute__((format)) in sal/log.h (requires call-site cleanup). * Further functionality in tools/debug.hxx (DBG_MEMTEST, DBG_CTOR, etc.) not yet addressed. * Some replacements tools String -> rtl::OUString.
Diffstat (limited to 'tools')
-rw-r--r--tools/inc/tools/debug.hxx151
-rw-r--r--tools/qa/cppunit/test_reversemap.cxx2
-rw-r--r--tools/source/debug/debug.cxx110
-rw-r--r--tools/source/rc/resmgr.cxx8
4 files changed, 76 insertions, 195 deletions
diff --git a/tools/inc/tools/debug.hxx b/tools/inc/tools/debug.hxx
index 3d75f94437cd..95b320979913 100644
--- a/tools/inc/tools/debug.hxx
+++ b/tools/inc/tools/debug.hxx
@@ -31,9 +31,24 @@
#include "tools/toolsdllapi.h"
+#include <sal/log.h>
#include <sal/types.h>
#include <tools/solar.h>
+/** The facilities provided by this header are deprecated. True assertions
+ (that detect broken program logic) should use standard assert (which aborts
+ if an assertion fails, and is controlled by the standard NDEBUG macro).
+ Logging of warnings (e.g., about malformed input) and traces (e.g., about
+ steps taken while executing some protocol) should use the facilities
+ provided by sal/log.h.
+
+ Because the assertion macros (DBG_ASSERTWARNING, DBG_ASSERT, DBG_BF_ASSERT)
+ have been used for true assertions as well as for logged warnings, they map
+ to SAL_WARN instead of standard assert. The warning and error macros
+ (DBG_WARNING, DBG_WARNING1, ..., DBG_WARNING5, DBG_WARNINGFILE,
+ DBG_ERRORFILE) all map to SAL_WARN, too.
+*/
+
// ------------
// - DBG_UITL -
// ------------
@@ -348,24 +363,6 @@ TOOLS_DLLPUBLIC void DbgOutTypef( sal_uInt16 nOutType, const sal_Char* pFStr, ..
TOOLS_DLLPUBLIC void DbgOutf( const sal_Char* pFStr, ... );
TOOLS_DLLPUBLIC void ImpDbgOutfBuf( sal_Char* pBuf, const sal_Char* pFStr, ... );
-inline void DbgTrace( const sal_Char* pMsg,
- const sal_Char* pFile = NULL, sal_uInt16 nLine = 0 )
-{
- DbgOut( pMsg, DBG_OUT_TRACE, pFile, nLine );
-}
-
-inline void DbgWarning( const sal_Char* pMsg,
- const sal_Char* pFile = NULL, sal_uInt16 nLine = 0 )
-{
- DbgOut( pMsg, DBG_OUT_WARNING, pFile, nLine );
-}
-
-inline void DbgError( const sal_Char* pMsg,
- const sal_Char* pFile = NULL, sal_uInt16 nLine = 0 )
-{
- DbgOut( pMsg, DBG_OUT_ERROR, pFile, nLine );
-}
-
// --- Dbg-Test-Functions ---
inline void DbgMemTest( void* p = NULL )
@@ -469,110 +466,34 @@ public:
DbgXtor( DBG_FUNC( aName ), DBG_XTOR_CHKOBJ, \
(const void*)pObj, (DbgUsr)fTest )
-#define DBG_ASSERTWARNING( sCon, aWarning ) \
-do \
-{ \
- if ( DbgIsAssertWarning() ) \
- { \
- if ( !( sCon ) ) \
- { \
- DbgWarning( aWarning, __FILE__, \
- __LINE__ ); \
- } \
- } \
-} while(0)
+#define DBG_ASSERTWARNING( sCon, aWarning ) \
+ SAL_WARN_IF(!(sCon), "legacy.tools", aWarning)
-#define DBG_ASSERT( sCon, aError ) \
-do \
-{ \
- if ( DbgIsAssert() ) \
- { \
- if ( !( sCon ) ) \
- { \
- DbgError( aError, \
- __FILE__, __LINE__ ); \
- } \
- } \
-} while(0)
+#define DBG_ASSERT( sCon, aError ) \
+ SAL_WARN_IF(!(sCon), "legacy.tools", aError)
#ifdef DBG_BINFILTER
-#define DBG_BF_ASSERT( sCon, aError ) \
-do \
-{ \
- if ( !( sCon ) ) \
- { \
- DbgError( aError, \
- __FILE__, __LINE__ ); \
- } \
-} while(0)
+#define DBG_BF_ASSERT( sCon, aError ) \
+ SAL_WARN_IF(!(sCon), "legacy.binfilter", aError)
#else
#define DBG_BF_ASSERT( sCon, aError ) ((void)0)
#endif
-#define DBG_WARNING( aWarning ) \
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- DbgWarning( aWarning ); \
-} while(0)
-#define DBG_WARNING1( aWarning, x1 ) \
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- { \
- DbgOutTypef( DBG_OUT_WARNING, aWarning, \
- x1 ); \
- } \
-} while(0)
-#define DBG_WARNING2( aWarning, x1, x2 ) \
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- { \
- DbgOutTypef( DBG_OUT_WARNING, aWarning, \
- x1, x2 ); \
- } \
-} while(0)
-#define DBG_WARNING3( aWarning, x1, x2, x3 ) \
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- { \
- DbgOutTypef( DBG_OUT_WARNING, aWarning, \
- x1, x2, x3 ); \
- } \
-} while(0)
-#define DBG_WARNING4( aWarning, x1, x2, x3, x4 ) \
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- { \
- DbgOutTypef( DBG_OUT_WARNING, aWarning, \
- x1, x2, x3, x4 ); \
- } \
-} while(0)
-#define DBG_WARNING5( aWarning, x1, x2, x3, x4, x5 )\
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- { \
- DbgOutTypef( DBG_OUT_WARNING, aWarning, \
- x1, x2, x3, x4, x5 ); \
- } \
-} while(0)
-#define DBG_WARNINGFILE( aWarning ) \
-do \
-{ \
- if ( DbgIsWarningOut() ) \
- DbgWarning( aWarning, __FILE__, __LINE__ ); \
-} while(0)
-
-#define DBG_ERRORFILE( aError ) \
-do \
-{ \
- if ( DbgIsErrorOut() ) \
- DbgError( aError, __FILE__, __LINE__ ); \
-} while(0)
+#define DBG_WARNING( aWarning ) SAL_WARN("legacy.tools", aWarning)
+#define DBG_WARNING1( aWarning, x1 ) SAL_WARN("legacy.tools", aWarning, x1)
+#define DBG_WARNING2( aWarning, x1, x2 ) \
+ SAL_WARN("legacy.tools", aWarning, x1, x2)
+#define DBG_WARNING3( aWarning, x1, x2, x3 ) \
+ SAL_WARN("legacy.tools", aWarning, x1, x2, x3)
+#define DBG_WARNING4( aWarning, x1, x2, x3, x4 ) \
+ SAL_WARN("legacy.tools", aWarning, x1, x2, x3, x4)
+#define DBG_WARNING5( aWarning, x1, x2, x3, x4, x5 ) \
+ SAL_WARN("legacy.tools", aWarning, x1, x2, x3, x4, x5)
+#define DBG_WARNINGFILE( aWarning ) \
+ SAL_WARN("legacy.tools", aWarning, __FILE__, __LINE__)
+
+#define DBG_ERRORFILE( aError ) \
+ SAL_WARN("legacy.tools", aError, __FILE__, __LINE__)
#define DBG_TESTSOLARMUTEX() \
do \
diff --git a/tools/qa/cppunit/test_reversemap.cxx b/tools/qa/cppunit/test_reversemap.cxx
index 190b4b2c10f4..caaa6d2d1565 100644
--- a/tools/qa/cppunit/test_reversemap.cxx
+++ b/tools/qa/cppunit/test_reversemap.cxx
@@ -38,11 +38,11 @@
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
+#include "rtl/oustringostreaminserter.hxx"
#include <rtl/ustring.hxx>
#include <vector>
#include "tools/tenccvt.hxx"
-#include "unotest/oustringostreaminserter.hxx"
//Tests for getBestMSEncodingByChar
diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx
index b2b6367ca734..d3f2c088b897 100644
--- a/tools/source/debug/debug.cxx
+++ b/tools/source/debug/debug.cxx
@@ -50,6 +50,7 @@
#include <tools/debug.hxx>
#include <rtl/string.h>
+#include <sal/log.h>
#include <sal/macros.h>
#include <vector>
@@ -60,22 +61,6 @@
#ifdef DBG_UTIL
-// --- DbgErrors ---
-
-static sal_Char const DbgError_ProfEnd1[] = "DBG_PROF...() without DBG_PROFSTART(): ";
-static sal_Char const DbgError_Xtor1[] = "DBG_DTOR() or DBG_CHKTHIS() without DBG_CTOR(): ";
-
-static sal_Char const DbgError_CtorDtor1[] = "this == NULL in class ";
-static sal_Char const DbgError_CtorDtor2[] = "invalid this-Pointer %p in class ";
-static sal_Char const DbgError_CtorDtor3[] = "Error-Msg from Object %p in class ";
-
-static sal_Char const DbgTrace_EnterCtor[] = "Enter Ctor from class ";
-static sal_Char const DbgTrace_LeaveCtor[] = "Leave Ctor from class ";
-static sal_Char const DbgTrace_EnterDtor[] = "Enter Dtor from class ";
-static sal_Char const DbgTrace_LeaveDtor[] = "Leave Dtor from class ";
-static sal_Char const DbgTrace_EnterMeth[] = "Enter method from class ";
-static sal_Char const DbgTrace_LeaveMeth[] = "Leave method from class ";
-
// --- PointerList ---
#define PBLOCKCOUNT 1024
@@ -1345,14 +1330,13 @@ void DbgProf( sal_uInt16 nAction, DbgDataType* pDbgData )
if ( !(pData->aDbgData.nTestFlags & DBG_TEST_PROFILING) )
return;
- sal_Char aBuf[DBG_BUF_MAXLEN];
ProfType* pProfData = (ProfType*)pDbgData->pData;
sal_uIntPtr nTime;
if ( (nAction != DBG_PROF_START) && !pProfData )
{
- strcpy( aBuf, DbgError_ProfEnd1 );
- strcat( aBuf, pDbgData->pName );
- DbgError( aBuf );
+ SAL_WARN_S(
+ "tools.debug",
+ "DBG_PROF...() without DBG_PROFSTART(): " << pDbgData->pName);
return;
}
@@ -1387,7 +1371,8 @@ void DbgProf( sal_uInt16 nAction, DbgDataType* pDbgData )
if ( pProfData->nStart == 0xFFFFFFFF )
{
- DbgError( DbgError_ProfEnd1 );
+ SAL_WARN(
+ "tools.debug", "DBG_PROF...() without DBG_PROFSTART()");
return;
}
@@ -1467,25 +1452,15 @@ void DbgXtor( DbgDataType* pDbgData, sal_uInt16 nAction, const void* pThis,
if ( !pXtorData->bTest )
return;
- sal_Char aBuf[DBG_BUF_MAXLEN];
sal_uInt16 nAct = nAction & ~DBG_XTOR_DTOROBJ;
- // Trace (Enter)
- if ( (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE) &&
- !(nAction & DBG_XTOR_DTOROBJ) )
- {
- if ( nAct != DBG_XTOR_CHKOBJ )
- {
- if ( nAct == DBG_XTOR_CTOR )
- strcpy( aBuf, DbgTrace_EnterCtor );
- else if ( nAct == DBG_XTOR_DTOR )
- strcpy( aBuf, DbgTrace_EnterDtor );
- else
- strcpy( aBuf, DbgTrace_EnterMeth );
- strcat( aBuf, pDbgData->pName );
- DbgTrace( aBuf );
- }
- }
+ SAL_INFO_IF_S(
+ ((pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE)
+ && !(nAction & DBG_XTOR_DTOROBJ) && nAct != DBG_XTOR_CHKOBJ),
+ "tools.debug",
+ (nAct == DBG_XTOR_CTOR ? "Enter Ctor from class "
+ : nAct == DBG_XTOR_DTOR ? "Enter Dtor from class "
+ : "Enter method from class ") << pDbgData->pName);
// Sind noch Xtor-Tests als Trace an
if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXTRA )
@@ -1493,9 +1468,10 @@ void DbgXtor( DbgDataType* pDbgData, sal_uInt16 nAction, const void* pThis,
// DBG_CTOR-Aufruf vor allen anderen DBG_XTOR-Aufrufen
if ( ((nAction & ~DBG_XTOR_DTOROBJ) != DBG_XTOR_CTOR) && !pDbgData->pData )
{
- strcpy( aBuf, DbgError_Xtor1 );
- strcat( aBuf, pDbgData->pName );
- DbgError( aBuf );
+ SAL_WARN_S(
+ "tools.debug",
+ "DBG_DTOR() or DBG_CHKTHIS() without DBG_CTOR(): "
+ << pDbgData->pName);
return;
}
@@ -1508,20 +1484,17 @@ void DbgXtor( DbgDataType* pDbgData, sal_uInt16 nAction, const void* pThis,
// This-Pointer == NULL
if ( !pThis )
{
- strcpy( aBuf, DbgError_CtorDtor1 );
- strcat( aBuf, pDbgData->pName );
- DbgError( aBuf );
+ SAL_WARN_S(
+ "tools.debug",
+ "this == NULL in class " << pDbgData->pName);
return;
}
if ( (nAction & ~DBG_XTOR_DTOROBJ) != DBG_XTOR_CTOR )
{
- if ( !pXtorData->aThisList.IsIn( pThis ) )
- {
- sprintf( aBuf, DbgError_CtorDtor2, pThis );
- strcat( aBuf, pDbgData->pName );
- DbgError( aBuf );
- }
+ SAL_WARN_IF_S(
+ !pXtorData->aThisList.IsIn(pThis), "tools.debug",
+ "invalid this-Pointer %p in class " << pDbgData->pName);
}
}
}
@@ -1585,32 +1558,21 @@ void DbgXtor( DbgDataType* pDbgData, sal_uInt16 nAction, const void* pThis,
}
// Gegebenenfalls Fehlermeldung ausgeben
- if ( pMsg )
- {
- sprintf( aBuf, DbgError_CtorDtor3, pThis );
- strcat( aBuf, pDbgData->pName );
- strcat( aBuf, ": \n" );
- strcat( aBuf, pMsg );
- DbgError( aBuf );
- }
+ SAL_WARN_IF_S(
+ pMsg, "tools.debug",
+ "Error-Msg from Object " << pThis << " in class "
+ << pDbgData->pName << ": " << pMsg);
}
- // Trace (Leave)
- if ( (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE) &&
- (nAction & DBG_XTOR_DTOROBJ) )
- {
- if ( nAct != DBG_XTOR_CHKOBJ )
- {
- if ( nAct == DBG_XTOR_CTOR )
- strcpy( aBuf, DbgTrace_LeaveCtor );
- else if ( nAct == DBG_XTOR_DTOR )
- strcpy( aBuf, DbgTrace_LeaveDtor );
- else
- strcpy( aBuf, DbgTrace_LeaveMeth );
- strcat( aBuf, pDbgData->pName );
- DbgTrace( aBuf );
- }
- }
+ SAL_INFO_IF_S(
+ ((pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE)
+ && (nAction & DBG_XTOR_DTOROBJ) && nAct != DBG_XTOR_CHKOBJ),
+ "tools.debug",
+ (nAct == DBG_XTOR_CTOR
+ ? "Leave Ctor from class "
+ : nAct == DBG_XTOR_DTOR
+ ? "Leave Dtor from class "
+ : "Leave method from class ") << pDbgData->pName);
}
// -----------------------------------------------------------------------
diff --git a/tools/source/rc/resmgr.cxx b/tools/source/rc/resmgr.cxx
index 1733e6e1d1ae..2ea66b2dce7d 100644
--- a/tools/source/rc/resmgr.cxx
+++ b/tools/source/rc/resmgr.cxx
@@ -43,8 +43,10 @@
#include <osl/file.hxx>
#include <osl/mutex.hxx>
#include <osl/signal.h>
+#include <rtl/oustringostreaminserter.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx>
+#include <sal/log.h>
#include <tools/urlobj.hxx>
#include <rtl/instance.hxx>
#include <rtl/bootstrap.hxx>
@@ -947,11 +949,7 @@ void ResMgr::Init( const OUString& rFileName )
InternalResMgr::FreeGlobalRes( aResHandle, pVoid );
else
{
- rtl::OStringBuffer aStr(
- RTL_CONSTASCII_STRINGPARAM("Wrong version:\n"));
- aStr.append(rtl::OUStringToOString(pImpRes->aFileName,
- RTL_TEXTENCODING_UTF8));
- DbgError(aStr.getStr());
+ SAL_WARN_S("tools", "Wrong version: " << pImpRes->aFileName);
}
}
#endif