From 6e17e7a3ab74b8d59bd2405991c52e09649b481b Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Tue, 14 Dec 2010 13:00:02 +0100
Subject: [PATCH] debugger: thread 0 is valid for cdb. so use -1 as 'any' value

---
 src/plugins/debugger/breakhandler.cpp         | 15 +++++++++++----
 src/plugins/debugger/breakhandler.h           |  3 +++
 src/plugins/debugger/breakpoint.cpp           |  2 +-
 src/plugins/debugger/breakwindow.cpp          | 12 ++++++++----
 src/plugins/debugger/cdb2/cdbparsehelpers.cpp |  2 +-
 src/plugins/debugger/gdb/gdbengine.cpp        |  2 +-
 6 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp
index f7bb60320b4..571517488e6 100644
--- a/src/plugins/debugger/breakhandler.cpp
+++ b/src/plugins/debugger/breakhandler.cpp
@@ -375,9 +375,16 @@ Qt::ItemFlags BreakHandler::flags(const QModelIndex &index) const
 //    }
 }
 
-static QString threadString(int spec)
+QString BreakHandler::displayFromThreadSpec(int spec)
 {
-    return spec == 0 ? BreakHandler::tr("(all)") : QString::number(spec);
+    return spec == -1 ? BreakHandler::tr("(all)") : QString::number(spec);
+}
+
+int BreakHandler::threadSpecFromDisplay(const QString &str)
+{
+    bool ok = false;
+    int result = str.toInt(&ok);
+    return ok ? result : -1;
 }
 
 QVariant BreakHandler::data(const QModelIndex &mi, int role) const
@@ -494,11 +501,11 @@ QVariant BreakHandler::data(const QModelIndex &mi, int role) const
             break;
         case 7:
             if (role == Qt::DisplayRole)
-                return threadString(orig ? data.threadSpec : response.threadSpec);
+                return displayFromThreadSpec(orig ? data.threadSpec : response.threadSpec);
             if (role == Qt::ToolTipRole)
                 return tr("Breakpoint will only be hit in the specified thread(s).");
             if (role == Qt::UserRole + 1)
-                return data.threadSpec;
+                return displayFromThreadSpec(data.threadSpec);
             break;
     }
     if (role == Qt::ToolTipRole)
diff --git a/src/plugins/debugger/breakhandler.h b/src/plugins/debugger/breakhandler.h
index 383e8b0c797..9e8c24bb093 100644
--- a/src/plugins/debugger/breakhandler.h
+++ b/src/plugins/debugger/breakhandler.h
@@ -149,6 +149,9 @@ public:
     void notifyBreakpointAdjusted(BreakpointId id,
             const BreakpointParameters &data);
 
+    static QString displayFromThreadSpec(int spec);
+    static int threadSpecFromDisplay(const QString &str);
+
 private:
     // QAbstractItemModel implementation.
     int columnCount(const QModelIndex &parent) const;
diff --git a/src/plugins/debugger/breakpoint.cpp b/src/plugins/debugger/breakpoint.cpp
index 0d510c02931..9c4d56b9e90 100644
--- a/src/plugins/debugger/breakpoint.cpp
+++ b/src/plugins/debugger/breakpoint.cpp
@@ -43,7 +43,7 @@ namespace Internal {
 
 BreakpointParameters::BreakpointParameters(BreakpointType t)
   : type(t), enabled(true), useFullPath(false),
-    ignoreCount(0), lineNumber(0), address(0), threadSpec(0)
+    ignoreCount(0), lineNumber(0), address(0), threadSpec(-1)
 {}
 
 bool BreakpointParameters::equals(const BreakpointParameters &rhs) const
diff --git a/src/plugins/debugger/breakwindow.cpp b/src/plugins/debugger/breakwindow.cpp
index 310578d5444..f9c8f851fab 100644
--- a/src/plugins/debugger/breakwindow.cpp
+++ b/src/plugins/debugger/breakwindow.cpp
@@ -141,7 +141,8 @@ void BreakpointDialog::setParameters(const BreakpointParameters &data)
     setParts(AllParts, data);
     m_ui.lineEditCondition->setText(QString::fromUtf8(data.condition));
     m_ui.lineEditIgnoreCount->setText(QString::number(data.ignoreCount));
-    m_ui.lineEditThreadSpec->setText(QString::number(data.threadSpec));
+    m_ui.lineEditThreadSpec->
+        setText(BreakHandler::displayFromThreadSpec(data.threadSpec));
 }
 
 BreakpointParameters BreakpointDialog::parameters() const
@@ -150,7 +151,8 @@ BreakpointParameters BreakpointDialog::parameters() const
     getParts(AllParts, &data);
     data.condition = m_ui.lineEditCondition->text().toUtf8();
     data.ignoreCount = m_ui.lineEditIgnoreCount->text().toInt();
-    data.threadSpec = m_ui.lineEditThreadSpec->text().toInt();
+    data.threadSpec =
+        BreakHandler::threadSpecFromDisplay(m_ui.lineEditThreadSpec->text());
     return data;
 }
 
@@ -564,7 +566,8 @@ void BreakWindow::editBreakpoints(const BreakpointIds &ids)
     BreakHandler *handler = breakHandler();
     const QString oldCondition = QString::fromLatin1(handler->condition(id));
     const QString oldIgnoreCount = QString::number(handler->ignoreCount(id));
-    const QString oldThreadSpec = QString::number(handler->threadSpec(id));
+    const QString oldThreadSpec =
+        BreakHandler::displayFromThreadSpec(handler->threadSpec(id));
 
     ui.lineEditCondition->setText(oldCondition);
     ui.lineEditIgnoreCount->setText(oldIgnoreCount);
@@ -584,7 +587,8 @@ void BreakWindow::editBreakpoints(const BreakpointIds &ids)
     foreach (const BreakpointId id, ids) {
         handler->setCondition(id, newCondition.toLatin1());
         handler->setIgnoreCount(id, newIgnoreCount.toInt());
-        handler->setThreadSpec(id, newThreadSpec.toInt());
+        handler->setThreadSpec(id,
+            BreakHandler::threadSpecFromDisplay(newThreadSpec));
     }
 }
 
diff --git a/src/plugins/debugger/cdb2/cdbparsehelpers.cpp b/src/plugins/debugger/cdb2/cdbparsehelpers.cpp
index 82444570fdd..78e56a35519 100644
--- a/src/plugins/debugger/cdb2/cdbparsehelpers.cpp
+++ b/src/plugins/debugger/cdb2/cdbparsehelpers.cpp
@@ -61,7 +61,7 @@ QByteArray cdbAddBreakpointCommand(const Debugger::Internal::BreakpointParameter
     QByteArray rc;
     ByteArrayInputStream str(rc);
 
-    if (bp.threadSpec > 0)
+    if (bp.threadSpec >= 0)
         str << '~' << bp.threadSpec << ' ';
 
     str << (bp.type == Debugger::Internal::Watchpoint ? "ba" : "bp");
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index a252132c656..d6e268bf548 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -2486,7 +2486,7 @@ void GdbEngine::insertBreakpoint(BreakpointId id)
     } else if (m_gdbVersion >= 70000) {
         int spec = handler->threadSpec(id);
         cmd = "-break-insert ";
-        if (spec)
+        if (spec >= 0)
             cmd += "-p " + QByteArray::number(spec);
         cmd += " -f ";
     } else if (m_gdbVersion >= 60800) {
-- 
GitLab