update dev300-m57
[ooovba.git] / sal / osl / os2 / diagnose.c
blob509170088e0aff3d75f3920e8916e2eb8e0d8c62
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: diagnose.c,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
32 #include "system.h"
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <stdarg.h>
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()
53 __asm__("int $3\n");
56 /************************************************************************/
57 /* osl_trace */
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, ...)
64 va_list args;
66 #if defined(OSL_PROFILING)
67 fprintf(stderr, "Time: %06lu : ", osl_getGlobalTimer() );
68 #else
69 #if defined(OSL_TRACE_THREAD)
70 fprintf(stderr,"Thread: %6d :",osl_getThreadIdentifier(NULL));
71 #else
72 fprintf(stderr, "Trace Message: ");
73 #endif
74 #endif
76 va_start(args, lpszFormat);
77 vfprintf(stderr, lpszFormat, args);
78 va_end(args);
80 fprintf(stderr,"\n");
81 fflush(stderr);
84 /*----------------------------------------------------------------------------*/
86 void SAL_CALL osl_trace__yd_os2(const sal_Char* lpszFormat, ...)
89 int nBuf;
90 sal_Char szBuffer[512];
91 sal_Char szPID[ 12 ];
92 va_list args;
93 FILE* pFile;
94 PID pid;
95 PSZ pszOslTraceFile;
97 /* if environment variable not set, do nothing */
98 if(DosScanEnv(oslTraceEnv, (PSZ*)&pszOslTraceFile))
100 return;
103 va_start(args, lpszFormat);
105 nBuf = vsprintf(szBuffer, lpszFormat, args);
106 OSL_ASSERT(nBuf < sizeof(szBuffer));
108 va_end(args);
110 /* get process ID */
112 PTIB pptib = NULL;
113 PPIB pppib = NULL;
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);
123 fclose( 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);
139 if(pszMessage != 0)
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);
155 return 0;
158 /*----------------------------------------------------------------------------*/
161 /************************************************************************/
162 /* osl_setDebugMessageFunc */
163 /************************************************************************/
164 oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc (
165 oslDebugMessageFunc pNewFunc)
167 oslDebugMessageFunc pOldFunc = g_pDebugMessageFunc;
168 g_pDebugMessageFunc = pNewFunc;
169 return pOldFunc;
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;
180 return pOldFunc;