Debugger: Simplify storages

Collect all debugger storages into one common DebuggerData struct.
This will simplify sub-recipes signatures.

Change-Id: I660a66b11a08dd1006ad8f51902e9dbef88f70fd
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2025-04-17 10:16:18 +02:00
parent 849f53cd61
commit ca482d4826

View File

@@ -126,31 +126,38 @@ private:
} // namespace Internal } // namespace Internal
ExecutableItem coreFileRecipe(RunControl *runControl, struct DebuggerData
const Storage<DebuggerRunParameters> &parametersStorage,
const Storage<FilePath> &tempCoreFileStorage)
{ {
const Storage<QFile> storage; // tempCoreFile DebuggerRunParameters runParameters;
RunControl *runControl = nullptr;
EnginesDriver enginesDriver = {};
FilePath tempCoreFile = {};
std::unique_ptr<Process> terminalProcess = {};
};
const auto onSetup = [runControl, parametersStorage, storage, tempCoreFileStorage](Process &process) { ExecutableItem coreFileRecipe(const Storage<DebuggerData> &storage)
const FilePath coreFile = parametersStorage->coreFile(); {
const Storage<QFile> fileStorage; // tempCoreFile
const auto onSetup = [storage, fileStorage](Process &process) {
const FilePath coreFile = storage->runParameters.coreFile();
if (!coreFile.endsWith(".gz") && !coreFile.endsWith(".lzo")) if (!coreFile.endsWith(".gz") && !coreFile.endsWith(".lzo"))
return SetupResult::StopWithSuccess; return SetupResult::StopWithSuccess;
{ {
TemporaryFile tmp("tmpcore-XXXXXX"); TemporaryFile tmp("tmpcore-XXXXXX");
QTC_CHECK(tmp.open()); QTC_CHECK(tmp.open());
*tempCoreFileStorage = FilePath::fromString(tmp.fileName()); storage->tempCoreFile = FilePath::fromString(tmp.fileName());
} }
QFile *tempCoreFile = storage.activeStorage(); QFile *tempCoreFile = fileStorage.activeStorage();
process.setWorkingDirectory(TemporaryDirectory::masterDirectoryFilePath()); process.setWorkingDirectory(TemporaryDirectory::masterDirectoryFilePath());
const QString msg = Tr::tr("Unpacking core file to %1"); const QString msg = Tr::tr("Unpacking core file to %1");
runControl->postMessage(msg.arg(tempCoreFileStorage->toUserOutput()), LogMessageFormat); storage->runControl->postMessage(msg.arg(storage->tempCoreFile.toUserOutput()), LogMessageFormat);
if (coreFile.endsWith(".lzo")) { if (coreFile.endsWith(".lzo")) {
process.setCommand({"lzop", {"-o", tempCoreFileStorage->path(), "-x", coreFile.path()}}); process.setCommand({"lzop", {"-o", storage->tempCoreFile.path(), "-x", coreFile.path()}});
} else { // ".gz" } else { // ".gz"
tempCoreFile->setFileName(tempCoreFileStorage->path()); tempCoreFile->setFileName(storage->tempCoreFile.path());
QTC_CHECK(tempCoreFile->open(QFile::WriteOnly)); QTC_CHECK(tempCoreFile->open(QFile::WriteOnly));
QObject::connect(&process, &Process::readyReadStandardOutput, &process, QObject::connect(&process, &Process::readyReadStandardOutput, &process,
[tempCoreFile, processPtr = &process] { [tempCoreFile, processPtr = &process] {
@@ -161,29 +168,27 @@ ExecutableItem coreFileRecipe(RunControl *runControl,
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onDone = [runControl, parametersStorage, storage, tempCoreFileStorage](DoneWith result) { const auto onDone = [storage, fileStorage](DoneWith result) {
if (result == DoneWith::Success) if (result == DoneWith::Success) {
parametersStorage->setCoreFilePath(*tempCoreFileStorage); storage->runParameters.setCoreFilePath(storage->tempCoreFile);
else } else {
runControl->postMessage("Error unpacking " + parametersStorage->coreFile().toUserOutput(), storage->runControl->postMessage("Error unpacking "
ErrorMessageFormat); + storage->runParameters.coreFile().toUserOutput(), ErrorMessageFormat);
if (storage->isOpen()) }
storage->close(); if (fileStorage->isOpen())
fileStorage->close();
}; };
return Group { return Group {
storage, fileStorage,
ProcessTask(onSetup, onDone) ProcessTask(onSetup, onDone)
}; };
} }
ExecutableItem terminalRecipe(const Storage<DebuggerRunParameters> &parametersStorage, ExecutableItem terminalRecipe(const Storage<DebuggerData> &storage, const SingleBarrier &barrier)
const Storage<EnginesDriver> &driverStorage,
const Storage<std::unique_ptr<Process>> &terminalStorage,
const SingleBarrier &barrier)
{ {
const auto onSetup = [barrier, parametersStorage, driverStorage, terminalStorage] { const auto onSetup = [storage, barrier] {
DebuggerRunParameters &runParameters = *parametersStorage; DebuggerRunParameters &runParameters = storage->runParameters;
const bool useCdbConsole = runParameters.cppEngineType() == CdbEngineType const bool useCdbConsole = runParameters.cppEngineType() == CdbEngineType
&& (runParameters.startMode() == StartInternal && (runParameters.startMode() == StartInternal
|| runParameters.startMode() == StartExternal) || runParameters.startMode() == StartExternal)
@@ -196,7 +201,7 @@ ExecutableItem terminalRecipe(const Storage<DebuggerRunParameters> &parametersSt
} }
Process *process = new Process; Process *process = new Process;
terminalStorage->reset(process); storage->terminalProcess.reset(process);
ProcessRunData stub = runParameters.inferior(); ProcessRunData stub = runParameters.inferior();
if (runParameters.runAsRoot()) { if (runParameters.runAsRoot()) {
process->setRunAsRoot(true); process->setRunAsRoot(true);
@@ -212,7 +217,7 @@ ExecutableItem terminalRecipe(const Storage<DebuggerRunParameters> &parametersSt
barrier->advance(); barrier->advance();
}); });
EnginesDriver *driver = driverStorage.activeStorage(); EnginesDriver *driver = &storage->enginesDriver;
QObject::connect(driver, &EnginesDriver::interruptTerminalRequested, QObject::connect(driver, &EnginesDriver::interruptTerminalRequested,
process, &Process::interrupt); process, &Process::interrupt);
QObject::connect(driver, &EnginesDriver::kickoffTerminalProcessRequested, QObject::connect(driver, &EnginesDriver::kickoffTerminalProcessRequested,
@@ -223,11 +228,11 @@ ExecutableItem terminalRecipe(const Storage<DebuggerRunParameters> &parametersSt
return Sync(onSetup); return Sync(onSetup);
} }
ExecutableItem fixupParamsRecipe(RunControl *runControl, ExecutableItem fixupParamsRecipe(const Storage<DebuggerData> &storage)
const Storage<DebuggerRunParameters> &parametersStorage)
{ {
return Sync([runControl, parametersStorage] { return Sync([storage] {
DebuggerRunParameters &runParameters = *parametersStorage; RunControl *runControl = storage->runControl;
DebuggerRunParameters &runParameters = storage->runParameters;
TaskHub::clearTasks(Constants::TASK_CATEGORY_DEBUGGER_RUNTIME); TaskHub::clearTasks(Constants::TASK_CATEGORY_DEBUGGER_RUNTIME);
if (runControl->usesDebugChannel()) if (runControl->usesDebugChannel())
@@ -312,17 +317,16 @@ ExecutableItem fixupParamsRecipe(RunControl *runControl,
}); });
} }
ExecutableItem debugServerRecipe(RunControl *runControl, ExecutableItem debugServerRecipe(const Storage<DebuggerData> &storage, const SingleBarrier &barrier)
const Storage<DebuggerRunParameters> &parametersStorage,
const SingleBarrier &barrier)
{ {
const auto useDebugServer = [runControl, parametersStorage] { const auto useDebugServer = [storage] {
return runControl->usesDebugChannel() && !parametersStorage->skipDebugServer(); return storage->runControl->usesDebugChannel() && !storage->runParameters.skipDebugServer();
}; };
const auto onSetup = [runControl, parametersStorage, barrier](Process &process) { const auto onSetup = [storage, barrier](Process &process) {
process.setUtf8Codec(); process.setUtf8Codec();
DebuggerRunParameters &runParameters = *parametersStorage; DebuggerRunParameters &runParameters = storage->runParameters;
RunControl *runControl = storage->runControl;
CommandLine commandLine = runParameters.inferior().command; CommandLine commandLine = runParameters.inferior().command;
CommandLine cmd; CommandLine cmd;
@@ -432,8 +436,8 @@ ExecutableItem debugServerRecipe(RunControl *runControl,
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onDone = [runControl](const Process &process) { const auto onDone = [storage](const Process &process) {
runControl->postMessage(process.errorString(), ErrorMessageFormat); storage->runControl->postMessage(process.errorString(), ErrorMessageFormat);
}; };
return Group { return Group {
@@ -445,21 +449,20 @@ ExecutableItem debugServerRecipe(RunControl *runControl,
}; };
} }
static ExecutableItem doneAwaiter(const Storage<EnginesDriver> &driverStorage) static ExecutableItem doneAwaiter(const Storage<DebuggerData> &storage)
{ {
return BarrierTask([driverStorage](Barrier &barrier) { return BarrierTask([storage](Barrier &barrier) {
QObject::connect(driverStorage.activeStorage(), &EnginesDriver::done, &barrier, &Barrier::stopWithResult, QObject::connect(&storage->enginesDriver, &EnginesDriver::done, &barrier, &Barrier::stopWithResult,
static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::SingleShotConnection)); static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::SingleShotConnection));
}); });
} }
ExecutableItem startEnginesRecipe(RunControl *runControl, ExecutableItem startEnginesRecipe(const Storage<DebuggerData> &storage)
const Storage<DebuggerRunParameters> &parametersStorage,
const Storage<EnginesDriver> &driverStorage)
{ {
const auto setupEngines = [runControl, parametersStorage, driverStorage] { const auto setupEngines = [storage] {
DebuggerRunParameters &runParameters = *parametersStorage; RunControl *runControl = storage->runControl;
EnginesDriver *driver = driverStorage.activeStorage(); DebuggerRunParameters &runParameters = storage->runParameters;
EnginesDriver *driver = &storage->enginesDriver;
if (Result<> res = driver->setupEngines(runControl, runParameters); !res) { if (Result<> res = driver->setupEngines(runControl, runParameters); !res) {
runControl->postMessage(res.error(), ErrorMessageFormat); runControl->postMessage(res.error(), ErrorMessageFormat);
return false; return false;
@@ -491,34 +494,33 @@ ExecutableItem startEnginesRecipe(RunControl *runControl,
}; };
return If (setupEngines) >> Then { return If (setupEngines) >> Then {
doneAwaiter(driverStorage) doneAwaiter(storage)
}; };
} }
static ExecutableItem terminalAwaiter(const Storage<std::unique_ptr<Process>> &terminalStorage) static ExecutableItem terminalAwaiter(const Storage<DebuggerData> &storage)
{ {
return BarrierTask([terminalStorage](Barrier &barrier) { return BarrierTask([storage](Barrier &barrier) {
QObject::connect(terminalStorage->get(), &Process::done, &barrier, &Barrier::advance, QObject::connect(storage->terminalProcess.get(), &Process::done, &barrier, &Barrier::advance,
static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::SingleShotConnection)); static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::SingleShotConnection));
}); });
} }
ExecutableItem finalizeRecipe(const Storage<EnginesDriver> &driverStorage, ExecutableItem finalizeRecipe(const Storage<DebuggerData> &storage)
const Storage<std::unique_ptr<Process>> &terminalStorage)
{ {
const auto isRunning = [driverStorage] { return driverStorage->isRunning(); }; const auto isRunning = [storage] { return storage->enginesDriver.isRunning(); };
const auto isTerminalRunning = [terminalStorage] { const auto isTerminalRunning = [storage] {
return terminalStorage->get() && terminalStorage->get()->isRunning(); return storage->terminalProcess && storage->terminalProcess->isRunning();
}; };
return Group { return Group {
continueOnError, continueOnError,
If (isRunning) >> Then { If (isRunning) >> Then {
Sync([driverStorage] { driverStorage->stop(); }), Sync([storage] { storage->enginesDriver.stop(); }),
doneAwaiter(driverStorage) doneAwaiter(storage)
}, },
If (isTerminalRunning) >> Then { If (isTerminalRunning) >> Then {
terminalAwaiter(terminalStorage) terminalAwaiter(storage)
} }
}; };
} }
@@ -719,49 +721,43 @@ void EnginesDriver::showMessage(const QString &msg, int channel, int timeout)
Group debuggerRecipe(RunControl *runControl, const DebuggerRunParameters &initialParameters, Group debuggerRecipe(RunControl *runControl, const DebuggerRunParameters &initialParameters,
const std::function<void(DebuggerRunParameters &)> &parametersModifier) const std::function<void(DebuggerRunParameters &)> &parametersModifier)
{ {
const Storage<DebuggerRunParameters> parametersStorage{initialParameters}; const Storage<DebuggerData> storage{initialParameters, runControl};
const Storage<EnginesDriver> driverStorage;
const Storage<FilePath> tempCoreFileStorage;
const Storage<std::unique_ptr<Process>> terminalStorage;
const auto onSetup = [runControl, parametersStorage, parametersModifier] { const auto onSetup = [storage, parametersModifier] {
parametersStorage->setAttachPid(runControl->attachPid()); storage->runParameters.setAttachPid(storage->runControl->attachPid());
if (parametersModifier) if (parametersModifier)
parametersModifier(*parametersStorage); parametersModifier(storage->runParameters);
}; };
const auto terminalKicker = [parametersStorage, driverStorage, terminalStorage](const SingleBarrier &barrier) { const auto terminalKicker = [storage](const SingleBarrier &barrier) {
return terminalRecipe(parametersStorage, driverStorage, terminalStorage, barrier); return terminalRecipe(storage, barrier);
}; };
const auto debugServerKicker = [runControl, parametersStorage](const SingleBarrier &barrier) { const auto debugServerKicker = [storage](const SingleBarrier &barrier) {
return debugServerRecipe(runControl, parametersStorage, barrier); return debugServerRecipe(storage, barrier);
}; };
const auto onDone = [parametersStorage, tempCoreFileStorage] { const auto onDone = [storage] {
if (tempCoreFileStorage->exists()) if (storage->tempCoreFile.exists())
tempCoreFileStorage->removeFile(); storage->tempCoreFile.removeFile();
if (parametersStorage->isSnapshot() && !parametersStorage->coreFile().isEmpty()) if (storage->runParameters.isSnapshot() && !storage->runParameters.coreFile().isEmpty())
parametersStorage->coreFile().removeFile(); storage->runParameters.coreFile().removeFile();
}; };
return { return {
parametersStorage, storage,
driverStorage,
terminalStorage,
tempCoreFileStorage,
continueOnError, continueOnError,
onGroupSetup(onSetup), onGroupSetup(onSetup),
Group { Group {
coreFileRecipe(runControl, parametersStorage, tempCoreFileStorage), coreFileRecipe(storage),
When (terminalKicker) >> Do { When (terminalKicker) >> Do {
fixupParamsRecipe(runControl, parametersStorage), fixupParamsRecipe(storage),
When (debugServerKicker) >> Do { When (debugServerKicker) >> Do {
startEnginesRecipe(runControl, parametersStorage, driverStorage) startEnginesRecipe(storage)
} }
} }
}.withCancel(canceler()), }.withCancel(canceler()),
finalizeRecipe(driverStorage, terminalStorage), finalizeRecipe(storage),
onGroupDone(onDone) onGroupDone(onDone)
}; };
} }