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