diff options
author | Juergen Funk <juergen.funk_ml@cib.de> | 2019-11-04 10:42:06 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-04-21 17:17:54 +0200 |
commit | c9408eceb0274c6c3bc6d726433af990bf34995b (patch) | |
tree | eb169452ec2dbee9bf177e6a2ee40c8e2010e9c9 /desktop/source/app | |
parent | Related tdf#97694 Fix macro preservation on Windows (diff) | |
download | core-c9408eceb0274c6c3bc6d726433af990bf34995b.tar.gz core-c9408eceb0274c6c3bc6d726433af990bf34995b.zip |
tdf#127711 - A runtime-switch for the MiniCrashDump and associated changes
- add CrashDumpEnable to soffice.ini
- also check env var CRASH_DUMP_ENABLE (overrides soffice.ini)
- make sure _all_ binaries are added to symstore
This is a squash of:
https://gerrit.libreoffice.org/79273
https://gerrit.libreoffice.org/81989
https://gerrit.libreoffice.org/c/core/+/87260
https://gerrit.libreoffice.org/c/core/+/87261
https://gerrit.libreoffice.org/79272
https://gerrit.libreoffice.org/83171
https://gerrit.libreoffice.org/82751
https://gerrit.libreoffice.org/83066
https://gerrit.libreoffice.org/83726
https://gerrit.libreoffice.org/c/core/+/86465
Diffstat (limited to 'desktop/source/app')
-rw-r--r-- | desktop/source/app/app.cxx | 39 | ||||
-rw-r--r-- | desktop/source/app/crashreport.cxx | 118 | ||||
-rw-r--r-- | desktop/source/app/sofficemain.cxx | 14 |
3 files changed, 96 insertions, 75 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index e7a4f82ba081..2682c49d769d 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -122,10 +122,6 @@ #include "langselect.hxx" -#if HAVE_FEATURE_BREAKPAD -#include <fstream> -#endif - #if defined MACOSX #include <errno.h> #include <sys/wait.h> @@ -889,26 +885,6 @@ void Desktop::HandleBootstrapErrors( namespace { -bool crashReportInfoExists() -{ -#if HAVE_FEATURE_BREAKPAD - std::string path = CrashReporter::getIniFileName(); - std::ifstream aFile(path); - while (aFile.good()) - { - std::string line; - std::getline(aFile, line); - int sep = line.find('='); - if (sep >= 0) - { - std::string key = line.substr(0, sep); - if (key == "DumpFile") - return true; - } - } -#endif - return false; -} #if HAVE_FEATURE_BREAKPAD void handleCrashReport() @@ -968,7 +944,12 @@ void impl_checkRecoveryState(bool& bCrashed , bool& bRecoveryDataExists, bool& bSessionDataExists ) { - bCrashed = officecfg::Office::Recovery::RecoveryInfo::Crashed::get() || crashReportInfoExists(); + bCrashed = officecfg::Office::Recovery::RecoveryInfo::Crashed::get() +#if HAVE_FEATURE_BREAKPAD + || CrashReporter::crashReportInfoExists(); +#else + ; +#endif bool elements = officecfg::Office::Recovery::RecoveryList::get()-> hasElements(); bool session @@ -2026,7 +2007,7 @@ void Desktop::OpenClients() #endif #if HAVE_FEATURE_BREAKPAD - if (crashReportInfoExists()) + if (CrashReporter::crashReportInfoExists()) handleCrashReport(); #endif @@ -2104,11 +2085,9 @@ void Desktop::OpenClients() } } } -#if HAVE_FEATURE_BREAKPAD - CrashReporter::writeCommonInfo(); + // write this information here to avoid depending on vcl in the crash reporter lib - CrashReporter::AddKeyValue("Language", Application::GetSettings().GetLanguageTag().getBcp47()); -#endif + CrashReporter::addKeyValue("Language", Application::GetSettings().GetLanguageTag().getBcp47(), CrashReporter::Create); RequestHandler::EnableRequests(); diff --git a/desktop/source/app/crashreport.cxx b/desktop/source/app/crashreport.cxx index 29001367bb91..71434ac5b965 100644 --- a/desktop/source/app/crashreport.cxx +++ b/desktop/source/app/crashreport.cxx @@ -14,17 +14,17 @@ #include <ucbhelper/proxydecider.hxx> #include <unotools/bootstrap.hxx> #include <o3tl/char16_t2wchar_t.hxx> +#include <desktop/minidump.hxx> #include <config_version.h> #include <config_folders.h> #include <string> -#include <fstream> -osl::Mutex CrashReporter::maMutex; #if HAVE_FEATURE_BREAKPAD +#include <fstream> #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID #include <client/linux/handler/exception_handler.h> #elif defined WNT @@ -38,41 +38,47 @@ osl::Mutex CrashReporter::maMutex; #endif #endif +osl::Mutex CrashReporter::maMutex; google_breakpad::ExceptionHandler* CrashReporter::mpExceptionHandler = nullptr; bool CrashReporter::mbInit = false; -std::map<OUString, OUString> CrashReporter::maKeyValues; +CrashReporter::vmaKeyValues CrashReporter::maKeyValues; -namespace { -void writeToStream(std::ofstream& strm, const OUString& rKey, const OUString& rValue) +void CrashReporter::writeToFile(std::ios_base::openmode Openmode) { - strm << rtl::OUStringToOString(rKey, RTL_TEXTENCODING_UTF8).getStr() << "="; - strm << rtl::OUStringToOString(rValue, RTL_TEXTENCODING_UTF8).getStr() << "\n"; -} + std::ofstream ini_file(getIniFileName(), Openmode); + for (auto& keyValue : maKeyValues) + { + ini_file << rtl::OUStringToOString(keyValue.first, RTL_TEXTENCODING_UTF8).getStr() << "="; + ini_file << rtl::OUStringToOString(keyValue.second, RTL_TEXTENCODING_UTF8).getStr() << "\n"; + } + + maKeyValues.clear(); + ini_file.close(); } -void CrashReporter::AddKeyValue(const OUString& rKey, const OUString& rValue) +void CrashReporter::addKeyValue(const OUString& rKey, const OUString& rValue, tAddKeyHandling AddKeyHandling) { osl::MutexGuard aGuard(maMutex); - if (mbInit) - { - std::string ini_path = getIniFileName(); - std::ofstream ini_file(ini_path, std::ios_base::app); - writeToStream(ini_file, rKey, rValue); - } - else + + if (IsDumpEnable()) { - maKeyValues.insert(std::pair<OUString, OUString>(rKey, rValue)); + if (!rKey.isEmpty()) + maKeyValues.push_back(mpair(rKey, rValue)); + + if (AddKeyHandling != AddItem) + { + if (mbInit) + writeToFile(std::ios_base::app); + else if (AddKeyHandling == Create) + writeCommonInfo(); + } } } -#endif - void CrashReporter::writeCommonInfo() { - osl::MutexGuard aGuard(maMutex); - ucbhelper::InternetProxyDecider proxy_decider(::comphelper::getProcessComponentContext()); const OUString protocol = "https"; @@ -81,31 +87,33 @@ void CrashReporter::writeCommonInfo() const ucbhelper::InternetProxyServer proxy_server = proxy_decider.getProxy(protocol, url, port); + // save the new Keys + vmaKeyValues atlast = maKeyValues; + // clear the keys, the following Keys should be at the begin + maKeyValues.clear(); + // limit the amount of code that needs to be executed before the crash reporting - std::string ini_path = CrashReporter::getIniFileName(); - std::ofstream minidump_file(ini_path, std::ios_base::trunc); - minidump_file << "ProductName=LibreOffice\n"; - minidump_file << "Version=" LIBO_VERSION_DOTTED "\n"; - minidump_file << "BuildID=" << utl::Bootstrap::getBuildIdData("") << "\n"; - minidump_file << "URL=" << protocol << "://" << url << "/submit/\n"; + addKeyValue("ProductName", "LibreOffice", AddItem); + addKeyValue("Version", LIBO_VERSION_DOTTED, AddItem); + addKeyValue("BuildID", utl::Bootstrap::getBuildIdData(""), AddItem); + addKeyValue("URL", protocol + "://" + url + "/submit/", AddItem); if (proxy_server.aName != OUString()) { - minidump_file << "Proxy=" << proxy_server.aName << ":" << proxy_server.nPort << "\n"; + addKeyValue("Proxy", proxy_server.aName + ":" + OUString::number(proxy_server.nPort), AddItem); } - for (auto& keyValue : maKeyValues) - { - writeToStream(minidump_file, keyValue.first, keyValue.second); - } - maKeyValues.clear(); - minidump_file.close(); + // write the new keys at the end + maKeyValues.insert(maKeyValues.end(), atlast.begin(), atlast.end()); mbInit = true; + writeToFile(std::ios_base::trunc); + updateMinidumpLocation(); } + namespace { OUString getCrashDirectory() @@ -144,11 +152,48 @@ void CrashReporter::updateMinidumpLocation() #endif } +bool CrashReporter::crashReportInfoExists() +{ + static bool first = true; + static bool InfoExist = false; + + if (first) + { + first = false; + InfoExist = crashreport::readConfig(CrashReporter::getIniFileName(), nullptr); + } + + return InfoExist; +} + +bool CrashReporter::readSendConfig(std::string& response) +{ + return crashreport::readConfig(CrashReporter::getIniFileName(), &response); +} + void CrashReporter::storeExceptionHandler(google_breakpad::ExceptionHandler* pExceptionHandler) { - mpExceptionHandler = pExceptionHandler; + if(IsDumpEnable()) + mpExceptionHandler = pExceptionHandler; } + + +bool CrashReporter::IsDumpEnable() +{ + OUString sToken; + OString sEnvVar(std::getenv("CRASH_DUMP_ENABLE")); + bool bEnable = true; // default, always on + // read configuration item 'CrashDumpEnable' -> bool on/off + if (rtl::Bootstrap::get("CrashDumpEnable", sToken) && sEnvVar.isEmpty()) + { + bEnable = sToken.toBoolean(); + } + + return bEnable; +} + + std::string CrashReporter::getIniFileName() { OUString url = getCrashDirectory() + "dump.ini"; @@ -157,4 +202,7 @@ std::string CrashReporter::getIniFileName() return aRet; } + +#endif //HAVE_FEATURE_BREAKPAD + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx index 4fb84d39d2d1..d8fc55d86596 100644 --- a/desktop/source/app/sofficemain.cxx +++ b/desktop/source/app/sofficemain.cxx @@ -41,7 +41,6 @@ #include <unotools/mediadescriptor.hxx> #if HAVE_FEATURE_BREAKPAD -#include <fstream> #include <desktop/crashreport.hxx> #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID @@ -76,11 +75,9 @@ #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* /*context*/, bool succeeded) { - std::string ini_path = CrashReporter::getIniFileName(); - std::ofstream minidump_file(ini_path, std::ios_base::app); - minidump_file << "DumpFile=" << descriptor.path() << "\n"; - minidump_file.close(); + CrashReporter::addKeyValue("DumpFile", OStringToOUString(descriptor.path(), RTL_TEXTENCODING_UTF8), CrashReporter::Write); SAL_WARN("desktop", "minidump generated: " << descriptor.path()); + return succeeded; } #elif defined WNT @@ -89,17 +86,14 @@ static bool dumpCallback(const wchar_t* path, const wchar_t* id, MDRawAssertionInfo* /*assertion*/, bool succeeded) { - std::string ini_path = CrashReporter::getIniFileName(); - std::ofstream minidump_file(ini_path, std::ios_base::app); // TODO: moggi: can we avoid this conversion #ifdef _MSC_VER #pragma warning (disable: 4996) #endif std::wstring_convert<std::codecvt_utf8<wchar_t>> conv1; std::string aPath = conv1.to_bytes(std::wstring(path)) + conv1.to_bytes(std::wstring(id)) + ".dmp"; - minidump_file << "DumpFile=" << aPath << "\n"; - minidump_file << "GDIHandles=" << ::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS) << "\n"; - minidump_file.close(); + CrashReporter::addKeyValue("DumpFile", OStringToOUString(aPath.c_str(), RTL_TEXTENCODING_UTF8), CrashReporter::AddItem); + CrashReporter::addKeyValue("GDIHandles", OUString::number(::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS)), CrashReporter::Write); SAL_WARN("desktop", "minidump generated: " << aPath); return succeeded; } |