diff --git a/src/FileChangeDetector.hpp b/src/FileChangeDetector.hpp index 989d061..7dd0b14 100644 --- a/src/FileChangeDetector.hpp +++ b/src/FileChangeDetector.hpp @@ -17,7 +17,8 @@ class FileChangeDetector ~FileChangeDetector() { _isThreadRunning = false; - _eventThread.join(); + if(_eventThread.joinable()) + _eventThread.join(); } private: diff --git a/src/Logger.cpp b/src/Logger.cpp index ff5f2a3..4ec966a 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -12,8 +12,7 @@ Logger::Logger(std::string module_name) : _moduleName(std::move(module_name)), - _logFilePath(LogConfig::Get()->GetGlobalConfig().LogsRootFolder + _moduleName + ".log"), - _logCounter(0) + _logFilePath(LogConfig::Get()->GetGlobalConfig().LogsRootFolder + _moduleName + ".log") { //create possibly non-existing folders before opening log file utils::EnsureFolders(_logFilePath); @@ -31,11 +30,6 @@ Logger::~Logger() { LogConfig::Get()->UnsubscribeLogger(this); LogRotationManager::Get()->UnregisterLogFile(_logFilePath); - - // wait until all log messages are processed, as we have this logger - // referenced in the action lambda and deleting it would be bad - while (_logCounter != 0) - std::this_thread::sleep_for(std::chrono::milliseconds(10)); } bool Logger::Log(LogLevel level, std::string msg, @@ -57,11 +51,8 @@ bool Logger::Log(LogLevel level, std::string msg, auto const &level_config = LogConfig::Get()->GetLogLevelConfig(level); if (_config.PrintToConsole || level_config.PrintToConsole) PrintLogString(time_str, level, log_msg); - - --_logCounter; }); - ++_logCounter; return true; } diff --git a/src/Logger.hpp b/src/Logger.hpp index a617639..c200d81 100644 --- a/src/Logger.hpp +++ b/src/Logger.hpp @@ -66,7 +66,6 @@ class Logger : public samplog::ILogger private: std::string const _moduleName; std::string const _logFilePath; - std::atomic _logCounter; Config _config; }; diff --git a/src/amx/amxdbg.c b/src/amx/amxdbg.c index 5eca36a..f891d52 100644 --- a/src/amx/amxdbg.c +++ b/src/amx/amxdbg.c @@ -145,21 +145,27 @@ int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, FILE *fp) amx_Align32((uint32_t*)&amxdbg->linetbl[index].line); } /* for */ #endif - ptr += dbghdr.lines * sizeof(AMX_DBG_LINE); - /* detect dbghdr.lines overflow */ - while ((line = (AMX_DBG_LINE *)ptr) - && (cell)line->address > (cell)(line - 1)->address) { - dbghdr.lines = -1; - #if BYTE_ORDER==BIG_ENDIAN - for (index = 0; index <= dbghdr.lines; index++) { - amx_AlignCell(&linetbl[index].address); - amx_Align32((uint32_t*)&linetbl[index].line); - line++; - } /* for */ - #endif - ptr += ((uint32_t)dbghdr.lines + 1) * sizeof(AMX_DBG_LINE); - } /* while */ + unsigned int biggest_possible_size = ( + sizeof(AMX_DBG_HDR) + + dbghdr.files * (sizeof(AMX_DBG_FILE) + 33) + + dbghdr.lines * sizeof(AMX_DBG_LINE) + + dbghdr.symbols * (sizeof(AMX_DBG_SYMBOL) + 33) + + dbghdr.tags * (sizeof(AMX_DBG_TAG) + 33) + + dbghdr.automatons * (sizeof(AMX_DBG_MACHINE) + 33) + + dbghdr.states * (sizeof(AMX_DBG_STATE) + 33) + ); + unsigned int lines_overflow_count = 0; + + while(biggest_possible_size < dbghdr.size) { + biggest_possible_size += 0x10000 * sizeof(AMX_DBG_LINE); + ++lines_overflow_count; + } + + ptr += ( + dbghdr.lines * sizeof(AMX_DBG_LINE) + + lines_overflow_count * 0x10000 * sizeof(AMX_DBG_LINE) + ); /* symbol table (plus index tags) */ for (index = 0; index < dbghdr.symbols; index++) { @@ -242,7 +248,7 @@ int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename) return AMX_ERR_NONE; } -int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, int *line) +int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line) { int index; @@ -256,7 +262,7 @@ int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, int *line) if (--index < 0) return AMX_ERR_NOTFOUND; - *line = amxdbg->linetbl[index].line; + *line = (long)amxdbg->linetbl[index].line; return AMX_ERR_NONE; } @@ -271,14 +277,14 @@ int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcn assert(amxdbg != NULL); assert(funcname != NULL); *funcname = NULL; - for (index = amxdbg->hdr->symbols - 1; index >= 0; index--) { + for (index = 0; index < amxdbg->hdr->symbols; index++) { if (amxdbg->symboltbl[index]->ident == iFUNCTN && amxdbg->symboltbl[index]->codestart <= address && amxdbg->symboltbl[index]->codeend > address) { break; } } /* for */ - if (index < 0) + if (index >= amxdbg->hdr->symbols) return AMX_ERR_NOTFOUND; *funcname = amxdbg->symboltbl[index]->name; diff --git a/src/amx/amxdbg.h b/src/amx/amxdbg.h index a5671b4..9884976 100644 --- a/src/amx/amxdbg.h +++ b/src/amx/amxdbg.h @@ -146,7 +146,7 @@ int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, FILE *fp); int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename); int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname); -int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, int *line); +int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line); int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address); int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address); diff --git a/src/crashhandler_unix.cpp b/src/crashhandler_unix.cpp index 194d840..7447848 100644 --- a/src/crashhandler_unix.cpp +++ b/src/crashhandler_unix.cpp @@ -74,10 +74,7 @@ namespace { //only one signal will be allowed past this point if (!IsFirstSignal()) - { - while (true) - std::this_thread::sleep_for(std::chrono::seconds(1)); - } + return; const std::string err_msg = fmt::format( "caught signal {:d} ({:s}) (errno: {}, signal code: {}, exit status: {})",