mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Hadrons: backtrace on abort
This commit is contained in:
parent
299e828d83
commit
bf71162b97
@ -48,6 +48,9 @@ using namespace Grid;
|
|||||||
using namespace Hadrons;
|
using namespace Hadrons;
|
||||||
using namespace Exceptions;
|
using namespace Exceptions;
|
||||||
|
|
||||||
|
// backtrace cache
|
||||||
|
std::vector<std::string> Grid::Hadrons::Exceptions::backtraceStr;
|
||||||
|
|
||||||
// logic errors
|
// logic errors
|
||||||
CTOR_EXC(Logic, logic_error(msg + ERR_SUFF))
|
CTOR_EXC(Logic, logic_error(msg + ERR_SUFF))
|
||||||
CTOR_EXC(Definition, Logic("definition error: " + msg, loc))
|
CTOR_EXC(Definition, Logic("definition error: " + msg, loc))
|
||||||
@ -82,6 +85,15 @@ void Grid::Hadrons::Exceptions::abort(const std::exception& e)
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
LOG(Error) << e.what() << std::endl;
|
LOG(Error) << e.what() << std::endl;
|
||||||
|
if (!backtraceStr.empty())
|
||||||
|
{
|
||||||
|
LOG(Error) << "-- BACKTRACE --------------" << std::endl;
|
||||||
|
for (auto &s: backtraceStr)
|
||||||
|
{
|
||||||
|
LOG(Error) << s << std::endl;
|
||||||
|
}
|
||||||
|
LOG(Error) << "---------------------------" << std::endl;
|
||||||
|
}
|
||||||
LOG(Error) << "Aborting program" << std::endl;
|
LOG(Error) << "Aborting program" << std::endl;
|
||||||
Grid_finalize();
|
Grid_finalize();
|
||||||
|
|
||||||
|
@ -30,16 +30,39 @@ See the full license in the file "LICENSE" in the top level distribution directo
|
|||||||
#define Hadrons_Exceptions_hpp_
|
#define Hadrons_Exceptions_hpp_
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <execinfo.h>
|
||||||
#ifndef Hadrons_Global_hpp_
|
#ifndef Hadrons_Global_hpp_
|
||||||
#include <Grid/Hadrons/Global.hpp>
|
#include <Grid/Hadrons/Global.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HADRONS_SRC_LOC std::string(__FUNCTION__) + " at " \
|
#define HADRONS_SRC_LOC std::string(__FUNCTION__) + " at " \
|
||||||
+ std::string(__FILE__) + ":" + std::to_string(__LINE__)
|
+ std::string(__FILE__) + ":" + std::to_string(__LINE__)
|
||||||
|
#define HADRONS_BACKTRACE_MAX 128
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
|
#define HADRONS_CACHE_BACKTRACE \
|
||||||
|
{\
|
||||||
|
void* _callstack[HADRONS_BACKTRACE_MAX];\
|
||||||
|
int _i, _frames = backtrace(_callstack, HADRONS_BACKTRACE_MAX);\
|
||||||
|
char** _strs = backtrace_symbols(_callstack, _frames);\
|
||||||
|
Grid::Hadrons::Exceptions::backtraceStr.clear();\
|
||||||
|
for (_i = 0; _i < _frames; ++_i)\
|
||||||
|
{\
|
||||||
|
Hadrons::Exceptions::backtraceStr.push_back(std::string(_strs[_i]));\
|
||||||
|
}\
|
||||||
|
free(_strs);\
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define HADRONS_CACHE_BACKTRACE \
|
||||||
|
Grid::Hadrons::Exceptions::backtraceStr.clear();\
|
||||||
|
Grid::Hadrons::Exceptions::backtraceStr.push_back("<backtrace not supported>");
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HADRONS_ERROR(exc, msg)\
|
#define HADRONS_ERROR(exc, msg)\
|
||||||
|
HADRONS_CACHE_BACKTRACE \
|
||||||
throw(Exceptions::exc(msg, HADRONS_SRC_LOC));
|
throw(Exceptions::exc(msg, HADRONS_SRC_LOC));
|
||||||
|
|
||||||
#define HADRONS_ERROR_REF(exc, msg, address)\
|
#define HADRONS_ERROR_REF(exc, msg, address)\
|
||||||
|
HADRONS_CACHE_BACKTRACE \
|
||||||
throw(Exceptions::exc(msg, HADRONS_SRC_LOC, address));
|
throw(Exceptions::exc(msg, HADRONS_SRC_LOC, address));
|
||||||
|
|
||||||
#define DECL_EXC(name, base) \
|
#define DECL_EXC(name, base) \
|
||||||
@ -60,6 +83,9 @@ BEGIN_HADRONS_NAMESPACE
|
|||||||
|
|
||||||
namespace Exceptions
|
namespace Exceptions
|
||||||
{
|
{
|
||||||
|
// backtrace cache
|
||||||
|
extern std::vector<std::string> backtraceStr;
|
||||||
|
|
||||||
// logic errors
|
// logic errors
|
||||||
DECL_EXC(Logic, std::logic_error);
|
DECL_EXC(Logic, std::logic_error);
|
||||||
DECL_EXC(Definition, Logic);
|
DECL_EXC(Definition, Logic);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user