/******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems * * Copyright (C) 2011 by M. Ferrero, O. Parcollet * * TRIQS is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * TRIQS. If not, see . * ******************************************************************************/ #include "./stack_trace.hpp" #include #ifndef TRIQS_TRACE_MAX_FRAMES #define TRIQS_TRACE_MAX_FRAMES 50 #endif #ifdef __GNUC__ #include #include #include #include #include #include #include #include #include #include #include "./typeid_name.hpp" namespace triqs { namespace utility { //#define TRIQS_STACKTRACE_WITH_GDB #ifdef TRIQS_STACKTRACE_WITH_GDB std::string stack_trace() { std::ostringstream buffer; char pid_buf[30]; sprintf(pid_buf, "%d", getpid()); char name_buf[512]; name_buf[readlink("/proc/self/exe", name_buf, 511)]=0; int child_pid = fork(); if (!child_pid) { dup2(2,1); // redirect output to stderr buffer << "stack trace for "< strs; boost::split(strs, symbol, boost::is_any_of("\t ()+"), boost::token_compress_on); for (std::vector::const_iterator it = strs.begin(); it !=strs.end(); ++it) buffer << " "<