From 429a26b3cd6fc481b319e6cfd2e8a481f3a80f92 Mon Sep 17 00:00:00 2001
From: hjk <hjk121@nokiamail.com>
Date: Tue, 26 Nov 2013 16:49:54 +0100
Subject: [PATCH] Debugger: Fix std::vector<bool> dumper for LLDB

Change-Id: I83788acb6cfa9a659482d64bead10dd27e71fade
Reviewed-by: hjk <hjk121@nokiamail.com>
---
 share/qtcreator/debugger/stdtypes.py | 16 +++++++++-------
 tests/auto/debugger/tst_dumpers.cpp  |  1 +
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/share/qtcreator/debugger/stdtypes.py b/share/qtcreator/debugger/stdtypes.py
index 588187e494a..973ecbd6295 100644
--- a/share/qtcreator/debugger/stdtypes.py
+++ b/share/qtcreator/debugger/stdtypes.py
@@ -513,16 +513,17 @@ def qdump__std__vector(d, value):
     impl = value["_M_impl"]
     type = d.templateArgument(value.type, 0)
     alloc = impl["_M_end_of_storage"]
-    isBool = str(type) == 'bool'
+    # The allocator case below is bogus, but that's what Apple
+    # LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
+    # produces.
+    isBool = str(type) == 'bool' or str(type) == 'std::allocator<bool>'
     if isBool:
         start = impl["_M_start"]["_M_p"]
         finish = impl["_M_finish"]["_M_p"]
         # FIXME: 8 is CHAR_BIT
-        storage = d.lookupType("unsigned long")
-        storagesize = storage.sizeof * 8
-        size = (finish - start) * storagesize
-        size += impl["_M_finish"]["_M_offset"]
-        size -= impl["_M_start"]["_M_offset"]
+        size = (int(finish) - int(start)) * 8
+        size += int(impl["_M_finish"]["_M_offset"])
+        size -= int(impl["_M_start"]["_M_offset"])
     else:
         start = impl["_M_start"]
         finish = impl["_M_finish"]
@@ -541,7 +542,8 @@ def qdump__std__vector(d, value):
             with Children(d, size, maxNumChild=10000, childType=type):
                 for i in d.childRange():
                     q = start + int(i / storagesize)
-                    d.putBoolItem(str(i), (q.dereference() >> (i % storagesize)) & 1)
+                    d.putBoolItem(str(i),
+                        (int(q.dereference()) >> (i % storagesize)) & 1)
         else:
             d.putArrayData(type, start, size)
 
diff --git a/tests/auto/debugger/tst_dumpers.cpp b/tests/auto/debugger/tst_dumpers.cpp
index b48602e7f64..90dbab7af1e 100644
--- a/tests/auto/debugger/tst_dumpers.cpp
+++ b/tests/auto/debugger/tst_dumpers.cpp
@@ -3115,6 +3115,7 @@ void tst_Dumpers::dumper_data()
                     "v.push_back(true);\n"
                     "v.push_back(false);\n"
                     "unused(&v);\n")
+                // Known issue: Clang produces "std::vector<std::allocator<bool>>
                % Check("v", "<5 items>", "std::vector<bool>")
                % Check("v.0", "[0]", "1", "bool")
                % Check("v.1", "[1]", "0", "bool")
-- 
GitLab