From 5476f6ab274503a56b135591c77184aa31e24682 Mon Sep 17 00:00:00 2001 From: Jie Date: Thu, 6 Sep 2018 07:23:48 +0800 Subject: [PATCH] Fix GDB not work for osrm-routed on Linux (#5157) As I mentioned in the issue #5156, I met below issue on my Win10+WSL(Ubuntu) env: The remote debugger (VSCode on Win10, gdb on Ubuntu 18.04 LTS) works well from the beginning of the main() function. But when I step over the code pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); (src/tools/routed.cpp(289)), below breakpoints can not work and displayed unverified breakpoint. Then I found that gdb breakpoint need at least SIGTRAP, SIGSTOP to work (Please refer to [how debugger works](http://www.alexonlinux.com/how-debugger-works) for more details), but all signals are blocked in the source code until server initialized done. In my understanding, block all signals DO NOT make sense for this osrm-routed process. Only several signals (SIGINT, SIGQUIT, SIGTERM) are expected to wait. So I made the change and it works well for me then. --- CHANGELOG.md | 1 + src/tools/routed.cpp | 22 +++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc24cbaa..5562c92bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - ADDED: Node bindings can return pre-rendered JSON buffer. [#5189](https://github.com/Project-OSRM/osrm-backend/pull/5189) - Bugfixes: - FIXED: collapsing of ExitRoundabout instructions [#5114](https://github.com/Project-OSRM/osrm-backend/issues/5114) + - FIXED: fix osrm-routed gdb not work issue [#5156](https://github.com/Project-OSRM/osrm-backend/issues/5156) - FIXED: negative distances in table plugin annotation [#5106](https://github.com/Project-OSRM/osrm-backend/issues/5106) - Misc: - CHANGED: Support up to 512 named shared memory regions [#5185](https://github.com/Project-OSRM/osrm-backend/pull/5185) diff --git a/src/tools/routed.cpp b/src/tools/routed.cpp index 66236d527..25a62b03a 100644 --- a/src/tools/routed.cpp +++ b/src/tools/routed.cpp @@ -70,8 +70,8 @@ std::istream &operator>>(std::istream &in, EngineConfig::Algorithm &algorithm) throw util::RuntimeError(token, ErrorCode::UnknownAlgorithm, SOURCE_REF); return in; } -} -} +} // namespace engine +} // namespace osrm // generate boost::program_options object for the routing part inline unsigned generateServerProgramOptions(const int argc, @@ -273,10 +273,12 @@ int main(int argc, const char *argv[]) try #ifndef _WIN32 int sig = 0; - sigset_t new_mask; - sigset_t old_mask; - sigfillset(&new_mask); - pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); + sigset_t wait_mask; + sigemptyset(&wait_mask); + sigaddset(&wait_mask, SIGINT); + sigaddset(&wait_mask, SIGQUIT); + sigaddset(&wait_mask, SIGTERM); + pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr); // only block necessary signals #endif auto service_handler = std::make_unique(config); @@ -298,19 +300,13 @@ int main(int argc, const char *argv[]) try std::thread server_thread(std::move(server_task)); #ifndef _WIN32 - sigset_t wait_mask; - pthread_sigmask(SIG_SETMASK, &old_mask, nullptr); - sigemptyset(&wait_mask); - sigaddset(&wait_mask, SIGINT); - sigaddset(&wait_mask, SIGQUIT); - sigaddset(&wait_mask, SIGTERM); - pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr); util::Log() << "running and waiting for requests"; if (std::getenv("SIGNAL_PARENT_WHEN_READY")) { kill(getppid(), SIGUSR1); } sigwait(&wait_mask, &sig); + util::Log() << "received signal " << sig; #else // Set console control handler to allow server to be stopped. console_ctrl_function = std::bind(&server::Server::Stop, routing_server);