Commit 2e40c54e authored by Friedemann Kleint's avatar Friedemann Kleint Committed by hjk

Debugger: Remove #ifdef Q_OS_WIN from hostutils.

- Provide stubs for Non-Windows
- Reduce #ifdefs, check Abi if possible.
- Remove unused winGetCurrentProcessId().

Task-number: QTCREATORBUG-8141
Change-Id: I80558ca4e52e87c7371597ea07c091af08097b34
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 31e2ddd0
......@@ -2079,7 +2079,6 @@ unsigned CdbEngine::examineStopReason(const GdbMi &stopReason,
WinException exception;
exception.fromGdbMI(stopReason);
QString description = exception.toString();
#ifdef Q_OS_WIN
// It is possible to hit on a startup trap or WOW86 exception while stepping (if something
// pulls DLLs. Avoid showing a 'stopped' Message box.
if (exception.exceptionCode == winExceptionStartupCompleteTrap
......@@ -2099,7 +2098,6 @@ unsigned CdbEngine::examineStopReason(const GdbMi &stopReason,
*message = msgInterrupted();
return rc;
}
#endif
*exceptionBoxMessage = msgStoppedByException(description, QString::number(threadId));
*message = description;
rc |= StopShowExceptionMessageBox|StopReportStatusMessage|StopNotifyStop;
......
......@@ -413,10 +413,8 @@ QString WinException::toString(bool includeLocation) const
{
QString rc;
QTextStream str(&rc);
#ifdef Q_OS_WIN
formatWindowsException(exceptionCode, exceptionAddress,
exceptionFlags, info1, info2, str);
#endif
if (includeLocation) {
if (lineNumber) {
str << " at " << QLatin1String(file) << ':' << lineNumber;
......
......@@ -1692,14 +1692,15 @@ void DebuggerPluginPrivate::attachToProcess(bool startServerOnly)
return;
}
#ifdef Q_OS_WIN
if (isWinProcessBeingDebugged(process.pid)) {
bool isWindows = false;
if (const ProjectExplorer::ToolChain *tc = ToolChainKitInformation::toolChain(kit))
isWindows = tc->targetAbi().os() == ProjectExplorer::Abi::WindowsOS;
if (isWindows && isWinProcessBeingDebugged(process.pid)) {
QMessageBox::warning(ICore::mainWindow(), tr("Process Already Under Debugger Control"),
tr("The process %1 is already under the control of a debugger.\n"
"Qt Creator cannot attach to it.").arg(process.pid));
return;
}
#endif
if (device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
DebuggerStartParameters sp;
......
......@@ -356,12 +356,7 @@ static inline QString msgWinException(const QByteArray &data)
QString rc;
QTextStream str(&rc);
str << GdbEngine::tr("An exception was triggered: ");
#ifdef Q_OS_WIN
formatWindowsException(exCode, address, 0, 0, 0, str);
#else
Q_UNUSED(exCode)
Q_UNUSED(address)
#endif
str << '.';
return rc;
}
......
......@@ -145,25 +145,29 @@ void GdbTermEngine::setupInferior()
void GdbTermEngine::handleStubAttached(const GdbResponse &response)
{
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
#ifdef Q_OS_WIN
QString errorMessage;
#endif // Q_OS_WIN
switch (response.resultClass) {
case GdbResultDone:
case GdbResultRunning:
#ifdef Q_OS_WIN
// Resume thread that was suspended by console stub process (see stub code).
if (winResumeThread(m_stubProc.applicationMainThreadID(), &errorMessage)) {
showMessage(QString::fromLatin1("Inferior attached, thread %1 resumed").
arg(m_stubProc.applicationMainThreadID()), LogMisc);
if (startParameters().toolChainAbi.os() != ProjectExplorer::Abi::WindowsOS) {
showMessage(_("INFERIOR ATTACHED"));
} else {
showMessage(QString::fromLatin1("Inferior attached, unable to resume thread %1: %2").
arg(m_stubProc.applicationMainThreadID()).arg(errorMessage),
LogWarning);
}
QString errorMessage;
// Resume thread that was suspended by console stub process (see stub code).
#ifdef Q_OS_WIN
const qint64 mainThreadId = m_stubProc.applicationMainThreadID();
#else
showMessage(_("INFERIOR ATTACHED"));
#endif // Q_OS_WIN
const qint64 mainThreadId = -1;
#endif
if (winResumeThread(mainThreadId, &errorMessage)) {
showMessage(QString::fromLatin1("Inferior attached, thread %1 resumed").
arg(mainThreadId), LogMisc);
} else {
showMessage(QString::fromLatin1("Inferior attached, unable to resume thread %1: %2").
arg(mainThreadId).arg(errorMessage),
LogWarning);
}
}
handleInferiorPrepared();
break;
case GdbResultError:
......
......@@ -82,11 +82,6 @@ bool winResumeThread(unsigned long dwThreadId, QString *errorMessage)
return ok;
}
unsigned long winGetCurrentProcessId()
{
return GetCurrentProcessId();
}
bool isWinProcessBeingDebugged(unsigned long pid)
{
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
......@@ -228,7 +223,16 @@ bool isFatalWinException(long code)
return true;
}
#endif // Q_OS_WIN
#else // Q_OS_WIN
bool winResumeThread(unsigned long, QString *) { return false; }
bool isWinProcessBeingDebugged(unsigned long) { return false; }
void formatWindowsException(unsigned long , quint64, unsigned long,
quint64, quint64, QTextStream &) { }
bool isFatalWinException(long) { return false; }
bool isDebuggerWinException(unsigned long) { return false; }
#endif // !Q_OS_WIN
} // namespace Internal
} // namespace Debugger
......@@ -40,13 +40,9 @@ QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
#ifdef Q_OS_WIN
// Resume a suspended thread by id.
bool winResumeThread(unsigned long dwThreadId, QString *errorMessage);
unsigned long winGetCurrentProcessId();
bool isWinProcessBeingDebugged(unsigned long pid);
// Special exception codes.
......@@ -75,8 +71,6 @@ bool isFatalWinException(long code);
// Check for EXCEPTION_BREAKPOINT, EXCEPTION_SINGLE_STEP
bool isDebuggerWinException(unsigned long code);
#endif // defined(Q_OS_WIN)
} // namespace Internal
} // namespace Debugger
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment