1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: diagnose.c,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
38 #include <osl/diagnose.h>
39 #include <osl/thread.h>
41 BYTE oslTraceEnv
[] = "OSL_TRACE_TO_FILE";
43 typedef pfunc_osl_printDebugMessage oslDebugMessageFunc
;
44 static oslDebugMessageFunc
volatile g_pDebugMessageFunc
= 0;
46 typedef pfunc_osl_printDetailedDebugMessage oslDetailedDebugMessageFunc
;
47 static oslDetailedDebugMessageFunc
volatile g_pDetailedDebugMessageFunc
= 0;
49 /*----------------------------------------------------------------------------*/
51 void SAL_CALL
osl_breakDebug()
56 /************************************************************************/
58 /************************************************************************/
59 /* comment this define to stop output thread identifier*/
60 #define OSL_TRACE_THREAD 1
61 void SAL_CALL
osl_trace (
62 const sal_Char
* lpszFormat
, ...)
66 #if defined(OSL_PROFILING)
67 fprintf(stderr
, "Time: %06lu : ", osl_getGlobalTimer() );
69 #if defined(OSL_TRACE_THREAD)
70 fprintf(stderr
,"Thread: %6d :",osl_getThreadIdentifier(NULL
));
72 fprintf(stderr
, "Trace Message: ");
76 va_start(args
, lpszFormat
);
77 vfprintf(stderr
, lpszFormat
, args
);
84 /*----------------------------------------------------------------------------*/
86 void SAL_CALL
osl_trace__yd_os2(const sal_Char
* lpszFormat
, ...)
90 sal_Char szBuffer
[512];
97 /* if environment variable not set, do nothing */
98 if(DosScanEnv(oslTraceEnv
, (PSZ
*)&pszOslTraceFile
))
103 va_start(args
, lpszFormat
);
105 nBuf
= vsprintf(szBuffer
, lpszFormat
, args
);
106 OSL_ASSERT(nBuf
< sizeof(szBuffer
));
115 DosGetInfoBlocks( &pptib
, &pppib
);
116 pid
= pppib
->pib_ulpid
;
119 pFile
= fopen( (const char*)pszOslTraceFile
, "a+" );
120 fputs(_itoa( pid
, szPID
, 10 ), pFile
);
121 fputs( ": ", pFile
);
122 fputs(szBuffer
, pFile
);
127 /*----------------------------------------------------------------------------*/
129 sal_Bool SAL_CALL
osl_assertFailedLine( const sal_Char
* pszFileName
, sal_Int32 nLine
, const sal_Char
* pszMessage
)
131 sal_Char szMessage
[512];
133 /* get app name or NULL if unknown (don't call assert) */
134 sal_Char
* lpszAppName
= "OSL";
136 /* format message into buffer */
137 sprintf(szMessage
, "Assertion Failed: %s: File %s, Line %d:\n",
138 lpszAppName
, pszFileName
, nLine
);
140 strcat( szMessage
, pszMessage
);
142 szMessage
[sizeof(szMessage
)-1] = '\0';
144 fputs(szMessage
, stderr
);
146 return sal_True
; /* abort */
149 /*----------------------------------------------------------------------------*/
151 sal_Int32 SAL_CALL
osl_reportError(sal_uInt32 nType
, const sal_Char
* pszMessage
)
153 fputs(pszMessage
, stderr
);
158 /*----------------------------------------------------------------------------*/
161 /************************************************************************/
162 /* osl_setDebugMessageFunc */
163 /************************************************************************/
164 oslDebugMessageFunc SAL_CALL
osl_setDebugMessageFunc (
165 oslDebugMessageFunc pNewFunc
)
167 oslDebugMessageFunc pOldFunc
= g_pDebugMessageFunc
;
168 g_pDebugMessageFunc
= pNewFunc
;
172 /************************************************************************/
173 /* osl_setDetailedDebugMessageFunc */
174 /************************************************************************/
175 pfunc_osl_printDetailedDebugMessage SAL_CALL
osl_setDetailedDebugMessageFunc (
176 pfunc_osl_printDetailedDebugMessage pNewFunc
)
178 oslDetailedDebugMessageFunc pOldFunc
= g_pDetailedDebugMessageFunc
;
179 g_pDetailedDebugMessageFunc
= pNewFunc
;