1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _TOOLS_DEBUG_HXX
20 #define _TOOLS_DEBUG_HXX
22 #include "tools/toolsdllapi.h"
24 #include <sal/detail/log.h>
25 #include <sal/types.h>
26 #include <tools/solar.h>
28 /** The facilities provided by this header are deprecated. True assertions
29 (that detect broken program logic) should use standard assert (which aborts
30 if an assertion fails, and is controlled by the standard NDEBUG macro).
31 Logging of warnings (e.g., about malformed input) and traces (e.g., about
32 steps taken while executing some protocol) should use the facilities
33 provided by sal/log.hxx.
35 Because the assertion macro (DBG_ASSERT) has been used for
36 true assertions as well as to log warnings, it maps to SAL_WARN instead of
37 standard assert. The warning and error macros (DBG_ASSERTWARNING,
38 DBG_WARNING, DBG_WARNING1, ..., DBG_WARNING3, DBG_ERRORFILE) all map to
44 typedef void (*DbgPrintLine
)( const sal_Char
* pLine
);
45 typedef const sal_Char
* (*DbgUsr
)(const void* pThis
);
46 typedef void (*DbgTestSolarMutexProc
)();
48 #define DBG_BUF_MAXLEN 16384
50 #define DBG_TEST_XTOR (0x00000FFF)
51 #define DBG_TEST_XTOR_THIS (0x00000001)
52 #define DBG_TEST_XTOR_FUNC (0x00000002)
53 #define DBG_TEST_XTOR_EXIT (0x00000004)
54 #define DBG_TEST_XTOR_REPORT (0x00000008)
55 #define DBG_TEST_XTOR_TRACE (0x00000010)
57 #define DBG_TEST_PROFILING (0x01000000)
58 #define DBG_TEST_RESOURCE (0x02000000)
59 #define DBG_TEST_DIALOG (0x04000000)
60 #define DBG_TEST_BOLDAPPFONT (0x08000000)
62 #define DBG_OUT_NULL 0
63 #define DBG_OUT_FILE 1
64 #define DBG_OUT_WINDOW 2
65 #define DBG_OUT_SHELL 3
66 #define DBG_OUT_MSGBOX 4
67 #define DBG_OUT_TESTTOOL 5
68 #define DBG_OUT_DEBUGGER 6
69 #define DBG_OUT_ABORT 7
71 #define DBG_OUT_COUNT 8
73 // user (runtime) defined output channels
74 #define DBG_OUT_USER_CHANNEL_0 100
78 sal_uIntPtr nTestFlags
;
79 sal_uIntPtr bOverwrite
;
80 sal_uIntPtr nTraceOut
;
81 sal_uIntPtr nWarningOut
;
82 sal_uIntPtr nErrorOut
;
83 sal_uIntPtr bHookOSLAssert
;
84 sal_Char aDebugName
[260];
85 sal_Char aInclFilter
[512];
86 sal_Char aExclFilter
[512];
87 sal_Char aInclClassFilter
[512];
88 sal_Char aExclClassFilter
[512];
89 sal_Char aDbgWinState
[50]; // DbgGUIData for VCL
95 sal_Char
const * pName
;
99 #define DBG_FUNC_DEBUGSTART 1
100 #define DBG_FUNC_DEBUGEND 2
101 #define DBG_FUNC_GLOBALDEBUGEND 3
102 #define DBG_FUNC_GETDATA 4
103 #define DBG_FUNC_SAVEDATA 5
104 #define DBG_FUNC_SETPRINTMSGBOX 6
105 #define DBG_FUNC_SETPRINTWINDOW 7
106 #define DBG_FUNC_SETPRINTTESTTOOL 8
107 #define DBG_FUNC_XTORINFO 10
108 #define DBG_FUNC_COREDUMP 12
109 #define DBG_FUNC_ALLERROROUT 13
110 #define DBG_FUNC_SETTESTSOLARMUTEX 14
111 #define DBG_FUNC_TESTSOLARMUTEX 15
112 #define DBG_FUNC_PRINTFILE 16
113 #define DBG_FUNC_GETPRINTMSGBOX 17
114 #define DBG_FUNC_FILTERMESSAGE 18 // new for #i38967
115 #define DBG_FUNC_UPDATEOSLHOOK 19
116 #define DBG_FUNC_SET_ABORT 20
118 TOOLS_DLLPUBLIC
void* DbgFunc( sal_uInt16 nAction
, void* pData
= NULL
);
120 inline void DbgUpdateOslHook( DbgData
* pData
)
122 DbgFunc( DBG_FUNC_UPDATEOSLHOOK
, pData
);
125 inline void DbgDebugStart()
127 DbgFunc( DBG_FUNC_DEBUGSTART
);
130 inline void DbgDebugEnd()
132 DbgFunc( DBG_FUNC_DEBUGEND
);
135 inline void DbgGlobalDebugEnd()
137 DbgFunc( DBG_FUNC_GLOBALDEBUGEND
);
140 inline void DbgSetPrintMsgBox( DbgPrintLine pProc
)
142 DbgFunc( DBG_FUNC_SETPRINTMSGBOX
, (void*)(long)pProc
);
145 inline DbgPrintLine
DbgGetPrintMsgBox()
147 return (DbgPrintLine
)(long)DbgFunc( DBG_FUNC_GETPRINTMSGBOX
);
150 inline void DbgSetPrintWindow( DbgPrintLine pProc
)
152 DbgFunc( DBG_FUNC_SETPRINTWINDOW
, (void*)(long)pProc
);
155 inline void DbgSetPrintTestTool( DbgPrintLine pProc
)
157 DbgFunc( DBG_FUNC_SETPRINTTESTTOOL
, (void*)(long)pProc
);
160 inline void DbgSetAbort( DbgPrintLine pProc
)
162 DbgFunc( DBG_FUNC_SET_ABORT
, (void*)(long)pProc
);
165 typedef sal_uInt16 DbgChannelId
;
167 /** registers a user-defined channel for emitting the diagnostic messages
169 Note that such a user-defined channel cannot be revoked during the lifetime
170 of the process. Thus, it's the caller's responsibility to ensure that the
171 procedure to which ->pProc points remains valid.
174 the function for emitting the diagnostic messages
176 a unique number for this channel, which can be used for ->DbgData::nErrorOut,
177 ->DbgData::nWarningOut and ->DbgData::nTraceOut
178 @see DBG_OUT_USER_CHANNEL_0
180 (In theory, this function could replace the other hard-coded channels. Well, at least
181 the ones for MsgBox, Window, Shell, TestTool. Perhaps in the next life ...)
183 TOOLS_DLLPUBLIC DbgChannelId
DbgRegisterUserChannel( DbgPrintLine pProc
);
185 inline sal_Bool
DbgFilterMessage( const char* pMsg
)
187 return (sal_Bool
)(long) DbgFunc( DBG_FUNC_FILTERMESSAGE
, (void*)pMsg
);
190 inline int DbgIsAllErrorOut()
192 return (DbgFunc( DBG_FUNC_ALLERROROUT
) != 0);
195 inline DbgData
* DbgGetData()
197 return (DbgData
*)DbgFunc( DBG_FUNC_GETDATA
);
200 inline void DbgSaveData( const DbgData
& rData
)
202 DbgFunc( DBG_FUNC_SAVEDATA
, (void*)&rData
);
205 inline sal_uIntPtr
DbgIsTraceOut()
207 DbgData
* pData
= DbgGetData();
209 return (pData
->nTraceOut
!= DBG_OUT_NULL
);
214 inline sal_uIntPtr
DbgIsWarningOut()
216 DbgData
* pData
= DbgGetData();
218 return (pData
->nWarningOut
!= DBG_OUT_NULL
);
223 inline sal_uIntPtr
DbgIsErrorOut()
225 DbgData
* pData
= DbgGetData();
227 return (pData
->nErrorOut
!= DBG_OUT_NULL
);
232 inline sal_uIntPtr
DbgGetErrorOut() // Testtool: test whether to collect OSL_ASSERTions as well
234 DbgData
* pData
= DbgGetData();
236 return pData
->nErrorOut
;
241 inline sal_uIntPtr
DbgIsAssertWarning()
243 return DbgIsWarningOut();
246 inline sal_uIntPtr
DbgIsAssert()
248 return DbgIsErrorOut();
251 inline sal_uIntPtr
DbgIsResource()
253 DbgData
* pData
= DbgGetData();
255 return pData
->nTestFlags
& DBG_TEST_RESOURCE
;
260 inline sal_uIntPtr
DbgIsDialog()
262 DbgData
* pData
= DbgGetData();
264 return pData
->nTestFlags
& DBG_TEST_DIALOG
;
269 inline sal_uIntPtr
DbgIsBoldAppFont()
271 DbgData
* pData
= DbgGetData();
273 return pData
->nTestFlags
& DBG_TEST_BOLDAPPFONT
;
278 inline void DbgXtorInfo( sal_Char
* pBuf
)
280 DbgFunc( DBG_FUNC_XTORINFO
, (void*)pBuf
);
283 inline void DbgCoreDump()
285 DbgFunc( DBG_FUNC_COREDUMP
);
288 inline void DbgSetTestSolarMutex( DbgTestSolarMutexProc pProc
)
290 DbgFunc( DBG_FUNC_SETTESTSOLARMUTEX
, (void*)(long)pProc
);
293 inline void DbgTestSolarMutex()
295 DbgFunc( DBG_FUNC_TESTSOLARMUTEX
);
298 inline void DbgPrintFile( const sal_Char
* pLine
)
300 DbgFunc( DBG_FUNC_PRINTFILE
, (void*)(sal_Char
*)pLine
);
304 #define DBG_OUT_TRACE 1
305 #define DBG_OUT_WARNING 2
306 #define DBG_OUT_ERROR 3
308 TOOLS_DLLPUBLIC
void DbgOut( const sal_Char
* pMsg
, sal_uInt16 nOutType
= DBG_OUT_TRACE
,
309 const sal_Char
* pFile
= NULL
, sal_uInt16 nLine
= 0 );
310 TOOLS_DLLPUBLIC
void DbgPrintShell(char const * message
);
311 TOOLS_DLLPUBLIC
void DbgOutTypef( sal_uInt16 nOutType
, const sal_Char
* pFStr
, ... );
312 TOOLS_DLLPUBLIC
void DbgOutf( const sal_Char
* pFStr
, ... );
313 TOOLS_DLLPUBLIC
void ImpDbgOutfBuf( sal_Char
* pBuf
, const sal_Char
* pFStr
, ... );
315 // Dbg test functions
317 #define DBG_PROF_START 1
318 #define DBG_PROF_STOP 2
319 #define DBG_PROF_CONTINUE 3
320 #define DBG_PROF_PAUSE 4
322 TOOLS_DLLPUBLIC
void DbgProf( sal_uInt16 nAction
, DbgDataType
* );
324 #define DBG_XTOR_CTOR 1
325 #define DBG_XTOR_DTOR 2
326 #define DBG_XTOR_CHKTHIS 3
327 #define DBG_XTOR_CHKOBJ 4
328 #define DBG_XTOR_DTOROBJ 0x8000
330 TOOLS_DLLPUBLIC
void DbgXtor( DbgDataType
* pDbgData
,
331 sal_uInt16 nAction
, const void* pThis
, DbgUsr fDbgUsr
);
336 DbgDataType
* pDbgData
;
342 DbgXtorObj( DbgDataType
* pData
,
343 sal_uInt16 nAct
, const void* pThs
, DbgUsr fUsr
)
345 DbgXtor( pData
, nAct
, pThs
, fUsr
);
354 DbgXtor( pDbgData
, nAction
| DBG_XTOR_DTOROBJ
,
359 // (internally used) defines
361 #define DBG_FUNC( aName ) DbgName_##aName()
362 #define DBG_NAME( aName ) static DbgDataType aImpDbgData_##aName = { 0, #aName }; \
363 DbgDataType* DBG_FUNC( aName ) { return &aImpDbgData_##aName; }
364 #define DBG_NAMEEX_VISIBILITY( aName, vis ) vis DbgDataType* DBG_FUNC( aName );
365 #define DBG_NAMEEX( aName ) DBG_NAMEEX_VISIBILITY( aName, )
367 // (externally used) defines
369 #define DBG_DEBUGSTART() DbgDebugStart()
370 #define DBG_DEBUGEND() DbgDebugEnd()
371 #define DBG_GLOBALDEBUGEND() DbgGlobalDebugEnd()
373 #define DBG_PROFSTART( aName ) \
374 DbgProf( DBG_PROF_START, DBG_FUNC( aName ) )
376 #define DBG_PROFSTOP( aName ) \
377 DbgProf( DBG_PROF_STOP, DBG_FUNC( aName ) )
379 #define DBG_PROFCONTINUE( aName ) \
380 DbgProf( DBG_PROF_CONTINUE, DBG_FUNC( aName ) )
382 #define DBG_PROFPAUSE( aName ) \
383 DbgProf( DBG_PROF_PAUSE, DBG_FUNC( aName ) )
385 #define DBG_CTOR( aName, fTest ) \
386 DbgXtorObj aDbgXtorObj( DBG_FUNC( aName ), \
391 #define DBG_DTOR( aName, fTest ) \
392 DbgXtorObj aDbgXtorObj( DBG_FUNC( aName ), \
397 #define DBG_CHKTHIS( aName, fTest ) \
398 DbgXtorObj aDbgXtorObj( DBG_FUNC( aName ), \
403 #define DBG_CHKOBJ( pObj, aName, fTest ) \
404 DbgXtor( DBG_FUNC( aName ), DBG_XTOR_CHKOBJ, \
405 (const void*)pObj, (DbgUsr)fTest )
407 #define DBG_ASSERTWARNING( sCon, aWarning ) \
408 SAL_DETAIL_INFO_IF_FORMAT(!(sCon), "legacy.tools", aWarning)
410 #define DBG_ASSERT( sCon, aError ) \
411 SAL_DETAIL_WARN_IF_FORMAT(!(sCon), "legacy.tools", aError)
413 #define DBG_WARNING( aWarning ) \
414 SAL_DETAIL_INFO_IF_FORMAT(true, "legacy.tools", aWarning)
415 #define DBG_WARNING1( aWarning, x1 ) \
416 SAL_DETAIL_INFO_IF_FORMAT(true, "legacy.tools", aWarning, x1)
417 #define DBG_WARNING2( aWarning, x1, x2 ) \
418 SAL_DETAIL_INFO_IF_FORMAT(true, "legacy.tools", aWarning, x1, x2)
419 #define DBG_WARNING3( aWarning, x1, x2, x3 ) \
420 SAL_DETAIL_INFO_IF_FORMAT(true, "legacy.tools", aWarning, x1, x2, x3)
422 #define DBG_ERRORFILE( aError ) \
423 SAL_DETAIL_INFO_IF_FORMAT(true, "legacy.tools", aError, __FILE__, __LINE__)
425 #define DBG_TESTSOLARMUTEX() \
428 DbgTestSolarMutex(); \
431 // en-/disable debug defines
433 #define DBG_INSTOUTTRACE( nOut ) \
436 DbgGetData()->nTraceOut = nOut; \
439 #define DBG_INSTOUTWARNING( nOut ) \
442 DbgGetData()->nWarningOut = nOut; \
445 #define DBG_INSTOUTERROR( nOut ) \
448 DbgGetData()->nErrorOut = nOut; \
457 typedef void (*DbgPrintLine
)( const sal_Char
* pLine
);
458 typedef const sal_Char
* (*DbgUsr
)(const void* pThis
);
460 #define DBG_DEBUGSTART() ((void)0)
461 #define DBG_DEBUGEND() ((void)0)
462 #define DBG_GLOBALDEBUGEND() ((void)0)
464 #define DBG_NAME( aName )
465 #define DBG_NAMEEX( aName )
466 #define DBG_NAMEEX_VISIBILITY( aName, vis )
468 #define DBG_PROFSTART( aName ) ((void)0)
469 #define DBG_PROFSTOP( aName ) ((void)0)
470 #define DBG_PROFCONTINUE( aName ) ((void)0)
471 #define DBG_PROFPAUSE( aName ) ((void)0)
473 #define DBG_CTOR( aName, fTest ) ((void)0)
474 #define DBG_DTOR( aName, fTest ) ((void)0)
475 #define DBG_CHKTHIS( aName, fTest ) ((void)0)
476 #define DBG_CHKOBJ( pObj, aName, fTest ) ((void)0)
478 #define DBG_ASSERTWARNING( sCon, aWarning ) ((void)0)
479 #define DBG_ASSERT( sCon, aError ) ((void)0)
480 #define DBG_WARNING( aWarning ) ((void)0)
481 #define DBG_WARNING1( aWarning, x1 ) ((void)0)
482 #define DBG_WARNING2( aWarning, x1, x2 ) ((void)0)
483 #define DBG_WARNING3( aWarning, x1, x2, x3 ) ((void)0)
484 #define DBG_ERRORFILE( aError ) ((void)0)
486 #define DBG_TESTSOLARMUTEX() ((void)0)
488 #define DBG_INSTOUTTRACE( nOut ) ((void)0)
489 #define DBG_INSTOUTWARNING( nOut ) ((void)0)
490 #define DBG_INSTOUTERROR( nOut ) ((void)0)
496 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */