2010-11-18 13:55:52 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "outputcallback.h"
|
|
|
|
|
#include "stringutils.h"
|
|
|
|
|
#include "extensioncontext.h"
|
|
|
|
|
#include "base64.h"
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
2011-02-04 15:08:31 +01:00
|
|
|
/* \class OutputCallback
|
|
|
|
|
|
|
|
|
|
OutputCallback catches DEBUG_OUTPUT_DEBUGGEE and reports it
|
|
|
|
|
base64-encoded back to Qt Creator.
|
|
|
|
|
\ingroup qtcreatorcdbext
|
|
|
|
|
*/
|
|
|
|
|
|
2011-01-18 11:40:45 +01:00
|
|
|
OutputCallback::OutputCallback(IDebugOutputCallbacksWide *wrapped) :
|
|
|
|
|
m_wrapped(wrapped), m_recording(false)
|
2010-11-18 13:55:52 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputCallback::~OutputCallback() // must be present to avoid exit crashes
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STDMETHODIMP OutputCallback::QueryInterface(
|
|
|
|
|
THIS_
|
|
|
|
|
IN REFIID InterfaceId,
|
|
|
|
|
OUT PVOID* Interface
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
*Interface = NULL;
|
|
|
|
|
|
|
|
|
|
if (IsEqualIID(InterfaceId, __uuidof(IUnknown)) ||
|
|
|
|
|
IsEqualIID(InterfaceId, __uuidof(IDebugOutputCallbacksWide)))
|
|
|
|
|
{
|
|
|
|
|
*Interface = (IDebugOutputCallbacksWide*)this;
|
|
|
|
|
AddRef();
|
|
|
|
|
return S_OK;
|
|
|
|
|
} else {
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) OutputCallback::AddRef(THIS)
|
|
|
|
|
{
|
|
|
|
|
// This class is designed to be static so
|
|
|
|
|
// there's no true refcount.
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) OutputCallback::Release(THIS)
|
|
|
|
|
{
|
|
|
|
|
// This class is designed to be static so
|
|
|
|
|
// there's no true refcount.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STDMETHODIMP OutputCallback::Output(
|
|
|
|
|
THIS_
|
|
|
|
|
IN ULONG mask,
|
|
|
|
|
IN PCWSTR text
|
|
|
|
|
)
|
|
|
|
|
{
|
2011-01-18 11:40:45 +01:00
|
|
|
|
|
|
|
|
if (m_recording)
|
|
|
|
|
m_recorded.append(text);
|
2010-11-18 13:55:52 +01:00
|
|
|
// Do not unconditionally output ourselves here, as this causes an endless
|
|
|
|
|
// recursion. Suppress prompts (note that sequences of prompts may mess parsing up)
|
|
|
|
|
if (!m_wrapped || mask == DEBUG_OUTPUT_PROMPT)
|
|
|
|
|
return S_OK;
|
|
|
|
|
// Wrap debuggee output in gdbmi such that creator recognizes it
|
|
|
|
|
if (mask != DEBUG_OUTPUT_DEBUGGEE) {
|
|
|
|
|
m_wrapped->Output(mask, text);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
// Base encode as GDBMI is not really made for wide chars
|
|
|
|
|
std::ostringstream str;
|
|
|
|
|
base64Encode(str, reinterpret_cast<const unsigned char *>(text), sizeof(wchar_t) * std::wcslen(text));
|
2011-01-11 14:58:32 +01:00
|
|
|
ExtensionContext::instance().reportLong('E', 0, "debuggee_output", str.str().c_str());
|
2010-11-18 13:55:52 +01:00
|
|
|
return S_OK;
|
|
|
|
|
}
|
2011-01-18 11:40:45 +01:00
|
|
|
|
|
|
|
|
void OutputCallback::startRecording()
|
|
|
|
|
{
|
|
|
|
|
m_recorded.clear();
|
|
|
|
|
m_recording = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::wstring OutputCallback::stopRecording()
|
|
|
|
|
{
|
|
|
|
|
const std::wstring rc = m_recorded;
|
|
|
|
|
m_recorded.clear();
|
|
|
|
|
m_recording = false;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|