4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Backtrace non-inline non-template implementation */
26 #include "Backtrace.hh"
27 //#include "Backtrace.ih"
34 #include <boost/regex.hpp>
37 //#include "Backtrace.mpp"
39 ///////////////////////////////cc.p////////////////////////////////////////
41 prefix_ void senf::formatBacktrace(std::ostream & os, void ** backtrace, unsigned numEntries)
44 char ** symbols (::backtrace_symbols(backtrace, numEntries));
46 static boost::regex const backtraceRx
47 ("(.*)\\((.*)\\+(0x[0-9a-f]+)\\) \\[(0x[0-9a-f]+)\\]");
53 for (unsigned i=0; i<numEntries; ++i) {
54 std::string sym (symbols[i]);
56 if (regex_match(sym, match, backtraceRx)) {
57 std::string symbol (match[Symbol]);
59 char * demangled ( abi::__cxa_demangle(symbol.c_str(), 0, 0, &status) );
61 symbol = std::string(demangled);
64 os << " " << symbol << " + " << match[Offset]
65 << "\n in " << match[File] << " [" << match[Address] << "]\n";
67 else if (sym == "[0xffffe410]")
68 os << " __kernel_vsyscall [0xffffe410]\n";
69 else if (sym == "[0xffffe420]")
70 os << " __kernel_sigreturn [0xffffe410]\n";
71 else if (sym == "[0xffffe440]")
72 os << " __kernel_rt_sigreturn [0xffffe440]\n";
74 os << " " << sym << "\n";
79 os << "no backtrace available please compile SENF without final=1\n";
84 prefix_ void senf::backtrace(std::ostream & os, unsigned numEntries)
87 SENF_SCOPED_BUFFER( void*, entries, numEntries);
88 unsigned n ( ::backtrace(entries, numEntries) );
89 senf::formatBacktrace(os, entries, n);
93 ///////////////////////////////cc.e////////////////////////////////////////
95 //#include "Backtrace.mpp"
101 // comment-column: 40
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"