OSDN Git Service

lldb: fetch source from remote, if not locally valid
authorArvid Ephraim Picciani <arvid.picciani@nokia.com>
Wed, 1 Dec 2010 16:46:11 +0000 (17:46 +0100)
committerArvid Ephraim Picciani <arvid.picciani@nokia.com>
Wed, 1 Dec 2010 16:46:55 +0000 (17:46 +0100)
src/plugins/debugger/lldb/guest/lldbengineguest.cpp
src/plugins/debugger/lldb/guest/lldbengineguest.h
src/plugins/debugger/lldb/ipcengineguest.cpp
src/plugins/debugger/lldb/ipcengineguest.h
src/plugins/debugger/lldb/ipcenginehost.cpp
src/plugins/debugger/lldb/ipcenginehost.h

index 0283a6a..d1e0986 100644 (file)
@@ -397,6 +397,13 @@ void LldbEngineGuest::disassemble(quint64 pc)
         }
     }
 }
+void LldbEngineGuest::fetchFrameSource(qint64 frame)
+{
+    QFile f(m_frame_to_file.value(frame));
+    f.open(QFile::ReadOnly);
+    frameSourceFetched(frame, QFileInfo(m_frame_to_file.value(frame)).fileName()
+            , QString::fromLocal8Bit(f.readAll()));
+}
 
 void LldbEngineGuest::addBreakpoint(BreakpointId id,
         const Internal::BreakpointParameters &bp_)
@@ -459,6 +466,7 @@ void LldbEngineGuest::selectThread(qint64 token)
     DEBUG_FUNC_ENTER;
     SYNC_INFERIOR_OR(return);
 
+    m_frame_to_file.clear();
     for (uint i = 0; i < m_process->GetNumThreads(); i++) {
         lldb::SBThread t = m_process->GetThreadAtIndex(i);
         if (t.GetThreadID() == token) {
@@ -537,7 +545,9 @@ void LldbEngineGuest::selectThread(qint64 token)
                 frame.address = fr.GetPCAddress().GetLoadAddress(*m_target);
                 frame.line = lineNumber;
                 frame.file = sourceFilePath;
+                frame.usable = QFileInfo(frame.file).isReadable();
                 frames.append(frame);
+                m_frame_to_file.insert(j, frame.file);
             }
             currentThreadChanged(token);
             listFrames(frames);
index df94e41..93f0c0a 100644 (file)
@@ -94,9 +94,9 @@ public:
     void addBreakpoint(BreakpointId id, const BreakpointParameters &bp);
     void removeBreakpoint(BreakpointId id);
     void changeBreakpoint(BreakpointId id, const BreakpointParameters &bp);
-
     void requestUpdateWatchData(const WatchData &data,
             const WatchUpdateFlags &flags);
+    void fetchFrameSource(qint64 frame);
 
 private:
     bool m_running;
@@ -115,6 +115,7 @@ private:
     bool m_relistFrames;
     QHash<QString, lldb::SBValue> m_localesCache;
     QHash<BreakpointId, lldb::SBBreakpoint> m_breakpoints;
+    QHash<qint64, QString> m_frame_to_file;
 
     void updateThreads();
     void getWatchDataR(lldb::SBValue v, int level,
index 68dc624..c7839fa 100644 (file)
@@ -312,6 +312,15 @@ void IPCEngineGuest::rpcCallback(quint64 f, QByteArray payload)
                 requestUpdateWatchData(data);
             }
             break;
+        case IPCEngineHost::FetchFrameSource:
+            {
+                QDataStream s(payload);
+                SET_NATIVE_BYTE_ORDER(s);
+                qint64 id;
+                s >> id;
+                fetchFrameSource(id);
+            }
+            break;
     };
 }
 
@@ -609,6 +618,19 @@ void IPCEngineGuest::updateWatchData(bool fullCycle, const QList<WatchData> &wd)
     rpcCall(UpdateWatchData, p);
 }
 
+void IPCEngineGuest::frameSourceFetched(qint64 id, const QString &name, const QString &source)
+{
+    QByteArray p;
+    {
+        QDataStream s(&p, QIODevice::WriteOnly);
+        SET_NATIVE_BYTE_ORDER(s);
+        s << id;
+        s << name;
+        s << source;
+    }
+    rpcCall(FrameSourceFetched, p);
+}
+
 } // namespace Internal
 } // namespace Debugger
 
index 525f36f..be939e4 100644 (file)
@@ -81,6 +81,7 @@ public:
     virtual void changeBreakpoint(BreakpointId id, const BreakpointParameters &bp) = 0;
     virtual void requestUpdateWatchData(const WatchData &data,
             const WatchUpdateFlags & flags = WatchUpdateFlags()) = 0;
+    virtual void fetchFrameSource(qint64 frame) = 0;
 
     enum Function
     {
@@ -120,7 +121,8 @@ public:
         NotifyChangeBreakpointOk         = 34,
         NotifyChangeBreakpointFailed     = 35,
         NotifyBreakpointAdjusted         = 36,
-        UpdateWatchData                  = 47
+        UpdateWatchData                  = 47,
+        FrameSourceFetched               = 48
     };
     Q_ENUMS(Function);
 
@@ -166,6 +168,8 @@ public:
 
     void updateWatchData(bool fullCycle, const QList<WatchData> &);
 
+    void frameSourceFetched(qint64 frame, const QString &name, const QString &sourceCode);
+
     void rpcCall(Function f, QByteArray payload = QByteArray());
 public slots:
     void rpcCallback(quint64 f, QByteArray payload = QByteArray());
index f14dbb7..70ec501 100644 (file)
@@ -40,6 +40,9 @@
 #include "threadshandler.h"
 #include "debuggeragents.h"
 #include "debuggerstreamops.h"
+#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/editormanager/ieditor.h>
+#include <cppeditor/cppeditorconstants.h>
 
 #include <QSysInfo>
 #include <QDebug>
@@ -294,6 +297,17 @@ void IPCEngineHost::updateWatchData(const WatchData &data,
     rpcCall(RequestUpdateWatchData, p);
 }
 
+void IPCEngineHost::fetchFrameSource(qint64 id)
+{
+    QByteArray p;
+    {
+        QDataStream s(&p, QIODevice::WriteOnly);
+        SET_NATIVE_BYTE_ORDER(s);
+        s << id;
+    }
+    rpcCall(FetchFrameSource, p);
+}
+
 void IPCEngineHost::rpcCallback(quint64 f, QByteArray payload)
 {
     switch (f) {
@@ -410,7 +424,10 @@ void IPCEngineHost::rpcCallback(quint64 f, QByteArray payload)
                 resetLocation();
                 StackHandler *sh = stackHandler();
                 sh->setCurrentIndex(token);
-                gotoLocation(sh->currentFrame(), true);
+                if (QFileInfo(sh->currentFrame().file).exists())
+                    gotoLocation(sh->currentFrame(), true);
+                else
+                    fetchFrameSource(token);
             }
             break;
         case IPCEngineGuest::CurrentThreadChanged:
@@ -539,6 +556,21 @@ void IPCEngineHost::rpcCallback(quint64 f, QByteArray payload)
                 breakHandler()->notifyBreakpointAdjusted(id, d);
             }
             break;
+        case IPCEngineGuest::FrameSourceFetched:
+            {
+                QDataStream s(payload);
+                SET_NATIVE_BYTE_ORDER(s);
+                qint64 token;
+                QString name;
+                QString source;
+                s >> token >> name >> source;
+                Core::EditorManager *editorManager = Core::EditorManager::instance();
+                Core::IEditor *editor = editorManager->openEditorWithContents(CppEditor::Constants::CPPEDITOR_ID, &name, source);
+                editorManager->activateEditor(editor);
+                editor->gotoLine(stackHandler()->currentFrame().line, 0);
+                editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
+            }
+            break;
     }
 }
 
index 224e363..a9db3c7 100644 (file)
@@ -81,7 +81,8 @@ public:
         AddBreakpoint          = 22,
         RemoveBreakpoint       = 23,
         ChangeBreakpoint       = 24,
-        RequestUpdateWatchData = 25
+        RequestUpdateWatchData = 25,
+        FetchFrameSource       = 26
     };
     Q_ENUMS(Function);
 
@@ -110,6 +111,7 @@ public:
     void changeBreakpoint(BreakpointId id);
     void updateWatchData(const WatchData &data,
             const WatchUpdateFlags &flags = WatchUpdateFlags());
+    void fetchFrameSource(qint64 id);
 
     void rpcCall(Function f, QByteArray payload = QByteArray());
 protected: