// $Id$
//
-// Copyright (C) 2008
+// Copyright (C) 2008
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//#include "Backtrace.ih"
// Custom includes
-#ifdef SENF_DEBUG
- #include <execinfo.h>
+#include <senf/config.hh>
+#ifdef SENF_BACKTRACE
+ #include <execinfo.h>
+ #include <errno.h>
#endif
#include <cxxabi.h>
#include <boost/regex.hpp>
//#include "Backtrace.mpp"
#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
-prefix_ void senf::formatBacktrace(std::ostream & os, void ** backtrace, unsigned numEntries)
+prefix_ void senf::formatBacktrace(std::ostream & os, void ** backtrace, int numEntries)
{
-#ifdef SENF_DEBUG
+#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
+ static boost::regex const backtraceRx
("(.*)\\((.*)\\+(0x[0-9a-f]+)\\) \\[(0x[0-9a-f]+)\\]");
enum { File = 1,
Symbol = 2,
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)) {
symbol = std::string(demangled);
free(demangled);
}
- os << " " << symbol << " + " << match[Offset]
+ os << " " << symbol << " + " << match[Offset]
<< "\n in " << match[File] << " [" << match[Address] << "]\n";
}
else if (sym == "[0xffffe410]")
}
-prefix_ void senf::backtrace(std::ostream & os, unsigned numEntries)
+prefix_ void senf::backtrace(std::ostream & os, int numEntries)
{
-#ifdef SENF_DEBUG
+#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
}
-///////////////////////////////cc.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
#undef prefix_
//#include "Backtrace.mpp"