[nemiver] Show source code lines in mixed asm/src mode



commit 0f2fbf595bda1886f60a43d25c666aec9bb00daf
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 |  129 +++++++++++++++++------
 src/uicommon/nmv-source-editor.cc               |    2 +
 2 files changed, 98 insertions(+), 33 deletions(-)
---
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index fa010f8..6496fe1 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,
@@ -2466,7 +2473,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 &)
 {
@@ -2482,25 +2489,12 @@ DBGPerspective::on_debugger_stopped_signal (IDebugger::StopReason a_reason,
     update_src_dependant_bp_actions_sensitiveness ();
     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);
@@ -4529,6 +4523,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;
 
@@ -5771,9 +5767,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 << "  ";
@@ -5784,9 +5834,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:
@@ -5794,12 +5844,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 ();
@@ -5857,7 +5916,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;
@@ -5971,6 +6030,8 @@ void
 DBGPerspective::pump_asm_including_address (SourceEditor *a_editor,
                                             const Address a_address)
 {
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
     Range r;
 
     if (!a_editor
@@ -7450,6 +7511,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]