diff options
Diffstat (limited to 'tdecore/kdebug.cpp')
| -rw-r--r-- | tdecore/kdebug.cpp | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/tdecore/kdebug.cpp b/tdecore/kdebug.cpp index d906f67fc..18af9c030 100644 --- a/tdecore/kdebug.cpp +++ b/tdecore/kdebug.cpp @@ -28,8 +28,8 @@ #include "tdeapplication.h" #include "tdeglobal.h" -#include "kinstance.h" -#include "kstandarddirs.h" +#include "tdeinstance.h" +#include "tdestandarddirs.h" #include <tqmessagebox.h> #include <tdelocale.h> @@ -59,7 +59,11 @@ #include <config.h> #ifdef HAVE_BACKTRACE -#include <execinfo.h> +#include BACKTRACE_H + +#ifdef HAVE_DLFCN_H +#include <dlfcn.h> +#endif #ifdef HAVE_ABI_CXA_DEMANGLE #include <cxxabi.h> @@ -285,24 +289,26 @@ static void kDebugBackend( unsigned short nLevel, unsigned int nArea, const char // If the application doesn't have a TQApplication object it can't use // a messagebox, as well as in case of GUI is disabled. - if ( nOutput == 1 && ( !kapp || !kapp->guiEnabled()) ) { + if ( nOutput == 1 && ( !tdeApp || !tdeApp->guiEnabled()) ) { nOutput = 2; } else if ( nOutput == 4 && nLevel != KDEBUG_FATAL ) { return; } - const int BUFSIZE = 4096; - char buf[BUFSIZE]; - if ( !kDebug_data->aAreaName.isEmpty() ) { - strlcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] [").ascii(), BUFSIZE ); - strlcat( buf, kDebug_data->aAreaName.data(), BUFSIZE ); - strlcat( buf, "] ", BUFSIZE ); - strlcat( buf, data, BUFSIZE ); - } - else { - strlcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").ascii(), BUFSIZE ); - strlcat( buf, data, BUFSIZE ); + const int BUF_SIZE = 4096; + const int BUF_PID_SIZE = 20; + char buf[BUF_SIZE]; + char buf_pid[BUF_PID_SIZE]; + strlcpy(buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").ascii(), BUF_SIZE); + if (!kDebug_data->aAreaName.isEmpty()) + { + strlcat( buf, "[", BUF_SIZE ); + strlcat( buf, kDebug_data->aAreaName.data(), BUF_SIZE ); + strlcat( buf, "] ", BUF_SIZE ); } + snprintf(buf_pid, BUF_PID_SIZE, "[%d] ", getpid()); + strlcat(buf, buf_pid, BUF_SIZE); + strlcat(buf, data, BUF_SIZE); // Output switch( nOutput ) @@ -327,7 +333,7 @@ static void kDebugBackend( unsigned short nLevel, unsigned int nArea, const char break; } TQFile aOutputFile( kDebug_data->config->readPathEntry(aKey, "kdebug.dbg") ); - aOutputFile.open( (TQIODevice_OpenModeFlag)((int)IO_WriteOnly | (int)IO_Append | (int)IO_Raw) ); + aOutputFile.open( IO_WriteOnly | IO_Append | IO_Raw ); aOutputFile.writeBlock( buf, strlen( buf ) ); aOutputFile.close(); break; @@ -337,7 +343,7 @@ static void kDebugBackend( unsigned short nLevel, unsigned int nArea, const char // Since we are in tdecore here, we cannot use KMsgBox and use // TQMessageBox instead if ( !kDebug_data->aAreaName.isEmpty() ) - aCaption += TQString("(%1)").arg( QString(kDebug_data->aAreaName) ); + aCaption += TQString("(%1)").arg( TQString(kDebug_data->aAreaName) ); TQMessageBox::warning( 0L, aCaption, data, i18n("&OK") ); break; } @@ -426,7 +432,7 @@ kdbgstream& kdbgstream::operator<< (TQChar ch) output += "\\x" + TQString::number( ch.unicode(), 16 ).rightJustify(2, '0'); else { output += ch; - if (ch == QChar('\n')) flush(); + if (ch == TQChar('\n')) flush(); } return *this; } @@ -465,7 +471,7 @@ kdbgstream& kdbgstream::operator<< (const TQWidget* widget) return *this; } output += string; - if (output.at(output.length() -1 ) == QChar('\n')) + if (output.at(output.length() -1 ) == TQChar('\n')) { flush(); } @@ -620,7 +626,7 @@ asymbol** bfdLoadSymtab (bfd *abfd) { long symCount; // count of entries in symbol table long symtab_sz; // size of the table asymbol** rv; - bfd_boolean dynamic = FALSE; + bool dynamic = false; // make shure the file has symbol table if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0){ @@ -631,7 +637,7 @@ asymbol** bfdLoadSymtab (bfd *abfd) { symtab_sz = bfd_get_symtab_upper_bound (abfd); if (symtab_sz == 0) { symtab_sz = bfd_get_dynamic_symtab_upper_bound (abfd); - dynamic = TRUE; + dynamic = true; } if (symtab_sz < 0) { return 0; @@ -687,10 +693,15 @@ void bfdFillAdditionalFunctionsInfo(BacktraceFunctionInfo &func) { // found source file and line for given address for (asection *sect = abfd->sections; sect != NULL; sect = sect->next) { - +#ifdef HAVE_LIBBFD_2_34_API + if (bfd_section_flags(sect) & SEC_ALLOC) { + bfd_vma sectStart = bfd_section_vma(sect); + bfd_vma sectEnd = sectStart + bfd_section_size(sect); +#else // HAVE_LIBBFD_2_34_API if (bfd_get_section_flags(abfd, sect) & SEC_ALLOC) { bfd_vma sectStart = bfd_get_section_vma(abfd, sect); bfd_vma sectEnd = sectStart + bfd_section_size(abfd, sect); +#endif // HAVE_LIBBFD_2_34_API if (sectStart <= func.offset && func.offset < sectEnd) { bfd_vma sectOffset = func.offset - sectStart; const char* functionName; @@ -753,7 +764,13 @@ TQString formatBacktrace(void *addr) { // NOTE: if somebody would compile for some non-linux-glibc platform // check if dladdr function is avalible there Dl_info info; - dladdr(func.addr, &info); // obtain information about the function. + + // obtain information about the function. +#ifdef Q_OS_SOLARIS + dladdr((void *)func.addr, &info); +#else + dladdr(func.addr, &info); +#endif /* Solaris */ func.fileName = info.dli_fname; func.base = info.dli_fbase; @@ -810,7 +827,7 @@ TQString kdBacktrace(int levels) if (levels) { for (int i = 0; i < levels; ++i) { - rv += QString().sprintf("#%-2d ", i); + rv += TQString().sprintf("#%-2d ", i); rv += formatBacktrace(trace[i]); rv += '\n'; } |
