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 #include <desktop/exithelper.h>
32 #include <osl/file.hxx>
33 #include <rtl/bootstrap.hxx>
34 #include <sal/log.hxx>
35 #include <tools/extendapplicationenvironment.hxx>
36 #include <vcl/svmain.hxx>
38 #include <com/sun/star/beans/NamedValue.hpp>
39 #include <comphelper/storagehelper.hxx>
40 #include <cppuhelper/bootstrap.hxx>
41 #include <unotools/mediadescriptor.hxx>
43 #if HAVE_FEATURE_BREAKPAD
45 #include <desktop/crashreport.hxx>
47 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
48 #include <client/linux/handler/exception_handler.h>
51 #pragma clang diagnostic push
52 #pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
54 #include <client/windows/handler/exception_handler.h>
56 #pragma clang diagnostic pop
67 # include <android/log.h>
68 # include <salhelper/thread.hxx>
70 # define LOGTAG "LibreOffice/sofficemain"
71 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
74 #if HAVE_FEATURE_BREAKPAD
76 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
77 static bool dumpCallback(const google_breakpad::MinidumpDescriptor
& descriptor
, void* /*context*/, bool succeeded
)
79 std::string ini_path
= CrashReporter::getIniFileName();
80 std::ofstream
minidump_file(ini_path
, std::ios_base::app
);
81 minidump_file
<< "DumpFile=" << descriptor
.path() << "\n";
82 minidump_file
.close();
83 SAL_WARN("desktop", "minidump generated: " << descriptor
.path());
87 static bool dumpCallback(const wchar_t* path
, const wchar_t* id
,
88 void* /*context*/, EXCEPTION_POINTERS
* /*exinfo*/,
89 MDRawAssertionInfo
* /*assertion*/,
92 std::string ini_path
= CrashReporter::getIniFileName();
93 std::ofstream
minidump_file(ini_path
, std::ios_base::app
);
94 // TODO: moggi: can we avoid this conversion
95 std::wstring_convert
<std::codecvt_utf8
<wchar_t>> conv1
;
96 std::string aPath
= conv1
.to_bytes(std::wstring(path
)) + conv1
.to_bytes(std::wstring(id
)) + ".dmp";
97 minidump_file
<< "DumpFile=" << aPath
<< "\n";
98 minidump_file
<< "GDIHandles=" << ::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS
) << "\n";
99 minidump_file
.close();
100 SAL_WARN("desktop", "minidump generated: " << aPath
);
106 extern "C" int DESKTOP_DLLPUBLIC
soffice_main()
108 #if HAVE_FEATURE_BREAKPAD
110 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
111 google_breakpad::MinidumpDescriptor
descriptor("/tmp");
112 google_breakpad::ExceptionHandler
eh(descriptor
, nullptr, dumpCallback
, nullptr, true, -1);
114 CrashReporter::storeExceptionHandler(&eh
);
116 google_breakpad::ExceptionHandler
eh(L
".", nullptr, dumpCallback
, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL
);
118 CrashReporter::storeExceptionHandler(&eh
);
122 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) && HAVE_FEATURE_OPENGL
123 /* Run test for OpenGL support in own process to avoid crash with broken
124 * OpenGL drivers. Start process as early as possible.
125 * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
126 * (vcl/opengl/x11/X11DeviceInfo.cxx). In headless mode, the process will be reaped late in
127 * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
128 * same #if condition as this code block.
130 bool bSuccess
= fire_glxtest_process();
131 SAL_WARN_IF(!bSuccess
, "desktop.opengl", "problems with glxtest");
136 rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
138 tools::extendApplicationEnvironment();
140 desktop::Desktop aDesktop
;
141 // This string is used during initialization of the Gtk+ VCL module
142 Application::SetAppName( "soffice" );
144 // handle --version and --help already here, otherwise they would be handled
145 // after VCL initialization that might fail if $DISPLAY is not set
146 const desktop::CommandLineArgs
& rCmdLineArgs
= desktop::Desktop::GetCommandLineArgs();
147 const OUString
& aUnknown( rCmdLineArgs
.GetUnknown() );
148 if ( !aUnknown
.isEmpty() )
150 desktop::Desktop::InitApplicationServiceManager();
151 desktop::displayCmdlineHelp( aUnknown
);
154 if ( rCmdLineArgs
.IsHelp() )
156 desktop::Desktop::InitApplicationServiceManager();
157 desktop::displayCmdlineHelp( OUString() );
160 if ( rCmdLineArgs
.IsVersion() )
162 desktop::Desktop::InitApplicationServiceManager();
163 desktop::displayVersion();
169 } catch (const css::uno::Exception
&e
) {
170 LOGI("Unhandled UNO exception: '%s'",
171 OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
172 throw; // to get exception type printed
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */