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 .
20 #include <sal/config.h>
21 #include <config_features.h>
22 #include <config_version.h>
23 #include <config_folders.h>
25 #include <desktop/dllapi.h>
28 #include "cmdlineargs.hxx"
29 #include "cmdlinehelp.hxx"
31 // needed before sal/main.h to avoid redefinition of macros
34 #include <desktop/exithelper.h>
35 #include <osl/file.hxx>
36 #include <rtl/bootstrap.hxx>
37 #include <sal/log.hxx>
39 #include <tools/extendapplicationenvironment.hxx>
40 #include <vcl/glxtestprocess.hxx>
41 #include <vcl/svmain.hxx>
43 #include <com/sun/star/beans/NamedValue.hpp>
44 #include <cppuhelper/bootstrap.hxx>
45 #include <unotools/mediadescriptor.hxx>
47 #if HAVE_FEATURE_BREAKPAD
48 #include <desktop/crashreport.hxx>
50 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
51 #include <client/linux/handler/exception_handler.h>
54 #pragma clang diagnostic push
55 #pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
57 #include <client/windows/handler/exception_handler.h>
59 #pragma clang diagnostic pop
71 # include <android/log.h>
72 # include <salhelper/thread.hxx>
74 # define LOGTAG "LibreOffice/sofficemain"
75 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
78 #if HAVE_FEATURE_BREAKPAD
80 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
81 static bool dumpCallback(const google_breakpad::MinidumpDescriptor
& descriptor
, void* /*context*/, bool succeeded
)
83 CrashReporter::addKeyValue("DumpFile", OStringToOUString(descriptor
.path(), RTL_TEXTENCODING_UTF8
), CrashReporter::Write
);
84 SAL_WARN("desktop", "minidump generated: " << descriptor
.path());
89 static bool dumpCallback(const wchar_t* path
, const wchar_t* id
,
90 void* /*context*/, EXCEPTION_POINTERS
* /*exinfo*/,
91 MDRawAssertionInfo
* /*assertion*/,
94 // TODO: moggi: can we avoid this conversion
96 #pragma warning (disable: 4996)
98 std::wstring_convert
<std::codecvt_utf8
<wchar_t>> conv1
;
99 std::string aPath
= conv1
.to_bytes(std::wstring(path
)) + conv1
.to_bytes(std::wstring(id
)) + ".dmp";
100 CrashReporter::addKeyValue("DumpFile", OStringToOUString(aPath
.c_str(), RTL_TEXTENCODING_UTF8
), CrashReporter::AddItem
);
101 CrashReporter::addKeyValue("GDIHandles", OUString::number(::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS
)), CrashReporter::Write
);
102 SAL_WARN("desktop", "minidump generated: " << aPath
);
108 extern "C" int DESKTOP_DLLPUBLIC
soffice_main()
110 sal_detail_initialize(sal::detail::InitializeSoffice
, nullptr);
112 #if HAVE_FEATURE_BREAKPAD
114 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
115 google_breakpad::MinidumpDescriptor
descriptor("/tmp");
116 google_breakpad::ExceptionHandler
eh(descriptor
, nullptr, dumpCallback
, nullptr, true, -1);
118 CrashReporter::storeExceptionHandler(&eh
);
120 google_breakpad::ExceptionHandler
eh(L
".", nullptr, dumpCallback
, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL
);
122 CrashReporter::storeExceptionHandler(&eh
);
126 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && HAVE_FEATURE_UI && HAVE_FEATURE_OPENGL
127 /* Run test for OpenGL support in own process to avoid crash with broken
128 * OpenGL drivers. Start process as early as possible.
129 * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
130 * (vcl/opengl/x11/X11DeviceInfo.cxx). In headless mode, the process will be reaped late in
131 * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
132 * same #if condition as this code block.
134 bool bSuccess
= fire_glxtest_process();
135 SAL_WARN_IF(!bSuccess
, "desktop.opengl", "problems with glxtest");
140 rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
142 tools::extendApplicationEnvironment();
144 desktop::Desktop aDesktop
;
145 // This string is used during initialization of the Gtk+ VCL module
146 Application::SetAppName( "soffice" );
148 // handle --version and --help already here, otherwise they would be handled
149 // after VCL initialization that might fail if $DISPLAY is not set
150 const desktop::CommandLineArgs
& rCmdLineArgs
= desktop::Desktop::GetCommandLineArgs();
151 const OUString
& aUnknown( rCmdLineArgs
.GetUnknown() );
152 if ( !aUnknown
.isEmpty() )
154 desktop::Desktop::InitApplicationServiceManager();
155 desktop::displayCmdlineHelp( aUnknown
);
158 if ( rCmdLineArgs
.IsHelp() )
160 desktop::Desktop::InitApplicationServiceManager();
161 desktop::displayCmdlineHelp( OUString() );
164 if ( rCmdLineArgs
.IsVersion() )
166 desktop::Desktop::InitApplicationServiceManager();
167 desktop::displayVersion();
173 } catch (const css::uno::Exception
&e
) {
174 LOGI("Unhandled UNO exception: '%s'",
175 OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
176 throw; // to get exception type printed
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */