#5 use terminate handler in debug mode

pull/32/head
Geoffrey Merck 4 years ago
parent f0a4320928
commit 3c991205be

@ -123,7 +123,9 @@ void* CAPRSHandlerThread::Entry()
startReconnectionTimer(); startReconnectionTimer();
} }
#ifndef DEBUG_DSTARGW
try { try {
#endif
m_keepAliveTimer.start(); m_keepAliveTimer.start();
while (!m_exit) { while (!m_exit) {
if (!m_connected) { if (!m_connected) {
@ -194,6 +196,7 @@ void* CAPRSHandlerThread::Entry()
auto s = m_queue.getData(); auto s = m_queue.getData();
s.clear(); s.clear();
} }
#ifndef DEBUG_DSTARGW
} }
catch (std::exception& e) { catch (std::exception& e) {
std::string message(e.what()); std::string message(e.what());
@ -202,6 +205,7 @@ void* CAPRSHandlerThread::Entry()
catch (...) { catch (...) {
CLog::logInfo("Unknown exception raised in the APRS Writer thread"); CLog::logInfo("Unknown exception raised in the APRS Writer thread");
} }
#endif
CLog::logInfo("Stopping the APRS Writer thread"); CLog::logInfo("Stopping the APRS Writer thread");

@ -72,7 +72,9 @@ void* CDPlusAuthenticator::Entry()
m_timer.start(); m_timer.start();
#ifndef DEBUG_DSTARGW
try { try {
#endif
while (!m_killed) { while (!m_killed) {
if (m_timer.hasExpired()) { if (m_timer.hasExpired()) {
authenticate(m_loginCallsign, OPENDSTAR_HOSTNAME, OPENDSTAR_PORT, '2', true); authenticate(m_loginCallsign, OPENDSTAR_HOSTNAME, OPENDSTAR_PORT, '2', true);
@ -83,6 +85,7 @@ void* CDPlusAuthenticator::Entry()
m_timer.clock(); m_timer.clock();
} }
#ifndef DEBUG_DSTARGW
} }
catch (std::exception& e) { catch (std::exception& e) {
std::string message(e.what()); std::string message(e.what());
@ -91,6 +94,7 @@ void* CDPlusAuthenticator::Entry()
catch (...) { catch (...) {
CLog::logError("Unknown exception raised in the D-Plus Authenticator thread"); CLog::logError("Unknown exception raised in the D-Plus Authenticator thread");
} }
#endif
CLog::logInfo("Stopping the D-Plus Authenticator thread"); CLog::logInfo("Stopping the D-Plus Authenticator thread");

@ -23,11 +23,11 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <stdio.h>
#include <execinfo.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <exception>
#include <unistd.h> #ifdef DEBUG_DSTARGW
#include <boost/stacktrace.hpp>
#endif
#include "DStarGatewayDefs.h" #include "DStarGatewayDefs.h"
#include "DStarGatewayConfig.h" #include "DStarGatewayConfig.h"
@ -52,8 +52,14 @@ int fakemain(int argc, char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
#endif #endif
{ {
// install sigHandler std::set_terminate(CDStarGatewayApp::terminateHandler);
signal(SIGSEGV, __sigHandler);
// 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); setbuf(stdout, NULL);
if (2 != argc) { if (2 != argc) {
@ -82,21 +88,6 @@ int main(int argc, char *argv[])
return 0; 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) CDStarGatewayApp::CDStarGatewayApp(const std::string &configFile) : m_configFile(configFile), m_thread(NULL)
{ {
} }
@ -285,3 +276,35 @@ bool CDStarGatewayApp::createThread()
return true; 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);
}

@ -36,4 +36,7 @@ public:
bool init(); bool init();
void run(); void run();
static void sigHandler(int sig);
static void terminateHandler();
}; };

@ -335,7 +335,9 @@ void* CDStarGatewayThread::Entry()
m_statusFileTimer.start(); m_statusFileTimer.start();
m_statusTimer2.start(); m_statusTimer2.start();
#ifndef DEBUG_DSTARGW
try { try {
#endif
while (!m_killed) { while (!m_killed) {
if (m_icomRepeaterHandler != NULL) if (m_icomRepeaterHandler != NULL)
processRepeater(m_icomRepeaterHandler); processRepeater(m_icomRepeaterHandler);
@ -411,6 +413,7 @@ void* CDStarGatewayThread::Entry()
::std::this_thread::sleep_for(std::chrono::milliseconds(TIME_PER_TIC_MS)); ::std::this_thread::sleep_for(std::chrono::milliseconds(TIME_PER_TIC_MS));
} }
#ifndef DEBUG_DSTARGW
} }
catch (std::exception& e) { catch (std::exception& e) {
std::string message(e.what()); std::string message(e.what());
@ -419,6 +422,7 @@ void* CDStarGatewayThread::Entry()
catch (...) { catch (...) {
CLog::logFatal("Unknown exception raised in the main thread"); CLog::logFatal("Unknown exception raised in the main thread");
} }
#endif
CLog::logInfo("Stopping the ircDDB Gateway thread"); CLog::logInfo("Stopping the ircDDB Gateway thread");

@ -135,7 +135,9 @@ void* CIcomRepeaterProtocolHandler::Entry()
{ {
CLog::logInfo("Starting the Icom Controller thread"); CLog::logInfo("Starting the Icom Controller thread");
#ifndef DEBUG_DSTARGW
try { try {
#endif
while (!m_killed) { while (!m_killed) {
sendGwyPackets(); sendGwyPackets();
@ -145,6 +147,7 @@ void* CIcomRepeaterProtocolHandler::Entry()
m_retryTimer.clock(); m_retryTimer.clock();
} }
#ifndef DEBUG_DSTARGW
} }
catch (std::exception& e) { catch (std::exception& e) {
std::string message(e.what()); std::string message(e.what());
@ -153,6 +156,7 @@ void* CIcomRepeaterProtocolHandler::Entry()
catch (...) { catch (...) {
CLog::logError("Unknown exception raised in the Icom Controller thread"); CLog::logError("Unknown exception raised in the Icom Controller thread");
} }
#endif
CLog::logInfo("Stopping the Icom Controller thread"); CLog::logInfo("Stopping the Icom Controller thread");

@ -23,14 +23,15 @@ export LOG_DIR=/var/log/dstargateway/
ifeq ($(ENABLE_DEBUG), 1) ifeq ($(ENABLE_DEBUG), 1)
# choose this if you want debugging help # 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 else
# or, you can choose this for a much smaller executable without debugging help # 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 endif
export CC=g++ export CC=g++
export LDFLAGS:=-lcurl -pthread export LDFLAGS+= -lcurl -pthread
ifeq ($(USE_GPSD), 1) ifeq ($(USE_GPSD), 1)
export CPPFLAGS+= -DUSE_GPSD export CPPFLAGS+= -DUSE_GPSD

@ -11,6 +11,7 @@
- [3.4. Prerequisites and dependencies](#34-prerequisites-and-dependencies) - [3.4. Prerequisites and dependencies](#34-prerequisites-and-dependencies)
- [3.5. Building](#35-building) - [3.5. Building](#35-building)
- [3.5.0.1. Build With GPSD Support](#3501-build-with-gpsd-support) - [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.6. Installing](#36-installing)
- [3.7. Configuring](#37-configuring) - [3.7. Configuring](#37-configuring)
- [4. Contributing](#4-contributing) - [4. Contributing](#4-contributing)
@ -91,6 +92,11 @@ make
``` ```
make USE_GPS=1 make USE_GPS=1
``` ```
#### 3.5.0.2. Debug Build
```
make ENABLE_DEBUG=1
```
Note that this will link with libl
## 3.6. Installing ## 3.6. Installing
The program is meant to run as a systemd service. All bits an pieces are provided. The program is meant to run as a systemd service. All bits an pieces are provided.
``` ```

Loading…
Cancel
Save

Powered by TurnKey Linux.