From ffbfa363d625343cd430c5bf5758c1335efbff8f Mon Sep 17 00:00:00 2001
From: Christian Stenger <christian.stenger@theqtcompany.com>
Date: Tue, 27 Jan 2015 09:35:53 +0100
Subject: [PATCH] Dumper: Fix failing GDB startup when using MinGW

Task-number: QTCREATORBUG-13892

Change-Id: Ia843cf4d88c574013e67cacaa8484b52fdbd4b8a
Signed-off-by: Christian Stenger <christian.stenger@theqtcompany.com>
---
 share/qtcreator/debugger/dumper.py | 108 +++++++++++++++++++------------------
 1 file changed, 57 insertions(+), 51 deletions(-)

diff --git a/share/qtcreator/debugger/dumper.py b/share/qtcreator/debugger/dumper.py
index 8622bbf..33c5785 100644
--- a/share/qtcreator/debugger/dumper.py
+++ b/share/qtcreator/debugger/dumper.py
@@ -33,8 +33,13 @@ import struct
 import sys
 import base64
 import re
-import subprocess
 import time
+try:
+    import subprocess
+    hasSubprocess = True
+except:
+    hasSubprocess = False
+    hasPlot = False
 
 if sys.version_info[0] >= 3:
     xrange = range
@@ -77,63 +82,64 @@ SeparateUtf8StringFormat \
 #
 # matplot based display for array-like structures.
 #
-try:
-    # FIXME: That might not be the one we want.
-    pythonExecutable = sys.executable
-    subprocess.check_call([pythonExecutable, '-c', 'import matplotlib'])
-    hasPlot = True
-except:
-    hasPlot = False
-
-
-matplotFigure = {}
-matplotCount = 0
-
-devNull = open(os.devnull)
-matplotProc = subprocess.Popen(args=[pythonExecutable, "-i"],
-            bufsize=0, stdin=subprocess.PIPE, stdout=devNull, stderr=devNull)
+if hasSubprocess:
+    try:
+        # FIXME: That might not be the one we want.
+        pythonExecutable = sys.executable
+        subprocess.check_call([pythonExecutable, '-c', 'import matplotlib'])
+        hasPlot = True
+    except:
+        hasPlot = False
 
-matplotProc.stdin.write(b"import sys\n")
-matplotProc.stdin.write(b"sys.ps1=''\n")
-matplotProc.stdin.write(b"from matplotlib import pyplot\n")
-matplotProc.stdin.write(b"import time\n")
-matplotProc.stdin.write(b"pyplot.ion()\n")
-matplotProc.stdin.flush()
+if hasPlot:
+    matplotFigure = {}
+    matplotCount = 0
 
-def matplotSend(iname, show, data):
-    global matplotFigure
-    global matplotCount
+    devNull = open(os.devnull)
+    matplotProc = subprocess.Popen(args=[pythonExecutable, "-i"],
+                bufsize=0, stdin=subprocess.PIPE, stdout=devNull, stderr=devNull)
 
-    def s(line):
-        matplotProc.stdin.write(line.encode("latin1"))
-        matplotProc.stdin.write(b"\n")
-        sys.stdout.flush()
-        matplotProc.stdin.flush()
+    matplotProc.stdin.write(b"import sys\n")
+    matplotProc.stdin.write(b"sys.ps1=''\n")
+    matplotProc.stdin.write(b"from matplotlib import pyplot\n")
+    matplotProc.stdin.write(b"import time\n")
+    matplotProc.stdin.write(b"pyplot.ion()\n")
+    matplotProc.stdin.flush()
 
-    if show:
-        s("pyplot.ion()")
-        if not iname in matplotFigure:
-            matplotCount += 1
-            matplotFigure[iname] = matplotCount
-        s("pyplot.figure(%s)" % matplotFigure[iname])
-        s("pyplot.suptitle('%s')" % iname)
-        s("data = %s" % data)
-        s("pyplot.plot([i for i in range(len(data))], data, 'b.')")
-        time.sleep(0.2)
-        s("pyplot.draw()")
-        matplotProc.stdin.flush()
-    else:
-        if iname in matplotFigure:
+    def matplotSend(iname, show, data):
+        global matplotFigure
+        global matplotCount
+
+        def s(line):
+            matplotProc.stdin.write(line.encode("latin1"))
+            matplotProc.stdin.write(b"\n")
+            sys.stdout.flush()
+            matplotProc.stdin.flush()
+
+        if show:
+            s("pyplot.ion()")
+            if not iname in matplotFigure:
+                matplotCount += 1
+                matplotFigure[iname] = matplotCount
             s("pyplot.figure(%s)" % matplotFigure[iname])
-            s("pyplot.close()")
-            del matplotFigure[iname]
+            s("pyplot.suptitle('%s')" % iname)
+            s("data = %s" % data)
+            s("pyplot.plot([i for i in range(len(data))], data, 'b.')")
+            time.sleep(0.2)
+            s("pyplot.draw()")
+            matplotProc.stdin.flush()
+        else:
+            if iname in matplotFigure:
+                s("pyplot.figure(%s)" % matplotFigure[iname])
+                s("pyplot.close()")
+                del matplotFigure[iname]
 
-    matplotProc.stdin.flush()
+        matplotProc.stdin.flush()
 
-def matplotQuit():
-    matplotProc.stdin.write(b"exit")
-    matplotProc.kill()
-    devNull.close()
+    def matplotQuit():
+        matplotProc.stdin.write(b"exit")
+        matplotProc.kill()
+        devNull.close()
 
 def arrayForms():
     global hasPlot
-- 
1.9.4

