diff --git a/src/plugins/debugger/cdb/cdbdebugeventcallback.cpp b/src/plugins/debugger/cdb/cdbdebugeventcallback.cpp index ac2e3ddb53851805be797f9e6c05a39c716f8d85..1909425fab0a5669b1f8260abb0b0f58f4639e4e 100644 --- a/src/plugins/debugger/cdb/cdbdebugeventcallback.cpp +++ b/src/plugins/debugger/cdb/cdbdebugeventcallback.cpp @@ -31,6 +31,7 @@ #include "cdbengine.h" #include "cdbexceptionutils.h" #include "cdbengine_p.h" +#include "dbgwinutils.h" #include <QtCore/QDebug> #include <QtCore/QTextStream> @@ -75,7 +76,7 @@ STDMETHODIMP CdbDebugEventCallback::Exception( QTextStream str(&msg); formatException(Exception, &m_pEngine->m_d->interfaces(), str); } - const bool fatal = isFatalException(Exception->ExceptionCode); + const bool fatal = isFatalWinException(Exception->ExceptionCode); if (debugCDB) qDebug() << Q_FUNC_INFO << "\nex=" << Exception->ExceptionCode << " fatal=" << fatal << msg; m_pEngine->showMessage(msg, AppError); @@ -226,7 +227,7 @@ STDMETHODIMP CdbExceptionLoggerEventCallback::Exception( __in ULONG /* FirstChance */ ) { - const bool recordException = !m_skipNonFatalExceptions || isFatalException(Exception->ExceptionCode); + const bool recordException = !m_skipNonFatalExceptions || isFatalWinException(Exception->ExceptionCode); QString msg; formatException(Exception, QTextStream(&msg)); if (recordException) { diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index bc0a100c8d754f5a4be40797dfa8f97ad20de802..41e5c37c789b23e444c3d1321a97ef71e2ec91df 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -43,6 +43,7 @@ #include "debuggeragents.h" #include "debuggeruiswitcher.h" #include "debuggercore.h" +#include "dbgwinutils.h" #include "debuggeractions.h" #include "breakhandler.h" diff --git a/src/plugins/debugger/cdb/cdbexceptionutils.cpp b/src/plugins/debugger/cdb/cdbexceptionutils.cpp index 643ba1fffd7533110968216cf0fbaf0ee540b98c..3f06779338135a2f48d2fc7c31f0e5e4b3d6d002 100644 --- a/src/plugins/debugger/cdb/cdbexceptionutils.cpp +++ b/src/plugins/debugger/cdb/cdbexceptionutils.cpp @@ -30,6 +30,7 @@ #include "cdbexceptionutils.h" #include "cdbengine_p.h" #include "stacktracecontext.h" +#include "dbgwinutils.h" #include <QtCore/QString> #include <QtCore/QTextStream> @@ -151,106 +152,15 @@ QString ExceptionBlocker::format(const DEBUG_EXCEPTION_FILTER_PARAMETERS &p) // ------------------ further exception utilities // Simple exception formatting + void formatException(const EXCEPTION_RECORD64 *e, QTextStream &str) { - str.setIntegerBase(16); - str << "\nException at 0x" << e->ExceptionAddress - << ", code: 0x" << e->ExceptionCode << ": "; - switch (e->ExceptionCode) { - case winExceptionCppException: - str << "C++ exception"; - break; - case winExceptionStartupCompleteTrap: - str << "Startup complete"; - break; - case winExceptionDllNotFound: - str << "DLL not found"; - break; - case winExceptionDllEntryPointNoFound: - str << "DLL entry point not found"; - break; - case winExceptionDllInitFailed: - str << "DLL failed to initialize"; - break; - case winExceptionMissingSystemFile: - str << "System file is missing"; - break; - case winExceptionRpcServerUnavailable: - str << "RPC server unavailable"; - break; - case winExceptionRpcServerInvalid: - str << "Invalid RPC server"; - break; - case EXCEPTION_ACCESS_VIOLATION: { - const bool writeOperation = e->ExceptionInformation[0]; - str << (writeOperation ? "write" : "read") - << " access violation at: 0x" << e->ExceptionInformation[1]; - } - break; - case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: - str << "arrary bounds exceeded"; - break; - case EXCEPTION_BREAKPOINT: - str << "breakpoint"; - break; - case EXCEPTION_DATATYPE_MISALIGNMENT: - str << "datatype misalignment"; - break; - case EXCEPTION_FLT_DENORMAL_OPERAND: - str << "floating point exception"; - break; - case EXCEPTION_FLT_DIVIDE_BY_ZERO: - str << "division by zero"; - break; - case EXCEPTION_FLT_INEXACT_RESULT: - str << " floating-point operation cannot be represented exactly as a decimal fraction"; - break; - case EXCEPTION_FLT_INVALID_OPERATION: - str << "invalid floating-point operation"; - break; - case EXCEPTION_FLT_OVERFLOW: - str << "floating-point overflow"; - break; - case EXCEPTION_FLT_STACK_CHECK: - str << "floating-point operation stack over/underflow"; - break; - case EXCEPTION_FLT_UNDERFLOW: - str << "floating-point UNDERFLOW"; - break; - case EXCEPTION_ILLEGAL_INSTRUCTION: - str << "invalid instruction"; - break; - case EXCEPTION_IN_PAGE_ERROR: - str << "page in error"; - break; - case EXCEPTION_INT_DIVIDE_BY_ZERO: - str << "integer division by zero"; - break; - case EXCEPTION_INT_OVERFLOW: - str << "integer overflow"; - break; - case EXCEPTION_INVALID_DISPOSITION: - str << "invalid disposition to exception dispatcher"; - break; - case EXCEPTION_NONCONTINUABLE_EXCEPTION: - str << "attempt to continue execution after noncontinuable exception"; - break; - case EXCEPTION_PRIV_INSTRUCTION: - str << "privileged instruction"; - break; - case EXCEPTION_SINGLE_STEP: - str << "single step"; - break; - case EXCEPTION_STACK_OVERFLOW: - str << "stack_overflow"; - break; - } - str << ", flags=0x" << e->ExceptionFlags; - if (e->ExceptionFlags == EXCEPTION_NONCONTINUABLE) { - str << " (execution cannot be continued)"; - } + formatWindowsException(e->ExceptionCode, e->ExceptionAddress, + e->ExceptionFlags, + e->ExceptionInformation[0], + e->ExceptionInformation[1], + str); str << "\n\n"; - str.setIntegerBase(10); } // Format exception with stacktrace in case of C++ exception @@ -270,23 +180,5 @@ void formatException(const EXCEPTION_RECORD64 *e, } } -bool isFatalException(LONG code) -{ - switch (code) { - case EXCEPTION_BREAKPOINT: - case EXCEPTION_SINGLE_STEP: - case winExceptionStartupCompleteTrap: // Mysterious exception at start of application - case winExceptionRpcServerUnavailable: - case winExceptionRpcServerInvalid: - case winExceptionDllNotFound: - case winExceptionDllEntryPointNoFound: - case winExceptionCppException: - return false; - default: - break; - } - return true; -} - } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/cdb/cdbexceptionutils.h b/src/plugins/debugger/cdb/cdbexceptionutils.h index 6a83348ba1eb5ab5b1b5fd47208766ad77fb9020..596b06d5cbc4cdb35f15da2b61c73bdf73a1cacc 100644 --- a/src/plugins/debugger/cdb/cdbexceptionutils.h +++ b/src/plugins/debugger/cdb/cdbexceptionutils.h @@ -46,18 +46,6 @@ namespace CdbCore { namespace Debugger { namespace Internal { -// Special exception codes. -enum { winExceptionCppException = 0xe06d7363, - winExceptionStartupCompleteTrap = 0x406d1388, - winExceptionRpcServerUnavailable = 0x6ba, - winExceptionRpcServerInvalid = 0x6a6, - winExceptionDllNotFound = 0xc0000135, - winExceptionDllEntryPointNoFound = 0xc0000139, - winExceptionDllInitFailed = 0xc0000142, - winExceptionMissingSystemFile = 0xc0000143, - winExceptionAppInitFailed = 0xc0000143 -}; - class CdbDumperHelper; // Utility class that blocks out exception handling (breaking) @@ -102,9 +90,6 @@ void formatException(const EXCEPTION_RECORD64 *e, const CdbCore::ComInterfaces *cif, QTextStream &str); -// Is this a crash/recoverable? -bool isFatalException(LONG code); - } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/shared/dbgwinutils.cpp b/src/plugins/debugger/shared/dbgwinutils.cpp index 034e01655f144a99331d27439948c303f8d23946..6a256dff3ecd16326f02db9346b6737d496aab85 100644 --- a/src/plugins/debugger/shared/dbgwinutils.cpp +++ b/src/plugins/debugger/shared/dbgwinutils.cpp @@ -28,10 +28,12 @@ **************************************************************************/ #include "winutils.h" +#include "dbgwinutils.h" #include "debuggerdialogs.h" #include <QtCore/QDebug> #include <QtCore/QString> +#include <QtCore/QTextStream> // Enable Win API of XP SP1 and later #ifdef Q_OS_WIN @@ -252,5 +254,132 @@ bool isWinProcessBeingDebugged(unsigned long pid) return debugged != FALSE; } +// Simple exception formatting +void formatWindowsException(unsigned long code, quint64 address, + unsigned long flags, quint64 info1, quint64 info2, + QTextStream &str) +{ + str.setIntegerBase(16); + str << "\nException at 0x" << address + << ", code: 0x" << code << ": "; + switch (code) { + case winExceptionCppException: + str << "C++ exception"; + break; + case winExceptionStartupCompleteTrap: + str << "Startup complete"; + break; + case winExceptionDllNotFound: + str << "DLL not found"; + break; + case winExceptionDllEntryPointNoFound: + str << "DLL entry point not found"; + break; + case winExceptionDllInitFailed: + str << "DLL failed to initialize"; + break; + case winExceptionMissingSystemFile: + str << "System file is missing"; + break; + case winExceptionRpcServerUnavailable: + str << "RPC server unavailable"; + break; + case winExceptionRpcServerInvalid: + str << "Invalid RPC server"; + break; + case EXCEPTION_ACCESS_VIOLATION: { + const bool writeOperation = info1; + str << (writeOperation ? "write" : "read") + << " access violation at: 0x" << info2; + } + break; + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: + str << "arrary bounds exceeded"; + break; + case EXCEPTION_BREAKPOINT: + str << "breakpoint"; + break; + case EXCEPTION_DATATYPE_MISALIGNMENT: + str << "datatype misalignment"; + break; + case EXCEPTION_FLT_DENORMAL_OPERAND: + str << "floating point exception"; + break; + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + str << "division by zero"; + break; + case EXCEPTION_FLT_INEXACT_RESULT: + str << " floating-point operation cannot be represented exactly as a decimal fraction"; + break; + case EXCEPTION_FLT_INVALID_OPERATION: + str << "invalid floating-point operation"; + break; + case EXCEPTION_FLT_OVERFLOW: + str << "floating-point overflow"; + break; + case EXCEPTION_FLT_STACK_CHECK: + str << "floating-point operation stack over/underflow"; + break; + case EXCEPTION_FLT_UNDERFLOW: + str << "floating-point UNDERFLOW"; + break; + case EXCEPTION_ILLEGAL_INSTRUCTION: + str << "invalid instruction"; + break; + case EXCEPTION_IN_PAGE_ERROR: + str << "page in error"; + break; + case EXCEPTION_INT_DIVIDE_BY_ZERO: + str << "integer division by zero"; + break; + case EXCEPTION_INT_OVERFLOW: + str << "integer overflow"; + break; + case EXCEPTION_INVALID_DISPOSITION: + str << "invalid disposition to exception dispatcher"; + break; + case EXCEPTION_NONCONTINUABLE_EXCEPTION: + str << "attempt to continue execution after noncontinuable exception"; + break; + case EXCEPTION_PRIV_INSTRUCTION: + str << "privileged instruction"; + break; + case EXCEPTION_SINGLE_STEP: + str << "single step"; + break; + case EXCEPTION_STACK_OVERFLOW: + str << "stack_overflow"; + break; + } + str << ", flags=0x" << flags; + if (flags == EXCEPTION_NONCONTINUABLE) { + str << " (execution cannot be continued)"; + } + str.setIntegerBase(10); +} + +bool isDebuggerWinException(long code) +{ + return code ==EXCEPTION_BREAKPOINT || code == EXCEPTION_SINGLE_STEP; +} + +bool isFatalWinException(long code) +{ + switch (code) { + case EXCEPTION_BREAKPOINT: + case EXCEPTION_SINGLE_STEP: + case winExceptionStartupCompleteTrap: // Mysterious exception at start of application + case winExceptionRpcServerUnavailable: + case winExceptionRpcServerInvalid: + case winExceptionDllNotFound: + case winExceptionDllEntryPointNoFound: + case winExceptionCppException: + return false; + default: + break; + } + return true; +} + } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/shared/dbgwinutils.h b/src/plugins/debugger/shared/dbgwinutils.h index 8f841acd5cc88581673bb59d8b479db8b9de7d81..5849ba7717624f2272e861418f4a993f1ef3b39f 100644 --- a/src/plugins/debugger/shared/dbgwinutils.h +++ b/src/plugins/debugger/shared/dbgwinutils.h @@ -33,6 +33,7 @@ #include <QtCore/QList> QT_FORWARD_DECLARE_CLASS(QString) +QT_FORWARD_DECLARE_CLASS(QTextStream) namespace Debugger { namespace Internal { @@ -59,6 +60,29 @@ QString winNormalizeFileName(const QString &f); bool isWinProcessBeingDebugged(unsigned long pid); +// Special exception codes. +enum { winExceptionCppException = 0xe06d7363, + winExceptionStartupCompleteTrap = 0x406d1388, + winExceptionRpcServerUnavailable = 0x6ba, + winExceptionRpcServerInvalid = 0x6a6, + winExceptionDllNotFound = 0xc0000135, + winExceptionDllEntryPointNoFound = 0xc0000139, + winExceptionDllInitFailed = 0xc0000142, + winExceptionMissingSystemFile = 0xc0000143, + winExceptionAppInitFailed = 0xc0000143 +}; + +// Format windows Exception +void formatWindowsException(unsigned long code, quint64 address, + unsigned long flags, quint64 info1, quint64 info2, + QTextStream &str); +// Check for access violation, etc. +bool isFatalWinException(long code); + +// Check for EXCEPTION_BREAKPOINT, EXCEPTION_SINGLE_STEP +bool isDebuggerWinException(long code); + + } // namespace Internal } // namespace Debugger