From 2a0bb34911bfa2cdbb4f27f6aad0109f9543e45a Mon Sep 17 00:00:00 2001
From: hjk <qthjk@ovi.com>
Date: Wed, 9 Jan 2013 14:51:49 +0100
Subject: [PATCH] Debugger: split fixCppExpression into some common and some
 cdb part

Task-number: QTCREATORBUG-8446
Change-Id: I79abc7f75779db15bd8700c085b9cd57411bb2e1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
---
 src/plugins/debugger/debuggerconstants.h | 3 ++-
 src/plugins/debugger/debuggerplugin.cpp  | 5 ++++-
 src/plugins/debugger/gdb/gdbengine.cpp   | 1 +
 src/plugins/debugger/watchutils.cpp      | 7 ++++++-
 src/plugins/debugger/watchutils.h        | 1 +
 5 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/plugins/debugger/debuggerconstants.h b/src/plugins/debugger/debuggerconstants.h
index a068d36c4d3..06bada5c835 100644
--- a/src/plugins/debugger/debuggerconstants.h
+++ b/src/plugins/debugger/debuggerconstants.h
@@ -170,7 +170,8 @@ enum DebuggerCapabilities
     OperateByInstructionCapability = 0x400000,
     RunToLineCapability = 0x800000,
     MemoryAddressCapability = 0x1000000,
-    ShowModuleSectionsCapability = 0x200000
+    ShowModuleSectionsCapability = 0x200000,
+    WatchComplexExpressionsCapability = 0x400000 // Used to filter out challenges for cdb.
 };
 
 enum LogChannel
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index c3b7021bf95..f204b44862b 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -1166,7 +1166,10 @@ public slots:
             int line, column;
             exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
         }
-        exp = fixCppExpression(exp);
+        if (currentEngine()->hasCapability(WatchComplexExpressionsCapability))
+            exp = removeObviousSideEffects(exp);
+        else
+            exp = fixCppExpression(exp);
         if (exp.isEmpty())
             return;
         currentEngine()->watchHandler()->watchVariable(exp);
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 156e2fa5cd4..59741ba3051 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -2132,6 +2132,7 @@ bool GdbEngine::hasCapability(unsigned cap) const
         | CatchCapability
         | OperateByInstructionCapability
         | RunToLineCapability
+        | WatchComplexExpressionsCapability
         | MemoryAddressCapability))
         return true;
 
diff --git a/src/plugins/debugger/watchutils.cpp b/src/plugins/debugger/watchutils.cpp
index c46dd182a1d..41aa9aa20f1 100644
--- a/src/plugins/debugger/watchutils.cpp
+++ b/src/plugins/debugger/watchutils.cpp
@@ -820,7 +820,7 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
 // free debugger expression.
 QString fixCppExpression(const QString &expIn)
 {
-    QString exp = expIn;
+    QString exp = expIn.trimmed();;
     // Extract the first identifier, everything else is considered
     // too dangerous.
     int pos1 = 0, pos2 = exp.size();
@@ -838,7 +838,12 @@ QString fixCppExpression(const QString &expIn)
         }
     }
     exp = exp.mid(pos1, pos2 - pos1);
+    return removeObviousSideEffects(exp);
+}
 
+QString removeObviousSideEffects(const QString &expIn)
+{
+    QString exp = expIn.trimmed();
     if (exp.isEmpty() || exp.startsWith(QLatin1Char('#')) || !hasLetterOrNumber(exp) || isKeyWord(exp))
         return QString();
 
diff --git a/src/plugins/debugger/watchutils.h b/src/plugins/debugger/watchutils.h
index 5e0f2a4d8f3..87f72d17387 100644
--- a/src/plugins/debugger/watchutils.h
+++ b/src/plugins/debugger/watchutils.h
@@ -120,6 +120,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 removeObviousSideEffects(const QString &exp);
 QString fixCppExpression(const QString &exp);
 QString cppFunctionAt(const QString &fileName, int line);
 // Decode string data as returned by the dumper helpers.
-- 
GitLab