static char const hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
static void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS];
- unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) );
- for (unsigned i (0); i < nEntries; ++i) {
+ int nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) );
+ for (int i=0; i < nEntries; ++i) {
senf::IGNORE( write(1, " 0x", 3) );
for (unsigned j (sizeof(void*)); j > 0; --j) {
uintptr_t v ( reinterpret_cast<uintptr_t>(entries[i]) >> (8*(j-1)) );
#endif
senf::IGNORE( write(1, "\n", 1) );
-#ifdef SENF_DEBUG
+#ifdef SENF_BACKTRACE
senf::IGNORE( write(1, "Task was initialized at\n", 24) );
senf::IGNORE( write(1, runningBacktrace_.c_str(), runningBacktrace_.size()) );
#endif
{
#ifdef SENF_BACKTRACE
std::stringstream ss;
- backtrace(ss, 32);
+ senf::backtrace(ss, 32);
backtrace_ = ss.str();
#endif
}
#include <senf/config.hh>
#ifdef SENF_BACKTRACE
#include <execinfo.h>
+ #include <errno.h>
#endif
#include <cxxabi.h>
#include <boost/regex.hpp>
#define prefix_
//-/////////////////////////////////////////////////////////////////////////////////////////////////
-prefix_ void senf::formatBacktrace(std::ostream & os, void ** backtrace, unsigned numEntries)
+prefix_ void senf::formatBacktrace(std::ostream & os, void ** backtrace, int numEntries)
{
#ifdef SENF_BACKTRACE
char ** symbols (::backtrace_symbols(backtrace, numEntries));
+ if (symbols == NULL) {
+ os << "error on translating backtrace addresses with ::backtrace_symbols: " << std::strerror(errno);
+ return;
+ }
static boost::regex const backtraceRx
("(.*)\\((.*)\\+(0x[0-9a-f]+)\\) \\[(0x[0-9a-f]+)\\]");
Offset = 3,
Address = 4 };
- for (unsigned i=0; i<numEntries; ++i) {
+ for (int i=0; i<numEntries; ++i) {
std::string sym (symbols[i]);
boost::smatch match;
if (regex_match(sym, match, backtraceRx)) {
}
-prefix_ void senf::backtrace(std::ostream & os, unsigned numEntries)
+prefix_ void senf::backtrace(std::ostream & os, int numEntries)
{
#ifdef SENF_BACKTRACE
SENF_SCOPED_BUFFER( void*, entries, numEntries);
- unsigned n ( ::backtrace(entries, numEntries) );
+ int n ( ::backtrace(entries, numEntries) );
senf::formatBacktrace(os, entries, n);
#endif
}
\ingroup backtraces
*/
- void formatBacktrace(std::ostream & os, void ** backtrace, unsigned numEntries);
+ void formatBacktrace(std::ostream & os, void ** backtrace, int numEntries);
/** \brief Write a backtrace to \a os
\ingroup backtraces
*/
- void backtrace(std::ostream & os, unsigned numEntries);
+ void backtrace(std::ostream & os, int numEntries);
}
std::cerr << "Invalid memory access at " << info->si_addr << "\n";
#ifdef SENF_BACKTRACE
static void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS];
- unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) );
+ int nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) );
// Hack the callers address into the backtrace
// entries[1] = reinterpret_cast<void *>(ucontext->uc_mcontext.gregs[REG_EIP]);
prefix_ void senf::ExceptionMixin::addBacktrace()
{
void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS];
- unsigned nEntries (::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS));
+ int nEntries (::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS));
std::stringstream ss;
ss << "\nException at\n";