xref: /aoo41x/main/sal/osl/os2/diagnose.c (revision 647f063d)
1*647f063dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647f063dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647f063dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647f063dSAndrew Rist  * distributed with this work for additional information
6*647f063dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647f063dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647f063dSAndrew Rist  * "License"); you may not use this file except in compliance
9*647f063dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647f063dSAndrew Rist  *
11*647f063dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647f063dSAndrew Rist  *
13*647f063dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647f063dSAndrew Rist  * software distributed under the License is distributed on an
15*647f063dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647f063dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647f063dSAndrew Rist  * specific language governing permissions and limitations
18*647f063dSAndrew Rist  * under the License.
19*647f063dSAndrew Rist  *
20*647f063dSAndrew Rist  *************************************************************/
21*647f063dSAndrew Rist 
22*647f063dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include "system.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include <stdlib.h>
29cdf0e10cSrcweir #include <stdarg.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <osl/diagnose.h>
32cdf0e10cSrcweir #include <osl/thread.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "printtrace.h"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir BYTE oslTraceEnv[] = "OSL_TRACE_TO_FILE";
37cdf0e10cSrcweir 
38cdf0e10cSrcweir typedef pfunc_osl_printDebugMessage oslDebugMessageFunc;
39cdf0e10cSrcweir static oslDebugMessageFunc volatile g_pDebugMessageFunc = 0;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir typedef pfunc_osl_printDetailedDebugMessage oslDetailedDebugMessageFunc;
42cdf0e10cSrcweir static oslDetailedDebugMessageFunc volatile g_pDetailedDebugMessageFunc = 0;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
45cdf0e10cSrcweir 
osl_breakDebug()46cdf0e10cSrcweir void SAL_CALL osl_breakDebug()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	__asm__("int $3\n");
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir /************************************************************************/
52cdf0e10cSrcweir /* osl_trace */
53cdf0e10cSrcweir /************************************************************************/
osl_trace(char const * pszFormat,...)54cdf0e10cSrcweir void osl_trace(char const * pszFormat, ...) {
55cdf0e10cSrcweir     va_list args;
56cdf0e10cSrcweir     va_start(args, pszFormat);
57cdf0e10cSrcweir     printTrace(0, pszFormat, args); /* TODO: pid */
58cdf0e10cSrcweir     va_end(args);
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
62cdf0e10cSrcweir 
osl_trace__yd_os2(const sal_Char * lpszFormat,...)63cdf0e10cSrcweir void SAL_CALL osl_trace__yd_os2(const sal_Char* lpszFormat, ...)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     int     nBuf;
67cdf0e10cSrcweir     sal_Char    szBuffer[512];
68cdf0e10cSrcweir     sal_Char    szPID[ 12 ];
69cdf0e10cSrcweir     va_list args;
70cdf0e10cSrcweir     FILE*   pFile;
71cdf0e10cSrcweir     PID     pid;
72cdf0e10cSrcweir     PSZ     pszOslTraceFile;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     /* if environment variable not set, do nothing */
75cdf0e10cSrcweir     if(DosScanEnv(oslTraceEnv, (PSZ*)&pszOslTraceFile))
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         return;
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     va_start(args, lpszFormat);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     nBuf = vsprintf(szBuffer, lpszFormat, args);
83cdf0e10cSrcweir     OSL_ASSERT(nBuf < sizeof(szBuffer));
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     va_end(args);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /* get process ID */
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir     PTIB pptib = NULL;
90cdf0e10cSrcweir     PPIB pppib = NULL;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     DosGetInfoBlocks( &pptib, &pppib );
93cdf0e10cSrcweir     pid = pppib->pib_ulpid;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     pFile = fopen( (const char*)pszOslTraceFile, "a+" );
97cdf0e10cSrcweir     fputs(_itoa( pid, szPID, 10 ), pFile );
98cdf0e10cSrcweir     fputs( ": ", pFile );
99cdf0e10cSrcweir     fputs(szBuffer, pFile);
100cdf0e10cSrcweir     fclose( pFile );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
105cdf0e10cSrcweir 
osl_assertFailedLine(const sal_Char * pszFileName,sal_Int32 nLine,const sal_Char * pszMessage)106cdf0e10cSrcweir sal_Bool SAL_CALL osl_assertFailedLine( const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     sal_Char szMessage[512];
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     /* get app name or NULL if unknown (don't call assert) */
111cdf0e10cSrcweir     sal_Char* lpszAppName = "OSL";
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /* format message into buffer */
114cdf0e10cSrcweir     sprintf(szMessage, "Assertion Failed: %s: File %s, Line %d:\n",
115cdf0e10cSrcweir             lpszAppName, pszFileName, nLine);
116cdf0e10cSrcweir     if(pszMessage != 0)
117cdf0e10cSrcweir         strcat( szMessage, pszMessage );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     szMessage[sizeof(szMessage)-1] = '\0';
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     fputs(szMessage, stderr);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
124cdf0e10cSrcweir     return ( ( env != NULL ) && ( *env != '\0' ) );
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
128cdf0e10cSrcweir 
osl_reportError(sal_uInt32 nType,const sal_Char * pszMessage)129cdf0e10cSrcweir sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     fputs(pszMessage, stderr);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     return 0;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir /*----------------------------------------------------------------------------*/
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139cdf0e10cSrcweir /************************************************************************/
140cdf0e10cSrcweir /* osl_setDebugMessageFunc */
141cdf0e10cSrcweir /************************************************************************/
osl_setDebugMessageFunc(oslDebugMessageFunc pNewFunc)142cdf0e10cSrcweir oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc (
143cdf0e10cSrcweir 	oslDebugMessageFunc pNewFunc)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	oslDebugMessageFunc pOldFunc = g_pDebugMessageFunc;
146cdf0e10cSrcweir 	g_pDebugMessageFunc = pNewFunc;
147cdf0e10cSrcweir 	return pOldFunc;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir /************************************************************************/
151cdf0e10cSrcweir /* osl_setDetailedDebugMessageFunc */
152cdf0e10cSrcweir /************************************************************************/
osl_setDetailedDebugMessageFunc(pfunc_osl_printDetailedDebugMessage pNewFunc)153cdf0e10cSrcweir pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
154cdf0e10cSrcweir     pfunc_osl_printDetailedDebugMessage pNewFunc)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc;
157cdf0e10cSrcweir     g_pDetailedDebugMessageFunc = pNewFunc;
158cdf0e10cSrcweir     return pOldFunc;
159cdf0e10cSrcweir }
160