Skip to content
Snippets Groups Projects
Commit 132ccc4b authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

first tries

parent 67d07faf
Branches
Tags
No related merge requests found
......@@ -24,7 +24,7 @@ include_directories(${PASTIS_SOURCE_DIR}/packages/CLI11/include)
# Kokkos
set(KOKKOS_ENABLE_OPENMP ON CACHE BOOL "")
add_subdirectory(${CMAKE_SOURCE_DIR}/packages/kokkos)
add_subdirectory(${PASTIS_SOURCE_DIR}/packages/kokkos)
include_directories(${Kokkos_INCLUDE_DIRS_RET})
# Pastis utils
......@@ -46,6 +46,8 @@ configure_file("${PASTIS_SOURCE_DIR}/pastis_config.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/pastis_config.hpp"
@ONLY)
link_libraries("-rdynamic")
# ------------------- Source files --------------------
# Pastis binary
add_executable(
......
......@@ -4,6 +4,45 @@
#include <rang.hpp>
#include <iomanip>
#include <execinfo.h>
#include <cxxabi.h>
#include <regex>
#include <vector>
void print_bt() {
const int size = 20;
void *buffer[size];
int ret = backtrace( buffer, size );
char **ptr = backtrace_symbols( buffer, ret );
std::vector<std::string> lines;
for (int i=0; i<ret; ++i) {
lines.push_back(ptr[i]);
}
free( ptr );
// abi::__cxa_demangle( "_Z16displayBacktracev", NULL, NULL, &status );
std::regex mangled_function(R"(\(.*\+)");
for (const auto& line : lines) {
std::cerr << "demangling " << line << '\n';
std::smatch matchex;
int status = -1;
if (std::regex_search(line, matchex, mangled_function)) {
std::string prefix = matchex.prefix().str();
std::string function = line.substr(matchex.position()+1,matchex.length()-2);
std::string suffix = matchex.suffix().str();
std::cerr << "Found " << function.c_str() << '\n';
std::string demangled = abi::__cxa_demangle(function.c_str(), NULL, NULL, &status);
std::cerr << "status=" << status << '\n';
std::cerr << demangled << '\n'<< '\n';
}
}
}
#warning must create a specific class for pausing and use enum class
#include <string>
std::string SignalManager::s_pause_on_error = "auto";
......@@ -27,6 +66,7 @@ std::string SignalManager::signalName(int s)
void SignalManager::pauseForDebug()
{
std::cerr << "\n======================================\n";
std::cerr << rang::style::reset
<< rang::fg::reset
......@@ -50,6 +90,7 @@ void SignalManager::pauseForDebug()
void SignalManager::handler(int s)
{
std::cerr << "\n *** "
<< rang::style::reset
<< rang::fg::reset
......@@ -62,18 +103,27 @@ void SignalManager::handler(int s)
<< rang::style::reset
<< " ***\n";
std::signal(SIGFPE, SIG_DFL);
std::signal(SIGSEGV, SIG_DFL);
std::signal(SIGTERM, SIG_DFL);
std::signal(SIGINT, SIG_DFL);
std::signal(SIGABRT, SIG_DFL);
print_bt();
SignalManager::pauseForDebug();
if ((ConsoleManager::isTerminal(std::cout) and
(s_pause_on_error == "auto")) or
(s_pause_on_error == "yes")) {
std::signal(SIGINT, SIG_DFL);
SignalManager::pauseForDebug();
} else {
std::exit(0);
// std::exit(0);
}
}
void SignalManager::init(const bool& enable)
{
if (enable) {
std::signal(SIGFPE, SignalManager::handler);
std::signal(SIGSEGV, SignalManager::handler);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment