From 295800196e899c401b4798935c031ddda65e5627 Mon Sep 17 00:00:00 2001
From: Arvid Ephraim Picciani <arvid.picciani@nokia.com>
Date: Wed, 24 Nov 2010 16:57:40 +0100
Subject: [PATCH] Adapt Lldb to dissasembler changes

---
 src/plugins/debugger/debugger.pro             |  2 +
 src/plugins/debugger/debuggeragents.cpp       | 50 -----------
 src/plugins/debugger/debuggeragents.h         | 30 +------
 src/plugins/debugger/debuggerstreamops.cpp    | 41 +++++++++
 src/plugins/debugger/debuggerstreamops.h      |  5 ++
 src/plugins/debugger/disassemblerlines.cpp    | 86 +++++++++++++++++++
 src/plugins/debugger/disassemblerlines.h      | 71 +++++++++++++++
 src/plugins/debugger/lldb/guest/lldb          |  1 +
 .../debugger/lldb/guest/lldbengineguest.cpp   |  8 +-
 .../debugger/lldb/guest/qtcreator-lldb.pro    |  2 +
 src/plugins/debugger/lldb/ipcengineguest.cpp  |  2 +-
 src/plugins/debugger/lldb/ipcengineguest.h    |  3 +-
 src/plugins/debugger/lldb/ipcenginehost.cpp   | 11 +--
 13 files changed, 225 insertions(+), 87 deletions(-)
 create mode 100644 src/plugins/debugger/disassemblerlines.cpp
 create mode 100644 src/plugins/debugger/disassemblerlines.h
 create mode 160000 src/plugins/debugger/lldb/guest/lldb

diff --git a/src/plugins/debugger/debugger.pro b/src/plugins/debugger/debugger.pro
index 015480eacd1..e39691323e0 100644
--- a/src/plugins/debugger/debugger.pro
+++ b/src/plugins/debugger/debugger.pro
@@ -35,6 +35,7 @@ HEADERS += breakhandler.h \
     debuggerstringutils.h \
     debuggertooltip.h \
     debuggeruiswitcher.h \
+    disassemblerlines.h \
     logwindow.h \
     moduleshandler.h \
     moduleswindow.h \
@@ -73,6 +74,7 @@ SOURCES += breakhandler.cpp \
     debuggerstreamops.cpp \
     debuggertooltip.cpp \
     debuggeruiswitcher.cpp \
+    disassemblerlines.cpp \
     logwindow.cpp \
     moduleshandler.cpp \
     moduleswindow.cpp \
diff --git a/src/plugins/debugger/debuggeragents.cpp b/src/plugins/debugger/debuggeragents.cpp
index bff396217df..3d28e5bd44f 100644
--- a/src/plugins/debugger/debuggeragents.cpp
+++ b/src/plugins/debugger/debuggeragents.cpp
@@ -405,55 +405,5 @@ quint64 DisassemblerViewAgent::addressFromDisassemblyLine(const QString &line)
     return DisassemblerLine(line).address;
 }
 
-DisassemblerLine::DisassemblerLine(const QString &unparsed)
-{
-    // Mac gdb has an overflow reporting 64bit addresses causing the instruction
-    // to follow the last digit "0x000000013fff4810mov 1,1". Truncate here.
-    const int pos = qMin(unparsed.indexOf(QLatin1Char(' ')), 19);
-    if (pos < 0) {
-        address = 0;
-        data = unparsed;
-        return;
-    }
-    QString addr = unparsed.left(pos);
-    // MSVC 64bit: Remove 64bit separator 00000000`00a45000'.
-    if (addr.size() >= 9 && addr.at(8) == QLatin1Char('`'))
-        addr.remove(8, 1);
-
-    if (addr.endsWith(':')) // clang
-        addr.chop(1);
-    if (addr.startsWith(QLatin1String("0x")))
-        addr.remove(0, 2);
-    bool ok;
-    address = addr.toULongLong(&ok, 16);
-    if (address)
-        data = unparsed.mid(pos + 1);
-    else
-        data = unparsed;
-}
-
-int DisassemblerLines::lineForAddress(quint64 address) const
-{
-    return m_rowCache.value(address);
-}
-
-bool DisassemblerLines::coversAddress(quint64 address) const
-{
-    return m_rowCache.value(address) != 0;
-}
-
-void DisassemblerLines::appendComment(const QString &comment)
-{
-    DisassemblerLine dl;
-    dl.data = comment;
-    m_data.append(dl);
-}
-
-void DisassemblerLines::appendLine(const DisassemblerLine &dl)
-{
-    m_data.append(dl);
-    m_rowCache[dl.address] = m_data.size();
-}
-
 } // namespace Internal
 } // namespace Debugger
diff --git a/src/plugins/debugger/debuggeragents.h b/src/plugins/debugger/debuggeragents.h
index 57d3c02c4b5..968e4ca148b 100644
--- a/src/plugins/debugger/debuggeragents.h
+++ b/src/plugins/debugger/debuggeragents.h
@@ -35,6 +35,8 @@
 #include <QtCore/QPointer>
 #include <QtCore/QVector>
 
+#include "disassemblerlines.h"
+
 namespace Core {
 class IEditor;
 }
@@ -76,34 +78,6 @@ private:
     QPointer<Debugger::DebuggerEngine> m_engine;
 };
 
-class DisassemblerLine
-{
-public:
-    DisassemblerLine() : address(0) {}
-    DisassemblerLine(const QString &unparsed);
-
-    quint64 address;
-    QString data;
-};
-
-class DisassemblerLines
-{
-public:
-    DisassemblerLines() {}
-
-    bool coversAddress(quint64 address) const;
-    void appendLine(const DisassemblerLine &dl);
-    void appendComment(const QString &comment);
-    int size() const { return m_data.size(); }
-    const DisassemblerLine &at(int i) const { return m_data.at(i); }
-    int lineForAddress(quint64 address) const;
-
-private:
-    friend class DisassemblerViewAgent;
-    QVector<DisassemblerLine> m_data;
-    QHash<quint64, int> m_rowCache;
-};
-
 class DisassemblerViewAgent : public QObject
 {
     Q_OBJECT
diff --git a/src/plugins/debugger/debuggerstreamops.cpp b/src/plugins/debugger/debuggerstreamops.cpp
index 9312bb9172c..85c0438c705 100644
--- a/src/plugins/debugger/debuggerstreamops.cpp
+++ b/src/plugins/debugger/debuggerstreamops.cpp
@@ -242,6 +242,47 @@ QDataStream &operator>>(QDataStream &stream, WatchData &wd)
     return stream;
 }
 
+QDataStream &operator<<(QDataStream& stream, const DisassemblerLine &o)
+{
+    stream << o.address;
+    stream << o.data;
+    return stream;
+}
+
+QDataStream &operator>>(QDataStream& stream, DisassemblerLine &o)
+{
+    stream >> o.address;
+    stream >> o.data;
+    return stream;
+}
+
+QDataStream &operator<<(QDataStream& stream, const DisassemblerLines &o)
+{
+    stream << quint64(o.size());
+    for (int i = 0; i < o.size(); i++)
+    {
+        stream << o.at(i);
+    }
+    return stream;
+}
+
+QDataStream &operator>>(QDataStream& stream, DisassemblerLines &o)
+{
+    DisassemblerLines r;
+    quint64 count;
+    stream >> count;
+    for (quint64 i = 0; i < count; i++)
+    {
+        DisassemblerLine line;
+        stream >> line;
+        r.appendLine(line);
+    }
+    o = r;
+    return stream;
+}
+
+
+
 } // namespace Internal
 } // namespace Debugger
 
diff --git a/src/plugins/debugger/debuggerstreamops.h b/src/plugins/debugger/debuggerstreamops.h
index 067332fba8c..b7bc2a7d0d2 100644
--- a/src/plugins/debugger/debuggerstreamops.h
+++ b/src/plugins/debugger/debuggerstreamops.h
@@ -34,6 +34,7 @@
 #include "stackframe.h"
 #include "threaddata.h"
 #include "watchdata.h"
+#include "disassemblerlines.h"
 
 #include <QtCore/QDataStream>
 #include <QtCore/QVector>
@@ -55,6 +56,10 @@ QDataStream &operator<<(QDataStream& stream, const BreakpointResponse &data);
 QDataStream &operator>>(QDataStream& stream, BreakpointResponse &data);
 QDataStream &operator<<(QDataStream& stream, const WatchData &data);
 QDataStream &operator>>(QDataStream& stream, WatchData &data);
+QDataStream &operator<<(QDataStream& stream, const DisassemblerLine &o);
+QDataStream &operator>>(QDataStream& stream, DisassemblerLine &o);
+QDataStream &operator<<(QDataStream& stream, const DisassemblerLines &o);
+QDataStream &operator>>(QDataStream& stream, DisassemblerLines &o);
 
 } // namespace Internal
 } // namespace Debugger
diff --git a/src/plugins/debugger/disassemblerlines.cpp b/src/plugins/debugger/disassemblerlines.cpp
new file mode 100644
index 00000000000..75f315a9ac8
--- /dev/null
+++ b/src/plugins/debugger/disassemblerlines.cpp
@@ -0,0 +1,86 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "disassemblerlines.h"
+
+namespace Debugger {
+namespace Internal {
+
+DisassemblerLine::DisassemblerLine(const QString &unparsed)
+{
+    // Mac gdb has an overflow reporting 64bit addresses causing the instruction
+    // to follow the last digit "0x000000013fff4810mov 1,1". Truncate here.
+    const int pos = qMin(unparsed.indexOf(QLatin1Char(' ')), 19);
+    if (pos < 0) {
+        address = 0;
+        data = unparsed;
+        return;
+    }
+    QString addr = unparsed.left(pos);
+    // MSVC 64bit: Remove 64bit separator 00000000`00a45000'.
+    if (addr.size() >= 9 && addr.at(8) == QLatin1Char('`'))
+        addr.remove(8, 1);
+
+    if (addr.endsWith(':')) // clang
+        addr.chop(1);
+    if (addr.startsWith(QLatin1String("0x")))
+        addr.remove(0, 2);
+    bool ok;
+    address = addr.toULongLong(&ok, 16);
+    if (address)
+        data = unparsed.mid(pos + 1);
+    else
+        data = unparsed;
+}
+
+int DisassemblerLines::lineForAddress(quint64 address) const
+{
+    return m_rowCache.value(address);
+}
+
+bool DisassemblerLines::coversAddress(quint64 address) const
+{
+    return m_rowCache.value(address) != 0;
+}
+
+void DisassemblerLines::appendComment(const QString &comment)
+{
+    DisassemblerLine dl;
+    dl.data = comment;
+    m_data.append(dl);
+}
+
+void DisassemblerLines::appendLine(const DisassemblerLine &dl)
+{
+    m_data.append(dl);
+    m_rowCache[dl.address] = m_data.size();
+}
+
+} // namespace Internal
+} // namespace Debugger
diff --git a/src/plugins/debugger/disassemblerlines.h b/src/plugins/debugger/disassemblerlines.h
new file mode 100644
index 00000000000..33612ab0346
--- /dev/null
+++ b/src/plugins/debugger/disassemblerlines.h
@@ -0,0 +1,71 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef DEBUGGER_disassemblerlines_H
+#define DEBUGGER_disassemblerlines_H
+
+#include <QtCore/QString>
+#include <QtCore/QHash>
+#include <QtCore/QVector>
+
+namespace Debugger {
+namespace Internal {
+
+class DisassemblerLine
+{
+public:
+    DisassemblerLine() : address(0) {}
+    DisassemblerLine(const QString &unparsed);
+
+    quint64 address;
+    QString data;
+};
+
+class DisassemblerLines
+{
+public:
+    DisassemblerLines() {}
+
+    bool coversAddress(quint64 address) const;
+    void appendLine(const DisassemblerLine &dl);
+    void appendComment(const QString &comment);
+    int size() const { return m_data.size(); }
+    const DisassemblerLine &at(int i) const { return m_data.at(i); }
+    int lineForAddress(quint64 address) const;
+
+private:
+    friend class DisassemblerViewAgent;
+    QVector<DisassemblerLine> m_data;
+    QHash<quint64, int> m_rowCache;
+};
+
+}
+}
+
+#endif
diff --git a/src/plugins/debugger/lldb/guest/lldb b/src/plugins/debugger/lldb/guest/lldb
new file mode 160000
index 00000000000..d75343c3ae8
--- /dev/null
+++ b/src/plugins/debugger/lldb/guest/lldb
@@ -0,0 +1 @@
+Subproject commit d75343c3ae88438ae4dd7d8a7ad87108e9f28f30
diff --git a/src/plugins/debugger/lldb/guest/lldbengineguest.cpp b/src/plugins/debugger/lldb/guest/lldbengineguest.cpp
index dd92f29a596..4adeb22371e 100644
--- a/src/plugins/debugger/lldb/guest/lldbengineguest.cpp
+++ b/src/plugins/debugger/lldb/guest/lldbengineguest.cpp
@@ -376,8 +376,12 @@ void LLDBEngineGuest::disassemble(quint64 pc)
     for (uint j = 0; j < m_currentThread.GetNumFrames(); j++) {
         lldb::SBFrame fr = m_currentThread.GetFrameAtIndex(j);
         if (pc == fr.GetPCAddress().GetLoadAddress(*m_target)) {
-            disassembled(pc, QString::fromLocal8Bit(fr.Disassemble()));
-            return;
+            QString linesStr = QString::fromLocal8Bit(fr.Disassemble());
+            DisassemblerLines lines;
+            foreach (const QString &lineStr, linesStr.split(QLatin1Char('\n'))) {
+                lines.appendLine(DisassemblerLine(lineStr));
+            }
+            disassembled(pc, lines);
         }
     }
 }
diff --git a/src/plugins/debugger/lldb/guest/qtcreator-lldb.pro b/src/plugins/debugger/lldb/guest/qtcreator-lldb.pro
index f9d58469608..c885675ebc3 100644
--- a/src/plugins/debugger/lldb/guest/qtcreator-lldb.pro
+++ b/src/plugins/debugger/lldb/guest/qtcreator-lldb.pro
@@ -21,6 +21,7 @@ HEADERS += ../ipcengineguest.h \
             ../breakpoint.h \
             ../watchdata.h \
             ../stackframe.h \
+            ../disassemblerlines.h \
             lldbengineguest.h
 
 SOURCES +=  ../ipcengineguest.cpp \
@@ -28,6 +29,7 @@ SOURCES +=  ../ipcengineguest.cpp \
             ../breakpoint.cpp \
             ../watchdata.cpp \
             ../stackframe.cpp \
+            ../disassemblerlines.cpp \
             lldbengineguest.cpp \
             main.cpp
 
diff --git a/src/plugins/debugger/lldb/ipcengineguest.cpp b/src/plugins/debugger/lldb/ipcengineguest.cpp
index 3ce8b80d1db..deede1da34a 100644
--- a/src/plugins/debugger/lldb/ipcengineguest.cpp
+++ b/src/plugins/debugger/lldb/ipcengineguest.cpp
@@ -503,7 +503,7 @@ void IPCEngineGuest::listThreads(const Threads &threads)
     rpcCall(ListThreads, p);
 }
 
-void IPCEngineGuest::disassembled(quint64 pc, const QString &da)
+void IPCEngineGuest::disassembled(quint64 pc, const DisassemblerLines &da)
 {
     QByteArray p;
     {
diff --git a/src/plugins/debugger/lldb/ipcengineguest.h b/src/plugins/debugger/lldb/ipcengineguest.h
index 5d849691f7b..126ecc18810 100644
--- a/src/plugins/debugger/lldb/ipcengineguest.h
+++ b/src/plugins/debugger/lldb/ipcengineguest.h
@@ -32,6 +32,7 @@
 
 #include "breakhandler.h"
 #include "debuggerengine.h"
+#include "disassemblerlines.h"
 #include "stackhandler.h"
 #include "threadshandler.h"
 
@@ -152,7 +153,7 @@ public:
     void currentThreadChanged(qint64 token);
     void listFrames(const StackFrames &);
     void listThreads(const Threads &);
-    void disassembled(quint64 pc, const QString &da);
+    void disassembled(quint64 pc, const DisassemblerLines &da);
 
     void notifyAddBreakpointOk(BreakpointId id);
     void notifyAddBreakpointFailed(BreakpointId id);
diff --git a/src/plugins/debugger/lldb/ipcenginehost.cpp b/src/plugins/debugger/lldb/ipcenginehost.cpp
index 2c0ee3d1994..997be0d80f6 100644
--- a/src/plugins/debugger/lldb/ipcenginehost.cpp
+++ b/src/plugins/debugger/lldb/ipcenginehost.cpp
@@ -31,6 +31,7 @@
 #include "ipcengineguest.h"
 #include "breakhandler.h"
 #include "breakpoint.h"
+#include "disassemblerlines.h"
 #include "moduleshandler.h"
 #include "registerhandler.h"
 #include "stackhandler.h"
@@ -443,12 +444,12 @@ void IPCEngineHost::rpcCallback(quint64 f, QByteArray payload)
                 QDataStream s(payload);
                 SET_NATIVE_BYTE_ORDER(s);
                 quint64 pc;
-                QString da;
+                DisassemblerLines lines;
                 s >> pc;
-                s >> da;
-                //DisassemblerViewAgent *view = m_frameToDisassemblerAgent.take(pc);
-                //if (view)
-                //    view->setContents(da);
+                s >> lines;
+                DisassemblerViewAgent *view = m_frameToDisassemblerAgent.take(pc);
+                if (view)
+                    view->setContents(lines);
             }
             break;
         case IPCEngineGuest::UpdateWatchData:
-- 
GitLab