Debugger: Move some Windows functionality around.

Preparing the introduction of the new CDB engine.
This commit is contained in:
Friedemann Kleint
2010-11-17 17:01:51 +01:00
parent 740eb6a987
commit d1c08e68cc
6 changed files with 164 additions and 132 deletions

View File

@@ -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