merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / osl / os2 / diagnose.c
blobb105e0b78c295681eda76ab804ebc30a742af270
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include "system.h"
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
35 #include <osl/diagnose.h>
36 #include <osl/thread.h>
38 #include "printtrace.h"
40 BYTE oslTraceEnv[] = "OSL_TRACE_TO_FILE";
42 typedef pfunc_osl_printDebugMessage oslDebugMessageFunc;
43 static oslDebugMessageFunc volatile g_pDebugMessageFunc = 0;
45 typedef pfunc_osl_printDetailedDebugMessage oslDetailedDebugMessageFunc;
46 static oslDetailedDebugMessageFunc volatile g_pDetailedDebugMessageFunc = 0;
48 /*----------------------------------------------------------------------------*/
50 void SAL_CALL osl_breakDebug()
52 __asm__("int $3\n");
55 /************************************************************************/
56 /* osl_trace */
57 /************************************************************************/
58 void osl_trace(char const * pszFormat, ...) {
59 va_list args;
60 va_start(args, pszFormat);
61 printTrace(0, pszFormat, args); /* TODO: pid */
62 va_end(args);
65 /*----------------------------------------------------------------------------*/
67 void SAL_CALL osl_trace__yd_os2(const sal_Char* lpszFormat, ...)
70 int nBuf;
71 sal_Char szBuffer[512];
72 sal_Char szPID[ 12 ];
73 va_list args;
74 FILE* pFile;
75 PID pid;
76 PSZ pszOslTraceFile;
78 /* if environment variable not set, do nothing */
79 if(DosScanEnv(oslTraceEnv, (PSZ*)&pszOslTraceFile))
81 return;
84 va_start(args, lpszFormat);
86 nBuf = vsprintf(szBuffer, lpszFormat, args);
87 OSL_ASSERT(nBuf < sizeof(szBuffer));
89 va_end(args);
91 /* get process ID */
93 PTIB pptib = NULL;
94 PPIB pppib = NULL;
96 DosGetInfoBlocks( &pptib, &pppib );
97 pid = pppib->pib_ulpid;
100 pFile = fopen( (const char*)pszOslTraceFile, "a+" );
101 fputs(_itoa( pid, szPID, 10 ), pFile );
102 fputs( ": ", pFile );
103 fputs(szBuffer, pFile);
104 fclose( pFile );
108 /*----------------------------------------------------------------------------*/
110 sal_Bool SAL_CALL osl_assertFailedLine( const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)
112 sal_Char szMessage[512];
114 /* get app name or NULL if unknown (don't call assert) */
115 sal_Char* lpszAppName = "OSL";
117 /* format message into buffer */
118 sprintf(szMessage, "Assertion Failed: %s: File %s, Line %d:\n",
119 lpszAppName, pszFileName, nLine);
120 if(pszMessage != 0)
121 strcat( szMessage, pszMessage );
123 szMessage[sizeof(szMessage)-1] = '\0';
125 fputs(szMessage, stderr);
127 return sal_True; /* abort */
130 /*----------------------------------------------------------------------------*/
132 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage)
134 fputs(pszMessage, stderr);
136 return 0;
139 /*----------------------------------------------------------------------------*/
142 /************************************************************************/
143 /* osl_setDebugMessageFunc */
144 /************************************************************************/
145 oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc (
146 oslDebugMessageFunc pNewFunc)
148 oslDebugMessageFunc pOldFunc = g_pDebugMessageFunc;
149 g_pDebugMessageFunc = pNewFunc;
150 return pOldFunc;
153 /************************************************************************/
154 /* osl_setDetailedDebugMessageFunc */
155 /************************************************************************/
156 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
157 pfunc_osl_printDetailedDebugMessage pNewFunc)
159 oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc;
160 g_pDetailedDebugMessageFunc = pNewFunc;
161 return pOldFunc;