forked from qt-creator/qt-creator
Debugger: Provide way to process debuggee output further
Output coming from the debuggee was limited to be printed inside the DebuggerLog and the Application Output pane, but the output might be useful to process differently or even additionally to the default logging. Provide functionality to be able to add an output processor. Change-Id: I715b90b28c64d3cf95bcc2a047a5aba1a56d1058 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -550,16 +550,6 @@ void DebuggerEngine::setRegisterValue(const QString &name, const QString &value)
|
||||
Q_UNUSED(value);
|
||||
}
|
||||
|
||||
static Utils::OutputFormat outputFormatForChannelType(int channel)
|
||||
{
|
||||
switch (channel) {
|
||||
case AppOutput: return Utils::StdOutFormatSameLine;
|
||||
case AppError: return Utils::StdErrFormatSameLine;
|
||||
case AppStuff: return Utils::DebugFormat;
|
||||
default: return Utils::NumberOfFormats;
|
||||
}
|
||||
}
|
||||
|
||||
void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) const
|
||||
{
|
||||
if (d->m_masterEngine) {
|
||||
@@ -577,7 +567,7 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
|
||||
case AppError:
|
||||
case AppStuff:
|
||||
if (d->m_runControl)
|
||||
d->m_runControl->appendMessage(msg, outputFormatForChannelType(channel));
|
||||
d->m_runControl->handleApplicationOutput(msg, channel);
|
||||
else
|
||||
qWarning("Warning: %s (no active run control)", qPrintable(msg));
|
||||
break;
|
||||
|
||||
@@ -129,6 +129,10 @@ DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfig, DebuggerEngi
|
||||
DebuggerRunControl::~DebuggerRunControl()
|
||||
{
|
||||
disconnect();
|
||||
if (m_outputProcessor) {
|
||||
delete m_outputProcessor;
|
||||
m_outputProcessor = 0;
|
||||
}
|
||||
if (m_engine) {
|
||||
DebuggerEngine *engine = m_engine;
|
||||
m_engine = 0;
|
||||
@@ -149,6 +153,32 @@ bool DebuggerRunControl::supportsReRunning() const
|
||||
return m_engine && !(m_engine->runParameters().languages & QmlLanguage);
|
||||
}
|
||||
|
||||
static OutputFormat outputFormatForChannelType(int channel)
|
||||
{
|
||||
switch (channel) {
|
||||
case AppOutput: return StdOutFormatSameLine;
|
||||
case AppError: return StdErrFormatSameLine;
|
||||
case AppStuff: return DebugFormat;
|
||||
default: return NumberOfFormats;
|
||||
}
|
||||
}
|
||||
|
||||
void DebuggerRunControl::handleApplicationOutput(const QString &msg, int channel)
|
||||
{
|
||||
OutputFormat format = outputFormatForChannelType(channel);
|
||||
QTC_ASSERT(format != NumberOfFormats, return);
|
||||
if (m_outputProcessor) {
|
||||
if (m_outputProcessor->logToAppOutputPane)
|
||||
appendMessage(msg, format);
|
||||
if (m_outputProcessor->process) {
|
||||
m_outputProcessor->process(msg, channel == AppError ? OutputProcessor::StandardError
|
||||
: OutputProcessor::StandardOut);
|
||||
}
|
||||
} else {
|
||||
appendMessage(msg, format);
|
||||
}
|
||||
}
|
||||
|
||||
void DebuggerRunControl::start()
|
||||
{
|
||||
Debugger::Internal::saveModeToRestore();
|
||||
@@ -277,6 +307,12 @@ DebuggerStartParameters &DebuggerRunControl::startParameters()
|
||||
return m_engine->runParameters();
|
||||
}
|
||||
|
||||
void DebuggerRunControl::setOutputProcessor(OutputProcessor *processor)
|
||||
{
|
||||
delete m_outputProcessor;
|
||||
m_outputProcessor = processor;
|
||||
}
|
||||
|
||||
void DebuggerRunControl::notifyInferiorIll()
|
||||
{
|
||||
m_engine->notifyInferiorIll();
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Debugger {
|
||||
|
||||
class RemoteSetupResult;
|
||||
@@ -43,6 +45,19 @@ DEBUGGER_EXPORT DebuggerRunControl *createDebuggerRunControl(const DebuggerStart
|
||||
QString *errorMessage,
|
||||
Core::Id runMode = ProjectExplorer::Constants::DEBUG_RUN_MODE);
|
||||
|
||||
|
||||
struct OutputProcessor
|
||||
{
|
||||
enum OutputChannel
|
||||
{
|
||||
StandardOut,
|
||||
StandardError
|
||||
};
|
||||
|
||||
std::function<void(const QString &msg, OutputChannel channel)> process;
|
||||
bool logToAppOutputPane = true;
|
||||
};
|
||||
|
||||
class DEBUGGER_EXPORT DebuggerRunControl : public ProjectExplorer::RunControl
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -57,6 +72,7 @@ public:
|
||||
bool isRunning() const override;
|
||||
QString displayName() const override;
|
||||
bool supportsReRunning() const override;
|
||||
void handleApplicationOutput(const QString &msg, int channel);
|
||||
|
||||
void startFailed();
|
||||
void notifyEngineRemoteServerRunning(const QByteArray &msg, int pid);
|
||||
@@ -71,6 +87,8 @@ public:
|
||||
|
||||
DebuggerStartParameters &startParameters();
|
||||
|
||||
void setOutputProcessor(OutputProcessor *processor);
|
||||
|
||||
signals:
|
||||
void requestRemoteSetup();
|
||||
void aboutToNotifyInferiorSetupOk();
|
||||
@@ -87,6 +105,7 @@ private:
|
||||
|
||||
Internal::DebuggerEngine *m_engine;
|
||||
bool m_running;
|
||||
OutputProcessor *m_outputProcessor = 0;
|
||||
};
|
||||
|
||||
} // namespace Debugger
|
||||
|
||||
Reference in New Issue
Block a user