diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
index 8681624a0571f1b6acb0d670fc272aeddda42ad5..0eb01c21b1bd487f96eb5fec29781247a13412cc 100644
--- a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
+++ b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
@@ -455,7 +455,10 @@ void JSDebuggerAgent::stopped(bool becauseOfException, const QScriptValue& excep
                 functionName = QLatin1String("<global>");
             }
         }
-        backtrace.append(qMakePair(functionName, qMakePair( QUrl(info.fileName()).toLocalFile(), info.lineNumber() ) ) );
+        int lineNumber = info.lineNumber();
+        if (lineNumber == -1) // if the line number is unknown, fallback to the function line number
+            lineNumber = info.functionStartLineNumber();
+        backtrace.append(qMakePair(functionName, qMakePair( QUrl(info.fileName()).toLocalFile(), lineNumber ) ) );
     }
     QList<JSAgentWatchData> watches;
     foreach (const QString &expr, watchExpressions)