diff --git a/APRSHandlerThread.cpp b/APRSHandlerThread.cpp index b13e99b..9745341 100644 --- a/APRSHandlerThread.cpp +++ b/APRSHandlerThread.cpp @@ -123,7 +123,9 @@ void* CAPRSHandlerThread::Entry() startReconnectionTimer(); } +#ifndef DEBUG_DSTARGW try { +#endif m_keepAliveTimer.start(); while (!m_exit) { if (!m_connected) { @@ -194,6 +196,7 @@ void* CAPRSHandlerThread::Entry() auto s = m_queue.getData(); s.clear(); } +#ifndef DEBUG_DSTARGW } catch (std::exception& e) { std::string message(e.what()); @@ -202,6 +205,7 @@ void* CAPRSHandlerThread::Entry() catch (...) { CLog::logInfo("Unknown exception raised in the APRS Writer thread"); } +#endif CLog::logInfo("Stopping the APRS Writer thread"); diff --git a/DPlusAuthenticator.cpp b/DPlusAuthenticator.cpp index 2921996..b9d1768 100644 --- a/DPlusAuthenticator.cpp +++ b/DPlusAuthenticator.cpp @@ -72,7 +72,9 @@ void* CDPlusAuthenticator::Entry() m_timer.start(); +#ifndef DEBUG_DSTARGW try { +#endif while (!m_killed) { if (m_timer.hasExpired()) { authenticate(m_loginCallsign, OPENDSTAR_HOSTNAME, OPENDSTAR_PORT, '2', true); @@ -83,6 +85,7 @@ void* CDPlusAuthenticator::Entry() m_timer.clock(); } +#ifndef DEBUG_DSTARGW } catch (std::exception& e) { std::string message(e.what()); @@ -91,6 +94,7 @@ void* CDPlusAuthenticator::Entry() catch (...) { CLog::logError("Unknown exception raised in the D-Plus Authenticator thread"); } +#endif CLog::logInfo("Stopping the D-Plus Authenticator thread"); diff --git a/DStarGatewayApp.cpp b/DStarGatewayApp.cpp index 1b47533..45f2c8a 100644 --- a/DStarGatewayApp.cpp +++ b/DStarGatewayApp.cpp @@ -23,11 +23,11 @@ #include #include #include -#include -#include #include -#include -#include +#include +#ifdef DEBUG_DSTARGW +#include +#endif #include "DStarGatewayDefs.h" #include "DStarGatewayConfig.h" @@ -52,8 +52,14 @@ int fakemain(int argc, char *argv[]) int main(int argc, char *argv[]) #endif { - // install sigHandler - signal(SIGSEGV, __sigHandler); + std::set_terminate(CDStarGatewayApp::terminateHandler); + + // TODO 2022-01-17 handle SIGTERM etc .... + // signal(SIGSEGV, CDStarGatewayApp::sigHandler); + // signal(SIGILL, CDStarGatewayApp::sigHandler); + // signal(SIGFPE, CDStarGatewayApp::sigHandler); + // signal(SIGABRT, CDStarGatewayApp::sigHandler); + // signal(SIGTERM, CDStarGatewayApp::sigHandler); setbuf(stdout, NULL); if (2 != argc) { @@ -82,21 +88,6 @@ int main(int argc, char *argv[]) return 0; } -void __sigHandler(int sig) -{ - if(sig == SIGSEGV) { - void *array[100]; - size_t size; - // get void*'s for all entries on the stack - size = backtrace(array, 100); - - // print out all the frames to stderr - fprintf(stderr, "Error: signal %d:\n", sig); - backtrace_symbols_fd(array, size, STDERR_FILENO); - exit(1); - } -} - CDStarGatewayApp::CDStarGatewayApp(const std::string &configFile) : m_configFile(configFile), m_thread(NULL) { } @@ -285,3 +276,35 @@ bool CDStarGatewayApp::createThread() return true; } +void CDStarGatewayApp::sigHandler(int /*sig*/) +{ + // TODO 2022-01-17 handle SIGTERM etc .... +} + +void CDStarGatewayApp::terminateHandler() +{ + +#ifdef DEBUG_DSTARGW + std::stringstream stackTrace; + stackTrace << boost::stacktrace::stacktrace(); +#endif + + std::exception_ptr eptr; + eptr = std::current_exception(); + + try { + if (eptr != nullptr) { + std::rethrow_exception(eptr); + } + else { + CLog::logFatal("Unhandled unkown exception occured"); + } + } catch(const std::exception& e) { + CLog::logFatal("Unhandled exception occured %s", e.what()); + } + +#ifdef DEBUG_DSTARGW + CLog::logFatal("%s", stackTrace.str().c_str()); +#endif + exit(1); +} \ No newline at end of file diff --git a/DStarGatewayApp.h b/DStarGatewayApp.h index 3461e88..4929018 100644 --- a/DStarGatewayApp.h +++ b/DStarGatewayApp.h @@ -36,4 +36,7 @@ public: bool init(); void run(); + + static void sigHandler(int sig); + static void terminateHandler(); }; diff --git a/DStarGatewayThread.cpp b/DStarGatewayThread.cpp index b2e9e7a..fce9403 100644 --- a/DStarGatewayThread.cpp +++ b/DStarGatewayThread.cpp @@ -335,7 +335,9 @@ void* CDStarGatewayThread::Entry() m_statusFileTimer.start(); m_statusTimer2.start(); +#ifndef DEBUG_DSTARGW try { +#endif while (!m_killed) { if (m_icomRepeaterHandler != NULL) processRepeater(m_icomRepeaterHandler); @@ -411,6 +413,7 @@ void* CDStarGatewayThread::Entry() ::std::this_thread::sleep_for(std::chrono::milliseconds(TIME_PER_TIC_MS)); } +#ifndef DEBUG_DSTARGW } catch (std::exception& e) { std::string message(e.what()); @@ -419,6 +422,7 @@ void* CDStarGatewayThread::Entry() catch (...) { CLog::logFatal("Unknown exception raised in the main thread"); } +#endif CLog::logInfo("Stopping the ircDDB Gateway thread"); diff --git a/IcomRepeaterProtocolHandler.cpp b/IcomRepeaterProtocolHandler.cpp index d220690..51f30cb 100644 --- a/IcomRepeaterProtocolHandler.cpp +++ b/IcomRepeaterProtocolHandler.cpp @@ -135,7 +135,9 @@ void* CIcomRepeaterProtocolHandler::Entry() { CLog::logInfo("Starting the Icom Controller thread"); +#ifndef DEBUG_DSTARGW try { +#endif while (!m_killed) { sendGwyPackets(); @@ -145,6 +147,7 @@ void* CIcomRepeaterProtocolHandler::Entry() m_retryTimer.clock(); } +#ifndef DEBUG_DSTARGW } catch (std::exception& e) { std::string message(e.what()); @@ -153,6 +156,7 @@ void* CIcomRepeaterProtocolHandler::Entry() catch (...) { CLog::logError("Unknown exception raised in the Icom Controller thread"); } +#endif CLog::logInfo("Stopping the Icom Controller thread"); diff --git a/Makefile b/Makefile index b057963..0174975 100644 --- a/Makefile +++ b/Makefile @@ -23,14 +23,15 @@ export LOG_DIR=/var/log/dstargateway/ ifeq ($(ENABLE_DEBUG), 1) # choose this if you want debugging help -export CPPFLAGS=-g -rdynamic -ggdb -W -Wall -Werror -std=c++17 +export CPPFLAGS=-g -rdynamic -DBOOST_STACKTRACE_USE_ADDR2LINE -DDEBUG_DSTARGW -no-pie -fno-pie -ggdb -W -Wall -Werror -std=c++17 +export LDFLAGS=-ldl -no-pie -fno-pie else # or, you can choose this for a much smaller executable without debugging help -CPPFLAGS=-W -O3 -Wall -Werror -std=c++17 +export CPPFLAGS=-W -O3 -Wall -Werror -std=c++17 endif export CC=g++ -export LDFLAGS:=-lcurl -pthread +export LDFLAGS+= -lcurl -pthread ifeq ($(USE_GPSD), 1) export CPPFLAGS+= -DUSE_GPSD diff --git a/README.md b/README.md index 9b75943..e89f7bd 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ - [3.4. Prerequisites and dependencies](#34-prerequisites-and-dependencies) - [3.5. Building](#35-building) - [3.5.0.1. Build With GPSD Support](#3501-build-with-gpsd-support) + - [3.5.0.2. Debug Build](#3502-debug-build) - [3.6. Installing](#36-installing) - [3.7. Configuring](#37-configuring) - [4. Contributing](#4-contributing) @@ -91,6 +92,11 @@ make ``` make USE_GPS=1 ``` +#### 3.5.0.2. Debug Build +``` +make ENABLE_DEBUG=1 +``` +Note that this will link with libl ## 3.6. Installing The program is meant to run as a systemd service. All bits an pieces are provided. ```