common/SigUtil.cpp | 15 +++++++++++++++ common/SigUtil.hpp | 3 +++ kit/ChildSession.cpp | 10 ++++++++++ wsd/DocumentBroker.cpp | 9 ++++++++- wsd/README | 4 ++++ 5 files changed, 40 insertions(+), 1 deletion(-)
New commits: commit 92909810136db2494e2700c6c5ff172339f759fd Author: Henry Castro <hcas...@collabora.com> AuthorDate: Wed Dec 18 16:28:14 2019 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Fri Dec 20 19:57:47 2019 +0100 wsd: debug: add env variable "PAUSEFORDEBUGGER" to attach debugger It is painful to check and search manually the PID to attach the LOKit process when exists several pre-spawned waiting to load a document. This patch helps to attach the debugger when the LOKit process is about to load a document then send the "signal SIGUSR1" to resume it. Change-Id: I3b15bd522c6ef3ef57dc3453b457dcf91f2661b9 Reviewed-on: https://gerrit.libreoffice.org/85430 Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Henry Castro <hcas...@collabora.com> Reviewed-by: Henry Castro <hcas...@collabora.com> diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp index f511aca60..8fe38b721 100644 --- a/common/SigUtil.cpp +++ b/common/SigUtil.cpp @@ -331,6 +331,10 @@ namespace SigUtil } } + static + void handleDebuggerSignal(const int /*signal*/) + {} + void setUserSignals() { struct sigaction action; @@ -342,6 +346,17 @@ namespace SigUtil sigaction(SIGUSR1, &action, nullptr); } + void setDebuggerSignal() + { + struct sigaction action; + + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + action.sa_handler = handleDebuggerSignal; + + sigaction(SIGUSR1, &action, nullptr); + } + /// Kill the given pid with SIGTERM. Returns true when the pid does not exist any more. bool killChild(const int pid) { diff --git a/common/SigUtil.hpp b/common/SigUtil.hpp index 95371f3a1..a0da03142 100644 --- a/common/SigUtil.hpp +++ b/common/SigUtil.hpp @@ -59,6 +59,9 @@ namespace SigUtil /// Trap generally useful signals void setUserSignals(); + /// Trap to unpause the process + void setDebuggerSignal(); + /// Requests the server to initiate graceful shutdown. /// Shutting down is a multi-stage process, because /// it can be requested via signals. diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 45ee614e4..cf65a51b9 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -24,6 +24,7 @@ #include <Poco/URI.h> #include <Poco/BinaryReader.h> #include <Poco/Base64Decoder.h> +#include <Poco/Process.h> #if !MOBILEAPP #include <Poco/Net/HTTPResponse.h> #include <Poco/Net/HTTPSClientSession.h> @@ -606,6 +607,15 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, const s std::unique_lock<std::recursive_mutex> lock(Mutex); +#ifdef ENABLE_DEBUG + if (std::getenv("PAUSEFORDEBUGGER")) + { + std::cerr << getDocURL() << " paused waiting for a debugger to attach: " << Poco::Process::id() << std::endl; + SigUtil::setDebuggerSignal(); + pause(); + } +#endif + const bool loaded = _docManager->onLoad(getId(), getJailedFilePathAnonym(), renderOpts, doctemplate); if (!loaded || _viewId < 0) { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index fecea32bc..7e163e769 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -283,7 +283,14 @@ void DocumentBroker::pollThread() auto lastBWUpdateTime = std::chrono::steady_clock::now(); auto lastClipboardHashUpdateTime = std::chrono::steady_clock::now(); - const int limit_load_secs = LOOLWSD::getConfigValue<int>("per_document.limit_load_secs", 100); + const int limit_load_secs = +#ifdef ENABLE_DEBUG + // paused waiting for a debugger to attach + // ignore load time out + std::getenv("PAUSEFORDEBUGGER") ? -1 : +#endif + LOOLWSD::getConfigValue<int>("per_document.limit_load_secs", 100); + const auto loadDeadline = std::chrono::steady_clock::now() + std::chrono::seconds(limit_load_secs); #endif auto last30SecCheckTime = std::chrono::steady_clock::now(); diff --git a/wsd/README b/wsd/README index 25d17db43..e56b970c6 100644 --- a/wsd/README +++ b/wsd/README @@ -240,6 +240,8 @@ limit the amount of concurrently running processes. When the crash happens too early, you also want to export SLEEPFORDEBUGGER=<number of seconds> +or + export PAUSEFORDEBUGGER=1 so that you have time to attach to the process. @@ -261,6 +263,8 @@ Use the ps command to find out exactly the path to use. Set LOOL_DEBUG=1 to trap SIGSEGV and SEGBUS and prompt for debugger. +if you choose PAUSEFORDEBUGGER send the signal SIGUSR1 to resume the process + In order to run and debug one unit test, set CPPUNIT_TEST_NAME to something non-empty: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits