merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / osl / w32 / diagnose.c
blob9c75e4502743f10a4f42e5765a4fbacbed7798cc
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 ************************************************************************/
28 #include "system.h"
30 #define NO_DEBUG_CRT
32 #include <osl/diagnose.h>
33 #include <osl/thread.h>
35 #include "printtrace.h"
37 #define NO_DEBUG_CRT
39 static pfunc_osl_printDebugMessage _pPrintDebugMessage = NULL;
40 static pfunc_osl_printDetailedDebugMessage _pPrintDetailedDebugMessage = NULL;
42 pfunc_osl_printDebugMessage SAL_CALL osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc )
44 pfunc_osl_printDebugMessage pOldFunc = _pPrintDebugMessage;
45 _pPrintDebugMessage = pNewFunc;
47 return pOldFunc;
50 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc )
52 pfunc_osl_printDetailedDebugMessage pOldFunc = _pPrintDetailedDebugMessage;
53 _pPrintDetailedDebugMessage = pNewFunc;
54 return pOldFunc;
58 Trace output
61 void SAL_CALL osl_breakDebug(void)
63 DebugBreak();
66 void osl_trace(char const * pszFormat, ...) {
67 va_list args;
68 va_start(args, pszFormat);
69 if ( IsDebuggerPresent() )
71 sal_Char szMessage[512];
72 int written = _vsnprintf(
73 szMessage, sizeof(szMessage) - 2, pszFormat, args );
74 if ( written == -1 )
75 written = sizeof(szMessage) - 2;
76 szMessage[ written++ ] = '\n';
77 szMessage[ written ] = 0;
78 OutputDebugString( szMessage );
80 printTrace((unsigned long) _getpid(), pszFormat, args);
81 va_end(args);
84 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)
86 #ifndef NO_DEBUG_CRT
87 return (_CrtDbgReport(_CRT_ASSERT, pszFileName, nLine, NULL, pszMessage));
88 #else
89 HWND hWndParent;
90 UINT nFlags;
91 int nCode;
93 /* get app name or NULL if unknown (don't call assert) */
94 LPCSTR lpszAppName = "Error";
95 sal_Char szMessage[512];
97 /* format message into buffer */
98 szMessage[sizeof(szMessage)-1] = '\0'; /* zero terminate always */
99 _snprintf(szMessage, sizeof(szMessage)-1, "%s: File %hs, Line %d\n:%s\n",
100 lpszAppName, pszFileName, nLine, pszMessage);
102 OutputDebugString(szMessage);
104 if ( _pPrintDetailedDebugMessage )
105 _pPrintDetailedDebugMessage( pszFileName, nLine, pszMessage );
106 else if ( _pPrintDebugMessage )
107 _pPrintDebugMessage( szMessage );
108 else if ( !getenv( "DISABLE_SAL_DBGBOX" ) )
110 TCHAR szBoxMessage[1024];
112 /* active popup window for the current thread */
113 hWndParent = GetActiveWindow();
114 if (hWndParent != NULL)
115 hWndParent = GetLastActivePopup(hWndParent);
117 /* set message box flags */
118 nFlags = MB_TASKMODAL | MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
119 if (hWndParent == NULL)
120 nFlags |= MB_SERVICE_NOTIFICATION;
122 /* display the assert */
124 szBoxMessage[sizeof(szBoxMessage)-1] = 0;
125 _snprintf(szBoxMessage, sizeof(szBoxMessage)-1, "%s\n( Yes=Abort / No=Ignore / Cancel=Debugger )",
126 szMessage);
128 nCode = MessageBox(hWndParent, szBoxMessage, "Assertion Failed!", nFlags);
130 if (nCode == IDYES)
131 FatalExit(-1);
133 if (nCode == IDNO)
134 return sal_False; /* ignore */
136 if (nCode == IDCANCEL)
137 return sal_True; /* will cause oslDebugBreak */
139 #endif /* NO_DEBUG_CRT */
140 return sal_False; /* not shure, not care */
143 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszMessage)
145 UINT nFlags;
146 int nDisposition;
148 // active popup window for the current thread
149 HWND hWndParent = GetActiveWindow();
150 if (hWndParent != NULL)
151 hWndParent = GetLastActivePopup(hWndParent);
153 nType = nType; /* avoid warnings */
155 /* set message box flags */
156 nFlags = MB_TASKMODAL | MB_ICONERROR | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND;
157 if (hWndParent == NULL)
158 nFlags |= MB_SERVICE_NOTIFICATION;
160 // display the assert
161 nDisposition = MessageBox(hWndParent, pszMessage, "Exception!", nFlags);
163 return nDisposition;