[nemiver/follow-fork-mode: 24/35] Show source code lines in mixed asm/src mode



commit 597f1eaa32423d14e55904785c50f651d20649ff
Author: Dodji Seketeli <dodji redhat com>
Date:   Sun Apr 25 23:15:08 2010 +0200

    Show source code lines in mixed asm/src mode
    
    	* src/persp/dbgperspective/nmv-dbg-perspective.cc
    	(DBGPerspective::on_debugger_stopped_signal): Make sure to pump
    	more asm insns in if necessary.
    	(DBGPerspective::read_file_line): New fn.
    	(DBGPerspective::write_asm_instr): Turn this into a member
    	function now. Also, for  mixed asm/source asm, show the actual
    	source code line. If not possible, then show the source code
    	line markers.
    	(DBGPerspective::set_where,
    	DBGPerspective::pump_asm_including_address,
    	DBGPerspective::disassemble_and_do): Add logging.
    	* src/uicommon/nmv-source-editor.cc
    	(SourceEditor::move_where_marker_to_line): Likewise.

 src/persp/dbgperspective/nmv-dbg-perspective.cc |  128 +++++++++++++++++------
 src/uicommon/nmv-source-editor.cc               |    2 +
 2 files changed, 98 insertions(+), 32 deletions(-)
---
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 5b029af..c0864aa 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <algorithm>
 #include <iostream>
+#include <fstream>
 #include <sstream>
 #include <glib/gi18n.h>
 
@@ -39,7 +40,6 @@
 #include <giomm/file.h>
 #include <giomm/contenttype.h>
 #else
-#include <fstream>
 #include <libgnomevfs/gnome-vfs-mime-utils.h>
 #include <libgnomevfs/gnome-vfs-monitor.h>
 #include <libgnomevfs/gnome-vfs-ops.h>
@@ -568,6 +568,13 @@ public:
                    const std::list<IDebugger::Asm> &a_asm,
                    Glib::RefPtr<gtksourceview::SourceBuffer> &a_buf);
 
+    bool read_file_line (const UString&, int, string&);
+    void write_asm_instr (std::ostringstream&,
+                          const IDebugger::AsmInstr&);
+
+    void write_asm_instr (std::ostringstream&,
+                          const IDebugger::Asm&);
+
     bool add_asm (const IDebugger::DisassembleInfo &a_info,
                   const std::list<IDebugger::Asm> &a_asm,
                   Glib::RefPtr<gtksourceview::SourceBuffer> &a_buf,
@@ -2464,7 +2471,7 @@ DBGPerspective::on_debugger_breakpoints_set_signal
 
 void
 DBGPerspective::on_debugger_stopped_signal (IDebugger::StopReason a_reason,
-                                            bool a_has_frame,
+                                            bool /*a_has_frame*/,
                                             const IDebugger::Frame &a_frame,
                                             int , int, const UString &)
 {
@@ -2481,24 +2488,12 @@ DBGPerspective::on_debugger_stopped_signal (IDebugger::StopReason a_reason,
 
     m_priv->current_frame = a_frame;
 
-    bool where_set = false;
-    UString file_path (a_frame.file_full_name ());
-    if (a_has_frame && file_path.empty ()
-        && !a_frame.file_name ().empty ()) {
+    UString file_path = a_frame.file_full_name ();
+    if (file_path.empty ())
         file_path = a_frame.file_name ();
-        if (!find_file_in_source_dirs (file_path, file_path)) {
-            UString message;
-            message.printf(_("Could not find file %s"), file_path.c_str ());
-            display_error (message);
-        }
-    }
-    if (a_has_frame && !file_path.empty ()) {
-        m_priv->current_frame.file_name (file_path);
-        where_set = set_where (file_path, a_frame,
-                               /*do_scroll=*/true,
-                               /*try_hard=*/true);
-    }
-
+    bool where_set = set_where (file_path, a_frame,
+                                /*do_scroll=*/true,
+                                /*try_hard=*/true);
     if (!where_set) {
         SourceEditor *e = bring_source_as_current (file_path);
         disassemble (e ? false : true);
@@ -4527,6 +4522,8 @@ DBGPerspective::set_where (SourceEditor *a_editor,
                            bool a_do_scroll,
                            bool a_try_hard)
 {
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
     if (!a_editor)
         return false;
 
@@ -5769,9 +5766,63 @@ DBGPerspective::load_asm (const IDebugger::DisassembleInfo &a_info,
     return true;
 }
 
-static void
-write_asm_instr (std::ostringstream &a_os,
-                 const IDebugger::AsmInstr &a_instr)
+bool
+DBGPerspective::read_file_line (const UString &a_file_path,
+                                int a_line_number,
+                                string &a_line)
+{
+    if (a_file_path.empty ())
+        return false;
+
+
+    UString path;
+    if (!find_absolute_path_or_ask_user (a_file_path, path))
+        return false;
+    bool found_line = false;
+    int line_num = 1;
+    char c = 0;
+
+    NEMIVER_TRY
+
+    std::ifstream file (path.c_str ());
+
+    if (!file.good ()) {
+        LOG_ERROR ("Could not open file " + path);
+        return false;
+    }
+
+    while (true) {
+        if (line_num == a_line_number) {
+            found_line = true;
+            break;
+        }
+        file.get (c);
+        if (!file.good ())
+            break;
+        if (c == '\n')
+            ++line_num;
+    }
+    if (found_line) {
+        a_line.clear ();
+        while (true) {
+            file.get (c);
+            if (!file.good ())
+                break;
+            if (c == '\n')
+                break;
+            a_line += c;
+        }
+    }
+    file.close ();
+
+    NEMIVER_CATCH
+
+    return found_line;
+}
+
+void
+DBGPerspective::write_asm_instr (std::ostringstream &a_os,
+                                 const IDebugger::AsmInstr &a_instr)
 {
     a_os << a_instr.address ();
     a_os << "  ";
@@ -5782,9 +5833,9 @@ write_asm_instr (std::ostringstream &a_os,
     a_os << a_instr.instruction ();
 }
 
-static void
-write_asm_instr (std::ostringstream &a_os,
-                 const IDebugger::Asm &a_asm)
+void
+DBGPerspective::write_asm_instr (std::ostringstream &a_os,
+                                 const IDebugger::Asm &a_asm)
 {
     switch (a_asm.which ()) {
         case IDebugger::Asm::TYPE_PURE:
@@ -5792,12 +5843,21 @@ write_asm_instr (std::ostringstream &a_os,
             break;
         case IDebugger::Asm::TYPE_MIXED: {
             const IDebugger::MixedAsmInstr &instr = a_asm.mixed_instr ();
-
-            a_os << "<src file=\""
-                     << instr.file_path ()
-                     << "\" line=\""
-                     << instr.line_number ()
-                     << "\"/>\n";
+            string line;
+            if (read_file_line (instr.file_path (),
+                                instr.line_number (),
+                                line)) {
+                if (!line.empty ()) {
+                    a_os << line; // line does not end with a '\n' char.
+                    a_os << '\n';
+                }
+            } else {
+                a_os << "<src file=\""
+                         << instr.file_path ()
+                         << "\" line=\""
+                         << instr.line_number ()
+                         << "\"/>\n";
+            }
 
             list<IDebugger::AsmInstr>::const_iterator it =
                                                     instr.instrs ().begin ();
@@ -5855,7 +5915,7 @@ DBGPerspective::add_asm (const IDebugger::DisassembleInfo &/*a_info*/,
     // Really insert the the first asm instrs.
     insert_it = a_buf->insert (insert_it, first_os.str ());
 
-    // Append the remaing asm instrs. Make sure to add an "end of line"
+    // Append the remaining asm instrs. Make sure to add an "end of line"
     // before each asm instr.
     for (++it; it != a_asm.end (); ++it) {
         ostringstream os;
@@ -5969,6 +6029,8 @@ void
 DBGPerspective::pump_asm_including_address (SourceEditor *a_editor,
                                             const Address a_address)
 {
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
     Range r;
 
     if (!a_editor
@@ -7448,6 +7510,8 @@ DBGPerspective::disassemble (bool a_show_asm_in_new_tab)
 void
 DBGPerspective::disassemble_and_do (IDebugger::DisassSlot &a_what_to_do)
 {
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
     // If we don't have the current instruction pointer (IP), there is
     // nothing we can do.
     if (!debugger ()->is_attached_to_target ()
diff --git a/src/uicommon/nmv-source-editor.cc b/src/uicommon/nmv-source-editor.cc
index 92ab648..05342cd 100644
--- a/src/uicommon/nmv-source-editor.cc
+++ b/src/uicommon/nmv-source-editor.cc
@@ -632,6 +632,8 @@ SourceEditor::current_column (int &a_col)
 bool
 SourceEditor::move_where_marker_to_line (int a_line, bool a_do_scroll)
 {
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
     LOG_DD ("a_line: " << a_line);
 
     THROW_IF_FAIL (a_line >= 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]