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.
This commit is contained in:
Jie 2018-09-06 07:23:48 +08:00 committed by Daniel Patterson
parent 0971f06193
commit 5476f6ab27
2 changed files with 10 additions and 13 deletions

View File

@ -6,6 +6,7 @@
- ADDED: Node bindings can return pre-rendered JSON buffer. [#5189](https://github.com/Project-OSRM/osrm-backend/pull/5189) - ADDED: Node bindings can return pre-rendered JSON buffer. [#5189](https://github.com/Project-OSRM/osrm-backend/pull/5189)
- Bugfixes: - Bugfixes:
- FIXED: collapsing of ExitRoundabout instructions [#5114](https://github.com/Project-OSRM/osrm-backend/issues/5114) - 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) - FIXED: negative distances in table plugin annotation [#5106](https://github.com/Project-OSRM/osrm-backend/issues/5106)
- Misc: - Misc:
- CHANGED: Support up to 512 named shared memory regions [#5185](https://github.com/Project-OSRM/osrm-backend/pull/5185) - CHANGED: Support up to 512 named shared memory regions [#5185](https://github.com/Project-OSRM/osrm-backend/pull/5185)

View File

@ -70,8 +70,8 @@ std::istream &operator>>(std::istream &in, EngineConfig::Algorithm &algorithm)
throw util::RuntimeError(token, ErrorCode::UnknownAlgorithm, SOURCE_REF); throw util::RuntimeError(token, ErrorCode::UnknownAlgorithm, SOURCE_REF);
return in; return in;
} }
} } // namespace engine
} } // namespace osrm
// generate boost::program_options object for the routing part // generate boost::program_options object for the routing part
inline unsigned generateServerProgramOptions(const int argc, inline unsigned generateServerProgramOptions(const int argc,
@ -273,10 +273,12 @@ int main(int argc, const char *argv[]) try
#ifndef _WIN32 #ifndef _WIN32
int sig = 0; int sig = 0;
sigset_t new_mask; sigset_t wait_mask;
sigset_t old_mask; sigemptyset(&wait_mask);
sigfillset(&new_mask); sigaddset(&wait_mask, SIGINT);
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr); // only block necessary signals
#endif #endif
auto service_handler = std::make_unique<server::ServiceHandler>(config); auto service_handler = std::make_unique<server::ServiceHandler>(config);
@ -298,19 +300,13 @@ int main(int argc, const char *argv[]) try
std::thread server_thread(std::move(server_task)); std::thread server_thread(std::move(server_task));
#ifndef _WIN32 #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"; util::Log() << "running and waiting for requests";
if (std::getenv("SIGNAL_PARENT_WHEN_READY")) if (std::getenv("SIGNAL_PARENT_WHEN_READY"))
{ {
kill(getppid(), SIGUSR1); kill(getppid(), SIGUSR1);
} }
sigwait(&wait_mask, &sig); sigwait(&wait_mask, &sig);
util::Log() << "received signal " << sig;
#else #else
// Set console control handler to allow server to be stopped. // Set console control handler to allow server to be stopped.
console_ctrl_function = std::bind(&server::Server::Stop, routing_server); console_ctrl_function = std::bind(&server::Server::Stop, routing_server);