2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-11-18 13:55:52 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-18 13:55:52 +01:00
|
|
|
|
|
|
|
|
#include "extensioncontext.h"
|
|
|
|
|
#include "symbolgroup.h"
|
2014-02-24 10:17:41 +01:00
|
|
|
#include "symbolgroupvalue.h"
|
2010-11-18 13:55:52 +01:00
|
|
|
#include "eventcallback.h"
|
|
|
|
|
#include "outputcallback.h"
|
|
|
|
|
#include "stringutils.h"
|
2011-01-25 18:35:31 +01:00
|
|
|
#include "gdbmihelpers.h"
|
2010-11-18 13:55:52 +01:00
|
|
|
|
2011-01-04 12:40:52 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2010-11-18 13:55:52 +01:00
|
|
|
// wdbgexts.h declares 'extern WINDBG_EXTENSION_APIS ExtensionApis;'
|
|
|
|
|
// and it's inline functions rely on its existence.
|
|
|
|
|
WINDBG_EXTENSION_APIS ExtensionApis = {sizeof(WINDBG_EXTENSION_APIS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
|
|
|
|
|
const char *ExtensionContext::stopReasonKeyC = "reason";
|
2011-02-02 13:45:40 +01:00
|
|
|
const char *ExtensionContext::breakPointStopReasonC = "breakpoint";
|
2010-11-18 13:55:52 +01:00
|
|
|
|
2013-01-31 14:24:39 +01:00
|
|
|
/*! \class Parameters
|
|
|
|
|
|
|
|
|
|
Externally configureable parameters.
|
|
|
|
|
\ingroup qtcreatorcdbext
|
|
|
|
|
*/
|
|
|
|
|
|
2014-03-11 08:26:54 +01:00
|
|
|
Parameters::Parameters() : maxStringLength(10000), maxArraySize(100) ,maxStackDepth(1000)
|
2013-01-31 14:24:39 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 10:01:01 +01:00
|
|
|
/*! \class StateNotificationBlocker
|
|
|
|
|
|
|
|
|
|
Blocks state (stopped) notification of ExtensionContext while instantiated
|
|
|
|
|
|
|
|
|
|
\ingroup qtcreatorcdbext
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class StateNotificationBlocker {
|
|
|
|
|
StateNotificationBlocker(const StateNotificationBlocker &);
|
|
|
|
|
StateNotificationBlocker &operator=(const StateNotificationBlocker &);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
StateNotificationBlocker(ExtensionContext *ec)
|
|
|
|
|
: m_oldValue(ec->stateNotification())
|
|
|
|
|
, m_extensionContext(ec)
|
|
|
|
|
{ m_extensionContext->setStateNotification(false); }
|
|
|
|
|
~StateNotificationBlocker() { m_extensionContext->setStateNotification(m_oldValue); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const bool m_oldValue;
|
|
|
|
|
ExtensionContext *m_extensionContext;
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-04 15:08:31 +01:00
|
|
|
/*! \class ExtensionContext
|
|
|
|
|
|
|
|
|
|
Global singleton with context.
|
|
|
|
|
Caches a symbolgroup per frame and thread as long as the session is accessible.
|
|
|
|
|
\ingroup qtcreatorcdbext
|
|
|
|
|
*/
|
|
|
|
|
|
2010-11-18 13:55:52 +01:00
|
|
|
ExtensionContext::ExtensionContext() :
|
|
|
|
|
m_hookedClient(0),
|
|
|
|
|
m_oldEventCallback(0), m_oldOutputCallback(0),
|
2011-01-18 11:40:45 +01:00
|
|
|
m_creatorEventCallback(0), m_creatorOutputCallback(0), m_stateNotification(true)
|
2010-11-18 13:55:52 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionContext::~ExtensionContext()
|
|
|
|
|
{
|
|
|
|
|
unhookCallbacks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionContext &ExtensionContext::instance()
|
|
|
|
|
{
|
|
|
|
|
static ExtensionContext extContext;
|
|
|
|
|
return extContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Redirect the event/output callbacks
|
|
|
|
|
void ExtensionContext::hookCallbacks(CIDebugClient *client)
|
|
|
|
|
{
|
|
|
|
|
if (!client || m_hookedClient || m_creatorEventCallback)
|
|
|
|
|
return;
|
|
|
|
|
// Store the hooked client. Any other client obtained
|
|
|
|
|
// is invalid for unhooking
|
|
|
|
|
m_hookedClient = client;
|
|
|
|
|
if (client->GetEventCallbacks(&m_oldEventCallback) == S_OK) {
|
|
|
|
|
m_creatorEventCallback = new EventCallback(m_oldEventCallback);
|
|
|
|
|
client->SetEventCallbacks(m_creatorEventCallback);
|
|
|
|
|
}
|
|
|
|
|
if (client->GetOutputCallbacksWide(&m_oldOutputCallback) == S_OK) {
|
|
|
|
|
m_creatorOutputCallback = new OutputCallback(m_oldOutputCallback);
|
|
|
|
|
client->SetOutputCallbacksWide(m_creatorOutputCallback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 11:40:45 +01:00
|
|
|
void ExtensionContext::startRecordingOutput()
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_creatorOutputCallback)
|
2011-01-18 11:40:45 +01:00
|
|
|
m_creatorOutputCallback->startRecording();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-01-18 11:40:45 +01:00
|
|
|
report('X', 0, 0, "Error", "ExtensionContext::startRecordingOutput() called with no output hooked.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::wstring ExtensionContext::stopRecordingOutput()
|
|
|
|
|
{
|
|
|
|
|
return m_creatorOutputCallback ? m_creatorOutputCallback->stopRecording() : std::wstring();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 13:55:52 +01:00
|
|
|
void ExtensionContext::setStopReason(const StopReasonMap &r, const std::string &reason)
|
|
|
|
|
{
|
|
|
|
|
m_stopReason = r;
|
|
|
|
|
if (!reason.empty())
|
|
|
|
|
m_stopReason.insert(StopReasonMap::value_type(stopReasonKeyC, reason));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Restore the callbacks.
|
|
|
|
|
void ExtensionContext::unhookCallbacks()
|
|
|
|
|
{
|
|
|
|
|
if (!m_hookedClient || (!m_creatorEventCallback && !m_creatorOutputCallback))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_creatorEventCallback) {
|
|
|
|
|
m_hookedClient->SetEventCallbacks(m_oldEventCallback);
|
|
|
|
|
delete m_creatorEventCallback;
|
|
|
|
|
m_creatorEventCallback = 0;
|
|
|
|
|
m_oldEventCallback = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_creatorOutputCallback) {
|
|
|
|
|
m_hookedClient->SetOutputCallbacksWide(m_oldOutputCallback);
|
|
|
|
|
delete m_creatorOutputCallback;
|
|
|
|
|
m_creatorOutputCallback = 0;
|
|
|
|
|
m_oldOutputCallback = 0;
|
|
|
|
|
}
|
|
|
|
|
m_hookedClient = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HRESULT ExtensionContext::initialize(PULONG Version, PULONG Flags)
|
|
|
|
|
{
|
|
|
|
|
if (isInitialized())
|
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
|
|
*Version = DEBUG_EXTENSION_VERSION(1, 0);
|
|
|
|
|
*Flags = 0;
|
|
|
|
|
|
|
|
|
|
IInterfacePointer<CIDebugClient> client;
|
|
|
|
|
if (!client.create())
|
|
|
|
|
return client.hr();
|
|
|
|
|
m_control.create(client.data());
|
|
|
|
|
if (!m_control)
|
|
|
|
|
return m_control.hr();
|
|
|
|
|
return m_control->GetWindbgExtensionApis64(&ExtensionApis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExtensionContext::isInitialized() const
|
|
|
|
|
{
|
|
|
|
|
return ExtensionApis.lpOutputRoutine != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ULONG ExtensionContext::executionStatus() const
|
|
|
|
|
{
|
|
|
|
|
ULONG ex = 0;
|
|
|
|
|
return (m_control && SUCCEEDED(m_control->GetExecutionStatus(&ex))) ? ex : ULONG(0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 10:17:41 +01:00
|
|
|
// Helpers for finding the address of the JS execution context in
|
|
|
|
|
// case of a QML crash: Find module
|
|
|
|
|
static std::string findModule(CIDebugSymbols *syms,
|
|
|
|
|
const std::string &name,
|
|
|
|
|
std::string *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
const Modules mods = getModules(syms, errorMessage);
|
|
|
|
|
const size_t count = mods.size();
|
|
|
|
|
for (size_t m = 0; m < count; ++m)
|
|
|
|
|
if (!mods.at(m).name.compare(0, name.size(), name))
|
|
|
|
|
return mods.at(m).name;
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to find a JS execution context passed as parameter in a complete stack dump (kp)
|
|
|
|
|
static ULONG64 jsExecutionContextFromStackTrace(const std::wstring &stack)
|
|
|
|
|
{
|
|
|
|
|
// Search for "QV4::ExecutionContext * - varying variable names - 0x...[,)]"
|
|
|
|
|
const wchar_t needle[] = L"struct QV4::ExecutionContext * "; // .. varying variable names .. 0x...
|
|
|
|
|
const std::string::size_type varPos = stack.find(needle);
|
|
|
|
|
if (varPos == std::string::npos)
|
|
|
|
|
return 0;
|
|
|
|
|
const std::string::size_type varEnd = varPos + sizeof(needle) / sizeof(wchar_t) - 1;
|
|
|
|
|
std::string::size_type numPos = stack.find(L"0x", varEnd);
|
|
|
|
|
if (numPos == std::string::npos || numPos > (varEnd + 20))
|
|
|
|
|
return 0;
|
|
|
|
|
numPos += 2;
|
|
|
|
|
const std::string::size_type endPos = stack.find_first_of(L",)", numPos);
|
|
|
|
|
if (endPos == std::string::npos)
|
|
|
|
|
return 0;
|
|
|
|
|
// Fix hex values: (0x)000000f5`cecae5b0 -> (0x)000000f5cecae5b0
|
|
|
|
|
std::wstring address = stack.substr(numPos, endPos - numPos);
|
|
|
|
|
if (address.size() > 8 && address.at(8) == L'`')
|
|
|
|
|
address.erase(8, 1);
|
|
|
|
|
std::wistringstream str(address);
|
|
|
|
|
ULONG64 result;
|
|
|
|
|
str >> std::hex >> result;
|
|
|
|
|
return str.fail() ? 0 : result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to find address of jsExecutionContext by looking at the
|
|
|
|
|
// stack trace in case QML is loaded.
|
|
|
|
|
ULONG64 ExtensionContext::jsExecutionContext(ExtensionCommandContext &exc,
|
|
|
|
|
std::string *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
const QtInfo &qtInfo = QtInfo::get(SymbolGroupValueContext(exc.dataSpaces(), exc.symbols()));
|
|
|
|
|
static const std::string qmlModule =
|
|
|
|
|
findModule(exc.symbols(), qtInfo.moduleName(QtInfo::Qml), errorMessage);
|
|
|
|
|
if (qmlModule.empty()) {
|
|
|
|
|
if (errorMessage->empty())
|
|
|
|
|
*errorMessage = "QML not loaded";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// Retrieve full stack (costly) and try to find a JS execution context passed as parameter
|
|
|
|
|
startRecordingOutput();
|
|
|
|
|
StateNotificationBlocker blocker(this);
|
|
|
|
|
const HRESULT hr = m_control->Execute(DEBUG_OUTCTL_ALL_CLIENTS, "kp", DEBUG_EXECUTE_ECHO);
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
|
stopRecordingOutput();
|
|
|
|
|
*errorMessage = msgDebugEngineComFailed("Execute", hr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
const std::wstring fullStackTrace = stopRecordingOutput();
|
|
|
|
|
if (fullStackTrace.empty()) {
|
|
|
|
|
*errorMessage = "Unable to obtain stack (output redirection in place?)";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
const ULONG64 result = jsExecutionContextFromStackTrace(fullStackTrace);
|
|
|
|
|
if (!result)
|
|
|
|
|
*errorMessage = "JS ExecutionContext address not found in stack";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 13:55:52 +01:00
|
|
|
// Complete stop parameters with common parameters and report
|
|
|
|
|
static inline ExtensionContext::StopReasonMap
|
2011-01-25 18:35:31 +01:00
|
|
|
completeStopReasons(CIDebugClient *client, ExtensionContext::StopReasonMap stopReasons, ULONG ex)
|
2010-11-18 13:55:52 +01:00
|
|
|
{
|
|
|
|
|
typedef ExtensionContext::StopReasonMap::value_type StopReasonMapValue;
|
|
|
|
|
|
|
|
|
|
stopReasons.insert(StopReasonMapValue(std::string("executionStatus"), toString(ex)));
|
|
|
|
|
|
2011-01-25 18:35:31 +01:00
|
|
|
if (const ULONG processId = currentProcessId(client))
|
|
|
|
|
stopReasons.insert(StopReasonMapValue(std::string("processId"), toString(processId)));
|
|
|
|
|
const ULONG threadId = currentThreadId(client);
|
|
|
|
|
stopReasons.insert(StopReasonMapValue(std::string("threadId"), toString(threadId)));
|
2010-11-18 13:55:52 +01:00
|
|
|
// Any reason?
|
|
|
|
|
const std::string reasonKey = std::string(ExtensionContext::stopReasonKeyC);
|
|
|
|
|
if (stopReasons.find(reasonKey) == stopReasons.end())
|
|
|
|
|
stopReasons.insert(StopReasonMapValue(reasonKey, "unknown"));
|
|
|
|
|
return stopReasons;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-25 18:35:31 +01:00
|
|
|
void ExtensionContext::notifyIdleCommand(CIDebugClient *client)
|
2010-11-18 13:55:52 +01:00
|
|
|
{
|
|
|
|
|
discardSymbolGroup();
|
2011-01-18 11:40:45 +01:00
|
|
|
if (m_stateNotification) {
|
2011-01-25 18:35:31 +01:00
|
|
|
// Format full thread and stack info along with completed stop reasons.
|
|
|
|
|
std::string errorMessage;
|
|
|
|
|
ExtensionCommandContext exc(client);
|
|
|
|
|
const StopReasonMap stopReasons = completeStopReasons(client, m_stopReason, executionStatus());
|
2011-01-18 11:40:45 +01:00
|
|
|
// Format
|
|
|
|
|
std::ostringstream str;
|
2011-01-25 18:35:31 +01:00
|
|
|
formatGdbmiHash(str, stopReasons, false);
|
|
|
|
|
const std::string threadInfo = gdbmiThreadList(exc.systemObjects(), exc.symbols(),
|
|
|
|
|
exc.control(), exc.advanced(), &errorMessage);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (threadInfo.empty())
|
2011-01-25 18:35:31 +01:00
|
|
|
str << ",threaderror=" << gdbmiStringFormat(errorMessage);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-01-25 18:35:31 +01:00
|
|
|
str << ",threads=" << threadInfo;
|
|
|
|
|
const std::string stackInfo = gdbmiStack(exc.control(), exc.symbols(),
|
2013-01-31 14:34:16 +01:00
|
|
|
ExtensionContext::instance().parameters().maxStackDepth,
|
|
|
|
|
false, &errorMessage);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (stackInfo.empty())
|
2011-01-25 18:35:31 +01:00
|
|
|
str << ",stackerror=" << gdbmiStringFormat(errorMessage);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-01-25 18:35:31 +01:00
|
|
|
str << ",stack=" << stackInfo;
|
|
|
|
|
str << '}';
|
2011-01-18 11:40:45 +01:00
|
|
|
reportLong('E', 0, "session_idle", str.str());
|
|
|
|
|
}
|
2010-11-18 13:55:52 +01:00
|
|
|
m_stopReason.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtensionContext::notifyState(ULONG Notify)
|
|
|
|
|
{
|
|
|
|
|
const ULONG ex = executionStatus();
|
2011-01-18 11:40:45 +01:00
|
|
|
if (m_stateNotification) {
|
|
|
|
|
switch (Notify) {
|
|
|
|
|
case DEBUG_NOTIFY_SESSION_ACTIVE:
|
|
|
|
|
report('E', 0, 0, "session_active", "%u", ex);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_NOTIFY_SESSION_ACCESSIBLE: // Meaning, commands accepted
|
|
|
|
|
report('E', 0, 0, "session_accessible", "%u", ex);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_NOTIFY_SESSION_INACCESSIBLE:
|
|
|
|
|
report('E', 0, 0, "session_inaccessible", "%u", ex);
|
|
|
|
|
break;
|
|
|
|
|
case DEBUG_NOTIFY_SESSION_INACTIVE:
|
|
|
|
|
report('E', 0, 0, "session_inactive", "%u", ex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE) {
|
2010-11-18 13:55:52 +01:00
|
|
|
discardSymbolGroup();
|
2011-01-14 16:50:31 +01:00
|
|
|
discardWatchesSymbolGroup();
|
2010-11-18 13:55:52 +01:00
|
|
|
// We lost the debuggee, at this point restore output.
|
|
|
|
|
if (ex & DEBUG_STATUS_NO_DEBUGGEE)
|
|
|
|
|
unhookCallbacks();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 16:50:31 +01:00
|
|
|
LocalsSymbolGroup *ExtensionContext::symbolGroup(CIDebugSymbols *symbols, ULONG threadId, int frame, std::string *errorMessage)
|
2010-11-18 13:55:52 +01:00
|
|
|
{
|
|
|
|
|
if (m_symbolGroup.get() && m_symbolGroup->frame() == frame && m_symbolGroup->threadId() == threadId)
|
|
|
|
|
return m_symbolGroup.get();
|
2011-01-14 16:50:31 +01:00
|
|
|
LocalsSymbolGroup *newSg = LocalsSymbolGroup::create(m_control.data(), symbols, threadId, frame, errorMessage);
|
2010-11-18 13:55:52 +01:00
|
|
|
if (!newSg)
|
|
|
|
|
return 0;
|
|
|
|
|
m_symbolGroup.reset(newSg);
|
|
|
|
|
return newSg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ExtensionContext::symbolGroupFrame() const
|
|
|
|
|
{
|
|
|
|
|
if (m_symbolGroup.get())
|
|
|
|
|
return m_symbolGroup->frame();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 16:50:31 +01:00
|
|
|
WatchesSymbolGroup *ExtensionContext::watchesSymbolGroup() const
|
|
|
|
|
{
|
|
|
|
|
if (m_watchesSymbolGroup.get())
|
|
|
|
|
return m_watchesSymbolGroup.get();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WatchesSymbolGroup *ExtensionContext::watchesSymbolGroup(CIDebugSymbols *symbols, std::string *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (m_watchesSymbolGroup.get())
|
|
|
|
|
return m_watchesSymbolGroup.get();
|
|
|
|
|
WatchesSymbolGroup *newSg = WatchesSymbolGroup::create(symbols, errorMessage);
|
|
|
|
|
if (!newSg)
|
|
|
|
|
return 0;
|
|
|
|
|
m_watchesSymbolGroup.reset(newSg);
|
|
|
|
|
return newSg;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 13:55:52 +01:00
|
|
|
void ExtensionContext::discardSymbolGroup()
|
|
|
|
|
{
|
|
|
|
|
if (m_symbolGroup.get())
|
|
|
|
|
m_symbolGroup.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 16:50:31 +01:00
|
|
|
void ExtensionContext::discardWatchesSymbolGroup()
|
|
|
|
|
{
|
|
|
|
|
if (m_watchesSymbolGroup.get())
|
|
|
|
|
m_watchesSymbolGroup.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 12:40:52 +01:00
|
|
|
bool ExtensionContext::report(char code, int token, int remainingChunks, const char *serviceName, PCSTR Format, ...)
|
2010-11-18 13:55:52 +01:00
|
|
|
{
|
|
|
|
|
if (!isInitialized())
|
|
|
|
|
return false;
|
|
|
|
|
// '<qtcreatorcdbext>|R|<token>|<serviceName>|<one-line-output>'.
|
2011-01-04 12:40:52 +01:00
|
|
|
m_control->Output(DEBUG_OUTPUT_NORMAL, "<qtcreatorcdbext>|%c|%d|%d|%s|",
|
|
|
|
|
code, token, remainingChunks, serviceName);
|
2010-11-18 13:55:52 +01:00
|
|
|
va_list Args;
|
|
|
|
|
va_start(Args, Format);
|
|
|
|
|
m_control->OutputVaList(DEBUG_OUTPUT_NORMAL, Format, Args);
|
|
|
|
|
va_end(Args);
|
|
|
|
|
m_control->Output(DEBUG_OUTPUT_NORMAL, "\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 12:40:52 +01:00
|
|
|
bool ExtensionContext::reportLong(char code, int token, const char *serviceName, const std::string &message)
|
|
|
|
|
{
|
|
|
|
|
const std::string::size_type size = message.size();
|
|
|
|
|
if (size < outputChunkSize)
|
|
|
|
|
return report(code, token, 0, serviceName, "%s", message.c_str());
|
|
|
|
|
// Split up
|
|
|
|
|
std::string::size_type chunkCount = size / outputChunkSize;
|
|
|
|
|
if (size % outputChunkSize)
|
|
|
|
|
chunkCount++;
|
|
|
|
|
std::string::size_type pos = 0;
|
|
|
|
|
for (int remaining = int(chunkCount) - 1; remaining >= 0 ; remaining--) {
|
|
|
|
|
std::string::size_type nextPos = pos + outputChunkSize; // No consistent std::min/std::max in VS8/10
|
|
|
|
|
if (nextPos > size)
|
|
|
|
|
nextPos = size;
|
|
|
|
|
report(code, token, remaining, serviceName, "%s", message.substr(pos, nextPos - pos).c_str());
|
|
|
|
|
pos = nextPos;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 10:08:38 +01:00
|
|
|
static const char *goCommandForCall(unsigned callFlags)
|
|
|
|
|
{
|
|
|
|
|
if (callFlags & ExtensionContext::CallWithExceptionsHandled)
|
|
|
|
|
return "~. gh";
|
|
|
|
|
else if (callFlags & ExtensionContext::CallWithExceptionsNotHandled)
|
|
|
|
|
return "~. gN";
|
|
|
|
|
return "~. g";
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 11:40:45 +01:00
|
|
|
bool ExtensionContext::call(const std::string &functionCall,
|
2014-02-24 10:08:38 +01:00
|
|
|
unsigned callFlags,
|
2011-01-18 11:40:45 +01:00
|
|
|
std::wstring *output,
|
|
|
|
|
std::string *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (!m_creatorOutputCallback) {
|
|
|
|
|
*errorMessage = "Attempt to issue a call with no output hooked.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Set up arguments
|
|
|
|
|
const std::string call = ".call " + functionCall;
|
|
|
|
|
HRESULT hr = m_control->Execute(DEBUG_OUTCTL_ALL_CLIENTS, call.c_str(), DEBUG_EXECUTE_ECHO);
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
|
*errorMessage = msgDebugEngineComFailed("Execute", hr);
|
2014-10-14 14:34:46 +02:00
|
|
|
return false;
|
2011-01-18 11:40:45 +01:00
|
|
|
}
|
|
|
|
|
// Execute in current thread. TODO: This must not crash, else we are in an inconsistent state
|
|
|
|
|
// (need to call 'gh', etc.)
|
2014-02-24 10:08:38 +01:00
|
|
|
hr = m_control->Execute(DEBUG_OUTCTL_ALL_CLIENTS, goCommandForCall(callFlags), DEBUG_EXECUTE_ECHO);
|
2011-01-18 11:40:45 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
|
*errorMessage = msgDebugEngineComFailed("Execute", hr);
|
2014-10-14 14:34:46 +02:00
|
|
|
return false;
|
2011-01-18 11:40:45 +01:00
|
|
|
}
|
|
|
|
|
// Wait until finished
|
|
|
|
|
startRecordingOutput();
|
2014-02-24 10:01:01 +01:00
|
|
|
StateNotificationBlocker blocker(this);
|
2011-01-18 11:40:45 +01:00
|
|
|
m_control->WaitForEvent(0, INFINITE);
|
|
|
|
|
*output = stopRecordingOutput();
|
|
|
|
|
// Crude attempt at recovering from a crash: Issue 'gN' (go with exception not handled).
|
|
|
|
|
const bool crashed = output->find(L"This exception may be expected and handled.") != std::string::npos;
|
2014-02-24 10:08:38 +01:00
|
|
|
if (crashed && !callFlags) {
|
2011-01-18 11:40:45 +01:00
|
|
|
m_stopReason.clear();
|
2014-02-24 10:08:38 +01:00
|
|
|
hr = m_control->Execute(DEBUG_OUTCTL_ALL_CLIENTS, goCommandForCall(CallWithExceptionsNotHandled), DEBUG_EXECUTE_ECHO);
|
2011-01-18 11:40:45 +01:00
|
|
|
m_control->WaitForEvent(0, INFINITE);
|
|
|
|
|
*errorMessage = "A crash occurred while calling: " + functionCall;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 13:55:52 +01:00
|
|
|
// Exported C-functions
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags)
|
|
|
|
|
{
|
|
|
|
|
return ExtensionContext::instance().initialize(Version, Flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CALLBACK DebugExtensionUninitialize(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CALLBACK DebugExtensionNotify(ULONG Notify, ULONG64)
|
|
|
|
|
{
|
|
|
|
|
ExtensionContext::instance().notifyState(Notify);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
|
2011-02-04 15:08:31 +01:00
|
|
|
/*! \class ExtensionCommandContext
|
|
|
|
|
|
|
|
|
|
Context for extension commands to be instantiated on stack in a command handler.
|
|
|
|
|
Provides the IDebug objects on demand. \ingroup qtcreatorcdbext
|
|
|
|
|
*/
|
2010-11-18 13:55:52 +01:00
|
|
|
|
|
|
|
|
ExtensionCommandContext *ExtensionCommandContext::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
ExtensionCommandContext::ExtensionCommandContext(CIDebugClient *client) : m_client(client)
|
|
|
|
|
{
|
|
|
|
|
ExtensionCommandContext::m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionCommandContext::~ExtensionCommandContext()
|
|
|
|
|
{
|
|
|
|
|
ExtensionCommandContext::m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CIDebugControl *ExtensionCommandContext::control()
|
|
|
|
|
{
|
|
|
|
|
if (!m_control)
|
|
|
|
|
m_control.create(m_client);
|
|
|
|
|
return m_control.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionCommandContext *ExtensionCommandContext::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CIDebugSymbols *ExtensionCommandContext::symbols()
|
|
|
|
|
{
|
|
|
|
|
if (!m_symbols)
|
|
|
|
|
m_symbols.create(m_client);
|
|
|
|
|
return m_symbols.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CIDebugSystemObjects *ExtensionCommandContext::systemObjects()
|
|
|
|
|
{
|
|
|
|
|
if (!m_systemObjects)
|
|
|
|
|
m_systemObjects.create(m_client);
|
|
|
|
|
return m_systemObjects.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CIDebugAdvanced *ExtensionCommandContext::advanced()
|
|
|
|
|
{
|
|
|
|
|
if (!m_advanced)
|
|
|
|
|
m_advanced.create(m_client);
|
|
|
|
|
return m_advanced.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CIDebugRegisters *ExtensionCommandContext::registers()
|
|
|
|
|
{
|
|
|
|
|
if (!m_registers)
|
|
|
|
|
m_registers.create(m_client);
|
|
|
|
|
return m_registers.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CIDebugDataSpaces *ExtensionCommandContext::dataSpaces()
|
|
|
|
|
{
|
|
|
|
|
if (!m_dataSpaces)
|
|
|
|
|
m_dataSpaces.create(m_client);
|
|
|
|
|
return m_dataSpaces.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ULONG ExtensionCommandContext::threadId()
|
|
|
|
|
{
|
|
|
|
|
if (CIDebugSystemObjects *so = systemObjects()) {
|
|
|
|
|
ULONG threadId = 0;
|
|
|
|
|
if (SUCCEEDED(so->GetCurrentThreadId(&threadId)))
|
|
|
|
|
return threadId;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|