X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Flogbacktrace_unix.cpp;h=cc9cbf67e856954f08e67f7eec54dcc085def34b;hp=2e023a9b3c947d014a9bfd2628d0b9d4c0e7245b;hb=13c1c8fd092079ff9bc4ff3acfa9100d008d5ea7;hpb=39c9cfeeb71c0e39c4ed12eeead9d5d808895b6d diff --git a/src/common/logbacktrace_unix.cpp b/src/common/logbacktrace_unix.cpp index 2e023a9b..cc9cbf67 100644 --- a/src/common/logbacktrace_unix.cpp +++ b/src/common/logbacktrace_unix.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-2014 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "quassel.h" @@ -30,65 +30,68 @@ # include #endif -void Quassel::logBacktrace(const QString &filename) { +void Quassel::logBacktrace(const QString &filename) +{ #ifndef BUILD_CRASHHANDLER - Q_UNUSED(filename) + Q_UNUSED(filename) #else - void* callstack[128]; - int i, frames = backtrace(callstack, 128); + void *callstack[128]; + int i, frames = backtrace(callstack, 128); - QFile dumpFile(filename); - dumpFile.open(QIODevice::Append); - QTextStream dumpStream(&dumpFile); + QFile dumpFile(filename); + dumpFile.open(QIODevice::Append); + QTextStream dumpStream(&dumpFile); - for (i = 0; i < frames; ++i) { - Dl_info info; - dladdr (callstack[i], &info); - // as a reference: - // typedef struct - // { - // __const char *dli_fname; /* File name of defining object. */ - // void *dli_fbase; /* Load address of that object. */ - // __const char *dli_sname; /* Name of nearest symbol. */ - // void *dli_saddr; /* Exact value of nearest symbol. */ - // } Dl_info; + for (i = 0; i < frames; ++i) { + Dl_info info; + dladdr(callstack[i], &info); + // as a reference: + // typedef struct + // { + // __const char *dli_fname; /* File name of defining object. */ + // void *dli_fbase; /* Load address of that object. */ + // __const char *dli_sname; /* Name of nearest symbol. */ + // void *dli_saddr; /* Exact value of nearest symbol. */ + // } Dl_info; - #if __LP64__ - int addrSize = 16; + #ifdef __LP64__ + int addrSize = 16; #else - int addrSize = 8; + int addrSize = 8; #endif - QString funcName; - if(info.dli_sname) { - char *func = abi::__cxa_demangle(info.dli_sname, 0, 0, 0); - if(func) { - funcName = QString(func); - free(func); - } else { - funcName = QString(info.dli_sname); - } - } else { - funcName = QString("0x%1").arg((ulong)(info.dli_saddr), addrSize, 16, QLatin1Char('0')); - } + QString funcName; + if (info.dli_sname) { + char *func = abi::__cxa_demangle(info.dli_sname, 0, 0, 0); + if (func) { + funcName = QString(func); + free(func); + } + else { + funcName = QString(info.dli_sname); + } + } + else { + funcName = QString("0x%1").arg((ulong)(info.dli_saddr), addrSize, 16, QLatin1Char('0')); + } - // prettificating the filename - QString fileName("???"); - if(info.dli_fname) { - fileName = QString(info.dli_fname); - int slashPos = fileName.lastIndexOf('/'); - if(slashPos != -1) - fileName = fileName.mid(slashPos + 1); - } + // prettificating the filename + QString fileName("???"); + if (info.dli_fname) { + fileName = QString(info.dli_fname); + int slashPos = fileName.lastIndexOf('/'); + if (slashPos != -1) + fileName = fileName.mid(slashPos + 1); + } - QString debugLine = QString("#%1 %2 0x%3 %4").arg(i, 3, 10) - .arg(fileName, - 20) - .arg((ulong)(callstack[i]), addrSize, 16, QLatin1Char('0')) - .arg(funcName); + QString debugLine = QString("#%1 %2 0x%3 %4").arg(i, 3, 10) + .arg(fileName, -20) + .arg((ulong)(callstack[i]), addrSize, 16, QLatin1Char('0')) + .arg(funcName); - dumpStream << debugLine << "\n"; - qDebug() << qPrintable(debugLine); - } - dumpFile.close(); + dumpStream << debugLine << "\n"; + qDebug() << qPrintable(debugLine); + } + dumpFile.close(); #endif /* BUILD_CRASHHANDLER */ }