1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
This file is part of kdev-python, the python language plugin for KDevelop
Copyright (C) 2012 Sven Brauch <svenbrauch@googlemail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "variable.h"
#include "debugsession.h"
#include <interfaces/icore.h>
#include <QDebug>
#include "debuggerdebug.h"
namespace Python {
Variable::Variable(KDevelop::TreeModel* model, KDevelop::TreeItem* parent, const QString& expression, const QString& display)
: KDevelop::Variable(model, parent, expression, display)
, m_notifyCreated(nullptr)
, m_pythonPtr(0)
{
}
void Variable::dataFetched(QByteArray rawData)
{
QList<QByteArray> data = rawData.split('\n');
data.removeLast();
QByteArray value;
foreach ( const QByteArray& item, data ) {
value.append(item);
}
setValue(value);
setHasMore(true);
qCDebug(KDEV_PYTHON_DEBUGGER) << "value set to" << value << ", calling update method";
if ( m_notifyCreated ) {
QMetaObject::invokeMethod(m_notifyCreated, m_notifyCreatedMethod, Qt::QueuedConnection, Q_ARG(bool, true));
m_notifyCreated = nullptr;
}
}
void Variable::attachMaybe(QObject* callback, const char* callbackMethod)
{
IDebugSession* is = ICore::self()->debugController()->currentSession();
DebugSession* s = static_cast<DebugSession*>(is);
s->createVariable(this, callback, callbackMethod);
}
// TODO: make it really fetch *more*, not just some
void Variable::fetchMoreChildren()
{
QString cmd;
if ( m_pythonPtr ) {
cmd = "__kdevpython_debugger_utils.format_ptr_children("+QString::number(m_pythonPtr)+")\n";
}
else {
cmd = "__kdevpython_debugger_utils.format_object_children("+expression()+")\n";
}
InternalPdbCommand* fetchChildrenScript = new InternalPdbCommand(this, "moreChildrenFetched", cmd);
static_cast<DebugSession*>(ICore::self()->debugController()->currentSession())->addCommand(fetchChildrenScript);
}
void Variable::setId(unsigned long int id)
{
m_pythonPtr = id;
}
void Variable::moreChildrenFetched(QByteArray rawData)
{
deleteChildren();
QList<QByteArray> data = rawData.split('\n');
data.removeLast();
int i = 0;
int initialLength = data.length();
QRegExp formatExtract("(ptr:<(\\d*)>\\s)?([\\[\\]\\.a-zA-Z0-9_]+) \\=\\> (.*)$");
formatExtract.setPatternSyntax(QRegExp::RegExp2);
formatExtract.setMinimal(true);
while ( i < data.length() ) {
QByteArray d = data.at(i);
// sort magic functions at the end of the list, they're not too interesting usually
if ( d.startsWith('_') && i < initialLength ) {
data.append(d);
i++;
continue;
}
QString childName;
QString realValue;
QString prettyName;
unsigned long int pythonId = 0;
if ( formatExtract.exactMatch(d) ) {
QString id = formatExtract.capturedTexts().at(2);
if ( ! id.isEmpty() ) {
pythonId = id.toLong();
}
childName = expression() + formatExtract.capturedTexts().at(3);
prettyName = formatExtract.capturedTexts().at(3);
realValue = formatExtract.capturedTexts().at(4);
}
else {
i++;
continue;
}
Variable* v = new Variable(model_, this, childName, prettyName);
appendChild(v);
qCDebug(KDEV_PYTHON_DEBUGGER) << "adding child:" << expression() << i << d;
v->setValue(realValue);
v->setId(pythonId);
v->setHasMoreInitial(true);
i++;
}
}
}
|