2009-03-25 13:42:47 +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).
|
2009-03-25 13:42:47 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-03-25 13:42:47 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2009-03-25 13:42:47 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2009-03-25 13:42:47 +01:00
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-03-25 13:42:47 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "watchutils.h"
|
2010-04-26 18:54:08 +02:00
|
|
|
#include "watchdata.h"
|
|
|
|
|
#include "debuggerstringutils.h"
|
2009-09-18 16:55:17 +02:00
|
|
|
#include "gdb/gdbmi.h"
|
2010-04-26 18:54:08 +02:00
|
|
|
|
2009-04-29 14:15:09 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-03-25 13:42:47 +01:00
|
|
|
|
2009-10-01 16:38:08 +02:00
|
|
|
#include <coreplugin/ifile.h>
|
|
|
|
|
|
2009-05-14 14:29:37 +02:00
|
|
|
#include <texteditor/basetexteditor.h>
|
|
|
|
|
#include <texteditor/basetextmark.h>
|
|
|
|
|
#include <texteditor/itexteditor.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
2010-11-04 11:46:16 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-05-14 14:29:37 +02:00
|
|
|
|
|
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2010-12-03 13:49:35 +01:00
|
|
|
#include <cpptools/abstracteditorsupport.h>
|
2009-05-14 14:29:37 +02:00
|
|
|
|
2010-12-03 13:49:35 +01:00
|
|
|
#include <cplusplus/ModelManagerInterface.h>
|
2009-05-14 14:29:37 +02:00
|
|
|
#include <cplusplus/ExpressionUnderCursor.h>
|
2009-10-16 16:26:28 +02:00
|
|
|
#include <cplusplus/Overview.h>
|
|
|
|
|
#include <Symbols.h>
|
|
|
|
|
#include <Scope.h>
|
2009-05-14 14:29:37 +02:00
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2009-03-25 13:42:47 +01:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QTime>
|
|
|
|
|
#include <QtCore/QStringList>
|
2009-04-29 14:15:09 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
#include <QtCore/QTextStream>
|
2009-10-16 16:26:28 +02:00
|
|
|
#include <QtCore/QHash>
|
2009-04-29 14:15:09 +02:00
|
|
|
|
2009-05-14 14:29:37 +02:00
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
|
#include <QtGui/QPlainTextEdit>
|
|
|
|
|
|
2009-04-29 14:15:09 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
|
enum { debug = 0 };
|
2009-10-16 16:26:28 +02:00
|
|
|
|
|
|
|
|
// Debug helpers for code model. @todo: Move to some CppTools library?
|
|
|
|
|
namespace CPlusPlus {
|
|
|
|
|
|
|
|
|
|
static void debugCppSymbolRecursion(QTextStream &str, const Overview &o,
|
|
|
|
|
const Symbol &s, bool doRecurse = true,
|
|
|
|
|
int recursion = 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < recursion; i++)
|
|
|
|
|
str << " ";
|
|
|
|
|
str << "Symbol: " << o.prettyName(s.name()) << " at line " << s.line();
|
|
|
|
|
if (s.isFunction())
|
|
|
|
|
str << " function";
|
|
|
|
|
if (s.isClass())
|
|
|
|
|
str << " class";
|
|
|
|
|
if (s.isDeclaration())
|
|
|
|
|
str << " declaration";
|
|
|
|
|
if (s.isBlock())
|
|
|
|
|
str << " block";
|
2010-08-12 12:35:22 +02:00
|
|
|
if (doRecurse && s.isScope()) {
|
2010-08-11 12:26:02 +02:00
|
|
|
const Scope *scoped = s.asScope();
|
2009-10-16 16:26:28 +02:00
|
|
|
const int size = scoped->memberCount();
|
|
|
|
|
str << " scoped symbol of " << size << '\n';
|
|
|
|
|
for (int m = 0; m < size; m++)
|
|
|
|
|
debugCppSymbolRecursion(str, o, *scoped->memberAt(m), true, recursion + 1);
|
|
|
|
|
} else {
|
|
|
|
|
str << '\n';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDebug operator<<(QDebug d, const Symbol &s)
|
|
|
|
|
{
|
|
|
|
|
QString output;
|
|
|
|
|
CPlusPlus::Overview o;
|
|
|
|
|
QTextStream str(&output);
|
|
|
|
|
debugCppSymbolRecursion(str, o, s, true, 0);
|
|
|
|
|
d.nospace() << output;
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDebug operator<<(QDebug d, const Scope &scope)
|
|
|
|
|
{
|
|
|
|
|
QString output;
|
|
|
|
|
Overview o;
|
|
|
|
|
QTextStream str(&output);
|
2010-08-11 12:26:02 +02:00
|
|
|
const int size = scope.memberCount();
|
2009-10-16 16:26:28 +02:00
|
|
|
str << "Scope of " << size;
|
2010-08-11 12:26:02 +02:00
|
|
|
if (scope.isNamespace())
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " namespace";
|
2010-08-11 12:26:02 +02:00
|
|
|
if (scope.isClass())
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " class";
|
2010-08-11 12:26:02 +02:00
|
|
|
if (scope.isEnum())
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " enum";
|
2010-08-11 12:26:02 +02:00
|
|
|
if (scope.isBlock())
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " block";
|
2010-08-11 12:26:02 +02:00
|
|
|
if (scope.isFunction())
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " function";
|
2010-08-11 12:26:02 +02:00
|
|
|
if (scope.isFunction())
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " prototype";
|
2010-08-11 15:48:21 +02:00
|
|
|
#if 0 // ### port me
|
2010-08-11 12:26:02 +02:00
|
|
|
if (const Symbol *owner = &scope) {
|
2009-10-16 16:26:28 +02:00
|
|
|
str << " owner: ";
|
|
|
|
|
debugCppSymbolRecursion(str, o, *owner, false, 0);
|
|
|
|
|
} else {
|
|
|
|
|
str << " 0-owner\n";
|
|
|
|
|
}
|
2010-08-11 12:26:02 +02:00
|
|
|
#endif
|
2009-10-16 16:26:28 +02:00
|
|
|
for (int s = 0; s < size; s++)
|
2010-08-11 12:26:02 +02:00
|
|
|
debugCppSymbolRecursion(str, o, *scope.memberAt(s), true, 2);
|
2009-10-16 16:26:28 +02:00
|
|
|
d.nospace() << output;
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
} // namespace CPlusPlus
|
|
|
|
|
|
2009-03-25 13:42:47 +01:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2011-02-17 10:08:57 +01:00
|
|
|
bool isEditorDebuggable(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
// Only blacklist Qml. Whitelisting would fail on C++ code in files
|
|
|
|
|
// with strange names, more harm would be done this way.
|
|
|
|
|
// IFile *file = editor->file();
|
|
|
|
|
// return !(file && file->mimeType() == "application/x-qml");
|
|
|
|
|
// Nowadays, even Qml is debuggable.
|
|
|
|
|
return editor;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-05 16:51:55 +01:00
|
|
|
QByteArray dotEscape(QByteArray str)
|
2009-03-25 13:42:47 +01:00
|
|
|
{
|
2010-01-05 16:51:55 +01:00
|
|
|
str.replace(' ', '.');
|
|
|
|
|
str.replace('\\', '.');
|
|
|
|
|
str.replace('/', '.');
|
2009-03-25 13:42:47 +01:00
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString currentTime()
|
|
|
|
|
{
|
|
|
|
|
return QTime::currentTime().toString(QLatin1String("hh:mm:ss.zzz"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isSkippableFunction(const QString &funcName, const QString &fileName)
|
|
|
|
|
{
|
2011-02-02 12:54:48 +01:00
|
|
|
if (fileName.endsWith(QLatin1String("/qobject.cpp")))
|
2009-03-25 13:42:47 +01:00
|
|
|
return true;
|
2011-02-02 12:54:48 +01:00
|
|
|
if (fileName.endsWith(QLatin1String("/moc_qobject.cpp")))
|
2009-03-25 13:42:47 +01:00
|
|
|
return true;
|
2011-02-02 12:54:48 +01:00
|
|
|
if (fileName.endsWith(QLatin1String("/qmetaobject.cpp")))
|
2009-03-25 13:42:47 +01:00
|
|
|
return true;
|
2011-02-02 12:54:48 +01:00
|
|
|
if (fileName.endsWith(QLatin1String("/qmetaobject_p.h")))
|
2009-08-20 11:49:56 +02:00
|
|
|
return true;
|
2009-03-25 13:42:47 +01:00
|
|
|
if (fileName.endsWith(QLatin1String(".moc")))
|
|
|
|
|
return true;
|
|
|
|
|
|
2010-02-01 12:43:56 +01:00
|
|
|
if (funcName.endsWith(QLatin1String("::qt_metacall")))
|
2009-03-25 13:42:47 +01:00
|
|
|
return true;
|
2010-02-01 12:43:56 +01:00
|
|
|
if (funcName.endsWith(QLatin1String("::d_func")))
|
2009-08-20 11:49:56 +02:00
|
|
|
return true;
|
2010-02-01 12:43:56 +01:00
|
|
|
if (funcName.endsWith(QLatin1String("::q_func")))
|
2009-08-20 11:49:56 +02:00
|
|
|
return true;
|
2009-03-25 13:42:47 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isLeavableFunction(const QString &funcName, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (funcName.endsWith(QLatin1String("QObjectPrivate::setCurrentSender")))
|
|
|
|
|
return true;
|
2009-08-20 11:49:56 +02:00
|
|
|
if (funcName.endsWith(QLatin1String("QMutexPool::get")))
|
|
|
|
|
return true;
|
2011-02-02 11:52:39 +01:00
|
|
|
|
|
|
|
|
if (fileName.endsWith(QLatin1String(".cpp"))) {
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qmetaobject.cpp"))
|
|
|
|
|
&& funcName.endsWith(QLatin1String("QMetaObject::methodOffset")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qobject.cpp"))
|
|
|
|
|
&& (funcName.endsWith(QLatin1String("QObjectConnectionListVector::at"))
|
|
|
|
|
|| funcName.endsWith(QLatin1String("~QObject"))))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qmutex.cpp")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qthread.cpp")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qthread_unix.cpp")))
|
|
|
|
|
return true;
|
|
|
|
|
} else if (fileName.endsWith(QLatin1String(".h"))) {
|
|
|
|
|
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qobject.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qmutex.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qvector.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qlist.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qhash.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qmap.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qshareddata.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qstring.h")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.endsWith(QLatin1String("/qglobal.h")))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (fileName.contains(QLatin1String("/qbasicatomic")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.contains(QLatin1String("/qorderedmutexlocker_p")))
|
|
|
|
|
return true;
|
|
|
|
|
if (fileName.contains(QLatin1String("/qatomic")))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-03-25 13:42:47 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
bool isLetterOrNumber(char c)
|
|
|
|
|
{
|
|
|
|
|
return (c >= 'a' && c <= 'z')
|
|
|
|
|
|| (c >= 'A' && c <= 'Z')
|
|
|
|
|
|| (c >= '0' && c <= '9');
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-25 13:42:47 +01:00
|
|
|
bool hasLetterOrNumber(const QString &exp)
|
|
|
|
|
{
|
|
|
|
|
const QChar underscore = QLatin1Char('_');
|
|
|
|
|
for (int i = exp.size(); --i >= 0; )
|
|
|
|
|
if (exp.at(i).isLetterOrNumber() || exp.at(i) == underscore)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasSideEffects(const QString &exp)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: complete?
|
|
|
|
|
return exp.contains(QLatin1String("-="))
|
|
|
|
|
|| exp.contains(QLatin1String("+="))
|
|
|
|
|
|| exp.contains(QLatin1String("/="))
|
2009-05-05 20:33:31 +02:00
|
|
|
|| exp.contains(QLatin1String("%="))
|
2009-03-25 13:42:47 +01:00
|
|
|
|| exp.contains(QLatin1String("*="))
|
|
|
|
|
|| exp.contains(QLatin1String("&="))
|
|
|
|
|
|| exp.contains(QLatin1String("|="))
|
|
|
|
|
|| exp.contains(QLatin1String("^="))
|
|
|
|
|
|| exp.contains(QLatin1String("--"))
|
|
|
|
|
|| exp.contains(QLatin1String("++"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isKeyWord(const QString &exp)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: incomplete
|
|
|
|
|
return exp == QLatin1String("class")
|
|
|
|
|
|| exp == QLatin1String("const")
|
|
|
|
|
|| exp == QLatin1String("do")
|
|
|
|
|
|| exp == QLatin1String("if")
|
|
|
|
|
|| exp == QLatin1String("return")
|
|
|
|
|
|| exp == QLatin1String("struct")
|
|
|
|
|
|| exp == QLatin1String("template")
|
|
|
|
|
|| exp == QLatin1String("void")
|
|
|
|
|
|| exp == QLatin1String("volatile")
|
|
|
|
|
|| exp == QLatin1String("while");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool startsWithDigit(const QString &str)
|
|
|
|
|
{
|
|
|
|
|
return !str.isEmpty() && str.at(0).isDigit();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
QByteArray stripPointerType(QByteArray type)
|
2009-03-25 13:42:47 +01:00
|
|
|
{
|
2010-09-01 17:36:09 +02:00
|
|
|
if (type.endsWith('*'))
|
2009-03-25 13:42:47 +01:00
|
|
|
type.chop(1);
|
2010-09-01 17:36:09 +02:00
|
|
|
if (type.endsWith("* const"))
|
2009-03-25 13:42:47 +01:00
|
|
|
type.chop(7);
|
2010-09-01 17:36:09 +02:00
|
|
|
if (type.endsWith(' '))
|
2009-03-25 13:42:47 +01:00
|
|
|
type.chop(1);
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-16 16:26:28 +02:00
|
|
|
/* getUninitializedVariables(): Get variables that are not initialized
|
|
|
|
|
* at a certain line of a function from the code model to be able to
|
|
|
|
|
* indicate them as not in scope in the locals view.
|
|
|
|
|
* Find document + function in the code model, do a double check and
|
|
|
|
|
* collect declarative symbols that are in the function past or on
|
|
|
|
|
* the current line. blockRecursion() recurses up the scopes
|
|
|
|
|
* and collect symbols declared past or on the current line.
|
|
|
|
|
* Recursion goes up from the innermost scope, keeping a map
|
|
|
|
|
* of occurrences seen, to be able to derive the names of
|
|
|
|
|
* shadowed variables as the debugger sees them:
|
|
|
|
|
\code
|
|
|
|
|
int x; // Occurrence (1), should be reported as "x <shadowed 1>"
|
|
|
|
|
if (true) {
|
|
|
|
|
int x = 5; (2) // Occurrence (2), should be reported as "x"
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef QHash<QString, int> SeenHash;
|
|
|
|
|
|
|
|
|
|
static void blockRecursion(const CPlusPlus::Overview &overview,
|
|
|
|
|
const CPlusPlus::Scope *scope,
|
|
|
|
|
unsigned line,
|
|
|
|
|
QStringList *uninitializedVariables,
|
|
|
|
|
SeenHash *seenHash,
|
|
|
|
|
int level = 0)
|
|
|
|
|
{
|
2010-08-11 12:26:02 +02:00
|
|
|
const int size = scope->memberCount();
|
2009-10-16 16:26:28 +02:00
|
|
|
for (int s = 0; s < size; s++){
|
2010-08-11 12:26:02 +02:00
|
|
|
const CPlusPlus::Symbol *symbol = scope->memberAt(s);
|
2009-10-16 16:26:28 +02:00
|
|
|
if (symbol->isDeclaration()) {
|
|
|
|
|
// Find out about shadowed symbols by bookkeeping
|
|
|
|
|
// the already seen occurrences in a hash.
|
|
|
|
|
const QString name = overview.prettyName(symbol->name());
|
|
|
|
|
SeenHash::iterator it = seenHash->find(name);
|
|
|
|
|
if (it == seenHash->end()) {
|
|
|
|
|
it = seenHash->insert(name, 0);
|
|
|
|
|
} else {
|
|
|
|
|
++(it.value());
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
2009-10-16 16:26:28 +02:00
|
|
|
// Is the declaration on or past the current line, that is,
|
|
|
|
|
// the variable not initialized.
|
|
|
|
|
if (symbol->line() >= line)
|
|
|
|
|
uninitializedVariables->push_back(WatchData::shadowedName(name, it.value()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Next block scope.
|
2010-08-11 12:26:02 +02:00
|
|
|
if (const CPlusPlus::Scope *enclosingScope = scope->enclosingBlock())
|
2009-10-16 16:26:28 +02:00
|
|
|
blockRecursion(overview, enclosingScope, line, uninitializedVariables, seenHash, level + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inline helper with integer error return codes.
|
|
|
|
|
static inline
|
|
|
|
|
int getUninitializedVariablesI(const CPlusPlus::Snapshot &snapshot,
|
|
|
|
|
const QString &functionName,
|
|
|
|
|
const QString &file,
|
|
|
|
|
int line,
|
|
|
|
|
QStringList *uninitializedVariables)
|
|
|
|
|
{
|
|
|
|
|
uninitializedVariables->clear();
|
|
|
|
|
// Find document
|
2009-12-07 10:54:27 +01:00
|
|
|
if (snapshot.isEmpty() || functionName.isEmpty() || file.isEmpty() || line < 1)
|
2009-10-16 16:26:28 +02:00
|
|
|
return 1;
|
2009-12-07 10:54:27 +01:00
|
|
|
const CPlusPlus::Snapshot::const_iterator docIt = snapshot.find(file);
|
|
|
|
|
if (docIt == snapshot.end())
|
2009-10-16 16:26:28 +02:00
|
|
|
return 2;
|
|
|
|
|
const CPlusPlus::Document::Ptr doc = docIt.value();
|
|
|
|
|
// Look at symbol at line and find its function. Either it is the
|
|
|
|
|
// function itself or some expression/variable.
|
2010-05-17 13:01:56 +02:00
|
|
|
const CPlusPlus::Symbol *symbolAtLine = doc->lastVisibleSymbolAt(line, 0);
|
2009-10-16 16:26:28 +02:00
|
|
|
if (!symbolAtLine)
|
|
|
|
|
return 4;
|
2009-10-19 10:59:46 +02:00
|
|
|
// First figure out the function to do a safety name check
|
|
|
|
|
// and the innermost scope at cursor position
|
2009-10-16 16:26:28 +02:00
|
|
|
const CPlusPlus::Function *function = 0;
|
2009-10-19 10:59:46 +02:00
|
|
|
const CPlusPlus::Scope *innerMostScope = 0;
|
|
|
|
|
if (symbolAtLine->isFunction()) {
|
2009-10-16 16:26:28 +02:00
|
|
|
function = symbolAtLine->asFunction();
|
2009-10-19 10:59:46 +02:00
|
|
|
if (function->memberCount() == 1) // Skip over function block
|
|
|
|
|
if (CPlusPlus::Block *block = function->memberAt(0)->asBlock())
|
2010-08-11 12:26:02 +02:00
|
|
|
innerMostScope = block;
|
2009-10-16 16:26:28 +02:00
|
|
|
} else {
|
2010-08-11 12:26:02 +02:00
|
|
|
if (const CPlusPlus::Scope *functionScope = symbolAtLine->enclosingFunction()) {
|
|
|
|
|
function = functionScope->asFunction();
|
2009-10-19 10:59:46 +02:00
|
|
|
innerMostScope = symbolAtLine->isBlock() ?
|
2010-08-11 12:26:02 +02:00
|
|
|
symbolAtLine->asBlock() :
|
|
|
|
|
symbolAtLine->enclosingBlock();
|
2009-10-19 10:59:46 +02:00
|
|
|
}
|
2009-10-16 16:26:28 +02:00
|
|
|
}
|
2009-10-19 10:59:46 +02:00
|
|
|
if (!function || !innerMostScope)
|
2009-10-16 16:26:28 +02:00
|
|
|
return 7;
|
|
|
|
|
// Compare function names with a bit off fuzz,
|
|
|
|
|
// skipping modules from a CDB symbol "lib!foo" or namespaces
|
|
|
|
|
// that the code model does not show at this point
|
|
|
|
|
CPlusPlus::Overview overview;
|
|
|
|
|
const QString name = overview.prettyName(function->name());
|
|
|
|
|
if (!functionName.endsWith(name))
|
|
|
|
|
return 11;
|
|
|
|
|
if (functionName.size() > name.size()) {
|
|
|
|
|
const char previousChar = functionName.at(functionName.size() - name.size() - 1).toLatin1();
|
|
|
|
|
if (previousChar != ':' && previousChar != '!' )
|
|
|
|
|
return 11;
|
|
|
|
|
}
|
2009-10-19 10:59:46 +02:00
|
|
|
// Starting from the innermost block scope, collect declarations.
|
2009-10-16 16:26:28 +02:00
|
|
|
SeenHash seenHash;
|
|
|
|
|
blockRecursion(overview, innerMostScope, line, uninitializedVariables, &seenHash);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool getUninitializedVariables(const CPlusPlus::Snapshot &snapshot,
|
|
|
|
|
const QString &function,
|
|
|
|
|
const QString &file,
|
|
|
|
|
int line,
|
|
|
|
|
QStringList *uninitializedVariables)
|
|
|
|
|
{
|
|
|
|
|
const int rc = getUninitializedVariablesI(snapshot, function, file, line, uninitializedVariables);
|
|
|
|
|
if (debug) {
|
|
|
|
|
QString msg;
|
|
|
|
|
QTextStream str(&msg);
|
|
|
|
|
str << "getUninitializedVariables() " << function << ' ' << file << ':' << line
|
|
|
|
|
<< " returns (int) " << rc << " '"
|
|
|
|
|
<< uninitializedVariables->join(QString(QLatin1Char(','))) << '\'';
|
|
|
|
|
if (rc)
|
2009-12-07 10:54:27 +01:00
|
|
|
str << " of " << snapshot.size() << " documents";
|
2009-10-16 16:26:28 +02:00
|
|
|
qDebug() << msg;
|
|
|
|
|
}
|
|
|
|
|
return rc == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
QByteArray gdbQuoteTypes(const QByteArray &type)
|
2009-03-25 13:42:47 +01:00
|
|
|
{
|
|
|
|
|
// gdb does not understand sizeof(Core::IFile*).
|
|
|
|
|
// "sizeof('Core::IFile*')" is also not acceptable,
|
|
|
|
|
// it needs to be "sizeof('Core::IFile'*)"
|
|
|
|
|
//
|
|
|
|
|
// We never will have a perfect solution here (even if we had a full blown
|
|
|
|
|
// C++ parser as we do not have information on what is a type and what is
|
|
|
|
|
// a variable name. So "a<b>::c" could either be two comparisons of values
|
|
|
|
|
// 'a', 'b' and '::c', or a nested type 'c' in a template 'a<b>'. We
|
|
|
|
|
// assume here it is the latter.
|
|
|
|
|
//return type;
|
|
|
|
|
|
|
|
|
|
// (*('myns::QPointer<myns::QObject>*'*)0x684060)" is not acceptable
|
|
|
|
|
// (*('myns::QPointer<myns::QObject>'**)0x684060)" is acceptable
|
|
|
|
|
if (isPointerType(type))
|
2010-09-01 17:36:09 +02:00
|
|
|
return gdbQuoteTypes(stripPointerType(type)) + '*';
|
2009-03-25 13:42:47 +01:00
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
QByteArray accu;
|
|
|
|
|
QByteArray result;
|
2009-03-25 13:42:47 +01:00
|
|
|
int templateLevel = 0;
|
|
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
const char colon = ':';
|
|
|
|
|
const char singleQuote = '\'';
|
|
|
|
|
const char lessThan = '<';
|
|
|
|
|
const char greaterThan = '>';
|
2009-03-25 13:42:47 +01:00
|
|
|
for (int i = 0; i != type.size(); ++i) {
|
2010-09-01 17:36:09 +02:00
|
|
|
const char c = type.at(i);
|
|
|
|
|
if (isLetterOrNumber(c) || c == '_' || c == colon || c == ' ') {
|
2009-03-25 13:42:47 +01:00
|
|
|
accu += c;
|
|
|
|
|
} else if (c == lessThan) {
|
|
|
|
|
++templateLevel;
|
|
|
|
|
accu += c;
|
|
|
|
|
} else if (c == greaterThan) {
|
|
|
|
|
--templateLevel;
|
|
|
|
|
accu += c;
|
|
|
|
|
} else if (templateLevel > 0) {
|
|
|
|
|
accu += c;
|
|
|
|
|
} else {
|
|
|
|
|
if (accu.contains(colon) || accu.contains(lessThan))
|
|
|
|
|
result += singleQuote + accu + singleQuote;
|
|
|
|
|
else
|
|
|
|
|
result += accu;
|
|
|
|
|
accu.clear();
|
|
|
|
|
result += c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (accu.contains(colon) || accu.contains(lessThan))
|
|
|
|
|
result += singleQuote + accu + singleQuote;
|
|
|
|
|
else
|
|
|
|
|
result += accu;
|
|
|
|
|
//qDebug() << "GDB_QUOTING" << type << " TO " << result;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString extractTypeFromPTypeOutput(const QString &str)
|
|
|
|
|
{
|
|
|
|
|
int pos0 = str.indexOf(QLatin1Char('='));
|
|
|
|
|
int pos1 = str.indexOf(QLatin1Char('{'));
|
|
|
|
|
int pos2 = str.lastIndexOf(QLatin1Char('}'));
|
|
|
|
|
QString res = str;
|
|
|
|
|
if (pos0 != -1 && pos1 != -1 && pos2 != -1)
|
|
|
|
|
res = str.mid(pos0 + 2, pos1 - 1 - pos0)
|
|
|
|
|
+ QLatin1String(" ... ") + str.right(str.size() - pos2);
|
|
|
|
|
return res.simplified();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
bool isSymbianIntType(const QByteArray &type)
|
2009-09-15 18:21:40 +02:00
|
|
|
{
|
2010-09-01 17:36:09 +02:00
|
|
|
return type == "TInt" || type == "TBool";
|
2009-09-15 18:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-29 14:15:09 +02:00
|
|
|
// Utilities to decode string data returned by the dumper helpers.
|
|
|
|
|
|
2009-05-08 15:37:41 +02:00
|
|
|
QString quoteUnprintableLatin1(const QByteArray &ba)
|
2009-04-29 14:15:09 +02:00
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
char buf[10];
|
|
|
|
|
for (int i = 0, n = ba.size(); i != n; ++i) {
|
|
|
|
|
const unsigned char c = ba.at(i);
|
|
|
|
|
if (isprint(c)) {
|
|
|
|
|
res += c;
|
|
|
|
|
} else {
|
|
|
|
|
qsnprintf(buf, sizeof(buf) - 1, "\\%x", int(c));
|
|
|
|
|
res += buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-29 18:03:35 +02:00
|
|
|
QString decodeData(const QByteArray &ba, int encoding)
|
2009-04-29 14:15:09 +02:00
|
|
|
{
|
|
|
|
|
switch (encoding) {
|
2011-04-08 14:39:36 +02:00
|
|
|
case Unencoded8Bit: // 0
|
2009-04-29 18:03:35 +02:00
|
|
|
return quoteUnprintableLatin1(ba);
|
2011-04-08 14:39:36 +02:00
|
|
|
case Base64Encoded8BitWithQuotes: { // 1, used for QByteArray
|
2009-04-29 14:15:09 +02:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QString rc = doubleQuote;
|
2009-04-29 18:03:35 +02:00
|
|
|
rc += quoteUnprintableLatin1(QByteArray::fromBase64(ba));
|
2009-04-29 14:15:09 +02:00
|
|
|
rc += doubleQuote;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Base64Encoded16BitWithQuotes: { // 2, used for QString
|
2009-04-29 14:15:09 +02:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
2009-05-04 12:12:45 +02:00
|
|
|
const QByteArray decodedBa = QByteArray::fromBase64(ba);
|
2009-04-29 14:15:09 +02:00
|
|
|
QString rc = doubleQuote;
|
2009-10-12 09:30:28 +02:00
|
|
|
rc += QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2);
|
2009-04-29 14:15:09 +02:00
|
|
|
rc += doubleQuote;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Base64Encoded32BitWithQuotes: { // 3
|
2009-05-04 12:12:45 +02:00
|
|
|
const QByteArray decodedBa = QByteArray::fromBase64(ba);
|
2009-04-29 14:15:09 +02:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QString rc = doubleQuote;
|
2009-10-12 09:30:28 +02:00
|
|
|
rc += QString::fromUcs4(reinterpret_cast<const uint *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 4);
|
2009-04-29 14:15:09 +02:00
|
|
|
rc += doubleQuote;
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Base64Encoded16Bit: { // 4, without quotes (see 2)
|
2009-05-04 12:12:45 +02:00
|
|
|
const QByteArray decodedBa = QByteArray::fromBase64(ba);
|
2009-10-12 09:30:28 +02:00
|
|
|
return QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2);
|
2009-04-29 14:15:09 +02:00
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Base64Encoded8Bit: { // 5, without quotes (see 1)
|
2009-07-01 14:15:10 +02:00
|
|
|
return quoteUnprintableLatin1(QByteArray::fromBase64(ba));
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex2EncodedLatin1: { // 6, %02x encoded 8 bit Latin1 data
|
2009-10-21 16:41:18 +02:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
|
|
|
|
return doubleQuote + QString::fromLatin1(decodedBa) + doubleQuote;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex4EncodedLittleEndian: { // 7, %04x encoded 16 bit data
|
2009-10-15 13:57:51 +02:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
2009-10-12 09:30:28 +02:00
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
2009-10-12 15:22:11 +02:00
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
2009-10-15 13:57:51 +02:00
|
|
|
return doubleQuote + QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2) + doubleQuote;
|
2009-10-12 09:30:28 +02:00
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex8EncodedLittleEndian: { // 8, %08x encoded 32 bit data
|
2010-03-05 11:10:58 +01:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
|
|
|
|
return doubleQuote + QString::fromUcs4(reinterpret_cast<const uint *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 4) + doubleQuote;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex2EncodedUtf8: { // 9, %02x encoded 8 bit Utf-8 data
|
2010-03-11 18:55:52 +01:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
|
|
|
|
return doubleQuote + QString::fromUtf8(decodedBa) + doubleQuote;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex8EncodedBigEndian: { // 10, %08x encoded 32 bit data
|
2010-03-11 18:55:52 +01:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
for (int i = 0; i < decodedBa.size(); i += 4) {
|
|
|
|
|
char c = decodedBa.at(i);
|
|
|
|
|
decodedBa[i] = decodedBa.at(i + 3);
|
|
|
|
|
decodedBa[i + 3] = c;
|
|
|
|
|
c = decodedBa.at(i + 1);
|
|
|
|
|
decodedBa[i + 1] = decodedBa.at(i + 2);
|
|
|
|
|
decodedBa[i + 2] = c;
|
|
|
|
|
}
|
|
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
|
|
|
|
return doubleQuote + QString::fromUcs4(reinterpret_cast<const uint *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 4) + doubleQuote;
|
|
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex4EncodedBigEndian: { // 11, %04x encoded 16 bit data
|
2010-03-11 18:55:52 +01:00
|
|
|
const QChar doubleQuote(QLatin1Char('"'));
|
|
|
|
|
QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
for (int i = 0; i < decodedBa.size(); i += 2) {
|
|
|
|
|
char c = decodedBa.at(i);
|
|
|
|
|
decodedBa[i] = decodedBa.at(i + 1);
|
|
|
|
|
decodedBa[i + 1] = c;
|
|
|
|
|
}
|
|
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
2010-07-09 11:00:20 +02:00
|
|
|
return doubleQuote + QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2) + doubleQuote;
|
2010-03-11 18:55:52 +01:00
|
|
|
}
|
2011-04-08 14:39:36 +02:00
|
|
|
case Hex4EncodedLittleEndianWithoutQuotes: { // 12, see 7, without quotes
|
2010-09-13 12:37:30 +02:00
|
|
|
const QByteArray decodedBa = QByteArray::fromHex(ba);
|
|
|
|
|
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
|
|
|
|
|
return QString::fromUtf16(reinterpret_cast<const ushort *>
|
|
|
|
|
(decodedBa.data()), decodedBa.size() / 2);
|
|
|
|
|
}
|
2009-04-29 14:15:09 +02:00
|
|
|
}
|
2009-10-21 16:41:18 +02:00
|
|
|
qDebug() << "ENCODING ERROR: " << encoding;
|
2009-04-29 14:15:09 +02:00
|
|
|
return QCoreApplication::translate("Debugger", "<Encoding error>");
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-14 14:29:37 +02:00
|
|
|
// Editor tooltip support
|
|
|
|
|
bool isCppEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
2010-08-27 16:36:35 +02:00
|
|
|
using namespace CppTools::Constants;
|
|
|
|
|
const Core::IFile *file = editor->file();
|
|
|
|
|
if (!file)
|
|
|
|
|
return false;
|
|
|
|
|
const QByteArray mimeType = file->mimeType().toLatin1();
|
|
|
|
|
return mimeType == C_SOURCE_MIMETYPE
|
|
|
|
|
|| mimeType == CPP_SOURCE_MIMETYPE
|
|
|
|
|
|| mimeType == CPP_HEADER_MIMETYPE
|
|
|
|
|
|| mimeType == OBJECTIVE_CPP_SOURCE_MIMETYPE;
|
2009-05-14 14:29:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return the Cpp expression, and, if desired, the function
|
|
|
|
|
QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
|
|
|
|
int *line, int *column, QString *function /* = 0 */)
|
|
|
|
|
{
|
2010-08-27 16:36:35 +02:00
|
|
|
using namespace CppTools;
|
2010-12-03 13:49:35 +01:00
|
|
|
using namespace CPlusPlus;
|
2009-05-14 14:29:37 +02:00
|
|
|
*line = *column = 0;
|
|
|
|
|
if (function)
|
|
|
|
|
function->clear();
|
|
|
|
|
|
|
|
|
|
const QPlainTextEdit *plaintext = qobject_cast<QPlainTextEdit*>(editor->widget());
|
|
|
|
|
if (!plaintext)
|
2010-09-01 17:36:09 +02:00
|
|
|
return QByteArray();
|
2009-05-14 14:29:37 +02:00
|
|
|
|
|
|
|
|
QString expr = plaintext->textCursor().selectedText();
|
2011-01-04 18:50:18 +01:00
|
|
|
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
|
2010-06-07 13:06:21 +02:00
|
|
|
if (expr.isEmpty() && modelManager) {
|
2009-05-14 14:29:37 +02:00
|
|
|
QTextCursor tc(plaintext->document());
|
|
|
|
|
tc.setPosition(pos);
|
|
|
|
|
|
|
|
|
|
const QChar ch = editor->characterAt(pos);
|
|
|
|
|
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
|
|
|
|
tc.movePosition(QTextCursor::EndOfWord);
|
|
|
|
|
|
|
|
|
|
// Fetch the expression's code.
|
2010-06-29 17:47:59 +02:00
|
|
|
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
|
2009-05-14 14:29:37 +02:00
|
|
|
expr = expressionUnderCursor(tc);
|
2010-06-15 10:44:07 +02:00
|
|
|
*column = tc.positionInBlock();
|
2009-05-14 14:29:37 +02:00
|
|
|
*line = tc.blockNumber();
|
|
|
|
|
} else {
|
|
|
|
|
const QTextCursor tc = plaintext->textCursor();
|
2010-06-15 10:44:07 +02:00
|
|
|
*column = tc.positionInBlock();
|
2009-05-14 14:29:37 +02:00
|
|
|
*line = tc.blockNumber();
|
2009-07-03 13:56:27 +02:00
|
|
|
}
|
2009-05-14 14:29:37 +02:00
|
|
|
|
|
|
|
|
if (function && !expr.isEmpty())
|
|
|
|
|
if (const Core::IFile *file = editor->file())
|
2010-06-07 13:06:21 +02:00
|
|
|
if (modelManager)
|
2010-08-27 16:36:35 +02:00
|
|
|
*function = AbstractEditorSupport::functionAt(modelManager,
|
|
|
|
|
file->fileName(), *line, *column);
|
2009-05-14 14:29:37 +02:00
|
|
|
|
2010-09-01 17:36:09 +02:00
|
|
|
return expr.toUtf8();
|
2009-05-14 14:29:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-27 16:36:35 +02:00
|
|
|
|
2010-04-26 18:54:08 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// GdbMi interaction
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
void setWatchDataValue(WatchData &data, const GdbMi &item)
|
|
|
|
|
{
|
|
|
|
|
GdbMi value = item.findChild("value");
|
|
|
|
|
if (value.isValid()) {
|
|
|
|
|
int encoding = item.findChild("valueencoded").data().toInt();
|
|
|
|
|
data.setValue(decodeData(value.data(), encoding));
|
|
|
|
|
} else {
|
|
|
|
|
data.setValueNeeded();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataValueToolTip(WatchData &data, const GdbMi &mi,
|
|
|
|
|
int encoding)
|
|
|
|
|
{
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.setValueToolTip(decodeData(mi.data(), encoding));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataChildCount(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.setHasChildren(mi.data().toInt() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataValueEnabled(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
if (mi.data() == "true")
|
|
|
|
|
data.valueEnabled = true;
|
|
|
|
|
else if (mi.data() == "false")
|
|
|
|
|
data.valueEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataValueEditable(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
if (mi.data() == "true")
|
|
|
|
|
data.valueEditable = true;
|
|
|
|
|
else if (mi.data() == "false")
|
|
|
|
|
data.valueEditable = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataExpression(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.exp = mi.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataAddress(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
setWatchDataAddressHelper(data, mi.data());
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 18:39:56 +02:00
|
|
|
void setWatchDataOrigAddress(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
data.origAddress = mi.data().toULongLong(0, 16);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 16:15:03 +02:00
|
|
|
void setWatchDataSize(WatchData &data, const GdbMi &mi)
|
|
|
|
|
{
|
|
|
|
|
if (mi.isValid()) {
|
|
|
|
|
bool ok = false;
|
|
|
|
|
const unsigned size = mi.data().toUInt(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
data.size = size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 18:54:08 +02:00
|
|
|
void setWatchDataAddressHelper(WatchData &data, const QByteArray &addr)
|
|
|
|
|
{
|
2010-09-22 11:19:35 +02:00
|
|
|
if (addr.startsWith("0x")) { // Item model dumpers pull tricks
|
|
|
|
|
data.setHexAddress(addr);
|
|
|
|
|
} else {
|
|
|
|
|
data.dumperFlags = addr;
|
|
|
|
|
}
|
|
|
|
|
if (data.exp.isEmpty() && !data.dumperFlags.startsWith('$'))
|
|
|
|
|
data.exp = "*(" + gdbQuoteTypes(data.type) + "*)" +data.hexAddress();
|
2010-04-26 18:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find the "type" and "displayedtype" children of root and set up type.
|
|
|
|
|
void setWatchDataType(WatchData &data, const GdbMi &item)
|
|
|
|
|
{
|
|
|
|
|
if (item.isValid())
|
2010-09-01 17:36:09 +02:00
|
|
|
data.setType(item.data());
|
2010-04-26 18:54:08 +02:00
|
|
|
else if (data.type.isEmpty())
|
|
|
|
|
data.setTypeNeeded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setWatchDataDisplayedType(WatchData &data, const GdbMi &item)
|
|
|
|
|
{
|
|
|
|
|
if (item.isValid())
|
|
|
|
|
data.displayedType = _(item.data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void parseWatchData(const QSet<QByteArray> &expandedINames,
|
2010-09-23 11:15:56 +02:00
|
|
|
const WatchData &data0, const GdbMi &item,
|
2010-10-08 14:55:57 +02:00
|
|
|
QList<WatchData> *list)
|
2010-04-26 18:54:08 +02:00
|
|
|
{
|
|
|
|
|
//qDebug() << "HANDLE CHILDREN: " << data0.toString() << item.toString();
|
|
|
|
|
WatchData data = data0;
|
|
|
|
|
bool isExpanded = expandedINames.contains(data.iname);
|
|
|
|
|
if (!isExpanded)
|
|
|
|
|
data.setChildrenUnneeded();
|
|
|
|
|
|
|
|
|
|
GdbMi children = item.findChild("children");
|
|
|
|
|
if (children.isValid() || !isExpanded)
|
|
|
|
|
data.setChildrenUnneeded();
|
|
|
|
|
|
|
|
|
|
setWatchDataType(data, item.findChild("type"));
|
|
|
|
|
GdbMi mi = item.findChild("editvalue");
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.editvalue = mi.data();
|
|
|
|
|
mi = item.findChild("editformat");
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.editformat = mi.data().toInt();
|
|
|
|
|
mi = item.findChild("typeformats");
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.typeFormats = QString::fromUtf8(mi.data());
|
2011-03-01 17:04:36 +01:00
|
|
|
mi = item.findChild("bitpos");
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.bitpos = mi.data().toInt();
|
|
|
|
|
mi = item.findChild("bitsize");
|
|
|
|
|
if (mi.isValid())
|
|
|
|
|
data.bitsize = mi.data().toInt();
|
2010-04-26 18:54:08 +02:00
|
|
|
|
|
|
|
|
setWatchDataValue(data, item);
|
|
|
|
|
setWatchDataAddress(data, item.findChild("addr"));
|
2011-04-06 18:39:56 +02:00
|
|
|
setWatchDataOrigAddress(data, item.findChild("origaddr"));
|
2011-04-04 16:15:03 +02:00
|
|
|
setWatchDataSize(data, item.findChild("size"));
|
2010-04-26 18:54:08 +02:00
|
|
|
setWatchDataExpression(data, item.findChild("exp"));
|
|
|
|
|
setWatchDataValueEnabled(data, item.findChild("valueenabled"));
|
|
|
|
|
setWatchDataValueEditable(data, item.findChild("valueeditable"));
|
|
|
|
|
setWatchDataChildCount(data, item.findChild("numchild"));
|
|
|
|
|
//qDebug() << "\nAPPEND TO LIST: " << data.toString() << "\n";
|
|
|
|
|
list->append(data);
|
|
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
qulonglong addressBase = item.findChild("addrbase").data().toULongLong(&ok, 0);
|
|
|
|
|
qulonglong addressStep = item.findChild("addrstep").data().toULongLong();
|
|
|
|
|
|
|
|
|
|
// Try not to repeat data too often.
|
|
|
|
|
WatchData childtemplate;
|
|
|
|
|
setWatchDataType(childtemplate, item.findChild("childtype"));
|
|
|
|
|
setWatchDataChildCount(childtemplate, item.findChild("childnumchild"));
|
|
|
|
|
//qDebug() << "CHILD TEMPLATE:" << childtemplate.toString();
|
|
|
|
|
|
2010-10-12 11:30:34 +02:00
|
|
|
for (int i = 0, n = children.children().size(); i != n; ++i) {
|
|
|
|
|
const GdbMi &child = children.children().at(i);
|
2010-04-26 18:54:08 +02:00
|
|
|
WatchData data1 = childtemplate;
|
2010-10-12 11:30:34 +02:00
|
|
|
data1.sortId = i;
|
2010-04-26 18:54:08 +02:00
|
|
|
GdbMi name = child.findChild("name");
|
|
|
|
|
if (name.isValid())
|
|
|
|
|
data1.name = _(name.data());
|
|
|
|
|
else
|
|
|
|
|
data1.name = QString::number(i);
|
|
|
|
|
GdbMi iname = child.findChild("iname");
|
2010-09-23 11:15:56 +02:00
|
|
|
if (iname.isValid()) {
|
2010-04-26 18:54:08 +02:00
|
|
|
data1.iname = iname.data();
|
2010-09-23 11:15:56 +02:00
|
|
|
} else {
|
|
|
|
|
data1.iname = data.iname;
|
|
|
|
|
data1.iname += '.';
|
|
|
|
|
data1.iname += data1.name.toLatin1();
|
|
|
|
|
}
|
2010-04-26 18:54:08 +02:00
|
|
|
if (!data1.name.isEmpty() && data1.name.at(0).isDigit())
|
|
|
|
|
data1.name = _c('[') + data1.name + _c(']');
|
|
|
|
|
if (addressStep) {
|
|
|
|
|
const QByteArray addr = "0x" + QByteArray::number(addressBase, 16);
|
|
|
|
|
setWatchDataAddressHelper(data1, addr);
|
|
|
|
|
addressBase += addressStep;
|
|
|
|
|
}
|
|
|
|
|
QByteArray key = child.findChild("key").data();
|
|
|
|
|
if (!key.isEmpty()) {
|
|
|
|
|
int encoding = child.findChild("keyencoded").data().toInt();
|
|
|
|
|
QString skey = decodeData(key, encoding);
|
|
|
|
|
if (skey.size() > 13) {
|
|
|
|
|
skey = skey.left(12);
|
|
|
|
|
skey += _("...");
|
|
|
|
|
}
|
|
|
|
|
//data1.name += " (" + skey + ")";
|
|
|
|
|
data1.name = skey;
|
|
|
|
|
}
|
2010-10-08 14:55:57 +02:00
|
|
|
parseWatchData(expandedINames, data1, child, list);
|
2010-04-26 18:54:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-05-05 10:22:44 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|