diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-08-17 17:09:09 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-08-18 17:10:19 +0200 |
commit | 91ba9654baa8d525e31614b03cd459cf7cb1f951 (patch) | |
tree | 81d58fed74cced15b450580fffb507f9e8f1511f /tools | |
parent | 9144e8c3f4dd9c0460ea8f258682825688920537 (diff) |
Move tools/diagnose_ex.h to comphelper/diagnose_ex.hxx
...so that its TOOLS_WARN_EXCEPTION can be used in
comphelper/source/misc/logging.cxx in a follow-up commit. (And while at it,
rename from diangose_ex.h to the more appropriate diagnose_ex.hxx. The
comphelper module is sufficiently low-level for this immediate use case, so use
that at least for now; o3tl might be even more suitable but doesn't have a
Library until now. Also, for the immediate use case it would have sufficed to
only break DbgGetCaughtException, exceptionToString, TOOLS_WARN_EXCEPTION,
TOOLS_WARN_EXCEPTION_IF, and TOOLS_INFO_EXCEPTION out of
include/tools/diagnose_ex.h into an additional new
include/comphelper/diagnose_ex.hxx, but its probably easier overall to just move
the complete include file as is.)
Change-Id: I9f3222d4ccf1a9ac29d7eb9ba1530d53e2affaee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138451
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/IwyuFilter_tools.yaml | 2 | ||||
-rw-r--r-- | tools/source/debug/debug.cxx | 371 |
2 files changed, 1 insertions, 372 deletions
diff --git a/tools/IwyuFilter_tools.yaml b/tools/IwyuFilter_tools.yaml index ecc4dd5f86f9..5c5dbaaec137 100644 --- a/tools/IwyuFilter_tools.yaml +++ b/tools/IwyuFilter_tools.yaml @@ -18,7 +18,7 @@ excludelist: - stdlib.h tools/source/debug/debug.cxx: # Needed for linker visibility - - tools/diagnose_ex.h + - comphelper/diagnose_ex.hxx # Keep for commented out "if defined __GLIBCXX__" path - cxxabi.h tools/source/misc/extendapplicationenvironment.cxx: diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx index 3bb080959e67..197ba2450493 100644 --- a/tools/source/debug/debug.cxx +++ b/tools/source/debug/debug.cxx @@ -17,46 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <com/sun/star/configuration/CorruptedConfigurationException.hpp> -#include <com/sun/star/configuration/backend/BackendSetupException.hpp> -#include <com/sun/star/configuration/backend/MalformedDataException.hpp> -#include <com/sun/star/configuration/InvalidBootstrapFileException.hpp> -#include <com/sun/star/configuration/MissingBootstrapFileException.hpp> -#include <com/sun/star/deployment/DependencyException.hpp> -#include <com/sun/star/deployment/DeploymentException.hpp> -#include <com/sun/star/document/CorruptedFilterConfigurationException.hpp> -#include <com/sun/star/document/UndoFailedException.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/lang/WrappedTargetException.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <com/sun/star/ldap/LdapGenericException.hpp> -#include <com/sun/star/script/BasicErrorException.hpp> -#include <com/sun/star/script/CannotConvertException.hpp> -#include <com/sun/star/script/provider/ScriptExceptionRaisedException.hpp> -#include <com/sun/star/script/provider/ScriptFrameworkErrorException.hpp> -#include <com/sun/star/sdbc/SQLException.hpp> -#include <com/sun/star/system/SystemShellExecuteException.hpp> -#include <com/sun/star/task/ErrorCodeIOException.hpp> -#include <com/sun/star/ucb/CommandFailedException.hpp> -#include <com/sun/star/ucb/ContentCreationException.hpp> -#include <com/sun/star/ucb/MissingPropertiesException.hpp> -#include <com/sun/star/ucb/NameClashException.hpp> -#include <com/sun/star/ucb/InteractiveIOException.hpp> -#include <com/sun/star/util/MalformedNumberFormatException.hpp> -#include <com/sun/star/xml/dom/DOMException.hpp> -#include <com/sun/star/xml/sax/SAXException.hpp> -#include <com/sun/star/xml/sax/SAXParseException.hpp> -#include <comphelper/anytostring.hxx> #include <tools/debug.hxx> #include <sal/log.hxx> -#include <osl/thread.h> -#include <rtl/strbuf.hxx> - -#include <tools/diagnose_ex.h> - -#if defined __GLIBCXX__ -#include <cxxabi.h> -#endif namespace { @@ -92,337 +54,4 @@ void DbgTestSolarMutex() aDebugData.pDbgTestSolarMutex(); } -static void exceptionToStringImpl(OStringBuffer& sMessage, const css::uno::Any & caught) -{ - auto toOString = [](OUString const & s) { - return OUStringToOString( s, osl_getThreadTextEncoding() ); - }; - sMessage.append(toOString(caught.getValueTypeName())); - css::uno::Exception exception; - caught >>= exception; - if ( !exception.Message.isEmpty() ) - { - sMessage.append(" message: \""); - sMessage.append(toOString(exception.Message)); - sMessage.append("\""); - } -/* TODO FIXME (see https://gerrit.libreoffice.org/#/c/83245/) - if ( exception.Context.is() ) - { - const char* pContext = typeid( *exception.Context ).name(); -#if defined __GLIBCXX__ - // demangle the type name, not necessary under windows, we already get demangled names there - int status; - pContext = abi::__cxa_demangle( pContext, nullptr, nullptr, &status); -#endif - sMessage.append(" context: "); - sMessage.append(pContext); -#if defined __GLIBCXX__ - std::free(const_cast<char *>(pContext)); -#endif - } -*/ - { - css::configuration::CorruptedConfigurationException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" details: "); - sMessage.append(toOString(specialized.Details)); - } - } - { - css::configuration::InvalidBootstrapFileException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" BootstrapFileURL: "); - sMessage.append(toOString(specialized.BootstrapFileURL)); - } - } - { - css::configuration::MissingBootstrapFileException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" BootstrapFileURL: "); - sMessage.append(toOString(specialized.BootstrapFileURL)); - } - } - { - css::configuration::backend::MalformedDataException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString(specialized.ErrorDetails)); - } - } - { - css::configuration::backend::BackendSetupException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString(specialized.BackendException)); - } - } - { - css::deployment::DependencyException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" UnsatisfiedDependencies: "); - sMessage.append(toOString(comphelper::anyToString(css::uno::Any(specialized.UnsatisfiedDependencies)))); - } - } - { - css::deployment::DeploymentException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString(specialized.Cause)); - } - } - { - css::document::CorruptedFilterConfigurationException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Details: "); - sMessage.append(toOString(specialized.Details)); - } - } - { - css::document::UndoFailedException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Reason: "); - sMessage.append(toOString(comphelper::anyToString(specialized.Reason))); - } - } - { - css::lang::IllegalArgumentException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" ArgumentPosition: "); - sMessage.append(static_cast<sal_Int32>(specialized.ArgumentPosition)); - } - } - { - css::lang::WrappedTargetException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString(specialized.TargetException)); - } - } - { - css::lang::WrappedTargetRuntimeException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString(specialized.TargetException)); - } - } - { - css::ldap::LdapGenericException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" ErrorCode: "); - sMessage.append(specialized.ErrorCode); - } - } - { - css::script::BasicErrorException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" ErrorCode: "); - sMessage.append(specialized.ErrorCode); - sMessage.append(" ErrorMessageArgument: "); - sMessage.append(toOString(specialized.ErrorMessageArgument)); - } - } - { - css::script::CannotConvertException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" DestinationTypeClass: "); - sMessage.append(toOString(comphelper::anyToString(css::uno::Any(specialized.DestinationTypeClass)))); - sMessage.append(" Reason: "); - sMessage.append(specialized.Reason); - sMessage.append(" ArgumentIndex: "); - sMessage.append(specialized.ArgumentIndex); - } - } - { - css::script::provider::ScriptErrorRaisedException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" scriptName: "); - sMessage.append(toOString(specialized.scriptName)); - sMessage.append(" language: "); - sMessage.append(toOString(specialized.language)); - sMessage.append(" lineNum: "); - sMessage.append(specialized.lineNum); - } - } - { - css::script::provider::ScriptExceptionRaisedException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" exceptionType: "); - sMessage.append(toOString(specialized.exceptionType)); - } - } - { - css::script::provider::ScriptFrameworkErrorException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" scriptName: "); - sMessage.append(toOString(specialized.scriptName)); - sMessage.append(" language: "); - sMessage.append(toOString(specialized.language)); - sMessage.append(" errorType: "); - sMessage.append(specialized.errorType); - } - } - { - css::sdbc::SQLException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" SQLState: "); - sMessage.append(toOString(specialized.SQLState)); - sMessage.append(" ErrorCode: "); - sMessage.append(specialized.ErrorCode); - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString(specialized.NextException)); - } - } - { - css::system::SystemShellExecuteException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" PosixError: "); - sMessage.append(specialized.PosixError); - } - } - { - css::task::ErrorCodeIOException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" errcode: "); - sMessage.append( specialized.ErrCode ); - } - } - { - css::ucb::CommandFailedException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n Reason: "); - sMessage.append(exceptionToString( specialized.Reason )); - } - } - { - css::ucb::ContentCreationException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" eError: "); - sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.eError) ))); - } - } - { - css::ucb::MissingPropertiesException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Properties: "); - sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.Properties) ))); - } - } - { - css::ucb::NameClashException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Name: "); - sMessage.append(toOString( specialized.Name )); - } - } - { - css::util::MalformedNumberFormatException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" CheckPos: "); - sMessage.append( specialized.CheckPos ); - } - } - { - css::xml::dom::DOMException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Code: "); - sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.Code) ))); - } - } - { - css::xml::dom::DOMException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Code: "); - sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.Code) ))); - } - } - { - css::xml::sax::SAXException specialized; - if ( caught >>= specialized ) - { - sMessage.append("\n wrapped: "); - sMessage.append(exceptionToString( specialized.WrappedException )); - } - } - { - css::xml::sax::SAXParseException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" PublicId: "); - sMessage.append(toOString( specialized.PublicId )); - sMessage.append(" SystemId: "); - sMessage.append(toOString( specialized.SystemId )); - sMessage.append(" LineNumber: "); - sMessage.append( specialized.LineNumber ); - sMessage.append(" ColumnNumber: "); - sMessage.append( specialized.ColumnNumber ); - } - } - { - css::ucb::InteractiveIOException specialized; - if ( caught >>= specialized ) - { - sMessage.append(" Code: "); - sMessage.append( static_cast<sal_Int32>(specialized.Code) ); - } - } -} - -OString exceptionToString(const css::uno::Any & caught) -{ - OStringBuffer sMessage(512); - exceptionToStringImpl(sMessage, caught); - return sMessage.makeStringAndClear(); -} - -void DbgUnhandledException(const css::uno::Any & caught, const char* currentFunction, const char* fileAndLineNo, - const char* area, const char* explanatory) -{ - OStringBuffer sMessage( 512 ); - sMessage.append( "DBG_UNHANDLED_EXCEPTION in " ); - sMessage.append(currentFunction); - if (explanatory) - { - sMessage.append("\n when: "); - sMessage.append(explanatory); - } - sMessage.append(" exception: "); - exceptionToStringImpl(sMessage, caught); - - if (area == nullptr) - area = "legacy.osl"; - - SAL_DETAIL_LOG_FORMAT( - SAL_DETAIL_ENABLE_LOG_WARN, SAL_DETAIL_LOG_LEVEL_WARN, - area, fileAndLineNo, "%s", sMessage.getStr()); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |