Commit e67e5837 authored by Friedemann Kleint's avatar Friedemann Kleint Committed by hjk

Debugger: Use gdb's tooltip expression fixup for CDB and editor.

Factor out to watchutils.

Change-Id: I8cf316be819d765dcea964ac6405bfa9b075de59
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 5fdb9f0d
......@@ -466,7 +466,7 @@ bool CdbEngine::setToolTipExpression(const QPoint &mousePos,
int line;
int column;
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
if (context.function.isEmpty() || exp.isEmpty() || context.function != stackHandler()->currentFrame().function)
return false;
......
......@@ -1140,6 +1140,7 @@ public slots:
int line, column;
exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
}
exp = fixCppExpression(exp);
if (exp.isEmpty())
return;
currentEngine()->watchHandler()->watchExpression(exp);
......
......@@ -3890,48 +3890,12 @@ bool GdbEngine::setToolTipExpression(const QPoint &mousePos,
DebuggerToolTipContext context = contextIn;
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())
qDebug() << "GdbEngine::setToolTipExpression1 " << exp << context;
if (exp.isEmpty())
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) {
showToolTip();
return true;
......
......@@ -805,6 +805,49 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
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)
{
using namespace CppTools;
......
......@@ -105,6 +105,7 @@ QString quoteUnprintableLatin1(const QByteArray &ba);
bool isCppEditor(Core::IEditor *editor);
QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
int *line, int *column, QString *function = 0);
QString fixCppExpression(const QString &exp);
QString cppFunctionAt(const QString &fileName, int line);
// Decode string data as returned by the dumper helpers.
QString decodeData(const QByteArray &baIn, int encoding);
......
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