From eb021724dfe1653d2f00dc5d3474fa25bb1ee5aa Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 28 Jan 2009 12:15:40 +0100
Subject: [PATCH]     Fixes:    debugger: sort array and list indices
 numerically

---
 share/qtcreator/gdbmacros/gdbmacros.cpp | 42 ++++++++++++-------------
 src/plugins/debugger/debuggerplugin.cpp |  5 +--
 src/plugins/debugger/gdbengine.cpp      |  2 ++
 src/plugins/debugger/watchhandler.cpp   | 17 ++--------
 src/plugins/fakevim/fakevimhandler.cpp  |  1 +
 tests/manual/gdbdebugger/simple/app.cpp |  3 +-
 6 files changed, 29 insertions(+), 41 deletions(-)

diff --git a/share/qtcreator/gdbmacros/gdbmacros.cpp b/share/qtcreator/gdbmacros/gdbmacros.cpp
index 6a1385359fb..c70e3b75a43 100644
--- a/share/qtcreator/gdbmacros/gdbmacros.cpp
+++ b/share/qtcreator/gdbmacros/gdbmacros.cpp
@@ -839,7 +839,7 @@ static void qDumpQByteArray(QDumper &d)
             unsigned char u = (isprint(c) && c != '\'' && c != '"') ? c : '?';
             sprintf(buf, "%02x  (%u '%c')", c, c, u);
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             P(d, "value", buf);
             d.endHash();
         }
@@ -1104,14 +1104,14 @@ static void qDumpQHash(QDumper &d)
         while (node != end) {
             d.beginHash();
                 if (simpleKey) {
-                    P(d, "name", "[" << i << "]");
+                    P(d, "name", i);
                     qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
                     if (simpleValue)
                         qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
                     P(d, "type", valueType);
                     P(d, "addr", addOffset(node, valueOffset));
                 } else {
-                    P(d, "name", "[" << i << "]");
+                    P(d, "name", i);
                     //P(d, "exp", "*(char*)" << node);
                     P(d, "exp", "*('"NS"QHashNode<" << keyType << "," << valueType << " >'*)" << node);
                     P(d, "type", "'"NS"QHashNode<" << keyType << "," << valueType << " >'");
@@ -1215,7 +1215,7 @@ static void qDumpQList(QDumper &d)
         d << ",children=[";
         for (int i = 0; i != n; ++i) {
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             if (innerTypeIsPointer) {
                 void *p = ldata.d->array + i + pdata->begin;
                 if (p) {
@@ -1275,7 +1275,7 @@ static void qDumpQLinkedList(QDumper &d)
         const void *p = deref(ldata);
         for (int i = 0; i != n; ++i) {
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             const void *addr = addOffset(p, 2 * sizeof(void*));
             qDumpInnerValueOrPointer(d, d.innertype, stripped, addr);
             p = deref(p);
@@ -1414,7 +1414,7 @@ static void qDumpQMap(QDumper &d)
 
         while (node != end) {
             d.beginHash();
-                P(d, "name", "[" << i << "]");
+                P(d, "name", i);
                 if (simpleKey) {
                     P(d, "type", valueType);
                     qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
@@ -1660,7 +1660,7 @@ static void qDumpQObjectMethodList(QDumper &d)
             const QMetaMethod & method = mo->method(i);
             int mt = method.methodType();
             d.beginHash();
-            P(d, "name", "["  << i << "] " << mo->indexOfMethod(method.signature())
+            P(d, "name", i << " " << mo->indexOfMethod(method.signature())
                 << " " << method.signature());
             P(d, "value", (mt == QMetaMethod::Signal ? "<Signal>" : "<Slot>") << " (" << mt << ")");
             d.endHash();
@@ -1712,11 +1712,11 @@ static void qDumpQObjectSignal(QDumper &d)
         for (int i = 0; i != connList.size(); ++i) {
             const QObjectPrivate::Connection &conn = connList.at(i);
             d.beginHash();
-                P(d, "name", "[" << i << "] receiver");
+                P(d, "name", i << " receiver");
                 qDumpInnerValueHelper(d, NS"QObject *", conn.receiver);
             d.endHash();
             d.beginHash();
-                P(d, "name", "[" << i << "] slot");
+                P(d, "name", i << " slot");
                 P(d, "type", "");
                 if (conn.receiver) 
                     P(d, "value", conn.receiver->metaObject()->method(conn.method).signature());
@@ -1725,7 +1725,7 @@ static void qDumpQObjectSignal(QDumper &d)
                 P(d, "numchild", "0");
             d.endHash();
             d.beginHash();
-                P(d, "name", "[" << i << "] type");
+                P(d, "name", i << " type");
                 P(d, "type", "");
                 P(d, "value", "<" << qConnectionTypes[conn.method] << " connection>");
                 P(d, "numchild", "0");
@@ -1756,7 +1756,7 @@ static void qDumpQObjectSignalList(QDumper &d)
                 int k = mo->indexOfSignal(method.signature());
                 const QObjectPrivate::ConnectionList &connList = qConnectionList(ob, k);
                 d.beginHash();
-                P(d, "name", "[" << k << "]");
+                P(d, "name", k);
                 P(d, "value", method.signature());
                 P(d, "numchild", connList.size());
                 //P(d, "numchild", "1");
@@ -1796,17 +1796,17 @@ static void qDumpQObjectSlot(QDumper &d)
                     const QMetaMethod & method =
                         sender.sender->metaObject()->method(sender.signal);
                     d.beginHash();
-                        P(d, "name", "[" << s << "] sender");
+                        P(d, "name", s << " sender");
                         qDumpInnerValueHelper(d, NS"QObject *", sender.sender);
                     d.endHash();
                     d.beginHash();
-                        P(d, "name", "[" << s << "] signal");
+                        P(d, "name", s << " signal");
                         P(d, "type", "");
                         P(d, "value", method.signature());
                         P(d, "numchild", "0");
                     d.endHash();
                     d.beginHash();
-                        P(d, "name", "[" << s << "] type");
+                        P(d, "name", s << " type");
                         P(d, "type", "");
                         P(d, "value", "<" << qConnectionTypes[conn.method] << " connection>");
                         P(d, "numchild", "0");
@@ -1843,7 +1843,7 @@ static void qDumpQObjectSlotList(QDumper &d)
             if (method.methodType() == QMetaMethod::Slot) {
                 d.beginHash();
                 int k = mo->indexOfSlot(method.signature());
-                P(d, "name", "[" << k << "]");
+                P(d, "name", k);
                 P(d, "value", method.signature());
 
                 // count senders. expensive...
@@ -1911,7 +1911,7 @@ static void qDumpQSet(QDumper &d)
         for (int bucket = 0; bucket != hd->numBuckets && i <= 10000; ++bucket) {
             for (node = hd->buckets[bucket]; node->next; node = node->next) {
                 d.beginHash();
-                P(d, "name", "[" << i << "]");
+                P(d, "name", i);
                 P(d, "type", d.innertype);
                 P(d, "exp", "(('"NS"QHashNode<" << d.innertype
                     << ","NS"QHashDummyValue>'*)"
@@ -1970,7 +1970,7 @@ static void qDumpQStringList(QDumper &d)
         d << ",children=[";
         for (int i = 0; i != n; ++i) {
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             P(d, "value", list[i]);
             P(d, "valueencoded", "1");
             d.endHash();
@@ -2108,7 +2108,7 @@ static void qDumpQVector(QDumper &d)
         d << ",children=[";
         for (int i = 0; i != n; ++i) {
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             qDumpInnerValueOrPointer(d, d.innertype, stripped,
                 addOffset(v, i * innersize + typeddatasize));
             d.endHash();
@@ -2156,7 +2156,7 @@ static void qDumpStdList(QDumper &d)
         it = list.begin();
         for (int i = 0; i < 1000 && it != list.end(); ++i, ++it) {
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             qDumpInnerValueOrPointer(d, d.innertype, stripped, it.operator->());
             d.endHash();
         }
@@ -2218,7 +2218,7 @@ static void qDumpStdMap(QDumper &d)
                 d.endHash();
             } else {
                 d.beginHash();
-                P(d, "name", "[" << i << "]");
+                P(d, "name", i);
                 P(d, "addr", it.operator->());
                 P(d, "type", pairType);
                 d.endHash();
@@ -2305,7 +2305,7 @@ static void qDumpStdVector(QDumper &d)
         d << ",children=[";
         for (int i = 0; i != n; ++i) {
             d.beginHash();
-            P(d, "name", "[" << i << "]");
+            P(d, "name", i);
             qDumpInnerValueOrPointer(d, d.innertype, stripped,
                 addOffset(v->start, i * innersize));
             d.endHash();
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index f8bb4a86b75..3f9cfc6caaa 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -565,10 +565,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *error_mes
     connect(resetToSimpleAction, SIGNAL(triggered()),
         m_manager, SLOT(setSimpleDockWidgetArrangement()));
 
-
-    m_generalOptionPage = 0;
-
-    // FIXME:
+   // FIXME:
     m_generalOptionPage = new GdbOptionPage(this);
     addObject(m_generalOptionPage);
 
diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp
index 14ad290a195..c559bcb2c1c 100644
--- a/src/plugins/debugger/gdbengine.cpp
+++ b/src/plugins/debugger/gdbengine.cpp
@@ -3548,6 +3548,8 @@ void GdbEngine::handleDumpCustomValue2(const GdbResultRecord &record,
         WatchData data1 = childtemplate;
         data1.name = item.findChild("name").data();
         data1.iname = data.iname + "." + data1.name;
+        if (!data1.name.isEmpty() && data1.name.at(0).isDigit())
+            data1.name = '[' + data1.name + ']';
         //qDebug() << "NAMEENCODED: " << item.findChild("nameencoded").data()
         //    << item.findChild("nameencoded").data()[1];
         if (item.findChild("nameencoded").data()[0] == '1')
diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index b2c43b28f64..a00b7fad7ce 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -255,7 +255,6 @@ QString WatchData::toString() const
     return res;
 }
 
-
 static bool iNameSorter(const WatchData &d1, const WatchData &d2)
 {
     if (d1.level != d2.level)
@@ -265,19 +264,9 @@ static bool iNameSorter(const WatchData &d1, const WatchData &d2)
         QString name1 = d1.iname.section('.', level, level);
         QString name2 = d2.iname.section('.', level, level);
         //MODEL_DEBUG(" SORT: " << name1 << name2 << (name1 < name2));
-
-        if (name1 != name2) {
-            // This formerly used inames. in this case 'lastIndexOf' probably
-            // makes more sense.
-            if (name1.startsWith('[') && name2.startsWith('[')) {
-                return name1.mid(1, name1.indexOf(']') - 1).toInt()
-                     < name2.mid(1, name2.indexOf(']') - 1).toInt();
-                // numbers should be sorted according to their numerical value
-                //int pos = d1.name.lastIndexOf('.');
-                //if (pos != -1 && pos + 1 != d1.name.size() && d1.name.at(pos + 1).isDigit())
-                //    return d1.name.size() < d2.name.size();
-                // fall through
-            }
+        if (name1 != name2 && !name1.isEmpty() && !name2.isEmpty()) {
+            if (name1.at(0).isDigit() && name2.at(0).isDigit())
+                return name1.toInt() < name2.toInt();
             return name1 < name2;
         }
     }
diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 26e127b9428..e23ba991fb0 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -437,6 +437,7 @@ void FakeVimHandler::Private::setupWidget()
         m_plaintextedit->setLineWrapMode(QPlainTextEdit::NoWrap);
     }
     m_wasReadOnly = EDITOR(isReadOnly());
+    //EDITOR(setReadOnly(true)); 
     showBlackMessage("vi emulation mode.");
     updateMiniBuffer();
 }
diff --git a/tests/manual/gdbdebugger/simple/app.cpp b/tests/manual/gdbdebugger/simple/app.cpp
index 442e0e23d1a..98fa2111dc9 100644
--- a/tests/manual/gdbdebugger/simple/app.cpp
+++ b/tests/manual/gdbdebugger/simple/app.cpp
@@ -244,7 +244,6 @@ void testQLinkedList()
     f.append(Foo(1));
     f.append(Foo(2));
 #endif
-
     QLinkedList<std::string> v;
     v.push_back("aa");
     v.push_back("bb");
@@ -258,7 +257,7 @@ void testQList()
     QList<int> li;
     QList<uint> lu;
 
-    for (int i = 0; i != 3; ++i) {
+    for (int i = 0; i != 30; ++i) {
         li.append(i);
     }
     li.append(101);
-- 
GitLab