Commit 6bb7b617 authored by hjk's avatar hjk
Browse files

debugger: add a cut-down version of the dumpers for python

parent 34db4fd3
import pdb;
import sys;
import linecache
class qdebug:
def __init__(self,
options = Null,
expanded = Null,
typeformats = Null,
individualformats = Null,
watchers = Null):
self.options = options
self.expanded = expanded
self.typeformats = typeformats
self.individualformats = individualformats
self.watchers = watchers
self.doit()
def put(self, value):
sys.stdout.write(value)
def putField(self, name, value):
self.put('%s="%s",' % (name, value))
def putItemCount(self, count):
self.put('value="<%s items>",' % count)
def putEllipsis(self):
self.put('{name="<incomplete>",value="",type="",numchild="0"},')
def cleanType(self, type):
t = str(type)
if t.startswith("<type '") and t.endswith("'>"):
t = t[7:-2]
return t
def putType(self, type, priority = 0):
self.putField("type", self.cleanType(type))
def putAddress(self, addr):
self.put('addr="%s",' % cleanAddress(addr))
def putNumChild(self, numchild):
self.put('numchild="%s",' % numchild)
def putValue(self, value, encoding = None, priority = 0):
self.putField("value", value)
def putName(self, name):
self.put('name="%s",' % name)
def isExpanded(self, item):
#warn("IS EXPANDED: %s in %s" % (item.iname, self.expandedINames))
if item.iname is None:
raise "Illegal iname 'None'"
if item.iname.startswith("None"):
raise "Illegal iname '%s'" % item.iname
#warn(" --> %s" % (item.iname in self.expandedINames))
return item.iname in self.expandedINames
def isExpandedIName(self, iname):
return iname in self.expandedINames
def itemFormat(self, item):
format = self.formats.get(str(cleanAddress(item.value.address)))
if format is None:
format = self.typeformats.get(stripClassTag(str(item.value.type)))
return format
def dumpFrame(self, frame):
for var in frame.f_locals.keys():
if var == "__file__":
continue
#if var == "__name__":
# continue
if var == "__package__":
continue
if var == "qdebug":
continue
if var != '__builtins__':
value = frame.f_locals[var]
self.dumpValue(value, var, "local.%s" % var)
def dumpValue(self, value, name, iname):
t = type(value)
tt = self.cleanType(t)
if tt == "module" or tt == "function":
return
if tt == "list":
self.warn("LIST: %s" % dir(value))
self.put("{")
self.putField("iname", iname)
self.putName(name)
self.putType(tt)
self.putValue(value)
self.put("children=[")
for i in xrange(len(value)):
self.dumpValue(value[i], str(i), "%s.%d" % (iname, i))
self.put("]")
self.put("},")
elif tt != "module" and tt != "function":
self.put("{")
self.putField("iname", iname)
self.putName(name)
self.putType(tt)
self.putValue(value)
self.put("},")
def warn(self, msg):
self.putField("warning", msg)
def doit(self):
# Trigger error to get a backtrace.
frame = None
#self.warn("frame: %s" % frame)
try:
raise ZeroDivisionError
except ZeroDivisionError:
frame = sys.exc_info()[2].tb_frame.f_back
limit = 30
n = 0
isActive = False
while frame is not None and n < limit:
#self.warn("frame: %s" % frame.f_locals.keys())
lineno = frame.f_lineno
code = frame.f_code
filename = code.co_filename
name = code.co_name
if isActive:
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, frame.f_globals)
self.dumpFrame(frame)
if name == "<module>":
isActive = False
if name == "trace_dispatch":
isActive = True
frame = frame.f_back
n = n + 1
sys.stdout.flush()
...@@ -57,6 +57,7 @@ SOURCES += breakhandler.cpp \ ...@@ -57,6 +57,7 @@ SOURCES += breakhandler.cpp \
debuggerplugin.cpp \ debuggerplugin.cpp \
debuggerrunner.cpp \ debuggerrunner.cpp \
debuggertooltip.cpp \ debuggertooltip.cpp \
idebuggerengine.cpp \
moduleshandler.cpp \ moduleshandler.cpp \
moduleswindow.cpp \ moduleswindow.cpp \
outputcollector.cpp \ outputcollector.cpp \
......
...@@ -141,11 +141,6 @@ private: ////////// Gdb Process Management ////////// ...@@ -141,11 +141,6 @@ private: ////////// Gdb Process Management //////////
void handleInferiorShutdown(const GdbResponse &response); void handleInferiorShutdown(const GdbResponse &response);
void handleGdbExit(const GdbResponse &response); void handleGdbExit(const GdbResponse &response);
void showDebuggerInput(int channel, const QString &msg)
{ m_manager->showDebuggerInput(channel, msg); }
void showDebuggerOutput(int channel, const QString &msg)
{ m_manager->showDebuggerOutput(channel, msg); }
private slots: private slots:
void handleGdbFinished(int, QProcess::ExitStatus status); void handleGdbFinished(int, QProcess::ExitStatus status);
void handleGdbError(QProcess::ProcessError error); void handleGdbError(QProcess::ProcessError error);
......
...@@ -55,10 +55,9 @@ void GdbEngine::updateLocalsPython(const QByteArray &varList) ...@@ -55,10 +55,9 @@ void GdbEngine::updateLocalsPython(const QByteArray &varList)
//m_toolTipExpression.clear(); //m_toolTipExpression.clear();
WatchHandler *handler = m_manager->watchHandler(); WatchHandler *handler = m_manager->watchHandler();
QByteArray expanded = handler->formatRequests(); QByteArray expanded = "expanded:" + handler->expansionRequests() + ' ';
if (expanded.isEmpty()) expanded += "typeformats:" + handler->typeFormatRequests() + ' ';
expanded.append("defaults,"); expanded += "formats:" + handler->individualFormatRequests();
expanded.chop(1);
QByteArray watchers; QByteArray watchers;
if (!m_toolTipExpression.isEmpty()) if (!m_toolTipExpression.isEmpty())
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "idebuggerengine.h"
#include "debuggermanager.h"
namespace Debugger {
namespace Internal {
void IDebuggerEngine::fetchMemory(MemoryViewAgent *, QObject *,
quint64 addr, quint64 length)
{
Q_UNUSED(addr);
Q_UNUSED(length);
}
void IDebuggerEngine::setRegisterValue(int regnr, const QString &value)
{
Q_UNUSED(regnr);
Q_UNUSED(value);
}
bool IDebuggerEngine::checkConfiguration(int toolChain,
QString *errorMessage, QString *settingsPage) const
{
Q_UNUSED(toolChain);
Q_UNUSED(errorMessage);
Q_UNUSED(settingsPage);
return true;
}
void IDebuggerEngine::showDebuggerInput(int channel, const QString &msg)
{
m_manager->showDebuggerInput(channel, msg);
}
void IDebuggerEngine::showDebuggerOutput(int channel, const QString &msg)
{
m_manager->showDebuggerOutput(channel, msg);
}
} // namespace Internal
} // namespace Debugger
...@@ -113,18 +113,23 @@ public: ...@@ -113,18 +113,23 @@ public:
virtual void reloadFullStack() = 0; virtual void reloadFullStack() = 0;
virtual void watchPoint(const QPoint &) {} virtual void watchPoint(const QPoint &) {}
virtual void fetchMemory(MemoryViewAgent *, QObject *, quint64 addr, quint64 length) virtual void fetchMemory(MemoryViewAgent *, QObject *,
{ Q_UNUSED(addr); Q_UNUSED(length); } quint64 addr, quint64 length);
virtual void fetchDisassembler(DisassemblerViewAgent *) {} virtual void fetchDisassembler(DisassemblerViewAgent *) {}
virtual void setRegisterValue(int regnr, const QString &value) virtual void setRegisterValue(int regnr, const QString &value);
{ Q_UNUSED(regnr); Q_UNUSED(value); }
virtual void addOptionPages(QList<Core::IOptionsPage*> *) const {} virtual void addOptionPages(QList<Core::IOptionsPage*> *) const {}
virtual unsigned debuggerCapabilities() const { return 0; } virtual unsigned debuggerCapabilities() const { return 0; }
virtual bool checkConfiguration(int /* toolChain */, QString * /* errorMessage */, QString * /* settingsPage */ = 0) const { return true; }
virtual bool checkConfiguration(int toolChain,
QString *errorMessage, QString *settingsPage = 0) const;
virtual bool isSynchroneous() const { return false; } virtual bool isSynchroneous() const { return false; }
virtual QString qtNamespace() const { return QString(); } virtual QString qtNamespace() const { return QString(); }
// Convenience
void showDebuggerInput(int channel, const QString &msg);
void showDebuggerOutput(int channel, const QString &msg);
protected: protected:
void showStatusMessage(const QString &msg, int timeout = -1); void showStatusMessage(const QString &msg, int timeout = -1);
DebuggerState state() const; DebuggerState state() const;
......
...@@ -1390,13 +1390,11 @@ int WatchHandler::format(const QByteArray &iname) const ...@@ -1390,13 +1390,11 @@ int WatchHandler::format(const QByteArray &iname) const
return result; return result;
} }
QByteArray WatchHandler::formatRequests() const QByteArray WatchHandler::expansionRequests() const
{ {
QByteArray ba; QByteArray ba;
//m_locals->formatRequests(&ba, m_locals->m_root); //m_locals->formatRequests(&ba, m_locals->m_root);
//m_watchers->formatRequests(&ba, m_watchers->m_root); //m_watchers->formatRequests(&ba, m_watchers->m_root);
ba.append("expanded:");
if (!m_expandedINames.isEmpty()) { if (!m_expandedINames.isEmpty()) {
QSetIterator<QByteArray> jt(m_expandedINames); QSetIterator<QByteArray> jt(m_expandedINames);
while (jt.hasNext()) { while (jt.hasNext()) {
...@@ -1406,9 +1404,12 @@ QByteArray WatchHandler::formatRequests() const ...@@ -1406,9 +1404,12 @@ QByteArray WatchHandler::formatRequests() const
} }
ba.chop(1); ba.chop(1);
} }
ba.append(' '); return ba;
}
ba.append("typeformats:"); QByteArray WatchHandler::typeFormatRequests() const
{
QByteArray ba;
if (!m_typeFormats.isEmpty()) { if (!m_typeFormats.isEmpty()) {
QHashIterator<QString, int> it(m_typeFormats); QHashIterator<QString, int> it(m_typeFormats);
while (it.hasNext()) { while (it.hasNext()) {
...@@ -1420,9 +1421,12 @@ QByteArray WatchHandler::formatRequests() const ...@@ -1420,9 +1421,12 @@ QByteArray WatchHandler::formatRequests() const
} }
ba.chop(1); ba.chop(1);
} }
ba.append(' '); return ba;
}
ba.append("formats:"); QByteArray WatchHandler::individualFormatRequests() const
{
QByteArray ba;
if (!m_individualFormats.isEmpty()) { if (!m_individualFormats.isEmpty()) {
QHashIterator<QByteArray, int> it(m_individualFormats); QHashIterator<QByteArray, int> it(m_individualFormats);
while (it.hasNext()) { while (it.hasNext()) {
...@@ -1434,8 +1438,6 @@ QByteArray WatchHandler::formatRequests() const ...@@ -1434,8 +1438,6 @@ QByteArray WatchHandler::formatRequests() const
} }
ba.chop(1); ba.chop(1);
} }
ba.append(' ');
return ba; return ba;
} }
......
...@@ -173,7 +173,10 @@ public: ...@@ -173,7 +173,10 @@ public:
QStringList watchedExpressions() const; QStringList watchedExpressions() const;
QHash<QByteArray, int> watcherNames() const QHash<QByteArray, int> watcherNames() const
{ return m_watcherNames; } { return m_watcherNames; }
QByteArray formatRequests() const;
QByteArray expansionRequests() const;
QByteArray typeFormatRequests() const;
QByteArray individualFormatRequests() const;
static QString watcherEditPlaceHolder(); static QString watcherEditPlaceHolder();
int format(const QByteArray &iname) const; int format(const QByteArray &iname) const;
......
...@@ -4,6 +4,7 @@ def square(a): ...@@ -4,6 +4,7 @@ def square(a):
return a return a
def cube(a): def cube(a):
l = [1, 2, 4]
x = square(a) x = square(a)
x = x * a x = x * a
x = x + 1 x = x + 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment