1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 #include <osl/diagnose.h>
26 static pfunc_osl_printDebugMessage _pPrintDebugMessage
= NULL
;
27 static pfunc_osl_printDetailedDebugMessage _pPrintDetailedDebugMessage
= NULL
;
29 pfunc_osl_printDebugMessage SAL_CALL
osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc
)
31 pfunc_osl_printDebugMessage pOldFunc
= _pPrintDebugMessage
;
32 _pPrintDebugMessage
= pNewFunc
;
37 pfunc_osl_printDetailedDebugMessage SAL_CALL
osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc
)
39 pfunc_osl_printDetailedDebugMessage pOldFunc
= _pPrintDetailedDebugMessage
;
40 _pPrintDetailedDebugMessage
= pNewFunc
;
48 void SAL_CALL
osl_breakDebug(void)
50 if ( IsDebuggerPresent() )
56 sal_Bool SAL_CALL
osl_assertFailedLine(const sal_Char
* pszFileName
, sal_Int32 nLine
, const sal_Char
* pszMessage
)
58 char const * env
= getenv( "SAL_DIAGNOSE_ABORT" );
59 #if defined(_DEBUG) && !defined(NO_DEBUG_CRT)
60 _CrtDbgReport(_CRT_ASSERT
, pszFileName
, nLine
, NULL
, pszMessage
);
61 return ( ( env
!= NULL
) && ( *env
!= '\0' ) );
67 /* get app name or NULL if unknown (don't call assert) */
68 LPCSTR lpszAppName
= "Error";
69 sal_Char szMessage
[512];
71 /* format message into buffer */
72 szMessage
[sizeof(szMessage
)-1] = '\0'; /* zero terminate always */
73 _snprintf(szMessage
, sizeof(szMessage
)-1, "%s: File %hs, Line %d\n:%s\n",
74 lpszAppName
, pszFileName
, nLine
, pszMessage
);
76 OutputDebugString(szMessage
);
78 if ( _pPrintDetailedDebugMessage
)
79 _pPrintDetailedDebugMessage( pszFileName
, nLine
, pszMessage
);
80 else if ( _pPrintDebugMessage
)
81 _pPrintDebugMessage( szMessage
);
84 if ( !getenv( "DISABLE_SAL_DBGBOX" ) )
86 TCHAR szBoxMessage
[1024];
88 /* active popup window for the current thread */
89 hWndParent
= GetActiveWindow();
90 if (hWndParent
!= NULL
)
91 hWndParent
= GetLastActivePopup(hWndParent
);
93 /* set message box flags */
94 nFlags
= MB_TASKMODAL
| MB_ICONWARNING
| MB_YESNOCANCEL
| MB_DEFBUTTON2
| MB_SETFOREGROUND
;
95 if (hWndParent
== NULL
)
96 nFlags
|= MB_SERVICE_NOTIFICATION
;
98 /* display the assert */
100 szBoxMessage
[sizeof(szBoxMessage
)-1] = 0;
101 _snprintf(szBoxMessage
, sizeof(szBoxMessage
)-1, "%s\n( Yes=Abort / No=Ignore / Cancel=Debugger )",
104 nCode
= MessageBox(hWndParent
, szBoxMessage
, "Assertion Failed!", nFlags
);
110 return sal_False
; /* ignore */
112 if (nCode
== IDCANCEL
)
113 return sal_True
; /* will cause oslDebugBreak */
117 fputs(szMessage
, stderr
); // fall back
119 return ( ( env
!= NULL
) && ( *env
!= '\0' ) );
123 #endif /* _DEBUG && !NO_DEBUG_CRT */
126 sal_Int32 SAL_CALL
osl_reportError(sal_uInt32 nType
, const sal_Char
* pszMessage
)
131 // active popup window for the current thread
132 HWND hWndParent
= GetActiveWindow();
133 if (hWndParent
!= NULL
)
134 hWndParent
= GetLastActivePopup(hWndParent
);
136 /* set message box flags */
137 nFlags
= MB_TASKMODAL
| MB_ICONERROR
| MB_YESNOCANCEL
| MB_DEFBUTTON2
| MB_SETFOREGROUND
;
138 if (hWndParent
== NULL
)
139 nFlags
|= MB_SERVICE_NOTIFICATION
;
141 // display the assert
142 nDisposition
= MessageBox(hWndParent
, pszMessage
, "Exception!", nFlags
);
143 (void)nType
; //unused, but part of public API/ABI
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */