1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: diagnose.c,v $
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 ************************************************************************/
35 #include <osl/diagnose.h>
36 #include <osl/thread.h>
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
;
51 pfunc_osl_printDetailedDebugMessage SAL_CALL
osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc
)
53 pfunc_osl_printDetailedDebugMessage pOldFunc
= _pPrintDetailedDebugMessage
;
54 _pPrintDetailedDebugMessage
= pNewFunc
;
62 void SAL_CALL
osl_breakDebug(void)
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
, ...)
78 va_start(args
, lpszFormat
);
80 #if defined(OSL_PROFILING)
81 fprintf(stderr
, "time : %06lu : ", osl_getGlobalTimer() );
83 #if defined(OSL_TRACE_THREAD)
84 fprintf(stderr
,"Thread: %6d :",osl_getThreadIdentifier(NULL
));
86 fprintf(stderr
,"Trace Message : ");
90 if ( IsDebuggerPresent() )
92 sal_Char szMessage
[512];
93 szMessage
[sizeof(szMessage
)-1] = 0;
94 written
= _vsnprintf( szMessage
, sizeof(szMessage
) - 2, lpszFormat
, args
);
96 written
= sizeof(szMessage
) - 2;
97 szMessage
[ written
++ ] = '\n';
98 szMessage
[ written
] = 0;
99 OutputDebugString( szMessage
);
102 vfprintf(stderr
,lpszFormat
, args
);
104 fprintf(stderr
,"\n");
111 sal_Bool SAL_CALL
osl_assertFailedLine(const sal_Char
* pszFileName
, sal_Int32 nLine
, const sal_Char
* pszMessage
)
114 return (_CrtDbgReport(_CRT_ASSERT
, pszFileName
, nLine
, NULL
, pszMessage
));
120 /* get app name or NULL if unknown (don't call assert) */
121 LPCSTR lpszAppName
= "Error";
122 sal_Char szMessage
[512];
124 /* format message into buffer */
125 szMessage
[sizeof(szMessage
)-1] = '\0'; /* zero terminate always */
126 _snprintf(szMessage
, sizeof(szMessage
)-1, "%s: File %hs, Line %d\n:%s\n",
127 lpszAppName
, pszFileName
, nLine
, pszMessage
);
129 OutputDebugString(szMessage
);
131 if ( _pPrintDetailedDebugMessage
)
132 _pPrintDetailedDebugMessage( pszFileName
, nLine
, pszMessage
);
133 else if ( _pPrintDebugMessage
)
134 _pPrintDebugMessage( szMessage
);
135 else if ( !getenv( "DISABLE_SAL_DBGBOX" ) )
137 TCHAR szBoxMessage
[1024];
139 /* active popup window for the current thread */
140 hWndParent
= GetActiveWindow();
141 if (hWndParent
!= NULL
)
142 hWndParent
= GetLastActivePopup(hWndParent
);
144 /* set message box flags */
145 nFlags
= MB_TASKMODAL
| MB_ICONWARNING
| MB_YESNOCANCEL
| MB_DEFBUTTON2
| MB_SETFOREGROUND
;
146 if (hWndParent
== NULL
)
147 nFlags
|= MB_SERVICE_NOTIFICATION
;
149 /* display the assert */
151 szBoxMessage
[sizeof(szBoxMessage
)-1] = 0;
152 _snprintf(szBoxMessage
, sizeof(szBoxMessage
)-1, "%s\n( Yes=Abort / No=Ignore / Cancel=Debugger )",
155 nCode
= MessageBox(hWndParent
, szBoxMessage
, "Assertion Failed!", nFlags
);
161 return sal_False
; /* ignore */
163 if (nCode
== IDCANCEL
)
164 return sal_True
; /* will cause oslDebugBreak */
166 #endif /* NO_DEBUG_CRT */
167 return sal_False
; /* not shure, not care */
170 sal_Int32 SAL_CALL
osl_reportError(sal_uInt32 nType
, const sal_Char
* pszMessage
)
175 // active popup window for the current thread
176 HWND hWndParent
= GetActiveWindow();
177 if (hWndParent
!= NULL
)
178 hWndParent
= GetLastActivePopup(hWndParent
);
180 nType
= nType
; /* avoid warnings */
182 /* set message box flags */
183 nFlags
= MB_TASKMODAL
| MB_ICONERROR
| MB_YESNOCANCEL
| MB_DEFBUTTON2
| MB_SETFOREGROUND
;
184 if (hWndParent
== NULL
)
185 nFlags
|= MB_SERVICE_NOTIFICATION
;
187 // display the assert
188 nDisposition
= MessageBox(hWndParent
, pszMessage
, "Exception!", nFlags
);