From 6da15db62c796de1cd1b01eb8976cdffeddeedf8 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Thu, 20 Oct 2011 10:45:59 +0200
Subject: [PATCH] Debugger: Prevent adding invalid breakpoints.

Check on session restore and add.
In particular, suppress watchpoints at 0x0,
which hang gdb.

Change-Id: I648f53a709fabdebe641e478f367f1354a315ab1
Reviewed-by: hjk <qthjk@ovi.com>
---
 src/plugins/debugger/breakhandler.cpp | 12 ++++++++++--
 src/plugins/debugger/breakpoint.cpp   | 27 +++++++++++++++++++++++++++
 src/plugins/debugger/breakpoint.h     |  1 +
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp
index 0bc771de6b6..e80b898aae2 100644
--- a/src/plugins/debugger/breakhandler.cpp
+++ b/src/plugins/debugger/breakhandler.cpp
@@ -396,7 +396,11 @@ void BreakHandler::loadBreakpoints()
         v = map.value(_("message"));
         if (v.isValid())
             data.message = v.toString();
-        appendBreakpoint(data);
+        if (data.isValid()) {
+            appendBreakpoint(data);
+        } else {
+            qWarning("Not restoring invalid breakpoint: %s", qPrintable(data.toString()));
+        }
     }
     //qDebug() << "LOADED BREAKPOINTS" << this << list.size();
 }
@@ -1036,7 +1040,11 @@ static int currentId = 0;
 
 void BreakHandler::appendBreakpoint(const BreakpointParameters &data)
 {
-    QTC_ASSERT(data.type != UnknownType, return);
+    if (!data.isValid()) {
+        qWarning("Not adding invalid breakpoint: %s", qPrintable(data.toString()));
+        return;
+    }
+
     BreakpointModelId id(++currentId);
     const int row = m_storage.size();
     beginInsertRows(QModelIndex(), row, row);
diff --git a/src/plugins/debugger/breakpoint.cpp b/src/plugins/debugger/breakpoint.cpp
index c61892c09bd..c0d93479774 100644
--- a/src/plugins/debugger/breakpoint.cpp
+++ b/src/plugins/debugger/breakpoint.cpp
@@ -220,6 +220,33 @@ BreakpointParts BreakpointParameters::differencesTo
     return parts;
 }
 
+bool BreakpointParameters::isValid() const
+{
+    switch (type) {
+    case Debugger::Internal::BreakpointByFileAndLine:
+        return !fileName.isEmpty() && lineNumber > 0;
+    case Debugger::Internal::BreakpointByFunction:
+        return !functionName.isEmpty();
+    case Debugger::Internal::WatchpointAtAddress:
+    case Debugger::Internal::BreakpointByAddress:
+        return address != 0;
+    case Debugger::Internal::BreakpointAtThrow:
+    case Debugger::Internal::BreakpointAtCatch:
+    case Debugger::Internal::BreakpointAtMain:
+    case Debugger::Internal::BreakpointAtFork:
+    case Debugger::Internal::BreakpointAtExec:
+    case Debugger::Internal::BreakpointAtSysCall:
+    case Debugger::Internal::BreakpointOnQmlSignalHandler:
+    case Debugger::Internal::BreakpointAtJavaScriptThrow:
+        break;
+    case Debugger::Internal::WatchpointAtExpression:
+        return !expression.isEmpty();
+    case Debugger::Internal::UnknownType:
+        return false;
+    }
+    return true;
+}
+
 bool BreakpointParameters::equals(const BreakpointParameters &rhs) const
 {
     return !differencesTo(rhs);
diff --git a/src/plugins/debugger/breakpoint.h b/src/plugins/debugger/breakpoint.h
index b1636be10c4..a04a718bf2a 100644
--- a/src/plugins/debugger/breakpoint.h
+++ b/src/plugins/debugger/breakpoint.h
@@ -203,6 +203,7 @@ class BreakpointParameters
 public:
     explicit BreakpointParameters(BreakpointType = UnknownType);
     BreakpointParts differencesTo(const BreakpointParameters &rhs) const;
+    bool isValid() const;
     bool equals(const BreakpointParameters &rhs) const;
     bool conditionsMatch(const QByteArray &other) const;
     bool isWatchpoint() const
-- 
GitLab