diff --git a/include/ioh/common/factory.hpp b/include/ioh/common/factory.hpp index 038d8c8a..4775e8cd 100644 --- a/include/ioh/common/factory.hpp +++ b/include/ioh/common/factory.hpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -20,6 +22,7 @@ #include "file.hpp" + namespace ioh::problem { //! Defintion interface of problems that are defined in static files @@ -57,6 +60,21 @@ namespace ioh::problem namespace ioh::common { + + void printStackTrace() { + const int MAX_CALLSTACK_SIZE = 128; + void *callstack[MAX_CALLSTACK_SIZE]; + int stackSize = backtrace(callstack, MAX_CALLSTACK_SIZE); + char **symbols = backtrace_symbols(callstack, stackSize); + + std::cerr << "Call Stack:" << std::endl; + for (int i = 0; i < stackSize; i++) { + std::cerr << symbols[i] << std::endl; + } + + free(symbols); + } + //! Function to get the next non zero value in an array of integers inline int get_next_id(const std::vector &ids) { @@ -135,7 +153,9 @@ namespace ioh::common std::cerr << error_message << std::endl; std::cout << error_message << std::endl; - assert(false); + printStackTrace(); + + assert(!already_defined && name.c_str()); } name_map[name] = std::move(creator);