43#include "crashprint.h"
72void wxCrashPrint::Report() {
74 wxString appname = wxTheApp->GetAppName();
78 btCount = backtrace(m_btBuffer, maxBtCount);
80 wxPrintf(_T(
"\n%s: Backtrace could not be created\n"), appname.c_str());
82 m_btStrings = backtrace_symbols(m_btBuffer, btCount);
84 wxPrintf(_T(
"\n%s: Backtrace could not get symbols\n"), appname.c_str());
88 wxPrintf(_T(
"\n*** %s (%s) crashed ***, see backtrace!\n"), appname.c_str(),
93 wxString cur, addr, func, addrs;
97 for (
int i = 0; i < btCount; ++i) {
98 cur = wxString::FromAscii(m_btStrings[i]);
99 pos1 = cur.rfind(
'[');
100 pos2 = cur.rfind(
']');
101 if ((pos1 != wxString::npos) && (pos2 != wxString::npos)) {
102 addr = cur.substr(pos1 + 1, pos2 - pos1 - 1);
103 addrs.Append(addr + _T(
" "));
105 pos1 = cur.rfind(_T(
"_Z"));
106 pos2 = cur.rfind(
'+');
107 if (pos2 == wxString::npos) pos2 = cur.rfind(
')');
108 if (pos1 != wxString::npos) {
109 func = cur.substr(pos1, pos2 - pos1);
110 func = wxString::FromAscii(
111 abi::__cxa_demangle(func.mb_str(), 0, 0, &status));
113 pos1 = cur.rfind(
'(');
114 if (pos1 != wxString::npos) {
115 func = cur.substr(pos1 + 1, pos2 - pos1 - 1);
117 pos2 = cur.rfind(
'[');
118 func = cur.substr(0, pos2 - 1);
121 lines.Add(addr + _T(
" in ") + func);
122 if (func == _T(
"main"))
break;
127 wxString::Format(_T(
"addr2line -e /proc/%d/exe -s "), getpid());
128 wxArrayString fnames;
129 if (wxExecute(cmd + addrs, fnames) != -1) {
130 for (
size_t i = 0; i < fnames.GetCount(); ++i) {
131 wxPrintf(_T(
"%s at %s\n"), lines[i].c_str(), fnames[i].c_str());
134 for (
size_t i = 0; i < lines.GetCount(); ++i) {
135 wxPrintf(_T(
"%s\n"), lines[i].c_str());
wxCrashPrint(int flags=0, const wxString &fname=wxEmptyString)
constructor