update dev300-m58
[ooovba.git] / sal / osl / w32 / diagnose.c
blobf1227d6c1ccc5e6bb9528c956f7fd1f65f4cbdac
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.14 $
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 ************************************************************************/
31 #include "system.h"
33 #define NO_DEBUG_CRT
35 #include <osl/diagnose.h>
36 #include <osl/thread.h>
38 #define NO_DEBUG_CRT
40 static pfunc_osl_printDebugMessage _pPrintDebugMessage = NULL;
41 static pfunc_osl_printDetailedDebugMessage _pPrintDetailedDebugMessage = NULL;
43 pfunc_osl_printDebugMessage SAL_CALL osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc )
45 pfunc_osl_printDebugMessage pOldFunc = _pPrintDebugMessage;
46 _pPrintDebugMessage = pNewFunc;
48 return pOldFunc;
51 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc )
53 pfunc_osl_printDetailedDebugMessage pOldFunc = _pPrintDetailedDebugMessage;
54 _pPrintDetailedDebugMessage = pNewFunc;
55 return pOldFunc;
59 Trace output
62 void SAL_CALL osl_breakDebug(void)
64 DebugBreak();
69 /* Uncomment this define to get profiling time output */
70 /* #define OSL_PROFILING */
71 /* comment this define to stop output thread identifier*/
72 #define OSL_TRACE_THREAD 1
73 void SAL_CALL osl_trace(const sal_Char* lpszFormat, ...)
75 va_list args;
76 int written = 0;
78 va_start(args, lpszFormat);
80 #if defined(OSL_PROFILING)
81 fprintf(stderr, "time : %06lu : ", osl_getGlobalTimer() );
82 #else
83 #if defined(OSL_TRACE_THREAD)
84 fprintf(stderr,"Thread: %6d :",osl_getThreadIdentifier(NULL));
85 #else
86 fprintf(stderr,"Trace Message : ");
87 #endif
88 #endif
90 if ( IsDebuggerPresent() )
92 sal_Char szMessage[512];
93 szMessage[sizeof(szMessage)-1] = 0;
94 written = _vsnprintf( szMessage, sizeof(szMessage) - 2, lpszFormat, args );
95 szMessage[ written == -1 ? sizeof(szMessage) - 2 : written ] = '\n';
96 OutputDebugString( szMessage );
99 vfprintf(stderr,lpszFormat, args);
101 fprintf(stderr,"\n");
103 fflush(stderr);
105 va_end(args);
108 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)
110 #ifndef NO_DEBUG_CRT
111 return (_CrtDbgReport(_CRT_ASSERT, pszFileName, nLine, NULL, pszMessage));
112 #else
113 HWND hWndParent;
114 UINT nFlags;
115 int nCode;
117 /* get app name or NULL if unknown (don't call assert) */
118 LPCSTR lpszAppName = "Error";
119 sal_Char szMessage[512];
121 /* format message into buffer */
122 szMessage[sizeof(szMessage)-1] = '\0'; /* zero terminate always */
123 _snprintf(szMessage, sizeof(szMessage)-1, "%s: File %hs, Line %d\n:%s\n",
124 lpszAppName, pszFileName, nLine, pszMessage);
126 OutputDebugString(szMessage);
128 if ( _pPrintDetailedDebugMessage )
129 _pPrintDetailedDebugMessage( pszFileName, nLine, pszMessage );
130 else if ( _pPrintDebugMessage )
131 _pPrintDebugMessage( szMessage );
132 else if ( !getenv( "DISABLE_SAL_DBGBOX" ) )
134 TCHAR szBoxMessage[1024];
136 /* active popup window for the current thread */
137 hWndParent = GetActiveWindow();
138 if (hWndParent != NULL)
139 hWndParent = GetLastActivePopup(hWndParent);
141 /* set message box flags */
142 nFlags = MB_TASKMODAL | MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
143 if (hWndParent == NULL)
144 nFlags |= MB_SERVICE_NOTIFICATION;
146 /* display the assert */
148 szBoxMessage[sizeof(szBoxMessage)-1] = 0;
149 _snprintf(szBoxMessage, sizeof(szBoxMessage)-1, "%s\n( Yes=Abort / No=Ignore / Cancel=Debugger )",
150 szMessage);
152 nCode = MessageBox(hWndParent, szBoxMessage, "Assertion Failed!", nFlags);
154 if (nCode == IDYES)
155 FatalExit(-1);
157 if (nCode == IDNO)
158 return sal_False; /* ignore */
160 if (nCode == IDCANCEL)
161 return sal_True; /* will cause oslDebugBreak */
163 #endif /* NO_DEBUG_CRT */
164 return sal_False; /* not shure, not care */
167 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage)
169 UINT nFlags;
170 int nDisposition;
172 // active popup window for the current thread
173 HWND hWndParent = GetActiveWindow();
174 if (hWndParent != NULL)
175 hWndParent = GetLastActivePopup(hWndParent);
177 nType = nType; /* avoid warnings */
179 /* set message box flags */
180 nFlags = MB_TASKMODAL | MB_ICONERROR | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
181 if (hWndParent == NULL)
182 nFlags |= MB_SERVICE_NOTIFICATION;
184 // display the assert
185 nDisposition = MessageBox(hWndParent, pszMessage, "Exception!", nFlags);
187 return nDisposition;