1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 29 #include "system.h" 30 31 #include <stdio.h> 32 #include <stdlib.h> 33 #include <stdarg.h> 34 35 #include <osl/diagnose.h> 36 #include <osl/thread.h> 37 38 #include "printtrace.h" 39 40 BYTE oslTraceEnv[] = "OSL_TRACE_TO_FILE"; 41 42 typedef pfunc_osl_printDebugMessage oslDebugMessageFunc; 43 static oslDebugMessageFunc volatile g_pDebugMessageFunc = 0; 44 45 typedef pfunc_osl_printDetailedDebugMessage oslDetailedDebugMessageFunc; 46 static oslDetailedDebugMessageFunc volatile g_pDetailedDebugMessageFunc = 0; 47 48 /*----------------------------------------------------------------------------*/ 49 50 void SAL_CALL osl_breakDebug() 51 { 52 __asm__("int $3\n"); 53 } 54 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); 63 } 64 65 /*----------------------------------------------------------------------------*/ 66 67 void SAL_CALL osl_trace__yd_os2(const sal_Char* lpszFormat, ...) 68 { 69 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; 77 78 /* if environment variable not set, do nothing */ 79 if(DosScanEnv(oslTraceEnv, (PSZ*)&pszOslTraceFile)) 80 { 81 return; 82 } 83 84 va_start(args, lpszFormat); 85 86 nBuf = vsprintf(szBuffer, lpszFormat, args); 87 OSL_ASSERT(nBuf < sizeof(szBuffer)); 88 89 va_end(args); 90 91 /* get process ID */ 92 { 93 PTIB pptib = NULL; 94 PPIB pppib = NULL; 95 96 DosGetInfoBlocks( &pptib, &pppib ); 97 pid = pppib->pib_ulpid; 98 } 99 100 pFile = fopen( (const char*)pszOslTraceFile, "a+" ); 101 fputs(_itoa( pid, szPID, 10 ), pFile ); 102 fputs( ": ", pFile ); 103 fputs(szBuffer, pFile); 104 fclose( pFile ); 105 106 } 107 108 /*----------------------------------------------------------------------------*/ 109 110 sal_Bool SAL_CALL osl_assertFailedLine( const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage) 111 { 112 sal_Char szMessage[512]; 113 114 /* get app name or NULL if unknown (don't call assert) */ 115 sal_Char* lpszAppName = "OSL"; 116 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 ); 122 123 szMessage[sizeof(szMessage)-1] = '\0'; 124 125 fputs(szMessage, stderr); 126 127 char const * env = getenv( "SAL_DIAGNOSE_ABORT" ); 128 return ( ( env != NULL ) && ( *env != '\0' ) ); 129 } 130 131 /*----------------------------------------------------------------------------*/ 132 133 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage) 134 { 135 fputs(pszMessage, stderr); 136 137 return 0; 138 } 139 140 /*----------------------------------------------------------------------------*/ 141 142 143 /************************************************************************/ 144 /* osl_setDebugMessageFunc */ 145 /************************************************************************/ 146 oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc ( 147 oslDebugMessageFunc pNewFunc) 148 { 149 oslDebugMessageFunc pOldFunc = g_pDebugMessageFunc; 150 g_pDebugMessageFunc = pNewFunc; 151 return pOldFunc; 152 } 153 154 /************************************************************************/ 155 /* osl_setDetailedDebugMessageFunc */ 156 /************************************************************************/ 157 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc ( 158 pfunc_osl_printDetailedDebugMessage pNewFunc) 159 { 160 oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc; 161 g_pDetailedDebugMessageFunc = pNewFunc; 162 return pOldFunc; 163 } 164