Skip to content

Commit

Permalink
Stack trace printing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Rusin committed Dec 4, 2023
1 parent 54654d9 commit fb66ea4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion include/ioh/common/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <execinfo.h>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
Expand All @@ -20,6 +22,7 @@
#include "file.hpp"



namespace ioh::problem
{
//! Defintion interface of problems that are defined in static files
Expand Down Expand Up @@ -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<int> &ids)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fb66ea4

Please sign in to comment.