xref: /AOO41X/main/tools/source/debug/debug.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_tools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define _TOOLS_DEBUG_CXX
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #if defined (UNX) || defined (GCC)
34*cdf0e10cSrcweir #include <unistd.h>
35*cdf0e10cSrcweir #else
36*cdf0e10cSrcweir #include <direct.h>
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <time.h>
40*cdf0e10cSrcweir #include <cstdarg>  // combinations
41*cdf0e10cSrcweir #include <stdlib.h>
42*cdf0e10cSrcweir #include <string.h>
43*cdf0e10cSrcweir #include <stdio.h>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #ifdef OS2
46*cdf0e10cSrcweir #define INCL_DOSSEMAPHORES
47*cdf0e10cSrcweir #define INCL_DOSMISC
48*cdf0e10cSrcweir #define INCL_WINDIALOGS
49*cdf0e10cSrcweir #define INCL_WINSHELLDATA
50*cdf0e10cSrcweir #include <svpm.h>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #if defined ( WNT )
54*cdf0e10cSrcweir #ifdef _MSC_VER
55*cdf0e10cSrcweir #pragma warning (push,1)
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #include <tools/svwin.h>
58*cdf0e10cSrcweir #ifdef _MSC_VER
59*cdf0e10cSrcweir #pragma warning (pop)
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #endif
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <tools/debug.hxx>
64*cdf0e10cSrcweir #include <rtl/string.h>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #include <vector>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #include <osl/diagnose.h>
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // =======================================================================
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir #ifdef DBG_UTIL
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir // --- DbgErrors ---
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir static sal_Char const DbgError_ProfEnd1[]   = "DBG_PROF...() without DBG_PROFSTART(): ";
77*cdf0e10cSrcweir static sal_Char const DbgError_Xtor1[]      = "DBG_DTOR() or DBG_CHKTHIS() without DBG_CTOR(): ";
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir static sal_Char const DbgError_CtorDtor1[]  = "this == NULL in class ";
80*cdf0e10cSrcweir static sal_Char const DbgError_CtorDtor2[]  = "invalid this-Pointer %p in class ";
81*cdf0e10cSrcweir static sal_Char const DbgError_CtorDtor3[]  = "Error-Msg from Object %p in class ";
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir static sal_Char const DbgTrace_EnterCtor[]  = "Enter Ctor from class ";
84*cdf0e10cSrcweir static sal_Char const DbgTrace_LeaveCtor[]  = "Leave Ctor from class ";
85*cdf0e10cSrcweir static sal_Char const DbgTrace_EnterDtor[]  = "Enter Dtor from class ";
86*cdf0e10cSrcweir static sal_Char const DbgTrace_LeaveDtor[]  = "Leave Dtor from class ";
87*cdf0e10cSrcweir static sal_Char const DbgTrace_EnterMeth[]  = "Enter method from class ";
88*cdf0e10cSrcweir static sal_Char const DbgTrace_LeaveMeth[]  = "Leave method from class ";
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir // --- PointerList ---
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir #define PBLOCKCOUNT     1024
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir struct PBlock
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     void*       aData[PBLOCKCOUNT];
97*cdf0e10cSrcweir     sal_uInt16      nCount;
98*cdf0e10cSrcweir     PBlock*     pPrev;
99*cdf0e10cSrcweir     PBlock*     pNext;
100*cdf0e10cSrcweir };
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir class PointerList
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir private:
105*cdf0e10cSrcweir     PBlock*     pFirst;
106*cdf0e10cSrcweir     PBlock*     pLast;
107*cdf0e10cSrcweir     sal_uIntPtr       nCount;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir public:
110*cdf0e10cSrcweir                 PointerList() { pFirst = NULL; pLast = NULL; nCount = 0; }
111*cdf0e10cSrcweir                 ~PointerList();
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     void        Add( const void* p );
114*cdf0e10cSrcweir     sal_Bool        Remove( const void* p );
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     const void* Get( sal_uIntPtr nPos ) const;
117*cdf0e10cSrcweir     sal_Bool        IsIn( const void* p ) const;
118*cdf0e10cSrcweir     sal_uIntPtr       Count() const { return nCount; }
119*cdf0e10cSrcweir };
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir // --- Datentypen ---
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir #define DBG_MAXNAME     28
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir struct ProfType
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     sal_uIntPtr                   nCount;
128*cdf0e10cSrcweir     sal_uIntPtr                   nTime;
129*cdf0e10cSrcweir     sal_uIntPtr                   nMinTime;
130*cdf0e10cSrcweir     sal_uIntPtr                   nMaxTime;
131*cdf0e10cSrcweir     sal_uIntPtr                   nStart;
132*cdf0e10cSrcweir     sal_uIntPtr                   nContinueTime;
133*cdf0e10cSrcweir     sal_uIntPtr                   nContinueStart;
134*cdf0e10cSrcweir     sal_Char                aName[DBG_MAXNAME+1];
135*cdf0e10cSrcweir };
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir struct XtorType
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     sal_uIntPtr                   nCtorCalls;
140*cdf0e10cSrcweir     sal_uIntPtr                   nDtorCalls;
141*cdf0e10cSrcweir     sal_uIntPtr                   nMaxCount;
142*cdf0e10cSrcweir     sal_uIntPtr                   nStatics;
143*cdf0e10cSrcweir     sal_Char                aName[DBG_MAXNAME+1];
144*cdf0e10cSrcweir     sal_Bool                    bTest;
145*cdf0e10cSrcweir     PointerList             aThisList;
146*cdf0e10cSrcweir };
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir struct DebugData
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     DbgData                 aDbgData;
151*cdf0e10cSrcweir     sal_uInt16                  bInit;
152*cdf0e10cSrcweir     DbgPrintLine            pDbgPrintMsgBox;
153*cdf0e10cSrcweir     DbgPrintLine            pDbgPrintWindow;
154*cdf0e10cSrcweir     DbgPrintLine            pDbgPrintTestTool;
155*cdf0e10cSrcweir 	DbgPrintLine			pDbgAbort;
156*cdf0e10cSrcweir     ::std::vector< DbgPrintLine >
157*cdf0e10cSrcweir                             aDbgPrintUserChannels;
158*cdf0e10cSrcweir     PointerList*            pProfList;
159*cdf0e10cSrcweir     PointerList*            pXtorList;
160*cdf0e10cSrcweir     DbgTestSolarMutexProc   pDbgTestSolarMutex;
161*cdf0e10cSrcweir     pfunc_osl_printDetailedDebugMessage
162*cdf0e10cSrcweir                             pOldDebugMessageFunc;
163*cdf0e10cSrcweir     bool                    bOslIsHooked;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     DebugData()
166*cdf0e10cSrcweir         :bInit( sal_False )
167*cdf0e10cSrcweir         ,pDbgPrintMsgBox( NULL )
168*cdf0e10cSrcweir         ,pDbgPrintWindow( NULL )
169*cdf0e10cSrcweir         ,pDbgPrintTestTool( NULL )
170*cdf0e10cSrcweir 		,pDbgAbort( NULL )
171*cdf0e10cSrcweir         ,pProfList( NULL )
172*cdf0e10cSrcweir         ,pXtorList( NULL )
173*cdf0e10cSrcweir         ,pDbgTestSolarMutex( NULL )
174*cdf0e10cSrcweir         ,pOldDebugMessageFunc( NULL )
175*cdf0e10cSrcweir         ,bOslIsHooked( false )
176*cdf0e10cSrcweir     {
177*cdf0e10cSrcweir         aDbgData.nTestFlags = DBG_TEST_RESOURCE | DBG_TEST_MEM_INIT;
178*cdf0e10cSrcweir         aDbgData.bOverwrite = sal_True;
179*cdf0e10cSrcweir         aDbgData.nTraceOut = DBG_OUT_NULL;
180*cdf0e10cSrcweir         aDbgData.nWarningOut = DBG_OUT_NULL;
181*cdf0e10cSrcweir         aDbgData.nErrorOut = DBG_OUT_MSGBOX;
182*cdf0e10cSrcweir         aDbgData.bMemInit = 0x77;
183*cdf0e10cSrcweir         aDbgData.bMemBound = 0x55;
184*cdf0e10cSrcweir         aDbgData.bMemFree = 0x33;
185*cdf0e10cSrcweir         aDbgData.bHookOSLAssert = sal_True;
186*cdf0e10cSrcweir         aDbgData.aDebugName[0] = 0;
187*cdf0e10cSrcweir         aDbgData.aInclFilter[0] = 0;
188*cdf0e10cSrcweir         aDbgData.aExclFilter[0] = 0;
189*cdf0e10cSrcweir         aDbgData.aInclClassFilter[0] = 0;
190*cdf0e10cSrcweir         aDbgData.aExclClassFilter[0] = 0;
191*cdf0e10cSrcweir         aDbgData.aDbgWinState[0] = 0;
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir };
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir #define DBG_TEST_XTOR_EXTRA (DBG_TEST_XTOR_THIS |  DBG_TEST_XTOR_FUNC |               \
196*cdf0e10cSrcweir                              DBG_TEST_XTOR_EXIT |  DBG_TEST_XTOR_REPORT )
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir // ------------------------------
199*cdf0e10cSrcweir // - statische Verwaltungsdaten -
200*cdf0e10cSrcweir // ------------------------------
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir static DebugData aDebugData;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir static sal_Char aCurPath[260];
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir static int bDbgImplInMain = sal_False;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir // =======================================================================
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir #if defined( WNT )
211*cdf0e10cSrcweir static CRITICAL_SECTION aImplCritDbgSection;
212*cdf0e10cSrcweir #elif defined( OS2 )
213*cdf0e10cSrcweir static HMTX             hImplCritDbgSection = 0;
214*cdf0e10cSrcweir #endif
215*cdf0e10cSrcweir static sal_Bool             bImplCritDbgSectionInit = sal_False;
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir // -----------------------------------------------------------------------
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir void ImplDbgInitLock()
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir #if defined( WNT )
222*cdf0e10cSrcweir     InitializeCriticalSection( &aImplCritDbgSection );
223*cdf0e10cSrcweir #elif defined( OS2 )
224*cdf0e10cSrcweir     DosCreateMutexSem( NULL, &hImplCritDbgSection, 0, sal_False );
225*cdf0e10cSrcweir #endif
226*cdf0e10cSrcweir     bImplCritDbgSectionInit = sal_True;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir // -----------------------------------------------------------------------
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir void ImplDbgDeInitLock()
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir #if defined( WNT )
234*cdf0e10cSrcweir     DeleteCriticalSection( &aImplCritDbgSection );
235*cdf0e10cSrcweir #elif defined( OS2 )
236*cdf0e10cSrcweir     DosCloseMutexSem( hImplCritDbgSection );
237*cdf0e10cSrcweir #endif
238*cdf0e10cSrcweir     bImplCritDbgSectionInit = sal_False;
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir // -----------------------------------------------------------------------
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir void ImplDbgLock()
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir     if ( !bImplCritDbgSectionInit )
246*cdf0e10cSrcweir         return;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir #if defined( WNT )
249*cdf0e10cSrcweir     EnterCriticalSection( &aImplCritDbgSection );
250*cdf0e10cSrcweir #elif defined( OS2 )
251*cdf0e10cSrcweir     DosRequestMutexSem( hImplCritDbgSection, SEM_INDEFINITE_WAIT );
252*cdf0e10cSrcweir #endif
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir // -----------------------------------------------------------------------
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir void ImplDbgUnlock()
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     if ( !bImplCritDbgSectionInit )
260*cdf0e10cSrcweir         return;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir #if defined( WNT )
263*cdf0e10cSrcweir     LeaveCriticalSection( &aImplCritDbgSection );
264*cdf0e10cSrcweir #elif defined( OS2 )
265*cdf0e10cSrcweir     DosReleaseMutexSem( hImplCritDbgSection );
266*cdf0e10cSrcweir #endif
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir // =======================================================================
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir #if (defined WNT || defined OS2) && !defined SVX_LIGHT
272*cdf0e10cSrcweir //#define SV_MEMMGR //
273*cdf0e10cSrcweir #endif
274*cdf0e10cSrcweir #ifdef SV_MEMMGR
275*cdf0e10cSrcweir void DbgImpCheckMemory( void* p = NULL );
276*cdf0e10cSrcweir void DbgImpCheckMemoryDeInit();
277*cdf0e10cSrcweir void DbgImpMemoryInfo( sal_Char* pBuf );
278*cdf0e10cSrcweir #endif
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir #define FILE_LINEEND    "\n"
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir // =======================================================================
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir static sal_Bool ImplActivateDebugger( const sal_Char* pMsg )
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir #if defined( WNT )
287*cdf0e10cSrcweir     static sal_Char aImplDbgOutBuf[DBG_BUF_MAXLEN];
288*cdf0e10cSrcweir     strcpy( aImplDbgOutBuf, pMsg );
289*cdf0e10cSrcweir     strcat( aImplDbgOutBuf, "\r\n" );
290*cdf0e10cSrcweir     OutputDebugString( aImplDbgOutBuf );
291*cdf0e10cSrcweir     DebugBreak();
292*cdf0e10cSrcweir     return sal_True;
293*cdf0e10cSrcweir #else
294*cdf0e10cSrcweir     (void) pMsg; // avoid warning about unused parameter
295*cdf0e10cSrcweir     return sal_False;
296*cdf0e10cSrcweir #endif
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir // -----------------------------------------------------------------------
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir static sal_Bool ImplCoreDump()
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir #if defined( WNT )
304*cdf0e10cSrcweir     DebugBreak();
305*cdf0e10cSrcweir #else
306*cdf0e10cSrcweir     long* pTemp = 0;
307*cdf0e10cSrcweir     *pTemp = 0xCCCC;
308*cdf0e10cSrcweir #endif
309*cdf0e10cSrcweir     return sal_True;
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir // =======================================================================
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir static sal_uIntPtr ImplGetPerfTime()
315*cdf0e10cSrcweir {
316*cdf0e10cSrcweir #if defined( WNT )
317*cdf0e10cSrcweir     return (sal_uIntPtr)GetTickCount();
318*cdf0e10cSrcweir #elif defined( OS2 )
319*cdf0e10cSrcweir     sal_uIntPtr nClock;
320*cdf0e10cSrcweir     DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &nClock, sizeof( nClock ) );
321*cdf0e10cSrcweir     return (sal_uIntPtr)nClock;
322*cdf0e10cSrcweir #else
323*cdf0e10cSrcweir     static sal_uIntPtr    nImplTicksPerSecond = 0;
324*cdf0e10cSrcweir     static double   dImplTicksPerSecond;
325*cdf0e10cSrcweir     sal_uIntPtr           nTicks = (sal_uIntPtr)clock();
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     if ( !nImplTicksPerSecond )
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir         nImplTicksPerSecond = CLOCKS_PER_SEC;
330*cdf0e10cSrcweir         dImplTicksPerSecond = nImplTicksPerSecond;
331*cdf0e10cSrcweir     }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     double fTicks = nTicks;
334*cdf0e10cSrcweir     fTicks *= 1000;
335*cdf0e10cSrcweir     fTicks /= dImplTicksPerSecond;
336*cdf0e10cSrcweir     return (sal_uIntPtr)fTicks;
337*cdf0e10cSrcweir #endif
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir // -----------------------------------------------------------------------
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir typedef FILE*       FILETYPE;
343*cdf0e10cSrcweir #define FileOpen    fopen
344*cdf0e10cSrcweir #define FileRead    fread
345*cdf0e10cSrcweir #define FileWrite   fwrite
346*cdf0e10cSrcweir #define FilePrintF  fprintf
347*cdf0e10cSrcweir #define FileClose   fclose
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir // =======================================================================
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir namespace
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir     enum ConfigSection
354*cdf0e10cSrcweir     {
355*cdf0e10cSrcweir         eOutput,
356*cdf0e10cSrcweir         eMemory,
357*cdf0e10cSrcweir         eGUI,
358*cdf0e10cSrcweir         eObjects,
359*cdf0e10cSrcweir         eTest,
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir         eUnknown
362*cdf0e10cSrcweir     };
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     void lcl_lineFeed( FILETYPE _pFile )
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         FilePrintF( _pFile, "%s", FILE_LINEEND );
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir     const sal_Char* lcl_getSectionName( ConfigSection _eSection )
370*cdf0e10cSrcweir     {
371*cdf0e10cSrcweir         const sal_Char* pSectionName = NULL;
372*cdf0e10cSrcweir         switch ( _eSection )
373*cdf0e10cSrcweir         {
374*cdf0e10cSrcweir             case eOutput    : pSectionName = "output";  break;
375*cdf0e10cSrcweir             case eMemory    : pSectionName = "memory";  break;
376*cdf0e10cSrcweir             case eGUI       : pSectionName = "gui";     break;
377*cdf0e10cSrcweir             case eObjects   : pSectionName = "objects"; break;
378*cdf0e10cSrcweir             case eTest      : pSectionName = "test";    break;
379*cdf0e10cSrcweir             case eUnknown:
380*cdf0e10cSrcweir                 OSL_ASSERT(false);
381*cdf0e10cSrcweir                 break;
382*cdf0e10cSrcweir         }
383*cdf0e10cSrcweir         return pSectionName;
384*cdf0e10cSrcweir     }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     ConfigSection lcl_getSectionFromName( const sal_Char* _pSectionName, size_t _nSectionNameLength )
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         if ( strncmp( _pSectionName, "output",  _nSectionNameLength < 6 ? _nSectionNameLength : 6 ) == 0 )
389*cdf0e10cSrcweir             return eOutput;
390*cdf0e10cSrcweir         if ( strncmp( _pSectionName, "memory",  _nSectionNameLength < 6 ? _nSectionNameLength : 6 ) == 0 )
391*cdf0e10cSrcweir             return eMemory;
392*cdf0e10cSrcweir         if ( strncmp( _pSectionName, "gui",     _nSectionNameLength < 3 ? _nSectionNameLength : 3 ) == 0 )
393*cdf0e10cSrcweir             return eGUI;
394*cdf0e10cSrcweir         if ( strncmp( _pSectionName, "objects", _nSectionNameLength < 7 ? _nSectionNameLength : 7 ) == 0 )
395*cdf0e10cSrcweir             return eObjects;
396*cdf0e10cSrcweir         if ( strncmp( _pSectionName, "test",    _nSectionNameLength < 4 ? _nSectionNameLength : 4 ) == 0 )
397*cdf0e10cSrcweir             return eTest;
398*cdf0e10cSrcweir         return eUnknown;
399*cdf0e10cSrcweir     }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     void lcl_startSection( FILETYPE _pFile, ConfigSection _eSection )
402*cdf0e10cSrcweir     {
403*cdf0e10cSrcweir         FilePrintF( _pFile, "[%s]%s", lcl_getSectionName( _eSection ), FILE_LINEEND );
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     void lcl_writeConfigString( FILETYPE _pFile, const sal_Char* _pKeyName, const sal_Char* _pValue )
407*cdf0e10cSrcweir     {
408*cdf0e10cSrcweir         FilePrintF( _pFile, "%s=%s%s", _pKeyName, _pValue, FILE_LINEEND );
409*cdf0e10cSrcweir     }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     void lcl_writeConfigBoolean( FILETYPE _pFile, const sal_Char* _pKeyName, bool _bValue )
412*cdf0e10cSrcweir     {
413*cdf0e10cSrcweir         lcl_writeConfigString( _pFile, _pKeyName, _bValue ? "1" : "0" );
414*cdf0e10cSrcweir     }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     void lcl_writeConfigFlag( FILETYPE _pFile, const sal_Char* _pKeyName, sal_uIntPtr _nAllFlags, sal_uIntPtr _nCheckFlag )
417*cdf0e10cSrcweir     {
418*cdf0e10cSrcweir         lcl_writeConfigBoolean( _pFile, _pKeyName, ( _nAllFlags & _nCheckFlag ) != 0 );
419*cdf0e10cSrcweir     }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir     void lcl_writeConfigOutChannel( FILETYPE _pFile, const sal_Char* _pKeyName, sal_uIntPtr _nValue )
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         const sal_Char* names[ DBG_OUT_COUNT ] =
424*cdf0e10cSrcweir         {
425*cdf0e10cSrcweir             "dev/null", "file", "window", "shell", "messagebox", "testtool", "debugger", "abort"
426*cdf0e10cSrcweir         };
427*cdf0e10cSrcweir         lcl_writeConfigString( _pFile, _pKeyName, names[ _nValue ] );
428*cdf0e10cSrcweir     }
429*cdf0e10cSrcweir     void lcl_writeHexByte( FILETYPE _pFile, const sal_Char* _pKeyName, sal_uInt8 _nValue )
430*cdf0e10cSrcweir     {
431*cdf0e10cSrcweir         sal_Char buf[RTL_STR_MAX_VALUEOFINT32];
432*cdf0e10cSrcweir         rtl_String* stringData = NULL;
433*cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &stringData, buf, rtl_str_valueOfInt32( buf, _nValue, 16 ) );
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir         lcl_writeConfigString( _pFile, _pKeyName, stringData->buffer );
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         rtl_string_release( stringData );
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir     bool lcl_isConfigSection( const sal_Char* _pLine, size_t _nLineLen )
440*cdf0e10cSrcweir     {
441*cdf0e10cSrcweir         if ( _nLineLen < 2 )
442*cdf0e10cSrcweir             // not even enough space for '[' and ']'
443*cdf0e10cSrcweir             return false;
444*cdf0e10cSrcweir         if ( ( _pLine[0] == '[' ) && ( _pLine[ _nLineLen - 1 ] == ']' ) )
445*cdf0e10cSrcweir             return true;
446*cdf0e10cSrcweir         return false;
447*cdf0e10cSrcweir     }
448*cdf0e10cSrcweir     bool lcl_isConfigKey( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName )
449*cdf0e10cSrcweir     {
450*cdf0e10cSrcweir         size_t nKeyLength = strlen( _pKeyName );
451*cdf0e10cSrcweir         if ( nKeyLength + 1 >= _nLineLen )
452*cdf0e10cSrcweir             // not even long enough for the key name plus "=" plus a one-character value
453*cdf0e10cSrcweir             return false;
454*cdf0e10cSrcweir         if ( ( strncmp( _pLine, _pKeyName, nKeyLength ) == 0 ) && ( _pLine[ nKeyLength ] == '=' ) )
455*cdf0e10cSrcweir             return true;
456*cdf0e10cSrcweir         return false;
457*cdf0e10cSrcweir     }
458*cdf0e10cSrcweir     sal_Int32 lcl_tryReadConfigString( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_Char* _pValue, size_t _nValueLen )
459*cdf0e10cSrcweir     {
460*cdf0e10cSrcweir         if ( !lcl_isConfigKey( _pLine, _nLineLen, _pKeyName ) )
461*cdf0e10cSrcweir             return 0;
462*cdf0e10cSrcweir         size_t nValuePos = strlen( _pKeyName ) + 1;
463*cdf0e10cSrcweir         size_t nValueLen = _nLineLen - nValuePos;
464*cdf0e10cSrcweir         const sal_Char* pValue = _pLine + nValuePos;
465*cdf0e10cSrcweir         strncpy( _pValue, pValue, ( _nValueLen > nValueLen ) ? nValueLen : _nValueLen );
466*cdf0e10cSrcweir         _pValue[ ( _nValueLen > nValueLen ) ? nValueLen : _nValueLen - 1 ] = 0;
467*cdf0e10cSrcweir         return strlen( _pValue );
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir     void lcl_tryReadConfigBoolean( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uIntPtr* _out_pnValue )
470*cdf0e10cSrcweir     {
471*cdf0e10cSrcweir         sal_Char aBuf[2];
472*cdf0e10cSrcweir         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
473*cdf0e10cSrcweir         if ( nValueLen )
474*cdf0e10cSrcweir             *_out_pnValue = strcmp( aBuf, "1" ) == 0 ? sal_True : sal_False;
475*cdf0e10cSrcweir     }
476*cdf0e10cSrcweir     void lcl_matchOutputChannel( sal_Char const * i_buffer, sal_uIntPtr* o_value )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         if ( i_buffer == NULL )
479*cdf0e10cSrcweir             return;
480*cdf0e10cSrcweir         const sal_Char* names[ DBG_OUT_COUNT ] =
481*cdf0e10cSrcweir         {
482*cdf0e10cSrcweir             "dev/null", "file", "window", "shell", "messagebox", "testtool", "debugger", "abort"
483*cdf0e10cSrcweir         };
484*cdf0e10cSrcweir         for ( sal_uIntPtr name = 0; name < sizeof( names ) / sizeof( names[0] ); ++name )
485*cdf0e10cSrcweir         {
486*cdf0e10cSrcweir             if ( strcmp( i_buffer, names[ name ] ) == 0 )
487*cdf0e10cSrcweir             {
488*cdf0e10cSrcweir                 *o_value = name;
489*cdf0e10cSrcweir                 return;
490*cdf0e10cSrcweir             }
491*cdf0e10cSrcweir         }
492*cdf0e10cSrcweir     }
493*cdf0e10cSrcweir     void lcl_tryReadOutputChannel( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uIntPtr* _out_pnValue )
494*cdf0e10cSrcweir     {
495*cdf0e10cSrcweir         sal_Char aBuf[20];
496*cdf0e10cSrcweir         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
497*cdf0e10cSrcweir         if ( nValueLen )
498*cdf0e10cSrcweir             lcl_matchOutputChannel( aBuf, _out_pnValue );
499*cdf0e10cSrcweir     }
500*cdf0e10cSrcweir     void lcl_tryReadConfigFlag( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uIntPtr* _out_pnAllFlags, sal_uIntPtr _nCheckFlag )
501*cdf0e10cSrcweir     {
502*cdf0e10cSrcweir         sal_Char aBuf[2];
503*cdf0e10cSrcweir         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
504*cdf0e10cSrcweir         if ( nValueLen )
505*cdf0e10cSrcweir             if ( strcmp( aBuf, "1" ) == 0 )
506*cdf0e10cSrcweir                 *_out_pnAllFlags |= _nCheckFlag;
507*cdf0e10cSrcweir             else
508*cdf0e10cSrcweir                 *_out_pnAllFlags &= ~_nCheckFlag;
509*cdf0e10cSrcweir     }
510*cdf0e10cSrcweir     void lcl_tryReadHexByte( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uInt8* _out_pnValue )
511*cdf0e10cSrcweir     {
512*cdf0e10cSrcweir         sal_Char aBuf[3];
513*cdf0e10cSrcweir         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
514*cdf0e10cSrcweir         if ( nValueLen )
515*cdf0e10cSrcweir             *_out_pnValue = (sal_uInt8)rtl_str_toInt32( aBuf, 16 );
516*cdf0e10cSrcweir     }
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir // =======================================================================
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir PointerList::~PointerList()
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir     PBlock* pBlock = pFirst;
524*cdf0e10cSrcweir     while ( pBlock )
525*cdf0e10cSrcweir     {
526*cdf0e10cSrcweir         PBlock* pNextBlock = pBlock->pNext;
527*cdf0e10cSrcweir         delete pBlock;
528*cdf0e10cSrcweir         pBlock = pNextBlock;
529*cdf0e10cSrcweir     }
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir // -----------------------------------------------------------------------
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir void PointerList::Add( const void* p )
535*cdf0e10cSrcweir {
536*cdf0e10cSrcweir     if ( !pFirst )
537*cdf0e10cSrcweir     {
538*cdf0e10cSrcweir         pFirst = new PBlock;
539*cdf0e10cSrcweir         memset( pFirst->aData, 0, PBLOCKCOUNT * sizeof( void* ) );
540*cdf0e10cSrcweir         pFirst->nCount = 0;
541*cdf0e10cSrcweir         pFirst->pPrev  = NULL;
542*cdf0e10cSrcweir         pFirst->pNext  = NULL;
543*cdf0e10cSrcweir         pLast = pFirst;
544*cdf0e10cSrcweir     }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     PBlock* pBlock = pFirst;
547*cdf0e10cSrcweir     while ( pBlock && (pBlock->nCount == PBLOCKCOUNT) )
548*cdf0e10cSrcweir         pBlock = pBlock->pNext;
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir     if ( !pBlock )
551*cdf0e10cSrcweir     {
552*cdf0e10cSrcweir         pBlock = new PBlock;
553*cdf0e10cSrcweir         memset( pBlock->aData, 0, PBLOCKCOUNT * sizeof( void* ) );
554*cdf0e10cSrcweir         pBlock->nCount = 0;
555*cdf0e10cSrcweir         pBlock->pPrev  = pLast;
556*cdf0e10cSrcweir         pBlock->pNext  = NULL;
557*cdf0e10cSrcweir         pLast->pNext   = pBlock;
558*cdf0e10cSrcweir         pLast          = pBlock;
559*cdf0e10cSrcweir     }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir     sal_uInt16 i = 0;
562*cdf0e10cSrcweir     while ( pBlock->aData[i] )
563*cdf0e10cSrcweir         i++;
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir     pBlock->aData[i] = (void*)p;
566*cdf0e10cSrcweir     pBlock->nCount++;
567*cdf0e10cSrcweir     nCount++;
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir // -----------------------------------------------------------------------
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir sal_Bool PointerList::Remove( const void* p )
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir     if ( !p )
575*cdf0e10cSrcweir        return sal_False;
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir     PBlock* pBlock = pFirst;
578*cdf0e10cSrcweir     while ( pBlock )
579*cdf0e10cSrcweir     {
580*cdf0e10cSrcweir         sal_uInt16 i = 0;
581*cdf0e10cSrcweir         while ( i < PBLOCKCOUNT )
582*cdf0e10cSrcweir         {
583*cdf0e10cSrcweir             if ( ((sal_uIntPtr)p) == ((sal_uIntPtr)pBlock->aData[i]) )
584*cdf0e10cSrcweir             {
585*cdf0e10cSrcweir                 pBlock->aData[i] = NULL;
586*cdf0e10cSrcweir                 pBlock->nCount--;
587*cdf0e10cSrcweir                 nCount--;
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir                 if ( !pBlock->nCount )
590*cdf0e10cSrcweir                 {
591*cdf0e10cSrcweir                     if ( pBlock->pPrev )
592*cdf0e10cSrcweir                         pBlock->pPrev->pNext = pBlock->pNext;
593*cdf0e10cSrcweir                     if ( pBlock->pNext )
594*cdf0e10cSrcweir                         pBlock->pNext->pPrev = pBlock->pPrev;
595*cdf0e10cSrcweir                     if ( pBlock == pFirst )
596*cdf0e10cSrcweir                         pFirst = pBlock->pNext;
597*cdf0e10cSrcweir                     if ( pBlock == pLast )
598*cdf0e10cSrcweir                         pLast = pBlock->pPrev;
599*cdf0e10cSrcweir                     delete pBlock;
600*cdf0e10cSrcweir                 }
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir                 return sal_True;
603*cdf0e10cSrcweir             }
604*cdf0e10cSrcweir             i++;
605*cdf0e10cSrcweir         }
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir         pBlock = pBlock->pNext;
608*cdf0e10cSrcweir     }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir     return sal_False;
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir // -----------------------------------------------------------------------
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir const void* PointerList::Get( sal_uIntPtr nPos ) const
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir     if ( nCount <= nPos )
618*cdf0e10cSrcweir         return NULL;
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     PBlock* pBlock = pFirst;
621*cdf0e10cSrcweir     sal_uIntPtr   nStart = 0;
622*cdf0e10cSrcweir     while ( pBlock )
623*cdf0e10cSrcweir     {
624*cdf0e10cSrcweir         sal_uInt16 i = 0;
625*cdf0e10cSrcweir         while ( i < PBLOCKCOUNT )
626*cdf0e10cSrcweir         {
627*cdf0e10cSrcweir             if ( pBlock->aData[i] )
628*cdf0e10cSrcweir             {
629*cdf0e10cSrcweir                 nStart++;
630*cdf0e10cSrcweir                 if ( (nStart-1) == nPos )
631*cdf0e10cSrcweir                     return pBlock->aData[i];
632*cdf0e10cSrcweir             }
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir             i++;
635*cdf0e10cSrcweir         }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir         pBlock = pBlock->pNext;
638*cdf0e10cSrcweir     }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     return NULL;
641*cdf0e10cSrcweir }
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir // -----------------------------------------------------------------------
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir sal_Bool PointerList::IsIn( const void* p ) const
646*cdf0e10cSrcweir {
647*cdf0e10cSrcweir     if ( !p )
648*cdf0e10cSrcweir        return sal_False;
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir     PBlock* pBlock = pFirst;
651*cdf0e10cSrcweir     while ( pBlock )
652*cdf0e10cSrcweir     {
653*cdf0e10cSrcweir         sal_uInt16 i = 0;
654*cdf0e10cSrcweir         while ( i < PBLOCKCOUNT )
655*cdf0e10cSrcweir         {
656*cdf0e10cSrcweir             if ( ((sal_uIntPtr)p) == ((sal_uIntPtr)pBlock->aData[i]) )
657*cdf0e10cSrcweir                 return sal_True;
658*cdf0e10cSrcweir             i++;
659*cdf0e10cSrcweir         }
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir         pBlock = pBlock->pNext;
662*cdf0e10cSrcweir     }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     return sal_False;
665*cdf0e10cSrcweir }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir // =======================================================================
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir static void DbgGetDbgFileName( sal_Char* pStr, sal_Int32 nMaxLen )
671*cdf0e10cSrcweir {
672*cdf0e10cSrcweir #if defined( UNX )
673*cdf0e10cSrcweir     const sal_Char* pName = getenv("DBGSV_INIT");
674*cdf0e10cSrcweir     if ( !pName )
675*cdf0e10cSrcweir         pName = ".dbgsv.init";
676*cdf0e10cSrcweir     strncpy( pStr, pName, nMaxLen );
677*cdf0e10cSrcweir #elif defined( WNT )
678*cdf0e10cSrcweir     const sal_Char* pName = getenv("DBGSV_INIT");
679*cdf0e10cSrcweir     if ( pName )
680*cdf0e10cSrcweir         strncpy( pStr, pName, nMaxLen );
681*cdf0e10cSrcweir     else
682*cdf0e10cSrcweir         GetProfileStringA( "sv", "dbgsv", "dbgsv.ini", pStr, nMaxLen );
683*cdf0e10cSrcweir #elif defined( OS2 )
684*cdf0e10cSrcweir     PrfQueryProfileString( HINI_PROFILE, (PSZ)"SV", (PSZ)"DBGSV",
685*cdf0e10cSrcweir                            "dbgsv.ini", (PSZ)pStr, nMaxLen );
686*cdf0e10cSrcweir #else
687*cdf0e10cSrcweir     strncpy( pStr, "dbgsv.ini", nMaxLen );
688*cdf0e10cSrcweir #endif
689*cdf0e10cSrcweir     pStr[ nMaxLen - 1 ] = 0;
690*cdf0e10cSrcweir }
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir // -----------------------------------------------------------------------
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir static void DbgGetLogFileName( sal_Char* pStr )
695*cdf0e10cSrcweir {
696*cdf0e10cSrcweir #if defined( UNX )
697*cdf0e10cSrcweir     const sal_Char* pName = getenv("DBGSV_LOG");
698*cdf0e10cSrcweir     if ( !pName )
699*cdf0e10cSrcweir         pName = "dbgsv.log";
700*cdf0e10cSrcweir     strcpy( pStr, pName );
701*cdf0e10cSrcweir #elif defined( WNT )
702*cdf0e10cSrcweir     const sal_Char* pName = getenv("DBGSV_LOG");
703*cdf0e10cSrcweir     if ( pName )
704*cdf0e10cSrcweir         strcpy( pStr, pName );
705*cdf0e10cSrcweir     else
706*cdf0e10cSrcweir         GetProfileStringA( "sv", "dbgsvlog", "dbgsv.log", pStr, 200 );
707*cdf0e10cSrcweir #elif defined( OS2 )
708*cdf0e10cSrcweir     PrfQueryProfileString( HINI_PROFILE, (PSZ)"SV", (PSZ)"DBGSVLOG",
709*cdf0e10cSrcweir                            "dbgsv.log", (PSZ)pStr, 200 );
710*cdf0e10cSrcweir #else
711*cdf0e10cSrcweir     strcpy( pStr, "dbgsv.log" );
712*cdf0e10cSrcweir #endif
713*cdf0e10cSrcweir }
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir // -----------------------------------------------------------------------
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir static void DbgDebugBeep()
718*cdf0e10cSrcweir {
719*cdf0e10cSrcweir #if defined( WNT )
720*cdf0e10cSrcweir     MessageBeep( MB_ICONHAND );
721*cdf0e10cSrcweir #elif defined( OS2 )
722*cdf0e10cSrcweir     WinAlarm( HWND_DESKTOP, WA_ERROR );
723*cdf0e10cSrcweir #endif
724*cdf0e10cSrcweir }
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir // -----------------------------------------------------------------------
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir static DebugData* GetDebugData()
729*cdf0e10cSrcweir {
730*cdf0e10cSrcweir     if ( !aDebugData.bInit )
731*cdf0e10cSrcweir     {
732*cdf0e10cSrcweir         aDebugData.bInit = sal_True;
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir         // Default Debug-Namen setzen
735*cdf0e10cSrcweir         DbgGetLogFileName( aDebugData.aDbgData.aDebugName );
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir         // DEBUG.INI-File
738*cdf0e10cSrcweir         sal_Char aBuf[ 4096 ];
739*cdf0e10cSrcweir         DbgGetDbgFileName( aBuf, sizeof( aBuf ) );
740*cdf0e10cSrcweir         FILETYPE pIniFile = FileOpen( aBuf, "r" );
741*cdf0e10cSrcweir         if ( pIniFile != NULL )
742*cdf0e10cSrcweir         {
743*cdf0e10cSrcweir             ConfigSection eCurrentSection = eUnknown;
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir             // no sophisticated algorithm here, assume that the whole file fits into aBuf ...
746*cdf0e10cSrcweir             sal_uIntPtr nReallyRead = FileRead( aBuf, 1, sizeof( aBuf ) / sizeof( sal_Char ) - 1, pIniFile );
747*cdf0e10cSrcweir             aBuf[ nReallyRead ] = 0;
748*cdf0e10cSrcweir             const sal_Char* pLine = aBuf;
749*cdf0e10cSrcweir             while ( const sal_Char* pNextLine = strstr( pLine, FILE_LINEEND ) )
750*cdf0e10cSrcweir             {
751*cdf0e10cSrcweir                 size_t nLineLength = pNextLine - pLine;
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir                 if ( lcl_isConfigSection( pLine, nLineLength ) )
754*cdf0e10cSrcweir                     eCurrentSection = lcl_getSectionFromName( pLine + 1, nLineLength - 2 );
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir                 // elements of the [output] section
757*cdf0e10cSrcweir                 if ( eCurrentSection == eOutput )
758*cdf0e10cSrcweir                 {
759*cdf0e10cSrcweir                     lcl_tryReadConfigString( pLine, nLineLength, "log_file", aDebugData.aDbgData.aDebugName, sizeof( aDebugData.aDbgData.aDebugName ) );
760*cdf0e10cSrcweir                     lcl_tryReadConfigBoolean( pLine, nLineLength, "overwrite", &aDebugData.aDbgData.bOverwrite );
761*cdf0e10cSrcweir                     lcl_tryReadConfigString( pLine, nLineLength, "include", aDebugData.aDbgData.aInclFilter, sizeof( aDebugData.aDbgData.aInclFilter ) );
762*cdf0e10cSrcweir                     lcl_tryReadConfigString( pLine, nLineLength, "exclude", aDebugData.aDbgData.aExclFilter, sizeof( aDebugData.aDbgData.aExclFilter ) );
763*cdf0e10cSrcweir                     lcl_tryReadConfigString( pLine, nLineLength, "include_class", aDebugData.aDbgData.aInclClassFilter, sizeof( aDebugData.aDbgData.aInclClassFilter ) );
764*cdf0e10cSrcweir                     lcl_tryReadConfigString( pLine, nLineLength, "exclude_class", aDebugData.aDbgData.aExclClassFilter, sizeof( aDebugData.aDbgData.aExclClassFilter ) );
765*cdf0e10cSrcweir                     lcl_tryReadOutputChannel( pLine, nLineLength, "trace", &aDebugData.aDbgData.nTraceOut );
766*cdf0e10cSrcweir                     lcl_tryReadOutputChannel( pLine, nLineLength, "warning", &aDebugData.aDbgData.nWarningOut );
767*cdf0e10cSrcweir                     lcl_tryReadOutputChannel( pLine, nLineLength, "error", &aDebugData.aDbgData.nErrorOut );
768*cdf0e10cSrcweir                     lcl_tryReadConfigBoolean( pLine, nLineLength, "oslhook", &aDebugData.aDbgData.bHookOSLAssert );
769*cdf0e10cSrcweir                 }
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir                 // elements of the [memory] section
772*cdf0e10cSrcweir                 if ( eCurrentSection == eMemory )
773*cdf0e10cSrcweir                 {
774*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "initialize", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_INIT );
775*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "overwrite", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_OVERWRITE );
776*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "overwrite_free", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_OVERWRITEFREE );
777*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "pointer", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_POINTER );
778*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "report", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_REPORT );
779*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "trace", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_TRACE );
780*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "new_and_delete", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_NEWDEL );
781*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "object_test", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_XTOR );
782*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "sys_alloc", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_SYSALLOC );
783*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "leak_report", &aDebugData.aDbgData.nTestFlags, DBG_TEST_MEM_LEAKREPORT );
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir                     lcl_tryReadHexByte( pLine, nLineLength, "init_byte", &aDebugData.aDbgData.bMemInit );
786*cdf0e10cSrcweir                     lcl_tryReadHexByte( pLine, nLineLength, "bound_byte", &aDebugData.aDbgData.bMemBound );
787*cdf0e10cSrcweir                     lcl_tryReadHexByte( pLine, nLineLength, "free_byte", &aDebugData.aDbgData.bMemFree );
788*cdf0e10cSrcweir                 }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir                 // elements of the [gui] section
791*cdf0e10cSrcweir                 if ( eCurrentSection == eGUI )
792*cdf0e10cSrcweir                 {
793*cdf0e10cSrcweir                     lcl_tryReadConfigString( pLine, nLineLength, "debug_window_state", aDebugData.aDbgData.aDbgWinState, sizeof( aDebugData.aDbgData.aDbgWinState ) );
794*cdf0e10cSrcweir                 }
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir                 // elements of the [objects] section
797*cdf0e10cSrcweir                 if ( eCurrentSection == eObjects )
798*cdf0e10cSrcweir                 {
799*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "check_this", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_THIS );
800*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "check_function", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_FUNC );
801*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "check_exit", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_EXIT );
802*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "generate_report", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_REPORT );
803*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "trace", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_TRACE );
804*cdf0e10cSrcweir                 }
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir                 // elements of the [test] section
807*cdf0e10cSrcweir                 if ( eCurrentSection == eTest )
808*cdf0e10cSrcweir                 {
809*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "profiling", &aDebugData.aDbgData.nTestFlags, DBG_TEST_PROFILING );
810*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "resources", &aDebugData.aDbgData.nTestFlags, DBG_TEST_RESOURCE );
811*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "dialog", &aDebugData.aDbgData.nTestFlags, DBG_TEST_DIALOG );
812*cdf0e10cSrcweir                     lcl_tryReadConfigFlag( pLine, nLineLength, "bold_app_font", &aDebugData.aDbgData.nTestFlags, DBG_TEST_BOLDAPPFONT );
813*cdf0e10cSrcweir                 }
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir                 pLine = pNextLine + strlen( FILE_LINEEND );
816*cdf0e10cSrcweir             }
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir             FileClose( pIniFile );
819*cdf0e10cSrcweir         }
820*cdf0e10cSrcweir         else
821*cdf0e10cSrcweir         {
822*cdf0e10cSrcweir             lcl_matchOutputChannel( getenv( "DBGSV_TRACE_OUT" ), &aDebugData.aDbgData.nTraceOut );
823*cdf0e10cSrcweir             lcl_matchOutputChannel( getenv( "DBGSV_WARNING_OUT" ), &aDebugData.aDbgData.nWarningOut );
824*cdf0e10cSrcweir             lcl_matchOutputChannel( getenv( "DBGSV_ERROR_OUT" ), &aDebugData.aDbgData.nErrorOut );
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir         }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir         getcwd( aCurPath, sizeof( aCurPath ) );
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir         // Daten initialisieren
831*cdf0e10cSrcweir         if ( aDebugData.aDbgData.nTestFlags & DBG_TEST_XTOR )
832*cdf0e10cSrcweir             aDebugData.pXtorList = new PointerList;
833*cdf0e10cSrcweir         if ( aDebugData.aDbgData.nTestFlags & DBG_TEST_PROFILING )
834*cdf0e10cSrcweir             aDebugData.pProfList = new PointerList;
835*cdf0e10cSrcweir     }
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir     return &aDebugData;
838*cdf0e10cSrcweir }
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir // -----------------------------------------------------------------------
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir inline DebugData* ImplGetDebugData()
843*cdf0e10cSrcweir {
844*cdf0e10cSrcweir     if ( !aDebugData.bInit )
845*cdf0e10cSrcweir         return GetDebugData();
846*cdf0e10cSrcweir     else
847*cdf0e10cSrcweir         return &aDebugData;
848*cdf0e10cSrcweir }
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir // -----------------------------------------------------------------------
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir static FILETYPE ImplDbgInitFile()
853*cdf0e10cSrcweir {
854*cdf0e10cSrcweir     static sal_Bool bFileInit = sal_False;
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir     sal_Char aBuf[4096];
857*cdf0e10cSrcweir     getcwd( aBuf, sizeof( aBuf ) );
858*cdf0e10cSrcweir     chdir( aCurPath );
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir     DebugData*  pData = GetDebugData();
861*cdf0e10cSrcweir     FILETYPE    pDebugFile;
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir     if ( !bFileInit )
864*cdf0e10cSrcweir     {
865*cdf0e10cSrcweir         bFileInit = sal_True;
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir         if ( pData->aDbgData.bOverwrite )
868*cdf0e10cSrcweir             pDebugFile = FileOpen( pData->aDbgData.aDebugName, "w" );
869*cdf0e10cSrcweir         else
870*cdf0e10cSrcweir             pDebugFile = FileOpen( pData->aDbgData.aDebugName, "a" );
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir         if ( pDebugFile )
873*cdf0e10cSrcweir         {
874*cdf0e10cSrcweir             time_t  nTime = time( 0 );
875*cdf0e10cSrcweir             tm*     pTime;
876*cdf0e10cSrcweir #ifdef UNX
877*cdf0e10cSrcweir             tm      aTime;
878*cdf0e10cSrcweir             pTime = localtime_r( &nTime, &aTime );
879*cdf0e10cSrcweir #else
880*cdf0e10cSrcweir             pTime = localtime( &nTime );
881*cdf0e10cSrcweir #endif
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir             // Header ausgeben
884*cdf0e10cSrcweir             FilePrintF( pDebugFile, "******************************************************************************%s", FILE_LINEEND );
885*cdf0e10cSrcweir             FilePrintF( pDebugFile, "%s%s", pData->aDbgData.aDebugName, FILE_LINEEND );
886*cdf0e10cSrcweir             if ( pTime )
887*cdf0e10cSrcweir                 FilePrintF( pDebugFile, "%s%s", asctime( pTime ), FILE_LINEEND );
888*cdf0e10cSrcweir         }
889*cdf0e10cSrcweir     }
890*cdf0e10cSrcweir     else
891*cdf0e10cSrcweir         pDebugFile = FileOpen( pData->aDbgData.aDebugName, "a" );
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir     chdir( aBuf );
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir     return pDebugFile;
896*cdf0e10cSrcweir }
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir // -----------------------------------------------------------------------
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir static void ImplDbgPrintFile( const sal_Char* pLine )
901*cdf0e10cSrcweir {
902*cdf0e10cSrcweir     FILETYPE pDebugFile = ImplDbgInitFile();
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir     if ( pDebugFile )
905*cdf0e10cSrcweir     {
906*cdf0e10cSrcweir         FilePrintF( pDebugFile, "%s%s", pLine, FILE_LINEEND );
907*cdf0e10cSrcweir         FileClose( pDebugFile );
908*cdf0e10cSrcweir     }
909*cdf0e10cSrcweir }
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir // -----------------------------------------------------------------------
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir static int ImplStrSearch( const sal_Char* pSearchStr, int nSearchLen,
914*cdf0e10cSrcweir                           const sal_Char* pStr, int nLen )
915*cdf0e10cSrcweir {
916*cdf0e10cSrcweir     int nPos = 0;
917*cdf0e10cSrcweir     while ( nPos+nSearchLen <= nLen )
918*cdf0e10cSrcweir     {
919*cdf0e10cSrcweir         if ( strncmp( pStr+nPos, pSearchStr, nSearchLen ) == 0 )
920*cdf0e10cSrcweir             return 1;
921*cdf0e10cSrcweir         nPos++;
922*cdf0e10cSrcweir     }
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir     return 0;
925*cdf0e10cSrcweir }
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir // -----------------------------------------------------------------------
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir static int ImplDbgFilter( const sal_Char* pFilter, const sal_Char* pMsg,
930*cdf0e10cSrcweir                           int bEmpty )
931*cdf0e10cSrcweir {
932*cdf0e10cSrcweir     int nStrLen = strlen( pFilter );
933*cdf0e10cSrcweir     if ( !nStrLen )
934*cdf0e10cSrcweir         return bEmpty;
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir     int nMsgLen = strlen( pMsg );
937*cdf0e10cSrcweir     const sal_Char* pTok = pFilter;
938*cdf0e10cSrcweir     int         nTok = 0;
939*cdf0e10cSrcweir     while ( pTok[nTok] )
940*cdf0e10cSrcweir     {
941*cdf0e10cSrcweir         if ( pTok[nTok] == ';' )
942*cdf0e10cSrcweir         {
943*cdf0e10cSrcweir             if ( nTok && ImplStrSearch( pTok, nTok, pMsg, nMsgLen ) )
944*cdf0e10cSrcweir                 return sal_True;
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir             pTok += nTok+1;
947*cdf0e10cSrcweir             nTok = 0;
948*cdf0e10cSrcweir         }
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir         nTok++;
951*cdf0e10cSrcweir     }
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir     if ( nTok && ImplStrSearch( pTok, nTok, pMsg, nMsgLen ) )
954*cdf0e10cSrcweir         return sal_True;
955*cdf0e10cSrcweir     else
956*cdf0e10cSrcweir         return sal_False;
957*cdf0e10cSrcweir }
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir // -----------------------------------------------------------------------
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir extern "C"
962*cdf0e10cSrcweir void SAL_CALL dbg_printOslDebugMessage( const sal_Char * pszFileName, sal_Int32 nLine, const sal_Char * pszMessage )
963*cdf0e10cSrcweir {
964*cdf0e10cSrcweir     DbgOut( pszMessage ? pszMessage : "assertion failed!", DBG_OUT_ERROR, pszFileName, (sal_uInt16)nLine );
965*cdf0e10cSrcweir }
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir // -----------------------------------------------------------------------
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir static void DebugInit()
970*cdf0e10cSrcweir {
971*cdf0e10cSrcweir     bDbgImplInMain = sal_True;
972*cdf0e10cSrcweir     ImplDbgInitLock();
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir     DebugData* pData = GetDebugData();
975*cdf0e10cSrcweir     if( pData->aDbgData.bHookOSLAssert && ! pData->bOslIsHooked )
976*cdf0e10cSrcweir     {
977*cdf0e10cSrcweir         pData->pOldDebugMessageFunc = osl_setDetailedDebugMessageFunc( &dbg_printOslDebugMessage );
978*cdf0e10cSrcweir         pData->bOslIsHooked = true;
979*cdf0e10cSrcweir     }
980*cdf0e10cSrcweir }
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir // -----------------------------------------------------------------------
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir static void DebugDeInit()
985*cdf0e10cSrcweir {
986*cdf0e10cSrcweir     DebugData*  pData = GetDebugData();
987*cdf0e10cSrcweir     sal_uIntPtr       i;
988*cdf0e10cSrcweir     sal_uIntPtr       nCount;
989*cdf0e10cSrcweir     sal_uIntPtr       nOldOut;
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir     if( pData->bOslIsHooked )
992*cdf0e10cSrcweir     {
993*cdf0e10cSrcweir         osl_setDetailedDebugMessageFunc( pData->pOldDebugMessageFunc );
994*cdf0e10cSrcweir         pData->bOslIsHooked = sal_False;
995*cdf0e10cSrcweir     }
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir     // Statistik-Ausgaben immer in File
998*cdf0e10cSrcweir     nOldOut = pData->aDbgData.nTraceOut;
999*cdf0e10cSrcweir     pData->aDbgData.nTraceOut = DBG_OUT_FILE;
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     // Xtor-Liste ausgeben
1002*cdf0e10cSrcweir     if ( pData->pXtorList && pData->pXtorList->Count() &&
1003*cdf0e10cSrcweir          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_REPORT) )
1004*cdf0e10cSrcweir     {
1005*cdf0e10cSrcweir         DbgOutf( "------------------------------------------------------------------------------" );
1006*cdf0e10cSrcweir         DbgOutf( "Object Report" );
1007*cdf0e10cSrcweir         DbgOutf( "------------------------------------------------------------------------------" );
1008*cdf0e10cSrcweir         DbgOutf( "%-27s : %-9s : %-9s : %-7s : %-3s : %-6s :",
1009*cdf0e10cSrcweir                  "XTor-List", "Ctor", "Dtor", "MaxInst", "St.", "Diff." );
1010*cdf0e10cSrcweir         DbgOutf( "----------------------------:-----------:-----------:---------:----:---------:" );
1011*cdf0e10cSrcweir         for( i = 0, nCount = pData->pXtorList->Count(); i < nCount; i++ )
1012*cdf0e10cSrcweir         {
1013*cdf0e10cSrcweir             XtorType* pXtorData = (XtorType*)pData->pXtorList->Get( i );
1014*cdf0e10cSrcweir             if ( pXtorData->bTest )
1015*cdf0e10cSrcweir             {
1016*cdf0e10cSrcweir                 // Static-Objekte dazurechnen
1017*cdf0e10cSrcweir                 pXtorData->nDtorCalls += pXtorData->nStatics;
1018*cdf0e10cSrcweir                 if ( pXtorData->nStatics && (pXtorData->nDtorCalls > pXtorData->nCtorCalls) )
1019*cdf0e10cSrcweir                     pXtorData->nDtorCalls = pXtorData->nCtorCalls;
1020*cdf0e10cSrcweir                 DbgOutf( "%-27s : %9lu : %9lu : %7lu : %3lu : %4lu %-1s :",
1021*cdf0e10cSrcweir                          pXtorData->aName, pXtorData->nCtorCalls, pXtorData->nDtorCalls,
1022*cdf0e10cSrcweir                          pXtorData->nMaxCount, pXtorData->nStatics,
1023*cdf0e10cSrcweir                          pXtorData->nCtorCalls - pXtorData->nDtorCalls,
1024*cdf0e10cSrcweir                          (pXtorData->nCtorCalls - pXtorData->nDtorCalls) ? "!" : " " );
1025*cdf0e10cSrcweir             }
1026*cdf0e10cSrcweir         }
1027*cdf0e10cSrcweir         DbgOutf( "==============================================================================" );
1028*cdf0e10cSrcweir     }
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir     // Aufraeumen
1031*cdf0e10cSrcweir     if ( pData->pXtorList )
1032*cdf0e10cSrcweir     {
1033*cdf0e10cSrcweir         for( i = 0, nCount = pData->pXtorList->Count(); i < nCount; i++ )
1034*cdf0e10cSrcweir         {
1035*cdf0e10cSrcweir             XtorType* pXtorData = (XtorType*)pData->pXtorList->Get( i );
1036*cdf0e10cSrcweir             delete pXtorData;
1037*cdf0e10cSrcweir         }
1038*cdf0e10cSrcweir         delete pData->pXtorList;
1039*cdf0e10cSrcweir         pData->pXtorList = NULL;
1040*cdf0e10cSrcweir     }
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir     // Alles auf sal_False setzen, damit globale Variablen nicht das
1043*cdf0e10cSrcweir     // System zum Abstuerzen bringt. Dabei muessen aber die
1044*cdf0e10cSrcweir     // Memory-Flags erhalten bleiben, da sonst new/delete in globalen
1045*cdf0e10cSrcweir     // Variablen abstuerzen, da die Pointeranpassung dann nicht mehr richtig
1046*cdf0e10cSrcweir     // funktioniert
1047*cdf0e10cSrcweir     pData->aDbgData.nTraceOut   = nOldOut;
1048*cdf0e10cSrcweir     pData->aDbgData.nTestFlags &= (DBG_TEST_MEM | DBG_TEST_PROFILING);
1049*cdf0e10cSrcweir     pData->aDbgPrintUserChannels.clear();
1050*cdf0e10cSrcweir     pData->pDbgPrintTestTool    = NULL;
1051*cdf0e10cSrcweir     pData->pDbgPrintWindow      = NULL;
1052*cdf0e10cSrcweir     pData->pOldDebugMessageFunc = NULL;
1053*cdf0e10cSrcweir     ImplDbgDeInitLock();
1054*cdf0e10cSrcweir }
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir // -----------------------------------------------------------------------
1057*cdf0e10cSrcweir 
1058*cdf0e10cSrcweir static void DebugGlobalDeInit()
1059*cdf0e10cSrcweir {
1060*cdf0e10cSrcweir     DebugData*  pData = GetDebugData();
1061*cdf0e10cSrcweir     sal_uIntPtr       i;
1062*cdf0e10cSrcweir     sal_uIntPtr       nCount;
1063*cdf0e10cSrcweir     sal_uIntPtr       nOldOut;
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir     // Statistik-Ausgaben immer in File
1066*cdf0e10cSrcweir     nOldOut = pData->aDbgData.nTraceOut;
1067*cdf0e10cSrcweir     pData->aDbgData.nTraceOut = DBG_OUT_FILE;
1068*cdf0e10cSrcweir 
1069*cdf0e10cSrcweir     // Profileliste ausgeben
1070*cdf0e10cSrcweir     if ( pData->pProfList && pData->pProfList->Count() )
1071*cdf0e10cSrcweir     {
1072*cdf0e10cSrcweir         DbgOutf( "------------------------------------------------------------------------------" );
1073*cdf0e10cSrcweir         DbgOutf( "Profiling Report" );
1074*cdf0e10cSrcweir         DbgOutf( "------------------------------------------------------------------------------" );
1075*cdf0e10cSrcweir         DbgOutf( "%-25s : %-9s : %-6s : %-6s : %-6s : %-9s :",
1076*cdf0e10cSrcweir                  "Prof-List (ms)", "Time", "Min", "Max", "Ave", "Count" );
1077*cdf0e10cSrcweir         DbgOutf( "--------------------------:-----------:--------:--------:--------:-----------:" );
1078*cdf0e10cSrcweir         for( i = 0, nCount = pData->pProfList->Count(); i < nCount; i++ )
1079*cdf0e10cSrcweir         {
1080*cdf0e10cSrcweir             ProfType* pProfData = (ProfType*)pData->pProfList->Get( i );
1081*cdf0e10cSrcweir             sal_uIntPtr nAve = pProfData->nTime / pProfData->nCount;
1082*cdf0e10cSrcweir             DbgOutf( "%-25s : %9lu : %6lu : %6lu : %6lu : %9lu :",
1083*cdf0e10cSrcweir                      pProfData->aName, pProfData->nTime,
1084*cdf0e10cSrcweir                      pProfData->nMinTime, pProfData->nMaxTime, nAve,
1085*cdf0e10cSrcweir                      pProfData->nCount );
1086*cdf0e10cSrcweir         }
1087*cdf0e10cSrcweir         DbgOutf( "==============================================================================" );
1088*cdf0e10cSrcweir     }
1089*cdf0e10cSrcweir 
1090*cdf0e10cSrcweir     // Aufraeumen
1091*cdf0e10cSrcweir     if ( pData->pProfList )
1092*cdf0e10cSrcweir     {
1093*cdf0e10cSrcweir         for( i = 0, nCount = pData->pProfList->Count(); i < nCount; i++ )
1094*cdf0e10cSrcweir         {
1095*cdf0e10cSrcweir             ProfType* pProfData = (ProfType*)pData->pProfList->Get( i );
1096*cdf0e10cSrcweir             delete pProfData;
1097*cdf0e10cSrcweir         }
1098*cdf0e10cSrcweir         delete pData->pProfList;
1099*cdf0e10cSrcweir         pData->pProfList = NULL;
1100*cdf0e10cSrcweir     }
1101*cdf0e10cSrcweir 
1102*cdf0e10cSrcweir #ifdef SV_MEMMGR
1103*cdf0e10cSrcweir     DbgImpCheckMemoryDeInit();
1104*cdf0e10cSrcweir #endif
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir     // Profiling-Flags ausschalten
1107*cdf0e10cSrcweir     pData->aDbgData.nTraceOut   = nOldOut;
1108*cdf0e10cSrcweir     pData->aDbgData.nTestFlags &= ~DBG_TEST_PROFILING;
1109*cdf0e10cSrcweir }
1110*cdf0e10cSrcweir 
1111*cdf0e10cSrcweir // -----------------------------------------------------------------------
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir void ImpDbgOutfBuf( sal_Char* pBuf, const sal_Char* pFStr, ... )
1114*cdf0e10cSrcweir {
1115*cdf0e10cSrcweir     va_list pList;
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir     va_start( pList, pFStr );
1118*cdf0e10cSrcweir     sal_Char aBuf[DBG_BUF_MAXLEN];
1119*cdf0e10cSrcweir     vsprintf( aBuf, pFStr, pList );
1120*cdf0e10cSrcweir     va_end( pList );
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir     strcat( pBuf, aBuf );
1123*cdf0e10cSrcweir     strcat( pBuf, "\n" );
1124*cdf0e10cSrcweir }
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir // -----------------------------------------------------------------------
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir static void DebugXTorInfo( sal_Char* pBuf )
1129*cdf0e10cSrcweir {
1130*cdf0e10cSrcweir     DebugData*  pData = GetDebugData();
1131*cdf0e10cSrcweir     sal_uIntPtr       i;
1132*cdf0e10cSrcweir     sal_uIntPtr       nCount;
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir     // Xtor-Liste ausgeben
1135*cdf0e10cSrcweir     if ( pData->pXtorList && pData->pXtorList->Count() &&
1136*cdf0e10cSrcweir          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_REPORT) )
1137*cdf0e10cSrcweir     {
1138*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "------------------------------------------------------------------------------" );
1139*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "Object Report" );
1140*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "------------------------------------------------------------------------------" );
1141*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "%-27s : %-9s : %-9s : %-7s : %-3s : %-6s :",
1142*cdf0e10cSrcweir                        "XTor-List", "Ctor", "Dtor", "MaxInst", "St.", "Diff." );
1143*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "----------------------------:-----------:-----------:---------:----:---------:" );
1144*cdf0e10cSrcweir         for( i = 0, nCount = pData->pXtorList->Count(); i < nCount; i++ )
1145*cdf0e10cSrcweir         {
1146*cdf0e10cSrcweir             XtorType* pXtorData = (XtorType*)pData->pXtorList->Get( i );
1147*cdf0e10cSrcweir             if ( pXtorData->bTest )
1148*cdf0e10cSrcweir             {
1149*cdf0e10cSrcweir                 ImpDbgOutfBuf( pBuf, "%-27s : %9lu : %9lu : %7lu : %3lu : %6lu :",
1150*cdf0e10cSrcweir                                pXtorData->aName, pXtorData->nCtorCalls, pXtorData->nDtorCalls,
1151*cdf0e10cSrcweir                                pXtorData->nMaxCount, pXtorData->nStatics,
1152*cdf0e10cSrcweir                                pXtorData->nCtorCalls - pXtorData->nDtorCalls );
1153*cdf0e10cSrcweir             }
1154*cdf0e10cSrcweir         }
1155*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "==============================================================================" );
1156*cdf0e10cSrcweir         ImpDbgOutfBuf( pBuf, "" );
1157*cdf0e10cSrcweir     }
1158*cdf0e10cSrcweir }
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir // -----------------------------------------------------------------------
1161*cdf0e10cSrcweir sal_Bool ImplDbgFilterMessage( const sal_Char* pMsg )
1162*cdf0e10cSrcweir {
1163*cdf0e10cSrcweir     DebugData*  pData = GetDebugData();
1164*cdf0e10cSrcweir     if ( !ImplDbgFilter( pData->aDbgData.aInclFilter, pMsg, sal_True ) )
1165*cdf0e10cSrcweir         return sal_True;
1166*cdf0e10cSrcweir     if ( ImplDbgFilter( pData->aDbgData.aExclFilter, pMsg, sal_False ) )
1167*cdf0e10cSrcweir         return sal_True;
1168*cdf0e10cSrcweir     return sal_False;
1169*cdf0e10cSrcweir }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir // -----------------------------------------------------------------------
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir void* DbgFunc( sal_uInt16 nAction, void* pParam )
1174*cdf0e10cSrcweir {
1175*cdf0e10cSrcweir     DebugData* pDebugData = ImplGetDebugData();
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir     if ( nAction == DBG_FUNC_GETDATA )
1178*cdf0e10cSrcweir         return (void*)&(pDebugData->aDbgData);
1179*cdf0e10cSrcweir     else if ( nAction == DBG_FUNC_GETPRINTMSGBOX )
1180*cdf0e10cSrcweir         return (void*)(long)(pDebugData->pDbgPrintMsgBox);
1181*cdf0e10cSrcweir     else if ( nAction == DBG_FUNC_FILTERMESSAGE )
1182*cdf0e10cSrcweir         if ( ImplDbgFilterMessage( (const sal_Char*) pParam ) )
1183*cdf0e10cSrcweir             return (void*) -1;
1184*cdf0e10cSrcweir         else
1185*cdf0e10cSrcweir             return (void*) 0;   // aka NULL
1186*cdf0e10cSrcweir     else
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir     {
1189*cdf0e10cSrcweir         switch ( nAction )
1190*cdf0e10cSrcweir         {
1191*cdf0e10cSrcweir             case DBG_FUNC_DEBUGSTART:
1192*cdf0e10cSrcweir                 DebugInit();
1193*cdf0e10cSrcweir                 break;
1194*cdf0e10cSrcweir 
1195*cdf0e10cSrcweir             case DBG_FUNC_DEBUGEND:
1196*cdf0e10cSrcweir                 DebugDeInit();
1197*cdf0e10cSrcweir                 break;
1198*cdf0e10cSrcweir 
1199*cdf0e10cSrcweir             case DBG_FUNC_GLOBALDEBUGEND:
1200*cdf0e10cSrcweir                 DebugGlobalDeInit();
1201*cdf0e10cSrcweir                 break;
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir             case DBG_FUNC_SETPRINTMSGBOX:
1204*cdf0e10cSrcweir                 pDebugData->pDbgPrintMsgBox = (DbgPrintLine)(long)pParam;
1205*cdf0e10cSrcweir                 break;
1206*cdf0e10cSrcweir 
1207*cdf0e10cSrcweir             case DBG_FUNC_SETPRINTWINDOW:
1208*cdf0e10cSrcweir                 pDebugData->pDbgPrintWindow = (DbgPrintLine)(long)pParam;
1209*cdf0e10cSrcweir                 break;
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir             case DBG_FUNC_SETPRINTTESTTOOL:
1212*cdf0e10cSrcweir                 pDebugData->pDbgPrintTestTool = (DbgPrintLine)(long)pParam;
1213*cdf0e10cSrcweir                 break;
1214*cdf0e10cSrcweir 
1215*cdf0e10cSrcweir             case DBG_FUNC_SET_ABORT:
1216*cdf0e10cSrcweir                 pDebugData->pDbgAbort = (DbgPrintLine)(long)pParam;
1217*cdf0e10cSrcweir                 break;
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir             case DBG_FUNC_SAVEDATA:
1220*cdf0e10cSrcweir                 {
1221*cdf0e10cSrcweir                 const DbgData* pData = static_cast< const DbgData* >( pParam );
1222*cdf0e10cSrcweir 
1223*cdf0e10cSrcweir                 sal_Char aBuf[ 4096 ];
1224*cdf0e10cSrcweir                 DbgGetDbgFileName( aBuf, sizeof( aBuf ) );
1225*cdf0e10cSrcweir                 FILETYPE pIniFile = FileOpen( aBuf, "w" );
1226*cdf0e10cSrcweir                 if ( pIniFile == NULL )
1227*cdf0e10cSrcweir                     break;
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir                 lcl_startSection( pIniFile, eOutput );
1230*cdf0e10cSrcweir                 lcl_writeConfigString( pIniFile, "log_file", pData->aDebugName );
1231*cdf0e10cSrcweir                 lcl_writeConfigBoolean( pIniFile, "overwrite", pData->bOverwrite );
1232*cdf0e10cSrcweir                 lcl_writeConfigString( pIniFile, "include", pData->aInclFilter );
1233*cdf0e10cSrcweir                 lcl_writeConfigString( pIniFile, "exclude", pData->aExclFilter );
1234*cdf0e10cSrcweir                 lcl_writeConfigString( pIniFile, "include_class", pData->aInclClassFilter );
1235*cdf0e10cSrcweir                 lcl_writeConfigString( pIniFile, "exclude_class", pData->aExclClassFilter );
1236*cdf0e10cSrcweir                 lcl_writeConfigOutChannel( pIniFile, "trace", pData->nTraceOut );
1237*cdf0e10cSrcweir                 lcl_writeConfigOutChannel( pIniFile, "warning", pData->nWarningOut );
1238*cdf0e10cSrcweir                 lcl_writeConfigOutChannel( pIniFile, "error", pData->nErrorOut );
1239*cdf0e10cSrcweir                 lcl_writeConfigBoolean( pIniFile, "oslhook", pData->bHookOSLAssert );
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir                 lcl_lineFeed( pIniFile );
1242*cdf0e10cSrcweir                 lcl_startSection( pIniFile, eMemory );
1243*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "initialize", pData->nTestFlags, DBG_TEST_MEM_INIT );
1244*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "overwrite", pData->nTestFlags, DBG_TEST_MEM_OVERWRITE );
1245*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "overwrite_free", pData->nTestFlags, DBG_TEST_MEM_OVERWRITEFREE );
1246*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "pointer", pData->nTestFlags, DBG_TEST_MEM_POINTER );
1247*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "report", pData->nTestFlags, DBG_TEST_MEM_REPORT );
1248*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "trace", pData->nTestFlags, DBG_TEST_MEM_TRACE );
1249*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "new_and_delete", pData->nTestFlags, DBG_TEST_MEM_NEWDEL );
1250*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "object_test", pData->nTestFlags, DBG_TEST_MEM_XTOR );
1251*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "sys_alloc", pData->nTestFlags, DBG_TEST_MEM_SYSALLOC );
1252*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "leak_report", pData->nTestFlags, DBG_TEST_MEM_LEAKREPORT );
1253*cdf0e10cSrcweir 
1254*cdf0e10cSrcweir                 lcl_lineFeed( pIniFile );
1255*cdf0e10cSrcweir                 lcl_writeHexByte( pIniFile, "init_byte", pData->bMemInit );
1256*cdf0e10cSrcweir                 lcl_writeHexByte( pIniFile, "bound_byte", pData->bMemBound );
1257*cdf0e10cSrcweir                 lcl_writeHexByte( pIniFile, "free_byte", pData->bMemFree );
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir                 lcl_lineFeed( pIniFile );
1260*cdf0e10cSrcweir                 lcl_startSection( pIniFile, eGUI );
1261*cdf0e10cSrcweir                 lcl_writeConfigString( pIniFile, "debug_window_state", pData->aDbgWinState );
1262*cdf0e10cSrcweir 
1263*cdf0e10cSrcweir                 lcl_lineFeed( pIniFile );
1264*cdf0e10cSrcweir                 lcl_startSection( pIniFile, eObjects );
1265*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "check_this", pData->nTestFlags, DBG_TEST_XTOR_THIS );
1266*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "check_function", pData->nTestFlags, DBG_TEST_XTOR_FUNC );
1267*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "check_exit", pData->nTestFlags, DBG_TEST_XTOR_EXIT );
1268*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "generate_report", pData->nTestFlags, DBG_TEST_XTOR_REPORT );
1269*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "trace", pData->nTestFlags, DBG_TEST_XTOR_TRACE );
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir                 lcl_lineFeed( pIniFile );
1272*cdf0e10cSrcweir                 lcl_startSection( pIniFile, eTest );
1273*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "profiling", pData->nTestFlags, DBG_TEST_PROFILING );
1274*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "resources", pData->nTestFlags, DBG_TEST_RESOURCE );
1275*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "dialog", pData->nTestFlags, DBG_TEST_DIALOG );
1276*cdf0e10cSrcweir                 lcl_writeConfigFlag( pIniFile, "bold_app_font", pData->nTestFlags, DBG_TEST_BOLDAPPFONT );
1277*cdf0e10cSrcweir 
1278*cdf0e10cSrcweir                 FileClose( pIniFile );
1279*cdf0e10cSrcweir                 }
1280*cdf0e10cSrcweir                 break;
1281*cdf0e10cSrcweir 
1282*cdf0e10cSrcweir             case DBG_FUNC_MEMTEST:
1283*cdf0e10cSrcweir #ifdef SV_MEMMGR
1284*cdf0e10cSrcweir                 DbgImpCheckMemory( pParam );
1285*cdf0e10cSrcweir #endif
1286*cdf0e10cSrcweir                 break;
1287*cdf0e10cSrcweir 
1288*cdf0e10cSrcweir             case DBG_FUNC_XTORINFO:
1289*cdf0e10cSrcweir                 DebugXTorInfo( (sal_Char*)pParam );
1290*cdf0e10cSrcweir                 break;
1291*cdf0e10cSrcweir 
1292*cdf0e10cSrcweir             case DBG_FUNC_MEMINFO:
1293*cdf0e10cSrcweir #ifdef SV_MEMMGR
1294*cdf0e10cSrcweir                 DbgImpMemoryInfo( (sal_Char*)pParam );
1295*cdf0e10cSrcweir #endif
1296*cdf0e10cSrcweir                 break;
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir             case DBG_FUNC_COREDUMP:
1299*cdf0e10cSrcweir                 ImplCoreDump();
1300*cdf0e10cSrcweir                 break;
1301*cdf0e10cSrcweir 
1302*cdf0e10cSrcweir             case DBG_FUNC_ALLERROROUT:
1303*cdf0e10cSrcweir                 return (void*)(sal_uIntPtr)sal_True;
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir             case DBG_FUNC_SETTESTSOLARMUTEX:
1306*cdf0e10cSrcweir                 pDebugData->pDbgTestSolarMutex = (DbgTestSolarMutexProc)(long)pParam;
1307*cdf0e10cSrcweir                 break;
1308*cdf0e10cSrcweir 
1309*cdf0e10cSrcweir             case DBG_FUNC_TESTSOLARMUTEX:
1310*cdf0e10cSrcweir                 if ( pDebugData->pDbgTestSolarMutex )
1311*cdf0e10cSrcweir                     pDebugData->pDbgTestSolarMutex();
1312*cdf0e10cSrcweir                 break;
1313*cdf0e10cSrcweir 
1314*cdf0e10cSrcweir             case DBG_FUNC_PRINTFILE:
1315*cdf0e10cSrcweir                 ImplDbgPrintFile( (const sal_Char*)pParam );
1316*cdf0e10cSrcweir                 break;
1317*cdf0e10cSrcweir             case DBG_FUNC_UPDATEOSLHOOK:
1318*cdf0e10cSrcweir             {
1319*cdf0e10cSrcweir                 const DbgData* pData = static_cast< const DbgData* >( pParam );
1320*cdf0e10cSrcweir                 pDebugData->aDbgData.bHookOSLAssert = pData->bHookOSLAssert;
1321*cdf0e10cSrcweir                 if( pDebugData->bOslIsHooked && ! pData->bHookOSLAssert )
1322*cdf0e10cSrcweir                 {
1323*cdf0e10cSrcweir                     osl_setDetailedDebugMessageFunc( pDebugData->pOldDebugMessageFunc );
1324*cdf0e10cSrcweir                     pDebugData->bOslIsHooked = sal_False;
1325*cdf0e10cSrcweir                 }
1326*cdf0e10cSrcweir                 else if( ! pDebugData->bOslIsHooked && pData->bHookOSLAssert )
1327*cdf0e10cSrcweir                 {
1328*cdf0e10cSrcweir                     pDebugData->pOldDebugMessageFunc = osl_setDetailedDebugMessageFunc( &dbg_printOslDebugMessage );
1329*cdf0e10cSrcweir                     pDebugData->bOslIsHooked = sal_True;
1330*cdf0e10cSrcweir                 }
1331*cdf0e10cSrcweir             }
1332*cdf0e10cSrcweir             break;
1333*cdf0e10cSrcweir        }
1334*cdf0e10cSrcweir 
1335*cdf0e10cSrcweir         return NULL;
1336*cdf0e10cSrcweir     }
1337*cdf0e10cSrcweir }
1338*cdf0e10cSrcweir 
1339*cdf0e10cSrcweir // -----------------------------------------------------------------------
1340*cdf0e10cSrcweir 
1341*cdf0e10cSrcweir DbgChannelId DbgRegisterUserChannel( DbgPrintLine pProc )
1342*cdf0e10cSrcweir {
1343*cdf0e10cSrcweir     DebugData* pData = ImplGetDebugData();
1344*cdf0e10cSrcweir     pData->aDbgPrintUserChannels.push_back( pProc );
1345*cdf0e10cSrcweir     return (DbgChannelId)( pData->aDbgPrintUserChannels.size() - 1 + DBG_OUT_USER_CHANNEL_0 );
1346*cdf0e10cSrcweir }
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir // -----------------------------------------------------------------------
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir void DbgProf( sal_uInt16 nAction, DbgDataType* pDbgData )
1351*cdf0e10cSrcweir {
1352*cdf0e10cSrcweir     // Ueberhaupt Profiling-Test an
1353*cdf0e10cSrcweir     DebugData* pData = ImplGetDebugData();
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir     if ( !(pData->aDbgData.nTestFlags & DBG_TEST_PROFILING) )
1356*cdf0e10cSrcweir         return;
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir     sal_Char    aBuf[DBG_BUF_MAXLEN];
1359*cdf0e10cSrcweir     ProfType*   pProfData = (ProfType*)pDbgData->pData;
1360*cdf0e10cSrcweir     sal_uIntPtr       nTime;
1361*cdf0e10cSrcweir     if ( (nAction != DBG_PROF_START) && !pProfData )
1362*cdf0e10cSrcweir     {
1363*cdf0e10cSrcweir         strcpy( aBuf, DbgError_ProfEnd1 );
1364*cdf0e10cSrcweir         strcat( aBuf, pDbgData->pName );
1365*cdf0e10cSrcweir         DbgError( aBuf );
1366*cdf0e10cSrcweir         return;
1367*cdf0e10cSrcweir     }
1368*cdf0e10cSrcweir 
1369*cdf0e10cSrcweir     switch ( nAction )
1370*cdf0e10cSrcweir     {
1371*cdf0e10cSrcweir         case DBG_PROF_START:
1372*cdf0e10cSrcweir             if ( !pDbgData->pData )
1373*cdf0e10cSrcweir             {
1374*cdf0e10cSrcweir                 pDbgData->pData = (void*)new ProfType;
1375*cdf0e10cSrcweir                 pProfData = (ProfType*)pDbgData->pData;
1376*cdf0e10cSrcweir                 strncpy( pProfData->aName, pDbgData->pName, DBG_MAXNAME );
1377*cdf0e10cSrcweir                 pProfData->aName[DBG_MAXNAME] = '\0';
1378*cdf0e10cSrcweir                 pProfData->nCount           = 0;
1379*cdf0e10cSrcweir                 pProfData->nTime            = 0;
1380*cdf0e10cSrcweir                 pProfData->nMinTime         = 0xFFFFFFFF;
1381*cdf0e10cSrcweir                 pProfData->nMaxTime         = 0;
1382*cdf0e10cSrcweir                 pProfData->nStart           = 0xFFFFFFFF;
1383*cdf0e10cSrcweir                 pProfData->nContinueTime    = 0;
1384*cdf0e10cSrcweir                 pProfData->nContinueStart   = 0xFFFFFFFF;
1385*cdf0e10cSrcweir                 pData->pProfList->Add( (void*)pProfData );
1386*cdf0e10cSrcweir             }
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir             if ( pProfData->nStart == 0xFFFFFFFF )
1389*cdf0e10cSrcweir             {
1390*cdf0e10cSrcweir                 pProfData->nStart = ImplGetPerfTime();
1391*cdf0e10cSrcweir                 pProfData->nCount++;
1392*cdf0e10cSrcweir             }
1393*cdf0e10cSrcweir             break;
1394*cdf0e10cSrcweir 
1395*cdf0e10cSrcweir         case DBG_PROF_STOP:
1396*cdf0e10cSrcweir             nTime = ImplGetPerfTime();
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir             if ( pProfData->nStart == 0xFFFFFFFF )
1399*cdf0e10cSrcweir             {
1400*cdf0e10cSrcweir                 DbgError( DbgError_ProfEnd1 );
1401*cdf0e10cSrcweir                 return;
1402*cdf0e10cSrcweir             }
1403*cdf0e10cSrcweir 
1404*cdf0e10cSrcweir             if ( pProfData->nContinueStart != 0xFFFFFFFF )
1405*cdf0e10cSrcweir             {
1406*cdf0e10cSrcweir                 pProfData->nContinueTime += ImplGetPerfTime() - pProfData->nContinueStart;
1407*cdf0e10cSrcweir                 pProfData->nContinueStart = 0xFFFFFFFF;
1408*cdf0e10cSrcweir             }
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir             nTime -= pProfData->nStart;
1411*cdf0e10cSrcweir             nTime -= pProfData->nContinueTime;
1412*cdf0e10cSrcweir 
1413*cdf0e10cSrcweir             if ( nTime < pProfData->nMinTime )
1414*cdf0e10cSrcweir                 pProfData->nMinTime = nTime;
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir             if ( nTime > pProfData->nMaxTime )
1417*cdf0e10cSrcweir                 pProfData->nMaxTime = nTime;
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir             pProfData->nTime += nTime;
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir             pProfData->nStart         = 0xFFFFFFFF;
1422*cdf0e10cSrcweir             pProfData->nContinueTime  = 0;
1423*cdf0e10cSrcweir             pProfData->nContinueStart = 0xFFFFFFFF;
1424*cdf0e10cSrcweir             break;
1425*cdf0e10cSrcweir 
1426*cdf0e10cSrcweir         case DBG_PROF_CONTINUE:
1427*cdf0e10cSrcweir             if ( pProfData->nContinueStart != 0xFFFFFFFF )
1428*cdf0e10cSrcweir             {
1429*cdf0e10cSrcweir                 pProfData->nContinueTime += ImplGetPerfTime() - pProfData->nContinueStart;
1430*cdf0e10cSrcweir                 pProfData->nContinueStart = 0xFFFFFFFF;
1431*cdf0e10cSrcweir             }
1432*cdf0e10cSrcweir             break;
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir         case DBG_PROF_PAUSE:
1435*cdf0e10cSrcweir             if ( pProfData->nContinueStart == 0xFFFFFFFF )
1436*cdf0e10cSrcweir                 pProfData->nContinueStart = ImplGetPerfTime();
1437*cdf0e10cSrcweir             break;
1438*cdf0e10cSrcweir     }
1439*cdf0e10cSrcweir }
1440*cdf0e10cSrcweir 
1441*cdf0e10cSrcweir // -----------------------------------------------------------------------
1442*cdf0e10cSrcweir 
1443*cdf0e10cSrcweir void DbgXtor( DbgDataType* pDbgData, sal_uInt16 nAction, const void* pThis,
1444*cdf0e10cSrcweir               DbgUsr fDbgUsr )
1445*cdf0e10cSrcweir {
1446*cdf0e10cSrcweir     DebugData* pData = ImplGetDebugData();
1447*cdf0e10cSrcweir 
1448*cdf0e10cSrcweir     // Verbindung zu Debug-Memory-Manager testen
1449*cdf0e10cSrcweir #ifdef SV_MEMMGR
1450*cdf0e10cSrcweir     if ( pData->aDbgData.nTestFlags & DBG_TEST_MEM_XTOR )
1451*cdf0e10cSrcweir         DbgImpCheckMemory();
1452*cdf0e10cSrcweir #endif
1453*cdf0e10cSrcweir 
1454*cdf0e10cSrcweir     // Schnell-Test
1455*cdf0e10cSrcweir     if ( !(pData->aDbgData.nTestFlags & DBG_TEST_XTOR) )
1456*cdf0e10cSrcweir         return;
1457*cdf0e10cSrcweir 
1458*cdf0e10cSrcweir     XtorType* pXtorData = (XtorType*)pDbgData->pData;
1459*cdf0e10cSrcweir     if ( !pXtorData )
1460*cdf0e10cSrcweir     {
1461*cdf0e10cSrcweir         pDbgData->pData = (void*)new XtorType;
1462*cdf0e10cSrcweir         pXtorData = (XtorType*)pDbgData->pData;
1463*cdf0e10cSrcweir         strncpy( pXtorData->aName, pDbgData->pName, DBG_MAXNAME );
1464*cdf0e10cSrcweir         pXtorData->aName[DBG_MAXNAME] = '\0';
1465*cdf0e10cSrcweir         pXtorData->nCtorCalls   = 0;
1466*cdf0e10cSrcweir         pXtorData->nDtorCalls   = 0;
1467*cdf0e10cSrcweir         pXtorData->nMaxCount    = 0;
1468*cdf0e10cSrcweir         pXtorData->nStatics     = 0;
1469*cdf0e10cSrcweir         pXtorData->bTest        = sal_True;
1470*cdf0e10cSrcweir         pData->pXtorList->Add( (void*)pXtorData );
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir         if ( !ImplDbgFilter( pData->aDbgData.aInclClassFilter, pXtorData->aName, sal_True ) )
1473*cdf0e10cSrcweir             pXtorData->bTest = sal_False;
1474*cdf0e10cSrcweir         if ( ImplDbgFilter( pData->aDbgData.aExclClassFilter, pXtorData->aName, sal_False ) )
1475*cdf0e10cSrcweir             pXtorData->bTest = sal_False;
1476*cdf0e10cSrcweir     }
1477*cdf0e10cSrcweir     if ( !pXtorData->bTest )
1478*cdf0e10cSrcweir         return;
1479*cdf0e10cSrcweir 
1480*cdf0e10cSrcweir     sal_Char    aBuf[DBG_BUF_MAXLEN];
1481*cdf0e10cSrcweir     sal_uInt16      nAct = nAction & ~DBG_XTOR_DTOROBJ;
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir     // Trace (Enter)
1484*cdf0e10cSrcweir     if ( (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE) &&
1485*cdf0e10cSrcweir          !(nAction & DBG_XTOR_DTOROBJ) )
1486*cdf0e10cSrcweir     {
1487*cdf0e10cSrcweir         if ( nAct != DBG_XTOR_CHKOBJ )
1488*cdf0e10cSrcweir         {
1489*cdf0e10cSrcweir             if ( nAct == DBG_XTOR_CTOR )
1490*cdf0e10cSrcweir                 strcpy( aBuf, DbgTrace_EnterCtor );
1491*cdf0e10cSrcweir             else if ( nAct == DBG_XTOR_DTOR )
1492*cdf0e10cSrcweir                 strcpy( aBuf, DbgTrace_EnterDtor );
1493*cdf0e10cSrcweir             else
1494*cdf0e10cSrcweir                 strcpy( aBuf, DbgTrace_EnterMeth );
1495*cdf0e10cSrcweir             strcat( aBuf, pDbgData->pName );
1496*cdf0e10cSrcweir             DbgTrace( aBuf );
1497*cdf0e10cSrcweir         }
1498*cdf0e10cSrcweir     }
1499*cdf0e10cSrcweir 
1500*cdf0e10cSrcweir     // Sind noch Xtor-Tests als Trace an
1501*cdf0e10cSrcweir     if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXTRA )
1502*cdf0e10cSrcweir     {
1503*cdf0e10cSrcweir         // DBG_CTOR-Aufruf vor allen anderen DBG_XTOR-Aufrufen
1504*cdf0e10cSrcweir         if ( ((nAction & ~DBG_XTOR_DTOROBJ) != DBG_XTOR_CTOR) && !pDbgData->pData )
1505*cdf0e10cSrcweir         {
1506*cdf0e10cSrcweir             strcpy( aBuf, DbgError_Xtor1 );
1507*cdf0e10cSrcweir             strcat( aBuf, pDbgData->pName );
1508*cdf0e10cSrcweir             DbgError( aBuf );
1509*cdf0e10cSrcweir             return;
1510*cdf0e10cSrcweir         }
1511*cdf0e10cSrcweir 
1512*cdf0e10cSrcweir         // Testen, ob This-Pointer gueltig
1513*cdf0e10cSrcweir         if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_THIS )
1514*cdf0e10cSrcweir         {
1515*cdf0e10cSrcweir             if ( (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXIT) ||
1516*cdf0e10cSrcweir                  !(nAction & DBG_XTOR_DTOROBJ) )
1517*cdf0e10cSrcweir             {
1518*cdf0e10cSrcweir                 // This-Pointer == NULL
1519*cdf0e10cSrcweir                 if ( !pThis )
1520*cdf0e10cSrcweir                 {
1521*cdf0e10cSrcweir                     strcpy( aBuf, DbgError_CtorDtor1 );
1522*cdf0e10cSrcweir                     strcat( aBuf, pDbgData->pName );
1523*cdf0e10cSrcweir                     DbgError( aBuf );
1524*cdf0e10cSrcweir                     return;
1525*cdf0e10cSrcweir                 }
1526*cdf0e10cSrcweir 
1527*cdf0e10cSrcweir                 if ( (nAction & ~DBG_XTOR_DTOROBJ) != DBG_XTOR_CTOR )
1528*cdf0e10cSrcweir                 {
1529*cdf0e10cSrcweir                     if ( !pXtorData->aThisList.IsIn( pThis ) )
1530*cdf0e10cSrcweir                     {
1531*cdf0e10cSrcweir                         sprintf( aBuf, DbgError_CtorDtor2, pThis );
1532*cdf0e10cSrcweir                         strcat( aBuf, pDbgData->pName );
1533*cdf0e10cSrcweir                         DbgError( aBuf );
1534*cdf0e10cSrcweir                     }
1535*cdf0e10cSrcweir                 }
1536*cdf0e10cSrcweir             }
1537*cdf0e10cSrcweir         }
1538*cdf0e10cSrcweir 
1539*cdf0e10cSrcweir         // Function-Test durchfuehren und Verwaltungsdaten updaten
1540*cdf0e10cSrcweir         const sal_Char* pMsg = NULL;
1541*cdf0e10cSrcweir         switch ( nAction & ~DBG_XTOR_DTOROBJ )
1542*cdf0e10cSrcweir         {
1543*cdf0e10cSrcweir             case DBG_XTOR_CTOR:
1544*cdf0e10cSrcweir                 if ( nAction & DBG_XTOR_DTOROBJ )
1545*cdf0e10cSrcweir                 {
1546*cdf0e10cSrcweir                     if ( fDbgUsr &&
1547*cdf0e10cSrcweir                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXIT) &&
1548*cdf0e10cSrcweir                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
1549*cdf0e10cSrcweir                         pMsg = fDbgUsr( pThis );
1550*cdf0e10cSrcweir                 }
1551*cdf0e10cSrcweir                 else
1552*cdf0e10cSrcweir                 {
1553*cdf0e10cSrcweir                     pXtorData->nCtorCalls++;
1554*cdf0e10cSrcweir                     if ( !bDbgImplInMain )
1555*cdf0e10cSrcweir                         pXtorData->nStatics++;
1556*cdf0e10cSrcweir                     if ( (pXtorData->nCtorCalls-pXtorData->nDtorCalls) > pXtorData->nMaxCount )
1557*cdf0e10cSrcweir                         pXtorData->nMaxCount = pXtorData->nCtorCalls - pXtorData->nDtorCalls;
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir                     if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_THIS )
1560*cdf0e10cSrcweir                         pXtorData->aThisList.Add( pThis );
1561*cdf0e10cSrcweir                 }
1562*cdf0e10cSrcweir                 break;
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir             case DBG_XTOR_DTOR:
1565*cdf0e10cSrcweir                 if ( nAction & DBG_XTOR_DTOROBJ )
1566*cdf0e10cSrcweir                 {
1567*cdf0e10cSrcweir                     pXtorData->nDtorCalls++;
1568*cdf0e10cSrcweir                     if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_THIS )
1569*cdf0e10cSrcweir                         pXtorData->aThisList.Remove( pThis );
1570*cdf0e10cSrcweir                 }
1571*cdf0e10cSrcweir                 else
1572*cdf0e10cSrcweir                 {
1573*cdf0e10cSrcweir                     if ( fDbgUsr &&
1574*cdf0e10cSrcweir                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
1575*cdf0e10cSrcweir                         pMsg = fDbgUsr( pThis );
1576*cdf0e10cSrcweir                 }
1577*cdf0e10cSrcweir                 break;
1578*cdf0e10cSrcweir 
1579*cdf0e10cSrcweir             case DBG_XTOR_CHKTHIS:
1580*cdf0e10cSrcweir             case DBG_XTOR_CHKOBJ:
1581*cdf0e10cSrcweir                 if ( nAction & DBG_XTOR_DTOROBJ )
1582*cdf0e10cSrcweir                 {
1583*cdf0e10cSrcweir                     if ( fDbgUsr &&
1584*cdf0e10cSrcweir                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXIT) &&
1585*cdf0e10cSrcweir                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
1586*cdf0e10cSrcweir                         pMsg = fDbgUsr( pThis );
1587*cdf0e10cSrcweir                 }
1588*cdf0e10cSrcweir                 else
1589*cdf0e10cSrcweir                 {
1590*cdf0e10cSrcweir                     if ( fDbgUsr &&
1591*cdf0e10cSrcweir                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
1592*cdf0e10cSrcweir                         pMsg = fDbgUsr( pThis );
1593*cdf0e10cSrcweir                 }
1594*cdf0e10cSrcweir                 break;
1595*cdf0e10cSrcweir         }
1596*cdf0e10cSrcweir 
1597*cdf0e10cSrcweir         // Gegebenenfalls Fehlermeldung ausgeben
1598*cdf0e10cSrcweir         if ( pMsg )
1599*cdf0e10cSrcweir         {
1600*cdf0e10cSrcweir             sprintf( aBuf, DbgError_CtorDtor3, pThis );
1601*cdf0e10cSrcweir             strcat( aBuf, pDbgData->pName );
1602*cdf0e10cSrcweir             strcat( aBuf, ": \n" );
1603*cdf0e10cSrcweir             strcat( aBuf, pMsg );
1604*cdf0e10cSrcweir             DbgError( aBuf );
1605*cdf0e10cSrcweir         }
1606*cdf0e10cSrcweir     }
1607*cdf0e10cSrcweir 
1608*cdf0e10cSrcweir     // Trace (Leave)
1609*cdf0e10cSrcweir     if ( (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE) &&
1610*cdf0e10cSrcweir          (nAction & DBG_XTOR_DTOROBJ) )
1611*cdf0e10cSrcweir     {
1612*cdf0e10cSrcweir         if ( nAct != DBG_XTOR_CHKOBJ )
1613*cdf0e10cSrcweir         {
1614*cdf0e10cSrcweir             if ( nAct == DBG_XTOR_CTOR )
1615*cdf0e10cSrcweir                 strcpy( aBuf, DbgTrace_LeaveCtor );
1616*cdf0e10cSrcweir             else if ( nAct == DBG_XTOR_DTOR )
1617*cdf0e10cSrcweir                 strcpy( aBuf, DbgTrace_LeaveDtor );
1618*cdf0e10cSrcweir             else
1619*cdf0e10cSrcweir                 strcpy( aBuf, DbgTrace_LeaveMeth );
1620*cdf0e10cSrcweir             strcat( aBuf, pDbgData->pName );
1621*cdf0e10cSrcweir             DbgTrace( aBuf );
1622*cdf0e10cSrcweir         }
1623*cdf0e10cSrcweir     }
1624*cdf0e10cSrcweir }
1625*cdf0e10cSrcweir 
1626*cdf0e10cSrcweir // -----------------------------------------------------------------------
1627*cdf0e10cSrcweir 
1628*cdf0e10cSrcweir void DbgOut( const sal_Char* pMsg, sal_uInt16 nDbgOut, const sal_Char* pFile, sal_uInt16 nLine )
1629*cdf0e10cSrcweir {
1630*cdf0e10cSrcweir     static sal_Bool bIn = sal_False;
1631*cdf0e10cSrcweir     if ( bIn )
1632*cdf0e10cSrcweir         return;
1633*cdf0e10cSrcweir     bIn = sal_True;
1634*cdf0e10cSrcweir 
1635*cdf0e10cSrcweir     DebugData*  pData = GetDebugData();
1636*cdf0e10cSrcweir     sal_Char const *   pStr;
1637*cdf0e10cSrcweir     sal_uIntPtr       nOut;
1638*cdf0e10cSrcweir     int         nBufLen = 0;
1639*cdf0e10cSrcweir 
1640*cdf0e10cSrcweir     if ( nDbgOut == DBG_OUT_ERROR )
1641*cdf0e10cSrcweir     {
1642*cdf0e10cSrcweir         nOut = pData->aDbgData.nErrorOut;
1643*cdf0e10cSrcweir         pStr = "Error: ";
1644*cdf0e10cSrcweir         if ( pData->aDbgData.nErrorOut == DBG_OUT_FILE )
1645*cdf0e10cSrcweir             DbgDebugBeep();
1646*cdf0e10cSrcweir     }
1647*cdf0e10cSrcweir     else if ( nDbgOut == DBG_OUT_WARNING )
1648*cdf0e10cSrcweir     {
1649*cdf0e10cSrcweir         nOut = pData->aDbgData.nWarningOut;
1650*cdf0e10cSrcweir         pStr = "Warning: ";
1651*cdf0e10cSrcweir     }
1652*cdf0e10cSrcweir     else
1653*cdf0e10cSrcweir     {
1654*cdf0e10cSrcweir         nOut = pData->aDbgData.nTraceOut;
1655*cdf0e10cSrcweir         pStr = NULL;
1656*cdf0e10cSrcweir     }
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir     if ( nOut == DBG_OUT_NULL )
1659*cdf0e10cSrcweir     {
1660*cdf0e10cSrcweir         bIn = sal_False;
1661*cdf0e10cSrcweir         return;
1662*cdf0e10cSrcweir     }
1663*cdf0e10cSrcweir 
1664*cdf0e10cSrcweir     if ( ImplDbgFilterMessage( pMsg ) )
1665*cdf0e10cSrcweir     {
1666*cdf0e10cSrcweir         bIn = sal_False;
1667*cdf0e10cSrcweir         return;
1668*cdf0e10cSrcweir     }
1669*cdf0e10cSrcweir 
1670*cdf0e10cSrcweir     ImplDbgLock();
1671*cdf0e10cSrcweir 
1672*cdf0e10cSrcweir     sal_Char aBufOut[DBG_BUF_MAXLEN];
1673*cdf0e10cSrcweir     if ( pStr )
1674*cdf0e10cSrcweir     {
1675*cdf0e10cSrcweir         strcpy( aBufOut, pStr );
1676*cdf0e10cSrcweir         nBufLen = strlen( pStr );
1677*cdf0e10cSrcweir     }
1678*cdf0e10cSrcweir     else
1679*cdf0e10cSrcweir         aBufOut[0] = '\0';
1680*cdf0e10cSrcweir 
1681*cdf0e10cSrcweir     int nMsgLen = strlen( pMsg );
1682*cdf0e10cSrcweir     if ( nBufLen+nMsgLen > DBG_BUF_MAXLEN )
1683*cdf0e10cSrcweir     {
1684*cdf0e10cSrcweir         int nCopyLen = DBG_BUF_MAXLEN-nBufLen-3;
1685*cdf0e10cSrcweir         strncpy( &(aBufOut[nBufLen]), pMsg, nCopyLen );
1686*cdf0e10cSrcweir         strcpy( &(aBufOut[nBufLen+nCopyLen]), "..." );
1687*cdf0e10cSrcweir     }
1688*cdf0e10cSrcweir     else
1689*cdf0e10cSrcweir         strcpy( &(aBufOut[nBufLen]), pMsg );
1690*cdf0e10cSrcweir 
1691*cdf0e10cSrcweir     if ( pFile && nLine && (nBufLen+nMsgLen < DBG_BUF_MAXLEN) )
1692*cdf0e10cSrcweir     {
1693*cdf0e10cSrcweir         if ( nOut == DBG_OUT_MSGBOX )
1694*cdf0e10cSrcweir             strcat( aBufOut, "\n" );
1695*cdf0e10cSrcweir         else
1696*cdf0e10cSrcweir             strcat( aBufOut, " " );
1697*cdf0e10cSrcweir         strcat( aBufOut, "From File " );
1698*cdf0e10cSrcweir         strcat( aBufOut, pFile );
1699*cdf0e10cSrcweir         strcat( aBufOut, " at Line " );
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir         // Line in String umwandeln und dranhaengen
1702*cdf0e10cSrcweir         sal_Char    aLine[9];
1703*cdf0e10cSrcweir         sal_Char*   pLine = &aLine[7];
1704*cdf0e10cSrcweir         sal_uInt16      i;
1705*cdf0e10cSrcweir         memset( aLine, 0, sizeof( aLine ) );
1706*cdf0e10cSrcweir         do
1707*cdf0e10cSrcweir         {
1708*cdf0e10cSrcweir             i = nLine % 10;
1709*cdf0e10cSrcweir             pLine--;
1710*cdf0e10cSrcweir             *(pLine) = (sal_Char)i + 48;
1711*cdf0e10cSrcweir             nLine /= 10;
1712*cdf0e10cSrcweir         }
1713*cdf0e10cSrcweir         while ( nLine );
1714*cdf0e10cSrcweir         strcat( aBufOut, pLine );
1715*cdf0e10cSrcweir     }
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir     if ( ( nOut >= DBG_OUT_USER_CHANNEL_0 ) && ( nOut - DBG_OUT_USER_CHANNEL_0 < pData->aDbgPrintUserChannels.size() ) )
1718*cdf0e10cSrcweir     {
1719*cdf0e10cSrcweir         DbgPrintLine pPrinter = pData->aDbgPrintUserChannels[ nOut - DBG_OUT_USER_CHANNEL_0 ];
1720*cdf0e10cSrcweir         if ( pPrinter )
1721*cdf0e10cSrcweir             pPrinter( aBufOut );
1722*cdf0e10cSrcweir         else
1723*cdf0e10cSrcweir             nOut = DBG_OUT_DEBUGGER;
1724*cdf0e10cSrcweir     }
1725*cdf0e10cSrcweir 
1726*cdf0e10cSrcweir     if ( nOut == DBG_OUT_ABORT )
1727*cdf0e10cSrcweir     {
1728*cdf0e10cSrcweir         if ( pData->pDbgAbort != NULL )
1729*cdf0e10cSrcweir             pData->pDbgAbort( aBufOut );
1730*cdf0e10cSrcweir         abort();
1731*cdf0e10cSrcweir     }
1732*cdf0e10cSrcweir 
1733*cdf0e10cSrcweir     if ( nOut == DBG_OUT_DEBUGGER )
1734*cdf0e10cSrcweir     {
1735*cdf0e10cSrcweir         if ( !ImplActivateDebugger( aBufOut ) )
1736*cdf0e10cSrcweir             nOut = DBG_OUT_TESTTOOL;
1737*cdf0e10cSrcweir     }
1738*cdf0e10cSrcweir 
1739*cdf0e10cSrcweir     if ( nOut == DBG_OUT_TESTTOOL )
1740*cdf0e10cSrcweir     {
1741*cdf0e10cSrcweir         if ( pData->pDbgPrintTestTool )
1742*cdf0e10cSrcweir             pData->pDbgPrintTestTool( aBufOut );
1743*cdf0e10cSrcweir         else
1744*cdf0e10cSrcweir             nOut = DBG_OUT_MSGBOX;
1745*cdf0e10cSrcweir     }
1746*cdf0e10cSrcweir 
1747*cdf0e10cSrcweir     if ( nOut == DBG_OUT_MSGBOX )
1748*cdf0e10cSrcweir     {
1749*cdf0e10cSrcweir         if ( pData->pDbgPrintMsgBox )
1750*cdf0e10cSrcweir             pData->pDbgPrintMsgBox( aBufOut );
1751*cdf0e10cSrcweir         else
1752*cdf0e10cSrcweir             nOut = DBG_OUT_WINDOW;
1753*cdf0e10cSrcweir     }
1754*cdf0e10cSrcweir 
1755*cdf0e10cSrcweir     if ( nOut == DBG_OUT_WINDOW )
1756*cdf0e10cSrcweir     {
1757*cdf0e10cSrcweir         if ( pData->pDbgPrintWindow )
1758*cdf0e10cSrcweir             pData->pDbgPrintWindow( aBufOut );
1759*cdf0e10cSrcweir         else
1760*cdf0e10cSrcweir             nOut = DBG_OUT_FILE;
1761*cdf0e10cSrcweir     }
1762*cdf0e10cSrcweir 
1763*cdf0e10cSrcweir     switch ( nOut )
1764*cdf0e10cSrcweir     {
1765*cdf0e10cSrcweir     case DBG_OUT_SHELL:
1766*cdf0e10cSrcweir         DbgPrintShell( aBufOut );
1767*cdf0e10cSrcweir         break;
1768*cdf0e10cSrcweir     case DBG_OUT_FILE:
1769*cdf0e10cSrcweir         ImplDbgPrintFile( aBufOut );
1770*cdf0e10cSrcweir         break;
1771*cdf0e10cSrcweir     }
1772*cdf0e10cSrcweir 
1773*cdf0e10cSrcweir     ImplDbgUnlock();
1774*cdf0e10cSrcweir 
1775*cdf0e10cSrcweir     bIn = sal_False;
1776*cdf0e10cSrcweir }
1777*cdf0e10cSrcweir 
1778*cdf0e10cSrcweir void DbgPrintShell(char const * message) {
1779*cdf0e10cSrcweir     fprintf(stderr, "%s\n", message);
1780*cdf0e10cSrcweir #if defined WNT
1781*cdf0e10cSrcweir     OutputDebugStringA(message);
1782*cdf0e10cSrcweir #endif
1783*cdf0e10cSrcweir }
1784*cdf0e10cSrcweir 
1785*cdf0e10cSrcweir // -----------------------------------------------------------------------
1786*cdf0e10cSrcweir 
1787*cdf0e10cSrcweir void DbgOutTypef( sal_uInt16 nDbgOut, const sal_Char* pFStr, ... )
1788*cdf0e10cSrcweir {
1789*cdf0e10cSrcweir     va_list pList;
1790*cdf0e10cSrcweir 
1791*cdf0e10cSrcweir     va_start( pList, pFStr );
1792*cdf0e10cSrcweir     sal_Char aBuf[DBG_BUF_MAXLEN];
1793*cdf0e10cSrcweir     vsprintf( aBuf, pFStr, pList );
1794*cdf0e10cSrcweir     va_end( pList );
1795*cdf0e10cSrcweir 
1796*cdf0e10cSrcweir     DbgOut( aBuf, nDbgOut );
1797*cdf0e10cSrcweir }
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir // -----------------------------------------------------------------------
1800*cdf0e10cSrcweir 
1801*cdf0e10cSrcweir void DbgOutf( const sal_Char* pFStr, ... )
1802*cdf0e10cSrcweir {
1803*cdf0e10cSrcweir     va_list pList;
1804*cdf0e10cSrcweir 
1805*cdf0e10cSrcweir     va_start( pList, pFStr );
1806*cdf0e10cSrcweir     sal_Char aBuf[DBG_BUF_MAXLEN];
1807*cdf0e10cSrcweir     vsprintf( aBuf, pFStr, pList );
1808*cdf0e10cSrcweir     va_end( pList );
1809*cdf0e10cSrcweir 
1810*cdf0e10cSrcweir     DbgOut( aBuf );
1811*cdf0e10cSrcweir }
1812*cdf0e10cSrcweir 
1813*cdf0e10cSrcweir // =======================================================================
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir #else
1816*cdf0e10cSrcweir 
1817*cdf0e10cSrcweir void* DbgFunc( sal_uInt16, void* ) { return NULL; }
1818*cdf0e10cSrcweir 
1819*cdf0e10cSrcweir void DbgProf( sal_uInt16, DbgDataType* ) {}
1820*cdf0e10cSrcweir void DbgXtor( DbgDataType*, sal_uInt16, const void*, DbgUsr ) {}
1821*cdf0e10cSrcweir 
1822*cdf0e10cSrcweir void DbgOut( const sal_Char*, sal_uInt16, const sal_Char*, sal_uInt16 ) {}
1823*cdf0e10cSrcweir void DbgOutTypef( sal_uInt16, const sal_Char*, ... ) {}
1824*cdf0e10cSrcweir void DbgOutf( const sal_Char*, ... ) {}
1825*cdf0e10cSrcweir 
1826*cdf0e10cSrcweir #endif
1827