Commit 1a1c9bf8 authored by hjk's avatar hjk

Debugger: Use shared TerminalRunner also for CDB

Change-Id: I2dd9b16f5699d0551a2de3e8ebefc865b98ad862
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 96da2973
......@@ -49,6 +49,7 @@
#include <debugger/sourceutils.h>
#include <debugger/shared/cdbsymbolpathlisteditor.h>
#include <debugger/shared/hostutils.h>
#include <debugger/terminal.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagebox.h>
......@@ -178,12 +179,6 @@ Q_DECLARE_METATYPE(Debugger::Internal::MemoryChangeCookie)
namespace Debugger {
namespace Internal {
static inline bool isCreatorConsole(const DebuggerRunParameters &sp)
{
return !boolSetting(UseCdbConsole) && sp.inferior.runMode == ApplicationLauncher::Console
&& (sp.startMode == StartInternal || sp.startMode == StartExternal);
}
// Base data structure for command queue entries with callback
class CdbCommand
{
......@@ -372,68 +367,6 @@ int CdbEngine::elapsedLogTime() const
return delta;
}
// Start the console stub with the sub process. Continue in consoleStubProcessStarted.
bool CdbEngine::startConsole(const DebuggerRunParameters &sp, QString *errorMessage)
{
if (debug)
qDebug("startConsole %s", qPrintable(sp.inferior.executable));
m_consoleStub.reset(new ConsoleProcess);
m_consoleStub->setMode(ConsoleProcess::Suspend);
connect(m_consoleStub.data(), &ConsoleProcess::processError,
this, &CdbEngine::consoleStubError);
connect(m_consoleStub.data(), &ConsoleProcess::processStarted,
this, &CdbEngine::consoleStubProcessStarted);
connect(m_consoleStub.data(), &ConsoleProcess::stubStopped,
this, &CdbEngine::consoleStubExited);
m_consoleStub->setWorkingDirectory(sp.inferior.workingDirectory);
if (sp.stubEnvironment.size())
m_consoleStub->setEnvironment(sp.stubEnvironment);
if (!m_consoleStub->start(sp.inferior.executable, sp.inferior.commandLineArguments)) {
*errorMessage = tr("The console process \"%1\" could not be started.").arg(sp.inferior.executable);
return false;
}
return true;
}
void CdbEngine::consoleStubError(const QString &msg)
{
if (debug)
qDebug("consoleStubProcessMessage() in %s %s", qPrintable(stateName(state())), qPrintable(msg));
if (state() == EngineSetupRequested) {
STATE_DEBUG(state(), Q_FUNC_INFO, __LINE__, "notifyEngineSetupFailed")
notifyEngineSetupFailed();
} else {
STATE_DEBUG(state(), Q_FUNC_INFO, __LINE__, "notifyEngineIll")
notifyEngineIll();
}
Core::AsynchronousMessageBox::critical(tr("Debugger Error"), msg);
}
void CdbEngine::consoleStubProcessStarted()
{
if (debug)
qDebug("consoleStubProcessStarted() PID=%lld", m_consoleStub->applicationPID());
// Attach to console process.
DebuggerRunParameters attachParameters = runParameters();
attachParameters.inferior.executable.clear();
attachParameters.inferior.commandLineArguments.clear();
attachParameters.attachPID = ProcessHandle(m_consoleStub->applicationPID());
attachParameters.startMode = AttachExternal;
attachParameters.inferior.runMode = ApplicationLauncher::Gui; // Force no terminal.
showMessage(QString("Attaching to %1...").arg(attachParameters.attachPID.pid()), LogMisc);
QString errorMessage;
if (!launchCDB(attachParameters, &errorMessage)) {
showMessage(errorMessage, LogError);
Core::AsynchronousMessageBox::critical(tr("Failed to Start the Debugger"), errorMessage);
STATE_DEBUG(state(), Q_FUNC_INFO, __LINE__, "notifyEngineSetupFailed")
notifyEngineSetupFailed();
}
}
void CdbEngine::consoleStubExited()
{
}
void CdbEngine::createFullBacktrace()
{
runCommand({"~*kp", BuiltinCommand, [](const DebuggerResponse &response) {
......@@ -455,18 +388,33 @@ void CdbEngine::setupEngine()
// console, too, but that immediately closes when the debuggee quits.
// Use the Creator stub instead.
const DebuggerRunParameters &rp = runParameters();
const bool launchConsole = isCreatorConsole(rp);
m_effectiveStartMode = launchConsole ? AttachExternal : rp.startMode;
const bool ok = launchConsole ?
startConsole(runParameters(), &errorMessage) :
launchCDB(runParameters(), &errorMessage);
if (debug)
qDebug("<setupEngine ok=%d", ok);
if (!ok) {
showMessage(errorMessage, LogError);
Core::AsynchronousMessageBox::critical(tr("Failed to Start the Debugger"), errorMessage);
STATE_DEBUG(state(), Q_FUNC_INFO, __LINE__, "notifyEngineSetupFailed")
notifyEngineSetupFailed();
if (terminal()) {
m_effectiveStartMode = AttachExternal;
DebuggerRunParameters attachParameters = rp;
attachParameters.inferior.executable.clear();
attachParameters.inferior.commandLineArguments.clear();
attachParameters.attachPID = ProcessHandle(terminal()->applicationPid());
attachParameters.startMode = AttachExternal;
attachParameters.inferior.runMode = ApplicationLauncher::Gui; // Force no terminal.
showMessage(QString("Attaching to %1...").arg(attachParameters.attachPID.pid()), LogMisc);
QString errorMessage;
if (!launchCDB(attachParameters, &errorMessage)) {
showMessage(errorMessage, LogError);
Core::AsynchronousMessageBox::critical(tr("Failed to Start the Debugger"), errorMessage);
STATE_DEBUG(state(), Q_FUNC_INFO, __LINE__, "notifyEngineSetupFailed")
notifyEngineSetupFailed();
}
} else {
m_effectiveStartMode = rp.startMode;
const bool ok = launchCDB(runParameters(), &errorMessage);
if (debug)
qDebug("<setupEngine ok=%d", ok);
if (!ok) {
showMessage(errorMessage, LogError);
Core::AsynchronousMessageBox::critical(tr("Failed to Start the Debugger"), errorMessage);
STATE_DEBUG(state(), Q_FUNC_INFO, __LINE__, "notifyEngineSetupFailed")
notifyEngineSetupFailed();
}
}
}
......@@ -552,7 +500,7 @@ bool CdbEngine::launchCDB(const DebuggerRunParameters &sp, QString *errorMessage
if (sp.startMode == AttachCrashedExternal) {
arguments << "-e" << sp.crashParameter << "-g";
} else {
if (isCreatorConsole(runParameters()))
if (terminal())
arguments << "-pr" << "-pb";
}
break;
......
......@@ -38,7 +38,6 @@
#include <functional>
namespace Utils { class ConsoleProcess; }
namespace Debugger {
namespace Internal {
......@@ -123,10 +122,6 @@ private:
void runCommand(const DebuggerCommand &cmd) override;
void operateByInstructionTriggered(bool);
void consoleStubError(const QString &);
void consoleStubProcessStarted();
void consoleStubExited();
void createFullBacktrace();
void handleDoInterruptInferior(const QString &errorMessage);
......@@ -223,7 +218,6 @@ private:
const QString m_tokenPrefix;
QProcess m_process;
QScopedPointer<Utils::ConsoleProcess> m_consoleStub;
DebuggerStartMode m_effectiveStartMode = NoStartMode;
QByteArray m_outputBuffer;
//! Debugger accessible (expecting commands)
......
......@@ -855,6 +855,15 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, Kit *kit)
m_engine = createPdbEngine();
}
}
if (m_runParameters.cppEngineType == CdbEngineType
&& !boolSetting(UseCdbConsole)
&& m_runParameters.inferior.runMode == ApplicationLauncher::Console
&& (m_runParameters.startMode == StartInternal
|| m_runParameters.startMode == StartExternal)) {
d->terminalRunner = new TerminalRunner(this);
addStartDependency(d->terminalRunner);
}
}
DebuggerEngine *DebuggerRunTool::activeEngine() const
......
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