forked from qt-creator/qt-creator
Debugger: Use gdb's tooltip expression fixup for CDB and editor.
Factor out to watchutils. Change-Id: I8cf316be819d765dcea964ac6405bfa9b075de59 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -466,7 +466,7 @@ bool CdbEngine::setToolTipExpression(const QPoint &mousePos,
|
|||||||
int line;
|
int line;
|
||||||
int column;
|
int column;
|
||||||
DebuggerToolTipContext context = contextIn;
|
DebuggerToolTipContext context = contextIn;
|
||||||
QString exp = cppExpressionAt(editor, context.position, &line, &column, &context.function);
|
QString exp = fixCppExpression(cppExpressionAt(editor, context.position, &line, &column, &context.function));
|
||||||
// Are we in the current stack frame
|
// Are we in the current stack frame
|
||||||
if (context.function.isEmpty() || exp.isEmpty() || context.function != stackHandler()->currentFrame().function)
|
if (context.function.isEmpty() || exp.isEmpty() || context.function != stackHandler()->currentFrame().function)
|
||||||
return false;
|
return false;
|
||||||
|
@@ -1140,6 +1140,7 @@ public slots:
|
|||||||
int line, column;
|
int line, column;
|
||||||
exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
|
exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
|
||||||
}
|
}
|
||||||
|
exp = fixCppExpression(exp);
|
||||||
if (exp.isEmpty())
|
if (exp.isEmpty())
|
||||||
return;
|
return;
|
||||||
currentEngine()->watchHandler()->watchExpression(exp);
|
currentEngine()->watchHandler()->watchExpression(exp);
|
||||||
|
@@ -3890,48 +3890,12 @@ bool GdbEngine::setToolTipExpression(const QPoint &mousePos,
|
|||||||
|
|
||||||
DebuggerToolTipContext context = contextIn;
|
DebuggerToolTipContext context = contextIn;
|
||||||
int line, column;
|
int line, column;
|
||||||
QString exp = cppExpressionAt(editor, context.position, &line, &column, &context.function);
|
const QString exp = fixCppExpression(cppExpressionAt(editor, context.position, &line, &column, &context.function));
|
||||||
if (DebuggerToolTipManager::debug())
|
if (DebuggerToolTipManager::debug())
|
||||||
qDebug() << "GdbEngine::setToolTipExpression1 " << exp << context;
|
qDebug() << "GdbEngine::setToolTipExpression1 " << exp << context;
|
||||||
if (exp.isEmpty())
|
if (exp.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Extract the first identifier, everything else is considered
|
|
||||||
// too dangerous.
|
|
||||||
int pos1 = 0, pos2 = exp.size();
|
|
||||||
bool inId = false;
|
|
||||||
for (int i = 0; i != exp.size(); ++i) {
|
|
||||||
const QChar c = exp.at(i);
|
|
||||||
const bool isIdChar = c.isLetterOrNumber() || c.unicode() == '_';
|
|
||||||
if (inId && !isIdChar) {
|
|
||||||
pos2 = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!inId && isIdChar) {
|
|
||||||
inId = true;
|
|
||||||
pos1 = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exp = exp.mid(pos1, pos2 - pos1);
|
|
||||||
|
|
||||||
if (exp.isEmpty() || exp.startsWith(QLatin1Char('#')) || !hasLetterOrNumber(exp) || isKeyWord(exp))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (exp.startsWith(QLatin1Char('"')) && exp.endsWith(QLatin1Char('"')))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (exp.startsWith(QLatin1String("++")) || exp.startsWith(QLatin1String("--")))
|
|
||||||
exp = exp.mid(2);
|
|
||||||
|
|
||||||
if (exp.endsWith(QLatin1String("++")) || exp.endsWith(QLatin1String("--")))
|
|
||||||
exp = exp.mid(2);
|
|
||||||
|
|
||||||
if (exp.startsWith(QLatin1Char('<')) || exp.startsWith(QLatin1Char('[')))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (hasSideEffects(exp) || exp.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!m_toolTipContext.isNull() && m_toolTipContext->expression == exp) {
|
if (!m_toolTipContext.isNull() && m_toolTipContext->expression == exp) {
|
||||||
showToolTip();
|
showToolTip();
|
||||||
return true;
|
return true;
|
||||||
|
@@ -805,6 +805,49 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
|||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure an expression can be added as side-effect
|
||||||
|
// free debugger expression.
|
||||||
|
QString fixCppExpression(const QString &expIn)
|
||||||
|
{
|
||||||
|
QString exp = expIn;
|
||||||
|
// Extract the first identifier, everything else is considered
|
||||||
|
// too dangerous.
|
||||||
|
int pos1 = 0, pos2 = exp.size();
|
||||||
|
bool inId = false;
|
||||||
|
for (int i = 0; i != exp.size(); ++i) {
|
||||||
|
const QChar c = exp.at(i);
|
||||||
|
const bool isIdChar = c.isLetterOrNumber() || c.unicode() == '_';
|
||||||
|
if (inId && !isIdChar) {
|
||||||
|
pos2 = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!inId && isIdChar) {
|
||||||
|
inId = true;
|
||||||
|
pos1 = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exp = exp.mid(pos1, pos2 - pos1);
|
||||||
|
|
||||||
|
if (exp.isEmpty() || exp.startsWith(QLatin1Char('#')) || !hasLetterOrNumber(exp) || isKeyWord(exp))
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
if (exp.startsWith(QLatin1Char('"')) && exp.endsWith(QLatin1Char('"')))
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
if (exp.startsWith(QLatin1String("++")) || exp.startsWith(QLatin1String("--")))
|
||||||
|
exp.remove(0, 2);
|
||||||
|
|
||||||
|
if (exp.endsWith(QLatin1String("++")) || exp.endsWith(QLatin1String("--")))
|
||||||
|
exp.truncate(exp.size() - 2);
|
||||||
|
|
||||||
|
if (exp.startsWith(QLatin1Char('<')) || exp.startsWith(QLatin1Char('[')))
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
if (hasSideEffects(exp) || exp.isEmpty())
|
||||||
|
return QString();
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
QString cppFunctionAt(const QString &fileName, int line)
|
QString cppFunctionAt(const QString &fileName, int line)
|
||||||
{
|
{
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
@@ -105,6 +105,7 @@ QString quoteUnprintableLatin1(const QByteArray &ba);
|
|||||||
bool isCppEditor(Core::IEditor *editor);
|
bool isCppEditor(Core::IEditor *editor);
|
||||||
QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
||||||
int *line, int *column, QString *function = 0);
|
int *line, int *column, QString *function = 0);
|
||||||
|
QString fixCppExpression(const QString &exp);
|
||||||
QString cppFunctionAt(const QString &fileName, int line);
|
QString cppFunctionAt(const QString &fileName, int line);
|
||||||
// Decode string data as returned by the dumper helpers.
|
// Decode string data as returned by the dumper helpers.
|
||||||
QString decodeData(const QByteArray &baIn, int encoding);
|
QString decodeData(const QByteArray &baIn, int encoding);
|
||||||
|
Reference in New Issue
Block a user