LCOV - code coverage report
Current view: top level - tools/source/debug - debug.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 6 0.0 %
Date: 2012-08-25 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #if defined (UNX) || defined (GCC)
      21                 :            : #include <unistd.h>
      22                 :            : #else
      23                 :            : #include <direct.h>
      24                 :            : #endif
      25                 :            : 
      26                 :            : #include <errno.h>
      27                 :            : #include <time.h>
      28                 :            : #include <cstdarg>  // combinations
      29                 :            : #include <stdlib.h>
      30                 :            : #include <string.h>
      31                 :            : #include <stdio.h>
      32                 :            : 
      33                 :            : #if defined ( WNT )
      34                 :            : #include <windows.h>
      35                 :            : #endif
      36                 :            : 
      37                 :            : #include <tools/debug.hxx>
      38                 :            : #include <rtl/string.h>
      39                 :            : #include <sal/log.hxx>
      40                 :            : #include <sal/macros.h>
      41                 :            : 
      42                 :            : #include <vector>
      43                 :            : 
      44                 :            : #include <osl/diagnose.h>
      45                 :            : 
      46                 :            : #ifdef DBG_UTIL
      47                 :            : 
      48                 :            : // PointerList
      49                 :            : 
      50                 :            : #define PBLOCKCOUNT     1024
      51                 :            : 
      52                 :            : struct PBlock
      53                 :            : {
      54                 :            :     void*       aData[PBLOCKCOUNT];
      55                 :            :     sal_uInt16  nCount;
      56                 :            :     PBlock*     pPrev;
      57                 :            :     PBlock*     pNext;
      58                 :            : };
      59                 :            : 
      60                 :            : class PointerList
      61                 :            : {
      62                 :            : private:
      63                 :            :     PBlock*     pFirst;
      64                 :            :     PBlock*     pLast;
      65                 :            :     sal_uIntPtr nCount;
      66                 :            : 
      67                 :            : public:
      68                 :            :                 PointerList() { pFirst = NULL; pLast = NULL; nCount = 0; }
      69                 :            :                 ~PointerList();
      70                 :            : 
      71                 :            :     void        Add( const void* p );
      72                 :            :     sal_Bool    Remove( const void* p );
      73                 :            : 
      74                 :            :     const void* Get( sal_uIntPtr nPos ) const;
      75                 :            :     sal_Bool    IsIn( const void* p ) const;
      76                 :            :     sal_uIntPtr Count() const { return nCount; }
      77                 :            : };
      78                 :            : 
      79                 :            : // data types
      80                 :            : 
      81                 :            : #define DBG_MAXNAME     28
      82                 :            : 
      83                 :            : struct ProfType
      84                 :            : {
      85                 :            :     sal_uIntPtr             nCount;
      86                 :            :     sal_uIntPtr             nTime;
      87                 :            :     sal_uIntPtr             nMinTime;
      88                 :            :     sal_uIntPtr             nMaxTime;
      89                 :            :     sal_uIntPtr             nStart;
      90                 :            :     sal_uIntPtr             nContinueTime;
      91                 :            :     sal_uIntPtr             nContinueStart;
      92                 :            :     sal_Char                aName[DBG_MAXNAME+1];
      93                 :            : };
      94                 :            : 
      95                 :            : struct XtorType
      96                 :            : {
      97                 :            :     sal_uIntPtr             nCtorCalls;
      98                 :            :     sal_uIntPtr             nDtorCalls;
      99                 :            :     sal_uIntPtr             nMaxCount;
     100                 :            :     sal_uIntPtr             nStatics;
     101                 :            :     sal_Char                aName[DBG_MAXNAME+1];
     102                 :            :     sal_Bool                bTest;
     103                 :            :     PointerList             aThisList;
     104                 :            : };
     105                 :            : 
     106                 :            : struct DebugData
     107                 :            : {
     108                 :            :     DbgData                 aDbgData;
     109                 :            :     sal_uInt16              bInit;
     110                 :            :     DbgPrintLine            pDbgPrintMsgBox;
     111                 :            :     DbgPrintLine            pDbgPrintWindow;
     112                 :            :     DbgPrintLine            pDbgPrintTestTool;
     113                 :            :     DbgPrintLine            pDbgAbort;
     114                 :            :     ::std::vector< DbgPrintLine >
     115                 :            :                             aDbgPrintUserChannels;
     116                 :            :     PointerList*            pProfList;
     117                 :            :     PointerList*            pXtorList;
     118                 :            :     DbgTestSolarMutexProc   pDbgTestSolarMutex;
     119                 :            :     pfunc_osl_printDetailedDebugMessage
     120                 :            :                             pOldDebugMessageFunc;
     121                 :            :     bool                    bOslIsHooked;
     122                 :            : 
     123                 :            :     DebugData()
     124                 :            :         :bInit( sal_False )
     125                 :            :         ,pDbgPrintMsgBox( NULL )
     126                 :            :         ,pDbgPrintWindow( NULL )
     127                 :            :         ,pDbgPrintTestTool( NULL )
     128                 :            :         ,pDbgAbort( NULL )
     129                 :            :         ,pProfList( NULL )
     130                 :            :         ,pXtorList( NULL )
     131                 :            :         ,pDbgTestSolarMutex( NULL )
     132                 :            :         ,pOldDebugMessageFunc( NULL )
     133                 :            :         ,bOslIsHooked( false )
     134                 :            :     {
     135                 :            :         aDbgData.nTestFlags = DBG_TEST_RESOURCE;
     136                 :            :         aDbgData.bOverwrite = sal_True;
     137                 :            :         aDbgData.nTraceOut = DBG_OUT_NULL;
     138                 :            :         aDbgData.nWarningOut = DBG_OUT_NULL;
     139                 :            : #ifdef UNX
     140                 :            :         aDbgData.nErrorOut = DBG_OUT_SHELL;
     141                 :            : #else
     142                 :            :         aDbgData.nErrorOut = DBG_OUT_MSGBOX;
     143                 :            : #endif
     144                 :            :         aDbgData.bHookOSLAssert = sal_True;
     145                 :            :         aDbgData.aDebugName[0] = 0;
     146                 :            :         aDbgData.aInclFilter[0] = 0;
     147                 :            :         aDbgData.aExclFilter[0] = 0;
     148                 :            :         aDbgData.aInclClassFilter[0] = 0;
     149                 :            :         aDbgData.aExclClassFilter[0] = 0;
     150                 :            :         aDbgData.aDbgWinState[0] = 0;
     151                 :            :     }
     152                 :            : };
     153                 :            : 
     154                 :            : #define DBG_TEST_XTOR_EXTRA (DBG_TEST_XTOR_THIS |  DBG_TEST_XTOR_FUNC |               \
     155                 :            :                              DBG_TEST_XTOR_EXIT |  DBG_TEST_XTOR_REPORT )
     156                 :            : 
     157                 :            : // static maintenance variables
     158                 :            : 
     159                 :            : static DebugData aDebugData;
     160                 :            : static sal_Char aCurPath[260];
     161                 :            : static int bDbgImplInMain = sal_False;
     162                 :            : 
     163                 :            : #if defined( WNT )
     164                 :            : static CRITICAL_SECTION aImplCritDbgSection;
     165                 :            : #endif
     166                 :            : 
     167                 :            : static sal_Bool bImplCritDbgSectionInit = sal_False;
     168                 :            : 
     169                 :            : void ImplDbgInitLock()
     170                 :            : {
     171                 :            : #if defined( WNT )
     172                 :            :     InitializeCriticalSection( &aImplCritDbgSection );
     173                 :            : #endif
     174                 :            :     bImplCritDbgSectionInit = sal_True;
     175                 :            : }
     176                 :            : 
     177                 :            : void ImplDbgDeInitLock()
     178                 :            : {
     179                 :            : #if defined( WNT )
     180                 :            :     DeleteCriticalSection( &aImplCritDbgSection );
     181                 :            : #endif
     182                 :            :     bImplCritDbgSectionInit = sal_False;
     183                 :            : }
     184                 :            : 
     185                 :            : void ImplDbgLock()
     186                 :            : {
     187                 :            :     if ( !bImplCritDbgSectionInit )
     188                 :            :         return;
     189                 :            : 
     190                 :            : #if defined( WNT )
     191                 :            :     EnterCriticalSection( &aImplCritDbgSection );
     192                 :            : #endif
     193                 :            : }
     194                 :            : 
     195                 :            : void ImplDbgUnlock()
     196                 :            : {
     197                 :            :     if ( !bImplCritDbgSectionInit )
     198                 :            :         return;
     199                 :            : 
     200                 :            : #if defined( WNT )
     201                 :            :     LeaveCriticalSection( &aImplCritDbgSection );
     202                 :            : #endif
     203                 :            : }
     204                 :            : 
     205                 :            : #define FILE_LINEEND    "\n"
     206                 :            : 
     207                 :            : static sal_Bool ImplActivateDebugger( const sal_Char* pMsg )
     208                 :            : {
     209                 :            : #if defined( WNT )
     210                 :            :     static sal_Char aImplDbgOutBuf[DBG_BUF_MAXLEN];
     211                 :            :     strcpy( aImplDbgOutBuf, pMsg );
     212                 :            :     strcat( aImplDbgOutBuf, "\r\n" );
     213                 :            :     OutputDebugString( aImplDbgOutBuf );
     214                 :            :     DebugBreak();
     215                 :            :     return sal_True;
     216                 :            : #else
     217                 :            :     (void) pMsg; // avoid warning about unused parameter
     218                 :            :     return sal_False;
     219                 :            : #endif
     220                 :            : }
     221                 :            : 
     222                 :            : static sal_Bool ImplCoreDump()
     223                 :            : {
     224                 :            : #if defined( WNT )
     225                 :            :     DebugBreak();
     226                 :            : #else
     227                 :            :     long* pTemp = 0;
     228                 :            :     *pTemp = 0xCCCC;
     229                 :            : #endif
     230                 :            :     return sal_True;
     231                 :            : }
     232                 :            : 
     233                 :            : static sal_uIntPtr ImplGetPerfTime()
     234                 :            : {
     235                 :            : #if defined( WNT )
     236                 :            :     return (sal_uIntPtr)GetTickCount();
     237                 :            : #else
     238                 :            :     static sal_uIntPtr    nImplTicksPerSecond = 0;
     239                 :            :     static double   dImplTicksPerSecond;
     240                 :            :     sal_uIntPtr           nTicks = (sal_uIntPtr)clock();
     241                 :            : 
     242                 :            :     if ( !nImplTicksPerSecond )
     243                 :            :     {
     244                 :            :         nImplTicksPerSecond = CLOCKS_PER_SEC;
     245                 :            :         dImplTicksPerSecond = nImplTicksPerSecond;
     246                 :            :     }
     247                 :            : 
     248                 :            :     double fTicks = nTicks;
     249                 :            :     fTicks *= 1000;
     250                 :            :     fTicks /= dImplTicksPerSecond;
     251                 :            :     return (sal_uIntPtr)fTicks;
     252                 :            : #endif
     253                 :            : }
     254                 :            : 
     255                 :            : typedef FILE*       FILETYPE;
     256                 :            : #define FileOpen    fopen
     257                 :            : #define FileRead    fread
     258                 :            : #define FileWrite   fwrite
     259                 :            : #define FilePrintF  fprintf
     260                 :            : #define FileClose   fclose
     261                 :            : 
     262                 :            : namespace
     263                 :            : {
     264                 :            :     enum ConfigSection
     265                 :            :     {
     266                 :            :         eOutput,
     267                 :            :         eMemory,
     268                 :            :         eGUI,
     269                 :            :         eObjects,
     270                 :            :         eTest,
     271                 :            : 
     272                 :            :         eUnknown
     273                 :            :     };
     274                 :            : 
     275                 :            :     void lcl_lineFeed( FILETYPE _pFile )
     276                 :            :     {
     277                 :            :         FilePrintF( _pFile, "%s", FILE_LINEEND );
     278                 :            :     }
     279                 :            : 
     280                 :            :     const sal_Char* lcl_getSectionName( ConfigSection _eSection )
     281                 :            :     {
     282                 :            :         const sal_Char* pSectionName = NULL;
     283                 :            :         switch ( _eSection )
     284                 :            :         {
     285                 :            :             case eOutput    : pSectionName = "output";  break;
     286                 :            :             case eMemory    : pSectionName = "memory";  break;
     287                 :            :             case eGUI       : pSectionName = "gui";     break;
     288                 :            :             case eObjects   : pSectionName = "objects"; break;
     289                 :            :             case eTest      : pSectionName = "test";    break;
     290                 :            :             case eUnknown:
     291                 :            :                 OSL_ASSERT(false);
     292                 :            :                 break;
     293                 :            :         }
     294                 :            :         return pSectionName;
     295                 :            :     }
     296                 :            : 
     297                 :            :     ConfigSection lcl_getSectionFromName( const sal_Char* _pSectionName, size_t _nSectionNameLength )
     298                 :            :     {
     299                 :            :         if ( strncmp( _pSectionName, "output",  _nSectionNameLength < 6 ? _nSectionNameLength : 6 ) == 0 )
     300                 :            :             return eOutput;
     301                 :            :         if ( strncmp( _pSectionName, "memory",  _nSectionNameLength < 6 ? _nSectionNameLength : 6 ) == 0 )
     302                 :            :             return eMemory;
     303                 :            :         if ( strncmp( _pSectionName, "gui",     _nSectionNameLength < 3 ? _nSectionNameLength : 3 ) == 0 )
     304                 :            :             return eGUI;
     305                 :            :         if ( strncmp( _pSectionName, "objects", _nSectionNameLength < 7 ? _nSectionNameLength : 7 ) == 0 )
     306                 :            :             return eObjects;
     307                 :            :         if ( strncmp( _pSectionName, "test",    _nSectionNameLength < 4 ? _nSectionNameLength : 4 ) == 0 )
     308                 :            :             return eTest;
     309                 :            :         return eUnknown;
     310                 :            :     }
     311                 :            : 
     312                 :            :     void lcl_startSection( FILETYPE _pFile, ConfigSection _eSection )
     313                 :            :     {
     314                 :            :         FilePrintF( _pFile, "[%s]%s", lcl_getSectionName( _eSection ), FILE_LINEEND );
     315                 :            :     }
     316                 :            : 
     317                 :            :     void lcl_writeConfigString( FILETYPE _pFile, const sal_Char* _pKeyName, const sal_Char* _pValue )
     318                 :            :     {
     319                 :            :         FilePrintF( _pFile, "%s=%s%s", _pKeyName, _pValue, FILE_LINEEND );
     320                 :            :     }
     321                 :            : 
     322                 :            :     void lcl_writeConfigBoolean( FILETYPE _pFile, const sal_Char* _pKeyName, bool _bValue )
     323                 :            :     {
     324                 :            :         lcl_writeConfigString( _pFile, _pKeyName, _bValue ? "1" : "0" );
     325                 :            :     }
     326                 :            : 
     327                 :            :     void lcl_writeConfigFlag( FILETYPE _pFile, const sal_Char* _pKeyName, sal_uIntPtr _nAllFlags, sal_uIntPtr _nCheckFlag )
     328                 :            :     {
     329                 :            :         lcl_writeConfigBoolean( _pFile, _pKeyName, ( _nAllFlags & _nCheckFlag ) != 0 );
     330                 :            :     }
     331                 :            : 
     332                 :            :     void lcl_writeConfigOutChannel( FILETYPE _pFile, const sal_Char* _pKeyName, sal_uIntPtr _nValue )
     333                 :            :     {
     334                 :            :         const sal_Char* names[ DBG_OUT_COUNT ] =
     335                 :            :         {
     336                 :            :             "dev/null", "file", "window", "shell", "messagebox", "testtool", "debugger", "abort"
     337                 :            :         };
     338                 :            :         lcl_writeConfigString( _pFile, _pKeyName, names[ _nValue ] );
     339                 :            :     }
     340                 :            : 
     341                 :            :     bool lcl_isConfigSection( const sal_Char* _pLine, size_t _nLineLen )
     342                 :            :     {
     343                 :            :         if ( _nLineLen < 2 )
     344                 :            :             // not even enough space for '[' and ']'
     345                 :            :             return false;
     346                 :            :         if ( ( _pLine[0] == '[' ) && ( _pLine[ _nLineLen - 1 ] == ']' ) )
     347                 :            :             return true;
     348                 :            :         return false;
     349                 :            :     }
     350                 :            : 
     351                 :            :     bool lcl_isConfigKey( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName )
     352                 :            :     {
     353                 :            :         size_t nKeyLength = strlen( _pKeyName );
     354                 :            :         if ( nKeyLength + 1 >= _nLineLen )
     355                 :            :             // not even long enough for the key name plus "=" plus a one-character value
     356                 :            :             return false;
     357                 :            :         if ( ( strncmp( _pLine, _pKeyName, nKeyLength ) == 0 ) && ( _pLine[ nKeyLength ] == '=' ) )
     358                 :            :             return true;
     359                 :            :         return false;
     360                 :            :     }
     361                 :            : 
     362                 :            :     sal_Int32 lcl_tryReadConfigString( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_Char* _pValue, size_t _nValueLen )
     363                 :            :     {
     364                 :            :         if ( !lcl_isConfigKey( _pLine, _nLineLen, _pKeyName ) )
     365                 :            :             return 0;
     366                 :            :         size_t nValuePos = strlen( _pKeyName ) + 1;
     367                 :            :         size_t nValueLen = _nLineLen - nValuePos;
     368                 :            :         const sal_Char* pValue = _pLine + nValuePos;
     369                 :            :         strncpy( _pValue, pValue, ( _nValueLen > nValueLen ) ? nValueLen : _nValueLen );
     370                 :            :         _pValue[ ( _nValueLen > nValueLen ) ? nValueLen : _nValueLen - 1 ] = 0;
     371                 :            :         return strlen( _pValue );
     372                 :            :     }
     373                 :            : 
     374                 :            :     void lcl_tryReadConfigBoolean( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uIntPtr* _out_pnValue )
     375                 :            :     {
     376                 :            :         sal_Char aBuf[2];
     377                 :            :         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
     378                 :            :         if ( nValueLen )
     379                 :            :             *_out_pnValue = strcmp( aBuf, "1" ) == 0 ? sal_True : sal_False;
     380                 :            :     }
     381                 :            : 
     382                 :            :     void lcl_matchOutputChannel( sal_Char const * i_buffer, sal_uIntPtr* o_value )
     383                 :            :     {
     384                 :            :         if ( i_buffer == NULL )
     385                 :            :             return;
     386                 :            :         const sal_Char* names[ DBG_OUT_COUNT ] =
     387                 :            :         {
     388                 :            :             "dev/null", "file", "window", "shell", "messagebox", "testtool", "debugger", "abort"
     389                 :            :         };
     390                 :            :         for ( size_t name = 0; name < SAL_N_ELEMENTS( names ); ++name )
     391                 :            :         {
     392                 :            :             if ( strcmp( i_buffer, names[ name ] ) == 0 )
     393                 :            :             {
     394                 :            :                 *o_value = name;
     395                 :            :                 return;
     396                 :            :             }
     397                 :            :         }
     398                 :            :     }
     399                 :            : 
     400                 :            :     void lcl_tryReadOutputChannel( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uIntPtr* _out_pnValue )
     401                 :            :     {
     402                 :            :         sal_Char aBuf[20];
     403                 :            :         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
     404                 :            :         if ( nValueLen )
     405                 :            :             lcl_matchOutputChannel( aBuf, _out_pnValue );
     406                 :            :     }
     407                 :            : 
     408                 :            :     void lcl_tryReadConfigFlag( const sal_Char* _pLine, size_t _nLineLen, const sal_Char* _pKeyName, sal_uIntPtr* _out_pnAllFlags, sal_uIntPtr _nCheckFlag )
     409                 :            :     {
     410                 :            :         sal_Char aBuf[2];
     411                 :            :         size_t nValueLen = lcl_tryReadConfigString( _pLine, _nLineLen, _pKeyName, aBuf, sizeof( aBuf ) );
     412                 :            :         if ( nValueLen )
     413                 :            :         {
     414                 :            :             if ( strcmp( aBuf, "1" ) == 0 )
     415                 :            :                 *_out_pnAllFlags |= _nCheckFlag;
     416                 :            :             else
     417                 :            :                 *_out_pnAllFlags &= ~_nCheckFlag;
     418                 :            :         }
     419                 :            :     }
     420                 :            : }
     421                 :            : 
     422                 :            : PointerList::~PointerList()
     423                 :            : {
     424                 :            :     PBlock* pBlock = pFirst;
     425                 :            :     while ( pBlock )
     426                 :            :     {
     427                 :            :         PBlock* pNextBlock = pBlock->pNext;
     428                 :            :         delete pBlock;
     429                 :            :         pBlock = pNextBlock;
     430                 :            :     }
     431                 :            : }
     432                 :            : 
     433                 :            : void PointerList::Add( const void* p )
     434                 :            : {
     435                 :            :     if ( !pFirst )
     436                 :            :     {
     437                 :            :         pFirst = new PBlock;
     438                 :            :         memset( pFirst->aData, 0, PBLOCKCOUNT * sizeof( void* ) );
     439                 :            :         pFirst->nCount = 0;
     440                 :            :         pFirst->pPrev  = NULL;
     441                 :            :         pFirst->pNext  = NULL;
     442                 :            :         pLast = pFirst;
     443                 :            :     }
     444                 :            : 
     445                 :            :     PBlock* pBlock = pFirst;
     446                 :            :     while ( pBlock && (pBlock->nCount == PBLOCKCOUNT) )
     447                 :            :         pBlock = pBlock->pNext;
     448                 :            : 
     449                 :            :     if ( !pBlock )
     450                 :            :     {
     451                 :            :         pBlock = new PBlock;
     452                 :            :         memset( pBlock->aData, 0, PBLOCKCOUNT * sizeof( void* ) );
     453                 :            :         pBlock->nCount = 0;
     454                 :            :         pBlock->pPrev  = pLast;
     455                 :            :         pBlock->pNext  = NULL;
     456                 :            :         pLast->pNext   = pBlock;
     457                 :            :         pLast          = pBlock;
     458                 :            :     }
     459                 :            : 
     460                 :            :     sal_uInt16 i = 0;
     461                 :            :     while ( pBlock->aData[i] )
     462                 :            :         i++;
     463                 :            : 
     464                 :            :     pBlock->aData[i] = (void*)p;
     465                 :            :     pBlock->nCount++;
     466                 :            :     nCount++;
     467                 :            : }
     468                 :            : 
     469                 :            : sal_Bool PointerList::Remove( const void* p )
     470                 :            : {
     471                 :            :     if ( !p )
     472                 :            :        return sal_False;
     473                 :            : 
     474                 :            :     PBlock* pBlock = pFirst;
     475                 :            :     while ( pBlock )
     476                 :            :     {
     477                 :            :         sal_uInt16 i = 0;
     478                 :            :         while ( i < PBLOCKCOUNT )
     479                 :            :         {
     480                 :            :             if ( ((sal_uIntPtr)p) == ((sal_uIntPtr)pBlock->aData[i]) )
     481                 :            :             {
     482                 :            :                 pBlock->aData[i] = NULL;
     483                 :            :                 pBlock->nCount--;
     484                 :            :                 nCount--;
     485                 :            : 
     486                 :            :                 if ( !pBlock->nCount )
     487                 :            :                 {
     488                 :            :                     if ( pBlock->pPrev )
     489                 :            :                         pBlock->pPrev->pNext = pBlock->pNext;
     490                 :            :                     if ( pBlock->pNext )
     491                 :            :                         pBlock->pNext->pPrev = pBlock->pPrev;
     492                 :            :                     if ( pBlock == pFirst )
     493                 :            :                         pFirst = pBlock->pNext;
     494                 :            :                     if ( pBlock == pLast )
     495                 :            :                         pLast = pBlock->pPrev;
     496                 :            :                     delete pBlock;
     497                 :            :                 }
     498                 :            : 
     499                 :            :                 return sal_True;
     500                 :            :             }
     501                 :            :             i++;
     502                 :            :         }
     503                 :            : 
     504                 :            :         pBlock = pBlock->pNext;
     505                 :            :     }
     506                 :            : 
     507                 :            :     return sal_False;
     508                 :            : }
     509                 :            : 
     510                 :            : const void* PointerList::Get( sal_uIntPtr nPos ) const
     511                 :            : {
     512                 :            :     if ( nCount <= nPos )
     513                 :            :         return NULL;
     514                 :            : 
     515                 :            :     PBlock* pBlock = pFirst;
     516                 :            :     sal_uIntPtr   nStart = 0;
     517                 :            :     while ( pBlock )
     518                 :            :     {
     519                 :            :         sal_uInt16 i = 0;
     520                 :            :         while ( i < PBLOCKCOUNT )
     521                 :            :         {
     522                 :            :             if ( pBlock->aData[i] )
     523                 :            :             {
     524                 :            :                 nStart++;
     525                 :            :                 if ( (nStart-1) == nPos )
     526                 :            :                     return pBlock->aData[i];
     527                 :            :             }
     528                 :            : 
     529                 :            :             i++;
     530                 :            :         }
     531                 :            : 
     532                 :            :         pBlock = pBlock->pNext;
     533                 :            :     }
     534                 :            : 
     535                 :            :     return NULL;
     536                 :            : }
     537                 :            : 
     538                 :            : sal_Bool PointerList::IsIn( const void* p ) const
     539                 :            : {
     540                 :            :     if ( !p )
     541                 :            :        return sal_False;
     542                 :            : 
     543                 :            :     PBlock* pBlock = pFirst;
     544                 :            :     while ( pBlock )
     545                 :            :     {
     546                 :            :         sal_uInt16 i = 0;
     547                 :            :         while ( i < PBLOCKCOUNT )
     548                 :            :         {
     549                 :            :             if ( ((sal_uIntPtr)p) == ((sal_uIntPtr)pBlock->aData[i]) )
     550                 :            :                 return sal_True;
     551                 :            :             i++;
     552                 :            :         }
     553                 :            : 
     554                 :            :         pBlock = pBlock->pNext;
     555                 :            :     }
     556                 :            : 
     557                 :            :     return sal_False;
     558                 :            : }
     559                 :            : 
     560                 :            : static void DbgGetDbgFileName( sal_Char* pStr, sal_Int32 nMaxLen )
     561                 :            : {
     562                 :            : #if defined( UNX )
     563                 :            :     const sal_Char* pName = getenv("DBGSV_INIT");
     564                 :            :     if ( !pName )
     565                 :            :         pName = ".dbgsv.init";
     566                 :            :     strncpy( pStr, pName, nMaxLen );
     567                 :            : #elif defined( WNT )
     568                 :            :     const sal_Char* pName = getenv("DBGSV_INIT");
     569                 :            :     if ( pName )
     570                 :            :         strncpy( pStr, pName, nMaxLen );
     571                 :            :     else
     572                 :            :         GetProfileStringA( "sv", "dbgsv", "dbgsv.ini", pStr, nMaxLen );
     573                 :            : #else
     574                 :            :     strncpy( pStr, "dbgsv.ini", nMaxLen );
     575                 :            : #endif
     576                 :            :     pStr[ nMaxLen - 1 ] = 0;
     577                 :            : }
     578                 :            : 
     579                 :            : static void DbgGetLogFileName( sal_Char* pStr )
     580                 :            : {
     581                 :            : #if defined( UNX )
     582                 :            :     const sal_Char* pName = getenv("DBGSV_LOG");
     583                 :            :     if ( !pName )
     584                 :            :         pName = "dbgsv.log";
     585                 :            :     strcpy( pStr, pName );
     586                 :            : #elif defined( WNT )
     587                 :            :     const sal_Char* pName = getenv("DBGSV_LOG");
     588                 :            :     if ( pName )
     589                 :            :         strcpy( pStr, pName );
     590                 :            :     else
     591                 :            :         GetProfileStringA( "sv", "dbgsvlog", "dbgsv.log", pStr, 200 );
     592                 :            : #else
     593                 :            :     strcpy( pStr, "dbgsv.log" );
     594                 :            : #endif
     595                 :            : }
     596                 :            : 
     597                 :            : static DebugData* GetDebugData()
     598                 :            : {
     599                 :            :     if ( !aDebugData.bInit )
     600                 :            :     {
     601                 :            :         aDebugData.bInit = sal_True;
     602                 :            : 
     603                 :            :         // set default debug names
     604                 :            :         DbgGetLogFileName( aDebugData.aDbgData.aDebugName );
     605                 :            : 
     606                 :            :         // DEBUG.INI-File
     607                 :            :         sal_Char aBuf[ 4096 ];
     608                 :            :         DbgGetDbgFileName( aBuf, sizeof( aBuf ) );
     609                 :            :         FILETYPE pIniFile = FileOpen( aBuf, "r" );
     610                 :            :         if ( pIniFile != NULL )
     611                 :            :         {
     612                 :            :             ConfigSection eCurrentSection = eUnknown;
     613                 :            : 
     614                 :            :             // no sophisticated algorithm here, assume that the whole file fits into aBuf ...
     615                 :            :             sal_uIntPtr nReallyRead = FileRead( aBuf, 1, sizeof( aBuf ) / sizeof( sal_Char ) - 1, pIniFile );
     616                 :            :             aBuf[ nReallyRead ] = 0;
     617                 :            :             const sal_Char* pLine = aBuf;
     618                 :            :             while ( const sal_Char* pNextLine = strstr( pLine, FILE_LINEEND ) )
     619                 :            :             {
     620                 :            :                 size_t nLineLength = pNextLine - pLine;
     621                 :            : 
     622                 :            :                 if ( lcl_isConfigSection( pLine, nLineLength ) )
     623                 :            :                     eCurrentSection = lcl_getSectionFromName( pLine + 1, nLineLength - 2 );
     624                 :            : 
     625                 :            :                 // elements of the [output] section
     626                 :            :                 if ( eCurrentSection == eOutput )
     627                 :            :                 {
     628                 :            :                     lcl_tryReadConfigString( pLine, nLineLength, "log_file", aDebugData.aDbgData.aDebugName, sizeof( aDebugData.aDbgData.aDebugName ) );
     629                 :            :                     lcl_tryReadConfigBoolean( pLine, nLineLength, "overwrite", &aDebugData.aDbgData.bOverwrite );
     630                 :            :                     lcl_tryReadConfigString( pLine, nLineLength, "include", aDebugData.aDbgData.aInclFilter, sizeof( aDebugData.aDbgData.aInclFilter ) );
     631                 :            :                     lcl_tryReadConfigString( pLine, nLineLength, "exclude", aDebugData.aDbgData.aExclFilter, sizeof( aDebugData.aDbgData.aExclFilter ) );
     632                 :            :                     lcl_tryReadConfigString( pLine, nLineLength, "include_class", aDebugData.aDbgData.aInclClassFilter, sizeof( aDebugData.aDbgData.aInclClassFilter ) );
     633                 :            :                     lcl_tryReadConfigString( pLine, nLineLength, "exclude_class", aDebugData.aDbgData.aExclClassFilter, sizeof( aDebugData.aDbgData.aExclClassFilter ) );
     634                 :            :                     lcl_tryReadOutputChannel( pLine, nLineLength, "trace", &aDebugData.aDbgData.nTraceOut );
     635                 :            :                     lcl_tryReadOutputChannel( pLine, nLineLength, "warning", &aDebugData.aDbgData.nWarningOut );
     636                 :            :                     lcl_tryReadOutputChannel( pLine, nLineLength, "error", &aDebugData.aDbgData.nErrorOut );
     637                 :            :                     lcl_tryReadConfigBoolean( pLine, nLineLength, "oslhook", &aDebugData.aDbgData.bHookOSLAssert );
     638                 :            :                 }
     639                 :            : 
     640                 :            :                 // elements of the [gui] section
     641                 :            :                 if ( eCurrentSection == eGUI )
     642                 :            :                 {
     643                 :            :                     lcl_tryReadConfigString( pLine, nLineLength, "debug_window_state", aDebugData.aDbgData.aDbgWinState, sizeof( aDebugData.aDbgData.aDbgWinState ) );
     644                 :            :                 }
     645                 :            : 
     646                 :            :                 // elements of the [objects] section
     647                 :            :                 if ( eCurrentSection == eObjects )
     648                 :            :                 {
     649                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "check_this", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_THIS );
     650                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "check_function", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_FUNC );
     651                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "check_exit", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_EXIT );
     652                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "generate_report", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_REPORT );
     653                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "trace", &aDebugData.aDbgData.nTestFlags, DBG_TEST_XTOR_TRACE );
     654                 :            :                 }
     655                 :            : 
     656                 :            :                 // elements of the [test] section
     657                 :            :                 if ( eCurrentSection == eTest )
     658                 :            :                 {
     659                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "profiling", &aDebugData.aDbgData.nTestFlags, DBG_TEST_PROFILING );
     660                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "resources", &aDebugData.aDbgData.nTestFlags, DBG_TEST_RESOURCE );
     661                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "dialog", &aDebugData.aDbgData.nTestFlags, DBG_TEST_DIALOG );
     662                 :            :                     lcl_tryReadConfigFlag( pLine, nLineLength, "bold_app_font", &aDebugData.aDbgData.nTestFlags, DBG_TEST_BOLDAPPFONT );
     663                 :            :                 }
     664                 :            : 
     665                 :            :                 pLine = pNextLine + strlen( FILE_LINEEND );
     666                 :            :             }
     667                 :            : 
     668                 :            :             FileClose( pIniFile );
     669                 :            :         }
     670                 :            :         else
     671                 :            :         {
     672                 :            :             lcl_matchOutputChannel( getenv( "DBGSV_TRACE_OUT" ), &aDebugData.aDbgData.nTraceOut );
     673                 :            :             lcl_matchOutputChannel( getenv( "DBGSV_WARNING_OUT" ), &aDebugData.aDbgData.nWarningOut );
     674                 :            :             lcl_matchOutputChannel( getenv( "DBGSV_ERROR_OUT" ), &aDebugData.aDbgData.nErrorOut );
     675                 :            : 
     676                 :            :         }
     677                 :            : 
     678                 :            :         sal_Char* getcwdResult = getcwd( aCurPath, sizeof( aCurPath ) );
     679                 :            :         if ( !getcwdResult )
     680                 :            :         {
     681                 :            :             OSL_TRACE( "getcwd failed with error %s", strerror(errno) );
     682                 :            :         }
     683                 :            : 
     684                 :            :         // initialize debug data
     685                 :            :         if ( aDebugData.aDbgData.nTestFlags & DBG_TEST_XTOR )
     686                 :            :             aDebugData.pXtorList = new PointerList;
     687                 :            :         if ( aDebugData.aDbgData.nTestFlags & DBG_TEST_PROFILING )
     688                 :            :             aDebugData.pProfList = new PointerList;
     689                 :            :     }
     690                 :            : 
     691                 :            :     return &aDebugData;
     692                 :            : }
     693                 :            : 
     694                 :            : inline DebugData* ImplGetDebugData()
     695                 :            : {
     696                 :            :     if ( !aDebugData.bInit )
     697                 :            :         return GetDebugData();
     698                 :            :     else
     699                 :            :         return &aDebugData;
     700                 :            : }
     701                 :            : 
     702                 :            : static FILETYPE ImplDbgInitFile()
     703                 :            : {
     704                 :            :     static sal_Bool bFileInit = sal_False;
     705                 :            : 
     706                 :            :     sal_Char aBuf[4096];
     707                 :            :     sal_Char* getcwdResult = getcwd( aBuf, sizeof( aBuf ) );
     708                 :            :     if ( !getcwdResult ) {
     709                 :            :         OSL_TRACE( "getcwd failed with error = %s", strerror(errno) );
     710                 :            :         return NULL;
     711                 :            :     }
     712                 :            : 
     713                 :            :     int chdirResult = chdir( aCurPath );
     714                 :            :     if ( !chdirResult ) {
     715                 :            :         OSL_TRACE ( "chdir failed with error = %s", strerror(errno) );
     716                 :            :         return NULL;
     717                 :            :     }
     718                 :            : 
     719                 :            :     DebugData*  pData = GetDebugData();
     720                 :            :     FILETYPE    pDebugFile;
     721                 :            : 
     722                 :            :     if ( !bFileInit )
     723                 :            :     {
     724                 :            :         bFileInit = sal_True;
     725                 :            : 
     726                 :            :         if ( pData->aDbgData.bOverwrite )
     727                 :            :             pDebugFile = FileOpen( pData->aDbgData.aDebugName, "w" );
     728                 :            :         else
     729                 :            :             pDebugFile = FileOpen( pData->aDbgData.aDebugName, "a" );
     730                 :            : 
     731                 :            :         if ( pDebugFile )
     732                 :            :         {
     733                 :            :             time_t  nTime = time( 0 );
     734                 :            :             tm*     pTime;
     735                 :            : #ifdef UNX
     736                 :            :             tm      aTime;
     737                 :            :             pTime = localtime_r( &nTime, &aTime );
     738                 :            : #else
     739                 :            :             pTime = localtime( &nTime );
     740                 :            : #endif
     741                 :            : 
     742                 :            :             // print header
     743                 :            :             FilePrintF( pDebugFile, "******************************************************************************%s", FILE_LINEEND );
     744                 :            :             FilePrintF( pDebugFile, "%s%s", pData->aDbgData.aDebugName, FILE_LINEEND );
     745                 :            :             if ( pTime )
     746                 :            :                 FilePrintF( pDebugFile, "%s%s", asctime( pTime ), FILE_LINEEND );
     747                 :            :         }
     748                 :            :     }
     749                 :            :     else
     750                 :            :         pDebugFile = FileOpen( pData->aDbgData.aDebugName, "a" );
     751                 :            : 
     752                 :            :     chdirResult = chdir( aBuf );
     753                 :            :     if ( !chdirResult )
     754                 :            :     {
     755                 :            :         OSL_TRACE( "chdir failed with error = %s", strerror(errno) );
     756                 :            :     }
     757                 :            : 
     758                 :            :     return pDebugFile;
     759                 :            : }
     760                 :            : 
     761                 :            : static void ImplDbgPrintFile( const sal_Char* pLine )
     762                 :            : {
     763                 :            :     FILETYPE pDebugFile = ImplDbgInitFile();
     764                 :            : 
     765                 :            :     if ( pDebugFile )
     766                 :            :     {
     767                 :            :         FilePrintF( pDebugFile, "%s%s", pLine, FILE_LINEEND );
     768                 :            :         FileClose( pDebugFile );
     769                 :            :     }
     770                 :            : }
     771                 :            : 
     772                 :            : static int ImplStrSearch( const sal_Char* pSearchStr, int nSearchLen,
     773                 :            :                           const sal_Char* pStr, int nLen )
     774                 :            : {
     775                 :            :     int nPos = 0;
     776                 :            :     while ( nPos+nSearchLen <= nLen )
     777                 :            :     {
     778                 :            :         if ( strncmp( pStr+nPos, pSearchStr, nSearchLen ) == 0 )
     779                 :            :             return 1;
     780                 :            :         nPos++;
     781                 :            :     }
     782                 :            : 
     783                 :            :     return 0;
     784                 :            : }
     785                 :            : 
     786                 :            : static int ImplDbgFilter( const sal_Char* pFilter, const sal_Char* pMsg,
     787                 :            :                           int bEmpty )
     788                 :            : {
     789                 :            :     int nStrLen = strlen( pFilter );
     790                 :            :     if ( !nStrLen )
     791                 :            :         return bEmpty;
     792                 :            : 
     793                 :            :     int nMsgLen = strlen( pMsg );
     794                 :            :     const sal_Char* pTok = pFilter;
     795                 :            :     int         nTok = 0;
     796                 :            :     while ( pTok[nTok] )
     797                 :            :     {
     798                 :            :         if ( pTok[nTok] == ';' )
     799                 :            :         {
     800                 :            :             if ( nTok && ImplStrSearch( pTok, nTok, pMsg, nMsgLen ) )
     801                 :            :                 return sal_True;
     802                 :            : 
     803                 :            :             pTok += nTok+1;
     804                 :            :             nTok = 0;
     805                 :            :         }
     806                 :            : 
     807                 :            :         nTok++;
     808                 :            :     }
     809                 :            : 
     810                 :            :     if ( nTok && ImplStrSearch( pTok, nTok, pMsg, nMsgLen ) )
     811                 :            :         return sal_True;
     812                 :            :     else
     813                 :            :         return sal_False;
     814                 :            : }
     815                 :            : 
     816                 :            : extern "C"
     817                 :            : void SAL_CALL dbg_printOslDebugMessage( const sal_Char * pszFileName, sal_Int32 nLine, const sal_Char * pszMessage )
     818                 :            : {
     819                 :            :     DbgOut( pszMessage ? pszMessage : "assertion failed!", DBG_OUT_ERROR, pszFileName, (sal_uInt16)nLine );
     820                 :            : }
     821                 :            : 
     822                 :            : static void DebugInit()
     823                 :            : {
     824                 :            :     bDbgImplInMain = sal_True;
     825                 :            :     ImplDbgInitLock();
     826                 :            : 
     827                 :            :     DebugData* pData = GetDebugData();
     828                 :            :     if( pData->aDbgData.bHookOSLAssert && ! pData->bOslIsHooked )
     829                 :            :     {
     830                 :            :         pData->pOldDebugMessageFunc = osl_setDetailedDebugMessageFunc( &dbg_printOslDebugMessage );
     831                 :            :         pData->bOslIsHooked = true;
     832                 :            :     }
     833                 :            : }
     834                 :            : 
     835                 :            : static void DebugDeInit()
     836                 :            : {
     837                 :            :     DebugData*  pData = GetDebugData();
     838                 :            :     sal_uIntPtr       i;
     839                 :            :     sal_uIntPtr       nCount;
     840                 :            :     sal_uIntPtr       nOldOut;
     841                 :            : 
     842                 :            :     if( pData->bOslIsHooked )
     843                 :            :     {
     844                 :            :         osl_setDetailedDebugMessageFunc( pData->pOldDebugMessageFunc );
     845                 :            :         pData->bOslIsHooked = sal_False;
     846                 :            :     }
     847                 :            : 
     848                 :            :     // Output statistics trace data to file
     849                 :            :     nOldOut = pData->aDbgData.nTraceOut;
     850                 :            :     pData->aDbgData.nTraceOut = DBG_OUT_FILE;
     851                 :            : 
     852                 :            :     // output Xtor list
     853                 :            :     if ( pData->pXtorList && pData->pXtorList->Count() &&
     854                 :            :          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_REPORT) )
     855                 :            :     {
     856                 :            :         DbgOutf( "------------------------------------------------------------------------------" );
     857                 :            :         DbgOutf( "Object Report" );
     858                 :            :         DbgOutf( "------------------------------------------------------------------------------" );
     859                 :            :         DbgOutf( "%-27s : %-9s : %-9s : %-7s : %-3s : %-6s :",
     860                 :            :                  "XTor-List", "Ctor", "Dtor", "MaxInst", "St.", "Diff." );
     861                 :            :         DbgOutf( "----------------------------:-----------:-----------:---------:----:---------:" );
     862                 :            :         for( i = 0, nCount = pData->pXtorList->Count(); i < nCount; i++ )
     863                 :            :         {
     864                 :            :             XtorType* pXtorData = (XtorType*)pData->pXtorList->Get( i );
     865                 :            :             if ( pXtorData->bTest )
     866                 :            :             {
     867                 :            :                 // Add static objects
     868                 :            :                 pXtorData->nDtorCalls += pXtorData->nStatics;
     869                 :            :                 if ( pXtorData->nStatics && (pXtorData->nDtorCalls > pXtorData->nCtorCalls) )
     870                 :            :                     pXtorData->nDtorCalls = pXtorData->nCtorCalls;
     871                 :            :                 DbgOutf( "%-27s : %9lu : %9lu : %7lu : %3lu : %4lu %-1s :",
     872                 :            :                          pXtorData->aName, pXtorData->nCtorCalls, pXtorData->nDtorCalls,
     873                 :            :                          pXtorData->nMaxCount, pXtorData->nStatics,
     874                 :            :                          pXtorData->nCtorCalls - pXtorData->nDtorCalls,
     875                 :            :                          (pXtorData->nCtorCalls - pXtorData->nDtorCalls) ? "!" : " " );
     876                 :            :             }
     877                 :            :         }
     878                 :            :         DbgOutf( "==============================================================================" );
     879                 :            :     }
     880                 :            : 
     881                 :            :     // free XtorList
     882                 :            :     if ( pData->pXtorList )
     883                 :            :     {
     884                 :            :         for( i = 0, nCount = pData->pXtorList->Count(); i < nCount; i++ )
     885                 :            :         {
     886                 :            :             XtorType* pXtorData = (XtorType*)pData->pXtorList->Get( i );
     887                 :            :             delete pXtorData;
     888                 :            :         }
     889                 :            :         delete pData->pXtorList;
     890                 :            :         pData->pXtorList = NULL;
     891                 :            :     }
     892                 :            : 
     893                 :            :     // Set everything to sal_False, as global variables
     894                 :            :     // may cause a system crash otherwise.
     895                 :            :     // Maintain memory flags, as otherwise new/delete calls
     896                 :            :     // for global variables will crash,
     897                 :            :     // as pointer alignment won't work then.
     898                 :            :     pData->aDbgData.nTraceOut   = nOldOut;
     899                 :            :     pData->aDbgData.nTestFlags &= DBG_TEST_PROFILING;
     900                 :            :     pData->aDbgPrintUserChannels.clear();
     901                 :            :     pData->pDbgPrintTestTool    = NULL;
     902                 :            :     pData->pDbgPrintWindow      = NULL;
     903                 :            :     pData->pOldDebugMessageFunc = NULL;
     904                 :            :     ImplDbgDeInitLock();
     905                 :            : }
     906                 :            : 
     907                 :            : static void DebugGlobalDeInit()
     908                 :            : {
     909                 :            :     DebugData*  pData = GetDebugData();
     910                 :            :     sal_uIntPtr       i;
     911                 :            :     sal_uIntPtr       nCount;
     912                 :            :     sal_uIntPtr       nOldOut;
     913                 :            : 
     914                 :            :     // Output statistics trace data to file
     915                 :            :     nOldOut = pData->aDbgData.nTraceOut;
     916                 :            :     pData->aDbgData.nTraceOut = DBG_OUT_FILE;
     917                 :            : 
     918                 :            :     // output profile liste
     919                 :            :     if ( pData->pProfList && pData->pProfList->Count() )
     920                 :            :     {
     921                 :            :         DbgOutf( "------------------------------------------------------------------------------" );
     922                 :            :         DbgOutf( "Profiling Report" );
     923                 :            :         DbgOutf( "------------------------------------------------------------------------------" );
     924                 :            :         DbgOutf( "%-25s : %-9s : %-6s : %-6s : %-6s : %-9s :",
     925                 :            :                  "Prof-List (ms)", "Time", "Min", "Max", "Ave", "Count" );
     926                 :            :         DbgOutf( "--------------------------:-----------:--------:--------:--------:-----------:" );
     927                 :            :         for( i = 0, nCount = pData->pProfList->Count(); i < nCount; i++ )
     928                 :            :         {
     929                 :            :             ProfType* pProfData = (ProfType*)pData->pProfList->Get( i );
     930                 :            :             sal_uIntPtr nAve = pProfData->nTime / pProfData->nCount;
     931                 :            :             DbgOutf( "%-25s : %9lu : %6lu : %6lu : %6lu : %9lu :",
     932                 :            :                      pProfData->aName, pProfData->nTime,
     933                 :            :                      pProfData->nMinTime, pProfData->nMaxTime, nAve,
     934                 :            :                      pProfData->nCount );
     935                 :            :         }
     936                 :            :         DbgOutf( "==============================================================================" );
     937                 :            :     }
     938                 :            : 
     939                 :            :     // free profile list
     940                 :            :     if ( pData->pProfList )
     941                 :            :     {
     942                 :            :         for( i = 0, nCount = pData->pProfList->Count(); i < nCount; i++ )
     943                 :            :         {
     944                 :            :             ProfType* pProfData = (ProfType*)pData->pProfList->Get( i );
     945                 :            :             delete pProfData;
     946                 :            :         }
     947                 :            :         delete pData->pProfList;
     948                 :            :         pData->pProfList = NULL;
     949                 :            :     }
     950                 :            : 
     951                 :            :     // disable profiling flags
     952                 :            :     pData->aDbgData.nTraceOut   = nOldOut;
     953                 :            :     pData->aDbgData.nTestFlags &= ~DBG_TEST_PROFILING;
     954                 :            : }
     955                 :            : 
     956                 :            : void ImpDbgOutfBuf( sal_Char* pBuf, const sal_Char* pFStr, ... )
     957                 :            : {
     958                 :            :     va_list pList;
     959                 :            : 
     960                 :            :     va_start( pList, pFStr );
     961                 :            :     sal_Char aBuf[DBG_BUF_MAXLEN];
     962                 :            :     vsprintf( aBuf, pFStr, pList );
     963                 :            :     va_end( pList );
     964                 :            : 
     965                 :            :     strcat( pBuf, aBuf );
     966                 :            :     strcat( pBuf, "\n" );
     967                 :            : }
     968                 :            : 
     969                 :            : static void DebugXTorInfo( sal_Char* pBuf )
     970                 :            : {
     971                 :            :     DebugData*  pData = GetDebugData();
     972                 :            :     sal_uIntPtr       i;
     973                 :            :     sal_uIntPtr       nCount;
     974                 :            : 
     975                 :            :     // output Xtor list
     976                 :            :     if ( pData->pXtorList && pData->pXtorList->Count() &&
     977                 :            :          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_REPORT) )
     978                 :            :     {
     979                 :            :         ImpDbgOutfBuf( pBuf, "------------------------------------------------------------------------------" );
     980                 :            :         ImpDbgOutfBuf( pBuf, "Object Report" );
     981                 :            :         ImpDbgOutfBuf( pBuf, "------------------------------------------------------------------------------" );
     982                 :            :         ImpDbgOutfBuf( pBuf, "%-27s : %-9s : %-9s : %-7s : %-3s : %-6s :",
     983                 :            :                        "XTor-List", "Ctor", "Dtor", "MaxInst", "St.", "Diff." );
     984                 :            :         ImpDbgOutfBuf( pBuf, "----------------------------:-----------:-----------:---------:----:---------:" );
     985                 :            :         for( i = 0, nCount = pData->pXtorList->Count(); i < nCount; i++ )
     986                 :            :         {
     987                 :            :             XtorType* pXtorData = (XtorType*)pData->pXtorList->Get( i );
     988                 :            :             if ( pXtorData->bTest )
     989                 :            :             {
     990                 :            :                 ImpDbgOutfBuf( pBuf, "%-27s : %9lu : %9lu : %7lu : %3lu : %6lu :",
     991                 :            :                                pXtorData->aName, pXtorData->nCtorCalls, pXtorData->nDtorCalls,
     992                 :            :                                pXtorData->nMaxCount, pXtorData->nStatics,
     993                 :            :                                pXtorData->nCtorCalls - pXtorData->nDtorCalls );
     994                 :            :             }
     995                 :            :         }
     996                 :            :         ImpDbgOutfBuf( pBuf, "==============================================================================" );
     997                 :            :         ImpDbgOutfBuf( pBuf, "" );
     998                 :            :     }
     999                 :            : }
    1000                 :            : 
    1001                 :            : sal_Bool ImplDbgFilterMessage( const sal_Char* pMsg )
    1002                 :            : {
    1003                 :            :     DebugData*  pData = GetDebugData();
    1004                 :            :     if ( !ImplDbgFilter( pData->aDbgData.aInclFilter, pMsg, sal_True ) )
    1005                 :            :         return sal_True;
    1006                 :            :     if ( ImplDbgFilter( pData->aDbgData.aExclFilter, pMsg, sal_False ) )
    1007                 :            :         return sal_True;
    1008                 :            :     return sal_False;
    1009                 :            : }
    1010                 :            : 
    1011                 :            : void* DbgFunc( sal_uInt16 nAction, void* pParam )
    1012                 :            : {
    1013                 :            :     DebugData* pDebugData = ImplGetDebugData();
    1014                 :            : 
    1015                 :            :     if ( nAction == DBG_FUNC_GETDATA )
    1016                 :            :         return (void*)&(pDebugData->aDbgData);
    1017                 :            :     else if ( nAction == DBG_FUNC_GETPRINTMSGBOX )
    1018                 :            :         return (void*)(long)(pDebugData->pDbgPrintMsgBox);
    1019                 :            :     else if ( nAction == DBG_FUNC_FILTERMESSAGE )
    1020                 :            :         if ( ImplDbgFilterMessage( (const sal_Char*) pParam ) )
    1021                 :            :             return (void*) -1;
    1022                 :            :         else
    1023                 :            :             return (void*) 0;   // aka NULL
    1024                 :            :     else
    1025                 :            : 
    1026                 :            :     {
    1027                 :            :         switch ( nAction )
    1028                 :            :         {
    1029                 :            :             case DBG_FUNC_DEBUGSTART:
    1030                 :            :                 DebugInit();
    1031                 :            :                 break;
    1032                 :            : 
    1033                 :            :             case DBG_FUNC_DEBUGEND:
    1034                 :            :                 DebugDeInit();
    1035                 :            :                 break;
    1036                 :            : 
    1037                 :            :             case DBG_FUNC_GLOBALDEBUGEND:
    1038                 :            :                 DebugGlobalDeInit();
    1039                 :            :                 break;
    1040                 :            : 
    1041                 :            :             case DBG_FUNC_SETPRINTMSGBOX:
    1042                 :            :                 pDebugData->pDbgPrintMsgBox = (DbgPrintLine)(long)pParam;
    1043                 :            :                 break;
    1044                 :            : 
    1045                 :            :             case DBG_FUNC_SETPRINTWINDOW:
    1046                 :            :                 pDebugData->pDbgPrintWindow = (DbgPrintLine)(long)pParam;
    1047                 :            :                 break;
    1048                 :            : 
    1049                 :            :             case DBG_FUNC_SETPRINTTESTTOOL:
    1050                 :            :                 pDebugData->pDbgPrintTestTool = (DbgPrintLine)(long)pParam;
    1051                 :            :                 break;
    1052                 :            : 
    1053                 :            :             case DBG_FUNC_SET_ABORT:
    1054                 :            :                 pDebugData->pDbgAbort = (DbgPrintLine)(long)pParam;
    1055                 :            :                 break;
    1056                 :            : 
    1057                 :            :             case DBG_FUNC_SAVEDATA:
    1058                 :            :                 {
    1059                 :            :                 const DbgData* pData = static_cast< const DbgData* >( pParam );
    1060                 :            : 
    1061                 :            :                 sal_Char aBuf[ 4096 ];
    1062                 :            :                 DbgGetDbgFileName( aBuf, sizeof( aBuf ) );
    1063                 :            :                 FILETYPE pIniFile = FileOpen( aBuf, "w" );
    1064                 :            :                 if ( pIniFile == NULL )
    1065                 :            :                     break;
    1066                 :            : 
    1067                 :            :                 lcl_startSection( pIniFile, eOutput );
    1068                 :            :                 lcl_writeConfigString( pIniFile, "log_file", pData->aDebugName );
    1069                 :            :                 lcl_writeConfigBoolean( pIniFile, "overwrite", pData->bOverwrite );
    1070                 :            :                 lcl_writeConfigString( pIniFile, "include", pData->aInclFilter );
    1071                 :            :                 lcl_writeConfigString( pIniFile, "exclude", pData->aExclFilter );
    1072                 :            :                 lcl_writeConfigString( pIniFile, "include_class", pData->aInclClassFilter );
    1073                 :            :                 lcl_writeConfigString( pIniFile, "exclude_class", pData->aExclClassFilter );
    1074                 :            :                 lcl_writeConfigOutChannel( pIniFile, "trace", pData->nTraceOut );
    1075                 :            :                 lcl_writeConfigOutChannel( pIniFile, "warning", pData->nWarningOut );
    1076                 :            :                 lcl_writeConfigOutChannel( pIniFile, "error", pData->nErrorOut );
    1077                 :            :                 lcl_writeConfigBoolean( pIniFile, "oslhook", pData->bHookOSLAssert );
    1078                 :            : 
    1079                 :            :                 lcl_lineFeed( pIniFile );
    1080                 :            :                 lcl_startSection( pIniFile, eGUI );
    1081                 :            :                 lcl_writeConfigString( pIniFile, "debug_window_state", pData->aDbgWinState );
    1082                 :            : 
    1083                 :            :                 lcl_lineFeed( pIniFile );
    1084                 :            :                 lcl_startSection( pIniFile, eObjects );
    1085                 :            :                 lcl_writeConfigFlag( pIniFile, "check_this", pData->nTestFlags, DBG_TEST_XTOR_THIS );
    1086                 :            :                 lcl_writeConfigFlag( pIniFile, "check_function", pData->nTestFlags, DBG_TEST_XTOR_FUNC );
    1087                 :            :                 lcl_writeConfigFlag( pIniFile, "check_exit", pData->nTestFlags, DBG_TEST_XTOR_EXIT );
    1088                 :            :                 lcl_writeConfigFlag( pIniFile, "generate_report", pData->nTestFlags, DBG_TEST_XTOR_REPORT );
    1089                 :            :                 lcl_writeConfigFlag( pIniFile, "trace", pData->nTestFlags, DBG_TEST_XTOR_TRACE );
    1090                 :            : 
    1091                 :            :                 lcl_lineFeed( pIniFile );
    1092                 :            :                 lcl_startSection( pIniFile, eTest );
    1093                 :            :                 lcl_writeConfigFlag( pIniFile, "profiling", pData->nTestFlags, DBG_TEST_PROFILING );
    1094                 :            :                 lcl_writeConfigFlag( pIniFile, "resources", pData->nTestFlags, DBG_TEST_RESOURCE );
    1095                 :            :                 lcl_writeConfigFlag( pIniFile, "dialog", pData->nTestFlags, DBG_TEST_DIALOG );
    1096                 :            :                 lcl_writeConfigFlag( pIniFile, "bold_app_font", pData->nTestFlags, DBG_TEST_BOLDAPPFONT );
    1097                 :            : 
    1098                 :            :                 FileClose( pIniFile );
    1099                 :            :                 }
    1100                 :            :                 break;
    1101                 :            : 
    1102                 :            :             case DBG_FUNC_XTORINFO:
    1103                 :            :                 DebugXTorInfo( (sal_Char*)pParam );
    1104                 :            :                 break;
    1105                 :            : 
    1106                 :            :             case DBG_FUNC_COREDUMP:
    1107                 :            :                 ImplCoreDump();
    1108                 :            :                 break;
    1109                 :            : 
    1110                 :            :             case DBG_FUNC_ALLERROROUT:
    1111                 :            :                 return (void*)(sal_uIntPtr)sal_True;
    1112                 :            : 
    1113                 :            :             case DBG_FUNC_SETTESTSOLARMUTEX:
    1114                 :            :                 pDebugData->pDbgTestSolarMutex = (DbgTestSolarMutexProc)(long)pParam;
    1115                 :            :                 break;
    1116                 :            : 
    1117                 :            :             case DBG_FUNC_TESTSOLARMUTEX:
    1118                 :            :                 if ( pDebugData->pDbgTestSolarMutex )
    1119                 :            :                     pDebugData->pDbgTestSolarMutex();
    1120                 :            :                 break;
    1121                 :            : 
    1122                 :            :             case DBG_FUNC_PRINTFILE:
    1123                 :            :                 ImplDbgPrintFile( (const sal_Char*)pParam );
    1124                 :            :                 break;
    1125                 :            :             case DBG_FUNC_UPDATEOSLHOOK:
    1126                 :            :             {
    1127                 :            :                 const DbgData* pData = static_cast< const DbgData* >( pParam );
    1128                 :            :                 pDebugData->aDbgData.bHookOSLAssert = pData->bHookOSLAssert;
    1129                 :            :                 if( pDebugData->bOslIsHooked && ! pData->bHookOSLAssert )
    1130                 :            :                 {
    1131                 :            :                     osl_setDetailedDebugMessageFunc( pDebugData->pOldDebugMessageFunc );
    1132                 :            :                     pDebugData->bOslIsHooked = sal_False;
    1133                 :            :                 }
    1134                 :            :                 else if( ! pDebugData->bOslIsHooked && pData->bHookOSLAssert )
    1135                 :            :                 {
    1136                 :            :                     pDebugData->pOldDebugMessageFunc = osl_setDetailedDebugMessageFunc( &dbg_printOslDebugMessage );
    1137                 :            :                     pDebugData->bOslIsHooked = sal_True;
    1138                 :            :                 }
    1139                 :            :             }
    1140                 :            :             break;
    1141                 :            :        }
    1142                 :            : 
    1143                 :            :         return NULL;
    1144                 :            :     }
    1145                 :            : }
    1146                 :            : 
    1147                 :            : DbgChannelId DbgRegisterUserChannel( DbgPrintLine pProc )
    1148                 :            : {
    1149                 :            :     DebugData* pData = ImplGetDebugData();
    1150                 :            :     pData->aDbgPrintUserChannels.push_back( pProc );
    1151                 :            :     return (DbgChannelId)( pData->aDbgPrintUserChannels.size() - 1 + DBG_OUT_USER_CHANNEL_0 );
    1152                 :            : }
    1153                 :            : 
    1154                 :            : void DbgProf( sal_uInt16 nAction, DbgDataType* pDbgData )
    1155                 :            : {
    1156                 :            :     DebugData* pData = ImplGetDebugData();
    1157                 :            : 
    1158                 :            :     if ( !(pData->aDbgData.nTestFlags & DBG_TEST_PROFILING) )
    1159                 :            :         return;
    1160                 :            : 
    1161                 :            :     ProfType*   pProfData = (ProfType*)pDbgData->pData;
    1162                 :            :     sal_uIntPtr       nTime;
    1163                 :            :     if ( (nAction != DBG_PROF_START) && !pProfData )
    1164                 :            :     {
    1165                 :            :         SAL_WARN(
    1166                 :            :             "tools.debug",
    1167                 :            :             "DBG_PROF...() without DBG_PROFSTART(): " << pDbgData->pName);
    1168                 :            :         return;
    1169                 :            :     }
    1170                 :            : 
    1171                 :            :     switch ( nAction )
    1172                 :            :     {
    1173                 :            :         case DBG_PROF_START:
    1174                 :            :             if ( !pDbgData->pData )
    1175                 :            :             {
    1176                 :            :                 pDbgData->pData = (void*)new ProfType;
    1177                 :            :                 pProfData = (ProfType*)pDbgData->pData;
    1178                 :            :                 strncpy( pProfData->aName, pDbgData->pName, DBG_MAXNAME );
    1179                 :            :                 pProfData->aName[DBG_MAXNAME] = '\0';
    1180                 :            :                 pProfData->nCount           = 0;
    1181                 :            :                 pProfData->nTime            = 0;
    1182                 :            :                 pProfData->nMinTime         = 0xFFFFFFFF;
    1183                 :            :                 pProfData->nMaxTime         = 0;
    1184                 :            :                 pProfData->nStart           = 0xFFFFFFFF;
    1185                 :            :                 pProfData->nContinueTime    = 0;
    1186                 :            :                 pProfData->nContinueStart   = 0xFFFFFFFF;
    1187                 :            :                 pData->pProfList->Add( (void*)pProfData );
    1188                 :            :             }
    1189                 :            : 
    1190                 :            :             if ( pProfData->nStart == 0xFFFFFFFF )
    1191                 :            :             {
    1192                 :            :                 pProfData->nStart = ImplGetPerfTime();
    1193                 :            :                 pProfData->nCount++;
    1194                 :            :             }
    1195                 :            :             break;
    1196                 :            : 
    1197                 :            :         case DBG_PROF_STOP:
    1198                 :            :             nTime = ImplGetPerfTime();
    1199                 :            : 
    1200                 :            :             if ( pProfData->nStart == 0xFFFFFFFF )
    1201                 :            :             {
    1202                 :            :                 SAL_WARN(
    1203                 :            :                     "tools.debug", "DBG_PROF...() without DBG_PROFSTART()");
    1204                 :            :                 return;
    1205                 :            :             }
    1206                 :            : 
    1207                 :            :             if ( pProfData->nContinueStart != 0xFFFFFFFF )
    1208                 :            :             {
    1209                 :            :                 pProfData->nContinueTime += ImplGetPerfTime() - pProfData->nContinueStart;
    1210                 :            :                 pProfData->nContinueStart = 0xFFFFFFFF;
    1211                 :            :             }
    1212                 :            : 
    1213                 :            :             nTime -= pProfData->nStart;
    1214                 :            :             nTime -= pProfData->nContinueTime;
    1215                 :            : 
    1216                 :            :             if ( nTime < pProfData->nMinTime )
    1217                 :            :                 pProfData->nMinTime = nTime;
    1218                 :            : 
    1219                 :            :             if ( nTime > pProfData->nMaxTime )
    1220                 :            :                 pProfData->nMaxTime = nTime;
    1221                 :            : 
    1222                 :            :             pProfData->nTime += nTime;
    1223                 :            : 
    1224                 :            :             pProfData->nStart         = 0xFFFFFFFF;
    1225                 :            :             pProfData->nContinueTime  = 0;
    1226                 :            :             pProfData->nContinueStart = 0xFFFFFFFF;
    1227                 :            :             break;
    1228                 :            : 
    1229                 :            :         case DBG_PROF_CONTINUE:
    1230                 :            :             if ( pProfData->nContinueStart != 0xFFFFFFFF )
    1231                 :            :             {
    1232                 :            :                 pProfData->nContinueTime += ImplGetPerfTime() - pProfData->nContinueStart;
    1233                 :            :                 pProfData->nContinueStart = 0xFFFFFFFF;
    1234                 :            :             }
    1235                 :            :             break;
    1236                 :            : 
    1237                 :            :         case DBG_PROF_PAUSE:
    1238                 :            :             if ( pProfData->nContinueStart == 0xFFFFFFFF )
    1239                 :            :                 pProfData->nContinueStart = ImplGetPerfTime();
    1240                 :            :             break;
    1241                 :            :     }
    1242                 :            : }
    1243                 :            : 
    1244                 :            : void DbgXtor( DbgDataType* pDbgData, sal_uInt16 nAction, const void* pThis,
    1245                 :            :               DbgUsr fDbgUsr )
    1246                 :            : {
    1247                 :            :     DebugData* pData = ImplGetDebugData();
    1248                 :            : 
    1249                 :            :     // quick test
    1250                 :            :     if ( !(pData->aDbgData.nTestFlags & DBG_TEST_XTOR) )
    1251                 :            :         return;
    1252                 :            : 
    1253                 :            :     XtorType* pXtorData = (XtorType*)pDbgData->pData;
    1254                 :            :     if ( !pXtorData )
    1255                 :            :     {
    1256                 :            :         pDbgData->pData = (void*)new XtorType;
    1257                 :            :         pXtorData = (XtorType*)pDbgData->pData;
    1258                 :            :         strncpy( pXtorData->aName, pDbgData->pName, DBG_MAXNAME );
    1259                 :            :         pXtorData->aName[DBG_MAXNAME] = '\0';
    1260                 :            :         pXtorData->nCtorCalls   = 0;
    1261                 :            :         pXtorData->nDtorCalls   = 0;
    1262                 :            :         pXtorData->nMaxCount    = 0;
    1263                 :            :         pXtorData->nStatics     = 0;
    1264                 :            :         pXtorData->bTest        = sal_True;
    1265                 :            :         pData->pXtorList->Add( (void*)pXtorData );
    1266                 :            : 
    1267                 :            :         if ( !ImplDbgFilter( pData->aDbgData.aInclClassFilter, pXtorData->aName, sal_True ) )
    1268                 :            :             pXtorData->bTest = sal_False;
    1269                 :            :         if ( ImplDbgFilter( pData->aDbgData.aExclClassFilter, pXtorData->aName, sal_False ) )
    1270                 :            :             pXtorData->bTest = sal_False;
    1271                 :            :     }
    1272                 :            :     if ( !pXtorData->bTest )
    1273                 :            :         return;
    1274                 :            : 
    1275                 :            :     sal_uInt16      nAct = nAction & ~DBG_XTOR_DTOROBJ;
    1276                 :            : 
    1277                 :            :     SAL_INFO_IF(
    1278                 :            :         ((pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE)
    1279                 :            :          && !(nAction & DBG_XTOR_DTOROBJ) && nAct != DBG_XTOR_CHKOBJ),
    1280                 :            :         "tools.debug",
    1281                 :            :         (nAct == DBG_XTOR_CTOR ? "Enter Ctor from class "
    1282                 :            :          : nAct == DBG_XTOR_DTOR ? "Enter Dtor from class "
    1283                 :            :          : "Enter method from class ") << pDbgData->pName);
    1284                 :            : 
    1285                 :            :     // If some Xtor-tests are still tracing
    1286                 :            :     if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXTRA )
    1287                 :            :     {
    1288                 :            :         // call DBG_CTOR before all other DBG_XTOR calls
    1289                 :            :         if ( ((nAction & ~DBG_XTOR_DTOROBJ) != DBG_XTOR_CTOR) && !pDbgData->pData )
    1290                 :            :         {
    1291                 :            :             SAL_WARN(
    1292                 :            :                 "tools.debug",
    1293                 :            :                 "DBG_DTOR() or DBG_CHKTHIS() without DBG_CTOR(): "
    1294                 :            :                     << pDbgData->pName);
    1295                 :            :             return;
    1296                 :            :         }
    1297                 :            : 
    1298                 :            :         // Test if the pointer is still valid
    1299                 :            :         if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_THIS )
    1300                 :            :         {
    1301                 :            :             if ( (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXIT) ||
    1302                 :            :                  !(nAction & DBG_XTOR_DTOROBJ) )
    1303                 :            :             {
    1304                 :            :                 // This-Pointer == NULL
    1305                 :            :                 if ( !pThis )
    1306                 :            :                 {
    1307                 :            :                     SAL_WARN(
    1308                 :            :                         "tools.debug",
    1309                 :            :                         "this == NULL in class " << pDbgData->pName);
    1310                 :            :                     return;
    1311                 :            :                 }
    1312                 :            : 
    1313                 :            :                 if ( (nAction & ~DBG_XTOR_DTOROBJ) != DBG_XTOR_CTOR )
    1314                 :            :                 {
    1315                 :            :                     SAL_WARN_IF(
    1316                 :            :                         !pXtorData->aThisList.IsIn(pThis), "tools.debug",
    1317                 :            :                         "invalid this-Pointer %p in class " << pDbgData->pName);
    1318                 :            :                 }
    1319                 :            :             }
    1320                 :            :         }
    1321                 :            : 
    1322                 :            :         // execute function test and update maintenance data
    1323                 :            :         const sal_Char* pMsg = NULL;
    1324                 :            :         switch ( nAction & ~DBG_XTOR_DTOROBJ )
    1325                 :            :         {
    1326                 :            :             case DBG_XTOR_CTOR:
    1327                 :            :                 if ( nAction & DBG_XTOR_DTOROBJ )
    1328                 :            :                 {
    1329                 :            :                     if ( fDbgUsr &&
    1330                 :            :                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXIT) &&
    1331                 :            :                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
    1332                 :            :                         pMsg = fDbgUsr( pThis );
    1333                 :            :                 }
    1334                 :            :                 else
    1335                 :            :                 {
    1336                 :            :                     pXtorData->nCtorCalls++;
    1337                 :            :                     if ( !bDbgImplInMain )
    1338                 :            :                         pXtorData->nStatics++;
    1339                 :            :                     if ( (pXtorData->nCtorCalls-pXtorData->nDtorCalls) > pXtorData->nMaxCount )
    1340                 :            :                         pXtorData->nMaxCount = pXtorData->nCtorCalls - pXtorData->nDtorCalls;
    1341                 :            : 
    1342                 :            :                     if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_THIS )
    1343                 :            :                         pXtorData->aThisList.Add( pThis );
    1344                 :            :                 }
    1345                 :            :                 break;
    1346                 :            : 
    1347                 :            :             case DBG_XTOR_DTOR:
    1348                 :            :                 if ( nAction & DBG_XTOR_DTOROBJ )
    1349                 :            :                 {
    1350                 :            :                     pXtorData->nDtorCalls++;
    1351                 :            :                     if ( pData->aDbgData.nTestFlags & DBG_TEST_XTOR_THIS )
    1352                 :            :                         pXtorData->aThisList.Remove( pThis );
    1353                 :            :                 }
    1354                 :            :                 else
    1355                 :            :                 {
    1356                 :            :                     if ( fDbgUsr &&
    1357                 :            :                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
    1358                 :            :                         pMsg = fDbgUsr( pThis );
    1359                 :            :                 }
    1360                 :            :                 break;
    1361                 :            : 
    1362                 :            :             case DBG_XTOR_CHKTHIS:
    1363                 :            :             case DBG_XTOR_CHKOBJ:
    1364                 :            :                 if ( nAction & DBG_XTOR_DTOROBJ )
    1365                 :            :                 {
    1366                 :            :                     if ( fDbgUsr &&
    1367                 :            :                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_EXIT) &&
    1368                 :            :                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
    1369                 :            :                         pMsg = fDbgUsr( pThis );
    1370                 :            :                 }
    1371                 :            :                 else
    1372                 :            :                 {
    1373                 :            :                     if ( fDbgUsr &&
    1374                 :            :                          (pData->aDbgData.nTestFlags & DBG_TEST_XTOR_FUNC) )
    1375                 :            :                         pMsg = fDbgUsr( pThis );
    1376                 :            :                 }
    1377                 :            :                 break;
    1378                 :            :         }
    1379                 :            : 
    1380                 :            :         SAL_WARN_IF(
    1381                 :            :             pMsg, "tools.debug",
    1382                 :            :             "Error-Msg from Object " << pThis << " in class "
    1383                 :            :                 << pDbgData->pName << ": " << pMsg);
    1384                 :            :     }
    1385                 :            : 
    1386                 :            :     SAL_INFO_IF(
    1387                 :            :         ((pData->aDbgData.nTestFlags & DBG_TEST_XTOR_TRACE)
    1388                 :            :          && (nAction & DBG_XTOR_DTOROBJ) && nAct != DBG_XTOR_CHKOBJ),
    1389                 :            :         "tools.debug",
    1390                 :            :         (nAct == DBG_XTOR_CTOR
    1391                 :            :          ? "Leave Ctor from class "
    1392                 :            :          : nAct == DBG_XTOR_DTOR
    1393                 :            :          ? "Leave Dtor from class "
    1394                 :            :          : "Leave method from class ") << pDbgData->pName);
    1395                 :            : }
    1396                 :            : 
    1397                 :            : void DbgOut( const sal_Char* pMsg, sal_uInt16 nDbgOut, const sal_Char* pFile, sal_uInt16 nLine )
    1398                 :            : {
    1399                 :            :     static sal_Bool bIn = sal_False;
    1400                 :            :     if ( bIn )
    1401                 :            :         return;
    1402                 :            :     bIn = sal_True;
    1403                 :            : 
    1404                 :            :     DebugData*  pData = GetDebugData();
    1405                 :            :     sal_Char const *   pStr;
    1406                 :            :     sal_uIntPtr       nOut;
    1407                 :            :     int         nBufLen = 0;
    1408                 :            : 
    1409                 :            :     if ( nDbgOut == DBG_OUT_ERROR )
    1410                 :            :     {
    1411                 :            :         nOut = pData->aDbgData.nErrorOut;
    1412                 :            :         pStr = "Error: ";
    1413                 :            :     }
    1414                 :            :     else if ( nDbgOut == DBG_OUT_WARNING )
    1415                 :            :     {
    1416                 :            :         nOut = pData->aDbgData.nWarningOut;
    1417                 :            :         pStr = "Warning: ";
    1418                 :            :     }
    1419                 :            :     else
    1420                 :            :     {
    1421                 :            :         nOut = pData->aDbgData.nTraceOut;
    1422                 :            :         pStr = NULL;
    1423                 :            :     }
    1424                 :            : 
    1425                 :            :     if ( nOut == DBG_OUT_NULL )
    1426                 :            :     {
    1427                 :            :         bIn = sal_False;
    1428                 :            :         return;
    1429                 :            :     }
    1430                 :            : 
    1431                 :            :     if ( ImplDbgFilterMessage( pMsg ) )
    1432                 :            :     {
    1433                 :            :         bIn = sal_False;
    1434                 :            :         return;
    1435                 :            :     }
    1436                 :            : 
    1437                 :            :     ImplDbgLock();
    1438                 :            : 
    1439                 :            :     sal_Char aBufOut[DBG_BUF_MAXLEN];
    1440                 :            :     if ( pStr )
    1441                 :            :     {
    1442                 :            :         strcpy( aBufOut, pStr );
    1443                 :            :         nBufLen = strlen( pStr );
    1444                 :            :     }
    1445                 :            :     else
    1446                 :            :         aBufOut[0] = '\0';
    1447                 :            : 
    1448                 :            :     int nMsgLen = strlen( pMsg );
    1449                 :            :     if ( nBufLen+nMsgLen > DBG_BUF_MAXLEN )
    1450                 :            :     {
    1451                 :            :         int nCopyLen = DBG_BUF_MAXLEN-nBufLen-4;
    1452                 :            :         strncpy( &(aBufOut[nBufLen]), pMsg, nCopyLen );
    1453                 :            :         strcpy( &(aBufOut[nBufLen+nCopyLen]), "..." );
    1454                 :            :     }
    1455                 :            :     else
    1456                 :            :         strcpy( &(aBufOut[nBufLen]), pMsg );
    1457                 :            : 
    1458                 :            :     if ( pFile && nLine && (nBufLen+nMsgLen < DBG_BUF_MAXLEN) )
    1459                 :            :     {
    1460                 :            :         if ( nOut == DBG_OUT_MSGBOX )
    1461                 :            :             strcat( aBufOut, "\n" );
    1462                 :            :         else
    1463                 :            :             strcat( aBufOut, " " );
    1464                 :            :         strcat( aBufOut, "From File " );
    1465                 :            :         strcat( aBufOut, pFile );
    1466                 :            :         strcat( aBufOut, " at Line " );
    1467                 :            : 
    1468                 :            :         // Convert line to String and append
    1469                 :            :         sal_Char    aLine[9];
    1470                 :            :         sal_Char*   pLine = &aLine[7];
    1471                 :            :         sal_uInt16      i;
    1472                 :            :         memset( aLine, 0, sizeof( aLine ) );
    1473                 :            :         do
    1474                 :            :         {
    1475                 :            :             i = nLine % 10;
    1476                 :            :             pLine--;
    1477                 :            :             *(pLine) = (sal_Char)i + 48;
    1478                 :            :             nLine /= 10;
    1479                 :            :         }
    1480                 :            :         while ( nLine );
    1481                 :            :         strcat( aBufOut, pLine );
    1482                 :            :     }
    1483                 :            : 
    1484                 :            :     if ( ( nOut >= DBG_OUT_USER_CHANNEL_0 ) && ( nOut - DBG_OUT_USER_CHANNEL_0 < pData->aDbgPrintUserChannels.size() ) )
    1485                 :            :     {
    1486                 :            :         DbgPrintLine pPrinter = pData->aDbgPrintUserChannels[ nOut - DBG_OUT_USER_CHANNEL_0 ];
    1487                 :            :         if ( pPrinter )
    1488                 :            :             pPrinter( aBufOut );
    1489                 :            :         else
    1490                 :            :             nOut = DBG_OUT_DEBUGGER;
    1491                 :            :     }
    1492                 :            : 
    1493                 :            :     if ( nOut == DBG_OUT_ABORT )
    1494                 :            :     {
    1495                 :            :         if ( pData->pDbgAbort != NULL )
    1496                 :            :             pData->pDbgAbort( aBufOut );
    1497                 :            :         abort();
    1498                 :            :     }
    1499                 :            : 
    1500                 :            :     if ( nOut == DBG_OUT_DEBUGGER )
    1501                 :            :     {
    1502                 :            :         if ( !ImplActivateDebugger( aBufOut ) )
    1503                 :            :             nOut = DBG_OUT_TESTTOOL;
    1504                 :            :     }
    1505                 :            : 
    1506                 :            :     if ( nOut == DBG_OUT_TESTTOOL )
    1507                 :            :     {
    1508                 :            :         if ( pData->pDbgPrintTestTool )
    1509                 :            :             pData->pDbgPrintTestTool( aBufOut );
    1510                 :            :         else
    1511                 :            :             nOut = DBG_OUT_MSGBOX;
    1512                 :            :     }
    1513                 :            : 
    1514                 :            :     if ( nOut == DBG_OUT_MSGBOX )
    1515                 :            :     {
    1516                 :            :         if ( pData->pDbgPrintMsgBox )
    1517                 :            :             pData->pDbgPrintMsgBox( aBufOut );
    1518                 :            :         else
    1519                 :            :             nOut = DBG_OUT_WINDOW;
    1520                 :            :     }
    1521                 :            : 
    1522                 :            :     if ( nOut == DBG_OUT_WINDOW )
    1523                 :            :     {
    1524                 :            :         if ( pData->pDbgPrintWindow )
    1525                 :            :             pData->pDbgPrintWindow( aBufOut );
    1526                 :            :         else
    1527                 :            :             nOut = DBG_OUT_FILE;
    1528                 :            :     }
    1529                 :            : 
    1530                 :            :     switch ( nOut )
    1531                 :            :     {
    1532                 :            :     case DBG_OUT_SHELL:
    1533                 :            :         DbgPrintShell( aBufOut );
    1534                 :            :         break;
    1535                 :            :     case DBG_OUT_FILE:
    1536                 :            :         ImplDbgPrintFile( aBufOut );
    1537                 :            :         break;
    1538                 :            :     }
    1539                 :            : 
    1540                 :            :     ImplDbgUnlock();
    1541                 :            : 
    1542                 :            :     bIn = sal_False;
    1543                 :            : }
    1544                 :            : 
    1545                 :            : void DbgPrintShell(char const * message) {
    1546                 :            :     fprintf(stderr, "%s\n", message);
    1547                 :            : #if defined WNT
    1548                 :            :     OutputDebugStringA(message);
    1549                 :            : #endif
    1550                 :            : }
    1551                 :            : 
    1552                 :            : void DbgOutTypef( sal_uInt16 nDbgOut, const sal_Char* pFStr, ... )
    1553                 :            : {
    1554                 :            :     va_list pList;
    1555                 :            : 
    1556                 :            :     va_start( pList, pFStr );
    1557                 :            :     sal_Char aBuf[DBG_BUF_MAXLEN];
    1558                 :            :     vsprintf( aBuf, pFStr, pList );
    1559                 :            :     va_end( pList );
    1560                 :            : 
    1561                 :            :     DbgOut( aBuf, nDbgOut );
    1562                 :            : }
    1563                 :            : 
    1564                 :            : void DbgOutf( const sal_Char* pFStr, ... )
    1565                 :            : {
    1566                 :            :     va_list pList;
    1567                 :            : 
    1568                 :            :     va_start( pList, pFStr );
    1569                 :            :     sal_Char aBuf[DBG_BUF_MAXLEN];
    1570                 :            :     vsprintf( aBuf, pFStr, pList );
    1571                 :            :     va_end( pList );
    1572                 :            : 
    1573                 :            :     DbgOut( aBuf );
    1574                 :            : }
    1575                 :            : 
    1576                 :            : #else
    1577                 :            : 
    1578                 :          0 : void* DbgFunc( sal_uInt16, void* ) { return NULL; }
    1579                 :            : 
    1580                 :          0 : void DbgProf( sal_uInt16, DbgDataType* ) {}
    1581                 :          0 : void DbgXtor( DbgDataType*, sal_uInt16, const void*, DbgUsr ) {}
    1582                 :            : 
    1583                 :          0 : void DbgOut( const sal_Char*, sal_uInt16, const sal_Char*, sal_uInt16 ) {}
    1584                 :          0 : void DbgOutTypef( sal_uInt16, const sal_Char*, ... ) {}
    1585                 :          0 : void DbgOutf( const sal_Char*, ... ) {}
    1586                 :            : 
    1587                 :            : #endif
    1588                 :            : 
    1589                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10