[nemiver] Support asm single stepping



commit 394ce032551c13547417ade78820cc8f04129a8a
Author: Dodji Seketeli <dodji gnome org>
Date:   Mon Apr 26 19:07:18 2010 +0200

    Support asm single stepping
    
    	* src/dbgengine/nmv-i-debugger.h (IDebugger::step_over_asm):
    	Renamed IDebugger::step_instruction into this.
    	(IDebugger::step_in_asm): Declare new fn.
    	* src/dbgengine/nmv-gdb-engine.h: Likewise.
    	* src/dbgengine/nmv-gdb-engine.cc (GDBEngine::step_over_asm):
    	Renamed GDBEngine::step_instruction into this.
    	(GDBEngine::step_in_asm): Define new fn.
    	* src/persp/dbgperspective/nmv-call-stack.cc
    	(CallStackCols::address): New column definition.
    	(CallStackCols::CallStackCols): Add the new column.
    	(CallStack::Priv::build_widget): Append a new graphical
    	address column.
    	(CallStack::Priv::append_frames_to_tree_view): Populate the new
    	address column. Do not show the address in the location column
    	when the frame has no location.
    	* src/persp/dbgperspective/nmv-dbg-perspective.cc
    	(DBGPerspective::on_step_in_asm_action,
    	 DBGPerspective::on_step_over_asm_action,
    	 DBGPerspective::step_in_asm, DBGPerspective::step_over_asm): New fns.
    	(DBGPerspective::get_current_source_editor): Add a flag to
    	decide whether to load a new source editor if the notebook is
    	empty.
    	(DBGPerspective::on_debugger_command_done_signal): Adjust for
    	IDebugger::step_instruction --> IDebugger::step_over_asm rename.
    	(DBGPerspective::init_actions): Add new actions to do asm step
    	into, asm step over. Add <control>-A shortcut for "switch to
    	asm" and <control><shift>-A for switch to source.
    	(DBGPerspective::get_source_editor_from_path): Avoid
    	dereferencing an iterator that points to the end of a container.
    	(DBGPerspective::apply_decorations_to_source): Use pointer
    	comparison to compare the source editor to decorate with the
    	current source editor. Before this change we where comparing the
    	file paths. That can lead to some misses when we got the source
    	editor from a non absolute path that got resolved by the user.
    	* src/uicommon/nmv-source-editor.cc
    	(SourceEditor::Priv::get_first_asm_address,
    	 SourceEditor::Priv::get_last_asm_address): New fns.
    	(SourceEditor::get_assembly_address_range): Use them.
    	* src/persp/dbgperspective/menus/menus.xml: Add
    	StepInAsmMenuItem and StepOverAsmMenuItem menu items.

 src/dbgengine/nmv-gdb-engine.cc                 |   15 ++++-
 src/dbgengine/nmv-gdb-engine.h                  |    6 +-
 src/dbgengine/nmv-i-debugger.h                  |    8 ++-
 src/persp/dbgperspective/menus/menus.xml        |    3 +
 src/persp/dbgperspective/nmv-call-stack.cc      |   10 ++-
 src/persp/dbgperspective/nmv-dbg-perspective.cc |   82 ++++++++++++++++++++---
 src/uicommon/nmv-source-editor.cc               |   42 ++++++++++--
 7 files changed, 139 insertions(+), 27 deletions(-)
---
diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index 24f6a79..e8270f1 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -3536,17 +3536,28 @@ GDBEngine::step_over (const UString &a_cookie)
 }
 
 void
-GDBEngine::step_instruction (const UString &a_cookie)
+GDBEngine::step_over_asm (const UString &a_cookie)
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD;
 
-    Command command ("step-instruction",
+    Command command ("step-over-asm",
                      "-exec-next-instruction",
                      a_cookie);
     queue_command (command);
 }
 
 void
+GDBEngine::step_in_asm (const UString &a_cookie)
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
+    Command command ("step-in-asm",
+                     "-exec-step-instruction",
+                     a_cookie);
+    queue_command (command);
+}
+
+void
 GDBEngine::continue_to_position (const UString &a_path,
                                  gint a_line_num,
                                  const UString &a_cookie)
diff --git a/src/dbgengine/nmv-gdb-engine.h b/src/dbgengine/nmv-gdb-engine.h
index 679f740..c6ae313 100644
--- a/src/dbgengine/nmv-gdb-engine.h
+++ b/src/dbgengine/nmv-gdb-engine.h
@@ -308,13 +308,15 @@ public:
 
     void get_mi_thread_and_frame_location (UString &a_str) const;
 
+    void step_over (const UString &a_cookie);
+
     void step_in (const UString &a_cookie);
 
     void step_out (const UString &a_cookie);
 
-    void step_instruction (const UString &a_cookie);
+    void step_over_asm (const UString &a_cookie);
 
-    void step_over (const UString &a_cookie);
+    void step_in_asm (const UString &a_cookie);
 
     void continue_to_position (const UString &a_path,
                                gint a_line_num,
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index 9b1c9c6..744f21e 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -1216,13 +1216,15 @@ public:
 
     virtual void exit_engine () = 0;
 
-    virtual void step_in (const UString &a_cookie="") = 0;
-
     virtual void step_over (const UString &a_cookie="") = 0;
 
+    virtual void step_in (const UString &a_cookie="") = 0;
+
     virtual void step_out (const UString &a_cookie="") = 0;
 
-    virtual void step_instruction (const UString &a_cookie="") = 0;
+    virtual void step_over_asm (const UString &a_cookie="") = 0;
+
+    virtual void step_in_asm (const UString &a_cookie="") = 0;
 
     virtual void continue_to_position (const UString &a_path,
                                        gint a_line_num,
diff --git a/src/persp/dbgperspective/menus/menus.xml b/src/persp/dbgperspective/menus/menus.xml
index 2019c95..49a2ceb 100644
--- a/src/persp/dbgperspective/menus/menus.xml
+++ b/src/persp/dbgperspective/menus/menus.xml
@@ -65,6 +65,9 @@
             <menuitem action="NextMenuItemAction" name="NextMenuItem"/>
             <menuitem action="StepMenuItemAction" name="StepMenuItem"/>
             <menuitem action="StepOutMenuItemAction" name="StepOutMenuItem"/>
+            <menuitem action="StepInAsmMenuItemAction" name="StepInAsmMenuItem"/>
+            <menuitem action="StepOverAsmMenuItemAction"
+                      name="StepOverAsmMenuItem"/>
             <separator/>
             <menuitem action="ToggleBreakpointMenuItemAction"
                 name="ToggleBreakMenuItem"/>
diff --git a/src/persp/dbgperspective/nmv-call-stack.cc b/src/persp/dbgperspective/nmv-call-stack.cc
index 3620b98..6999e84 100644
--- a/src/persp/dbgperspective/nmv-call-stack.cc
+++ b/src/persp/dbgperspective/nmv-call-stack.cc
@@ -58,6 +58,7 @@ typedef SafePtr<Glib::Object, GObjectMMRef, GObjectMMUnref> GObjectMMSafePtr;
 
 struct CallStackCols : public Gtk::TreeModelColumnRecord {
     Gtk::TreeModelColumn<Glib::ustring> location;
+    Gtk::TreeModelColumn<Glib::ustring> address;
     Gtk::TreeModelColumn<Glib::ustring> function_name;
     Gtk::TreeModelColumn<Glib::ustring> function_args;
     Gtk::TreeModelColumn<Glib::ustring> frame_index_caption;
@@ -66,6 +67,7 @@ struct CallStackCols : public Gtk::TreeModelColumnRecord {
 
     enum Index {
         LOCATION=0,
+        ADDRESS,
         FUNCTION_NAME,
         FUNCTION_ARGS
     };
@@ -73,6 +75,7 @@ struct CallStackCols : public Gtk::TreeModelColumnRecord {
     CallStackCols ()
     {
         add (location);
+        add (address);
         add (function_name);
         add (function_args);
         add (frame_index_caption);
@@ -530,6 +533,7 @@ struct CallStack::Priv {
         tree_view->append_column (_("Function"), columns ().function_name);
         tree_view->append_column (_("Arguments"), columns ().function_args);
         tree_view->append_column (_("Location"), columns ().location);
+        tree_view->append_column (_("Address"), columns ().address);
         tree_view->set_headers_visible (true);
         tree_view->get_selection ()->set_mode (Gtk::SELECTION_SINGLE);
 
@@ -663,11 +667,9 @@ struct CallStack::Priv {
                 (*store_iter)[columns ().location] =
                     a_frames[i].file_name () + ":"
                     + UString::from_int (a_frames[i].line ());
-            } else {
-                (*store_iter)[columns ().location] =
-                    a_frames[i].address ().to_string ();
             }
-
+            (*store_iter)[columns ().address] =
+                                        a_frames[i].address ().to_string ();
             (*store_iter)[columns ().frame_index] = a_frames[i].level ();
             (*store_iter)[columns ().frame_index_caption] =
                 UString::from_int (a_frames[i].level ());
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 6496fe1..222230d 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -292,6 +292,8 @@ private:
     void on_next_action ();
     void on_step_into_action ();
     void on_step_out_action ();
+    void on_step_in_asm_action ();
+    void on_step_over_asm_action ();
     void on_continue_action ();
     void on_continue_until_action ();
     void on_set_breakpoint_action ();
@@ -474,7 +476,7 @@ private:
     void clear_session_data ();
     void append_source_editor (SourceEditor &a_sv,
                                const UString &a_path);
-    SourceEditor* get_current_source_editor ();
+    SourceEditor* get_current_source_editor (bool a_load_if_nil = true);
     ISessMgr* session_manager_ptr ();
     UString get_current_file_path ();
     SourceEditor* get_source_editor_from_path (const UString& a_path,
@@ -645,6 +647,8 @@ public:
     void step_over ();
     void step_into ();
     void step_out ();
+    void step_in_asm ();
+    void step_over_asm ();
     void do_continue ();
     void do_continue_until ();
     void set_breakpoint_at_current_line_using_dialog ();
@@ -1539,6 +1543,7 @@ void
 DBGPerspective::on_step_out_action ()
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD;
+
     NEMIVER_TRY
 
     step_out ();
@@ -1547,6 +1552,30 @@ DBGPerspective::on_step_out_action ()
 }
 
 void
+DBGPerspective::on_step_in_asm_action ()
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
+    NEMIVER_TRY
+
+    step_in_asm ();
+
+    NEMIVER_CATCH
+}
+
+void
+DBGPerspective::on_step_over_asm_action ()
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+
+    NEMIVER_TRY
+
+    step_over_asm ();
+
+    NEMIVER_CATCH
+}
+
+void
 DBGPerspective::on_continue_action ()
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD;
@@ -2418,8 +2447,7 @@ DBGPerspective::on_debugger_command_done_signal (const UString &a_command,
 
     NEMIVER_TRY
     if (a_command == "attach-to-program") {
-        //attached_to_target_signal ().emit (true);
-        debugger ()->step_instruction ();
+        debugger ()->step_over_asm ();
         debugger ()->get_target_info ();
     }
     NEMIVER_CATCH
@@ -3300,6 +3328,26 @@ DBGPerspective::init_actions ()
             false
         },
         {
+            "StepInAsmMenuItemAction",
+            nil_stock_id,
+            _("Step Into asm"),
+            _("Step into the next assembly instruction"),
+            sigc::mem_fun (*this, &DBGPerspective::on_step_in_asm_action),
+            ActionEntry::DEFAULT,
+            "<control>I",
+            false
+        },
+        {
+            "StepOverAsmMenuItemAction",
+            nil_stock_id,
+            _("Step Over asm"),
+            _("Step over the next assembly instruction"),
+            sigc::mem_fun (*this, &DBGPerspective::on_step_over_asm_action),
+            ActionEntry::DEFAULT,
+            "<control>N",
+            false
+        },
+        {
             "ContinueMenuItemAction",
             Gtk::Stock::EXECUTE,
             _("_Continue"),
@@ -3445,7 +3493,7 @@ DBGPerspective::init_actions ()
                             (*this, &DBGPerspective::on_disassemble_action),
                         /*show_asm_in_new_tab=*/false),
             ActionEntry::DEFAULT,
-            "",
+            "<control>A",
             false
         },
         {
@@ -3455,7 +3503,7 @@ DBGPerspective::init_actions ()
             _("Show the source code being currently debugged"),
             sigc::mem_fun (*this, &DBGPerspective::switch_to_source_code),
             ActionEntry::DEFAULT,
-            "",
+            "<control><shift>A",
             false
         },
     };
@@ -4187,7 +4235,7 @@ DBGPerspective::append_source_editor (SourceEditor &a_sv,
 }
 
 SourceEditor*
-DBGPerspective::get_current_source_editor ()
+DBGPerspective::get_current_source_editor (bool a_load_if_nil)
 {
     THROW_IF_FAIL (m_priv);
 
@@ -4196,7 +4244,8 @@ DBGPerspective::get_current_source_editor ()
         return NULL;
     }
 
-    if (m_priv->sourceviews_notebook
+    if (a_load_if_nil
+        && m_priv->sourceviews_notebook
         && !m_priv->sourceviews_notebook->get_n_pages ()) {
         // The source notebook is empty. If the current frame
         // has file info, load the file, bring it to the front,
@@ -4357,15 +4406,14 @@ DBGPerspective::get_source_editor_from_path (const UString &a_path,
         iter = m_priv->basename_2_pagenum_map.find
                                         (Glib::filename_to_utf8 (basename));
         nil = m_priv->basename_2_pagenum_map.end ();
-        result = m_priv->pagenum_2_source_editor_map[iter->second];
     } else {
         iter = m_priv->path_2_pagenum_map.find (a_path);
         nil = m_priv->path_2_pagenum_map.end ();
-        result = m_priv->pagenum_2_source_editor_map[iter->second];
     }
     if (iter == nil) {
         return 0;
     }
+    result = m_priv->pagenum_2_source_editor_map[iter->second];
     THROW_IF_FAIL (result);
     result->get_path (a_actual_file_path);
     return result;
@@ -6748,6 +6796,18 @@ DBGPerspective::step_out ()
 }
 
 void
+DBGPerspective::step_in_asm ()
+{
+    debugger ()->step_in_asm ();
+}
+
+void
+DBGPerspective::step_over_asm ()
+{
+    debugger ()->step_over_asm ();
+}
+
+void
 DBGPerspective::do_continue ()
 {
     debugger ()->do_continue ();
@@ -7175,7 +7235,7 @@ DBGPerspective::apply_decorations_to_source (SourceEditor *a_editor,
         a_editor->scroll_to_line (cur_line);
     }
 
-    if (m_priv->current_frame.file_name () == a_editor->get_path ())
+    if (get_current_source_editor (false) == a_editor)
         set_where (a_editor,
                    m_priv->current_frame.line (),
                    /*a_scroll_to_where_marker=*/true);
@@ -7220,7 +7280,7 @@ DBGPerspective::apply_decorations_to_asm (SourceEditor *a_editor,
         a_editor->scroll_to_line (cur_line);
     }
 
-    if (m_priv->current_frame.file_name () == a_editor->get_path ())
+    if (get_current_source_editor () == a_editor)
         set_where (a_editor,
                    m_priv->current_frame.address (),
                    a_scroll_to_where_marker,
diff --git a/src/uicommon/nmv-source-editor.cc b/src/uicommon/nmv-source-editor.cc
index 05342cd..e6c536e 100644
--- a/src/uicommon/nmv-source-editor.cc
+++ b/src/uicommon/nmv-source-editor.cc
@@ -336,6 +336,41 @@ struct SourceEditor::Priv {
         return true;
     }
 
+    bool get_first_asm_address (Address &a_address) const
+    {
+        if (!asm_ctxt.buffer)
+            return false;
+
+        // Get the address of the first line that has an address on it.
+        // The assembly buf can contain lines that are not pure asm
+        // instruction, e.g. for cases where it contains mixed
+        // source/asm instrs.
+        int nb_lines = asm_ctxt.buffer->get_line_count ();
+        for (int i = 1; i <= nb_lines; ++i)
+            if (line_2_address (asm_ctxt.buffer, i, a_address))
+                return true;
+
+        return false;
+    }
+
+    bool get_last_asm_address (Address &a_address) const
+    {
+        if (!asm_ctxt.buffer)
+            return false;
+
+        // Get the address of the first line -- starting from the end of
+        // buf -- that has an address on it.
+        // The assembly buf can contain lines that are not pure asm
+        // instruction, e.g. for cases where it contains mixed
+        // source/asm instrs.
+        int nb_lines = asm_ctxt.buffer->get_line_count ();
+        for (int i = nb_lines; i >= 1; --i)
+            if (line_2_address (asm_ctxt.buffer, i, a_address))
+                return true;
+
+        return false;
+    }
+
     //**************
     //<signal slots>
     //**************
@@ -1137,15 +1172,12 @@ SourceEditor::assembly_buf_line_to_addr (int a_line, Address &a_address) const
 bool
 SourceEditor::get_assembly_address_range (Range &a) const
 {
-    Glib::RefPtr<SourceBuffer> buf = get_assembly_source_buffer ();
-    if (!buf)
-        return false;
     Address addr;
-    if (!m_priv->line_2_address (buf, 1, addr))
+    if (!m_priv->get_first_asm_address (addr))
         return false;
     Range range;
     range.min (addr);
-    if (!m_priv->line_2_address (buf, buf->get_line_count (), addr))
+    if (!m_priv->get_last_asm_address (addr))
         return false;
     range.max (addr);
     a = range;



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