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:
Christian Stenger
2016-07-19 11:06:32 +02:00
parent 4a829b9279
commit ca3bcd811e
3 changed files with 56 additions and 11 deletions

View File

@@ -550,16 +550,6 @@ void DebuggerEngine::setRegisterValue(const QString &name, const QString &value)
Q_UNUSED(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 void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) const
{ {
if (d->m_masterEngine) { if (d->m_masterEngine) {
@@ -577,7 +567,7 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
case AppError: case AppError:
case AppStuff: case AppStuff:
if (d->m_runControl) if (d->m_runControl)
d->m_runControl->appendMessage(msg, outputFormatForChannelType(channel)); d->m_runControl->handleApplicationOutput(msg, channel);
else else
qWarning("Warning: %s (no active run control)", qPrintable(msg)); qWarning("Warning: %s (no active run control)", qPrintable(msg));
break; break;

View File

@@ -129,6 +129,10 @@ DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfig, DebuggerEngi
DebuggerRunControl::~DebuggerRunControl() DebuggerRunControl::~DebuggerRunControl()
{ {
disconnect(); disconnect();
if (m_outputProcessor) {
delete m_outputProcessor;
m_outputProcessor = 0;
}
if (m_engine) { if (m_engine) {
DebuggerEngine *engine = m_engine; DebuggerEngine *engine = m_engine;
m_engine = 0; m_engine = 0;
@@ -149,6 +153,32 @@ bool DebuggerRunControl::supportsReRunning() const
return m_engine && !(m_engine->runParameters().languages & QmlLanguage); 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() void DebuggerRunControl::start()
{ {
Debugger::Internal::saveModeToRestore(); Debugger::Internal::saveModeToRestore();
@@ -277,6 +307,12 @@ DebuggerStartParameters &DebuggerRunControl::startParameters()
return m_engine->runParameters(); return m_engine->runParameters();
} }
void DebuggerRunControl::setOutputProcessor(OutputProcessor *processor)
{
delete m_outputProcessor;
m_outputProcessor = processor;
}
void DebuggerRunControl::notifyInferiorIll() void DebuggerRunControl::notifyInferiorIll()
{ {
m_engine->notifyInferiorIll(); m_engine->notifyInferiorIll();

View File

@@ -30,6 +30,8 @@
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <functional>
namespace Debugger { namespace Debugger {
class RemoteSetupResult; class RemoteSetupResult;
@@ -43,6 +45,19 @@ DEBUGGER_EXPORT DebuggerRunControl *createDebuggerRunControl(const DebuggerStart
QString *errorMessage, QString *errorMessage,
Core::Id runMode = ProjectExplorer::Constants::DEBUG_RUN_MODE); 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 class DEBUGGER_EXPORT DebuggerRunControl : public ProjectExplorer::RunControl
{ {
Q_OBJECT Q_OBJECT
@@ -57,6 +72,7 @@ public:
bool isRunning() const override; bool isRunning() const override;
QString displayName() const override; QString displayName() const override;
bool supportsReRunning() const override; bool supportsReRunning() const override;
void handleApplicationOutput(const QString &msg, int channel);
void startFailed(); void startFailed();
void notifyEngineRemoteServerRunning(const QByteArray &msg, int pid); void notifyEngineRemoteServerRunning(const QByteArray &msg, int pid);
@@ -71,6 +87,8 @@ public:
DebuggerStartParameters &startParameters(); DebuggerStartParameters &startParameters();
void setOutputProcessor(OutputProcessor *processor);
signals: signals:
void requestRemoteSetup(); void requestRemoteSetup();
void aboutToNotifyInferiorSetupOk(); void aboutToNotifyInferiorSetupOk();
@@ -87,6 +105,7 @@ private:
Internal::DebuggerEngine *m_engine; Internal::DebuggerEngine *m_engine;
bool m_running; bool m_running;
OutputProcessor *m_outputProcessor = 0;
}; };
} // namespace Debugger } // namespace Debugger