[nemiver/follow-fork-mode: 6/35] Iron out the disassembling interface



commit 37900c3d1e43ce3fb3e74ed1768c0fc01e6281e8
Author: Dodji Seketeli <dodji redhat com>
Date:   Sun Jan 10 18:44:39 2010 +0100

    Iron out the disassembling interface
    
    	* src/dbgengine/nmv-gdb-engine.cc
    	(OnDisassembleHandler::do_handle): Call back into the slot
    	passed in parameter to the disasemble method invocation.
    	(GDBEngine::disassemble): Overhaul. An overload of this uses has
    	a slot in parameter. Make the other overloads use it.
    	(GDBEngine::disassemble_lines): Renamed the disassemble
    	invocation that takes lines in parameter (instead of address)
    	into this.
    	* src/dbgengine/nmv-gdb-engine.h (GDBEngine::disassemble):
    	Update declarations.
    	(GDBEngine::disassemble_lines): Declare new method.
    	* src/dbgengine/nmv-i-debugger.h (IDebugger::AsmInstr):  Store
    	addresses in strings for now. Might want to change that later to
    	store them in a size_t. This is easier for now.
    	* src/dbgengine/nmv-gdbmi-parser.cc
    	(GDBMIParser::parse_asm_instruction_list): Address and string
    	are now represented in strings.
    	* tests/test-disassemble.cc: Update to the ironed out interface.

 src/dbgengine/nmv-gdb-engine.cc   |   47 +++++++++++++++++--
 src/dbgengine/nmv-gdb-engine.h    |   23 ++++++++--
 src/dbgengine/nmv-gdbmi-parser.cc |   12 ++---
 src/dbgengine/nmv-i-debugger.h    |   63 +++++++++++++++----------
 tests/Makefile.am                 |    1 -
 tests/test-disassemble.cc         |   93 +++++++++++++++++++-----------------
 6 files changed, 154 insertions(+), 85 deletions(-)
---
diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index cc74a51..3666276 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -2331,6 +2331,12 @@ struct OnDisassembleHandler : OutputHandler {
             it--;
             info.end_address (it->address ());
         }
+        // Call the slot associated to IDebugger::disassemble, if any.
+        if (a_in.command ().has_slot ()) {
+            IDebugger::DisassSlot slot =
+                a_in.command ().get_slot<IDebugger::DisassSlot> ();
+            slot (info, instrs);
+        }
         m_engine->instructions_disassembled_signal ().emit
                                (info, instrs, a_in.command ().cookie ());
 
@@ -4393,10 +4399,29 @@ GDBEngine::set_memory (size_t a_addr,
 }
 
 void
+null_disass_slot (const IDebugger::DisassembleInfo &,
+                  const std::list<IDebugger::AsmInstr> &)
+{
+}
+
+void
 GDBEngine::disassemble (size_t a_start_addr,
+                        bool a_start_addr_relative_to_pc,
                         size_t a_end_addr,
+                        bool a_end_addr_relative_to_pc,
+                        const UString &a_cookie)
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+    disassemble (a_start_addr, a_start_addr_relative_to_pc, a_end_addr,
+                 a_end_addr_relative_to_pc, &null_disass_slot, a_cookie);
+}
+
+void
+GDBEngine::disassemble (size_t a_start_addr,
                         bool a_start_addr_relative_to_pc,
+                        size_t a_end_addr,
                         bool a_end_addr_relative_to_pc,
+                        const DisassSlot &a_slot,
                         const UString &a_cookie)
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD;
@@ -4431,14 +4456,27 @@ GDBEngine::disassemble (size_t a_start_addr,
     LOG_DD ("cmd_str: " << cmd_str);
 
     Command command ("disassemble-address-range", cmd_str, a_cookie);
+    command.set_slot (a_slot);
     queue_command (command);
 }
 
 void
-GDBEngine::disassemble (const UString &a_file_name,
-                        int a_line_num,
-                        int a_nb_disassembled_lines,
-                        const UString &a_cookie)
+GDBEngine::disassemble_lines (const UString &a_file_name,
+                              int a_line_num,
+                              int a_nb_disassembled_lines,
+                              const UString &a_cookie)
+{
+    LOG_FUNCTION_SCOPE_NORMAL_DD;
+    disassemble_lines (a_file_name, a_line_num, a_nb_disassembled_lines,
+                       &null_disass_slot, a_cookie);
+}
+
+void
+GDBEngine::disassemble_lines (const UString &a_file_name,
+                              int a_line_num,
+                              int a_nb_disassembled_lines,
+                              const DisassSlot &a_slot,
+                              const UString &a_cookie)
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD;
 
@@ -4456,6 +4494,7 @@ GDBEngine::disassemble (const UString &a_file_name,
     Command command ("disassemble-line-range-in-file", cmd_str, a_cookie);
     command.tag0 (a_file_name);
     command.tag1 (UString::from_int (a_line_num));
+    command.set_slot (a_slot);
     queue_command (command);
 }
 
diff --git a/src/dbgengine/nmv-gdb-engine.h b/src/dbgengine/nmv-gdb-engine.h
index 23a5f33..5562396 100644
--- a/src/dbgengine/nmv-gdb-engine.h
+++ b/src/dbgengine/nmv-gdb-engine.h
@@ -448,17 +448,32 @@ public:
                      const UString& a_cookie);
 
     void disassemble (size_t a_start_addr,
-                      size_t a_end_addr,
                       bool a_start_addr_relative_to_pc,
+                      size_t a_end_addr,
                       bool a_end_addr_relative_to_pc,
                       const UString &a_cookie);
-    void disassemble (const UString &a_file_name,
-                      int a_line_num,
-                      int a_nb_disassembled_lines,
+
+    void disassemble (size_t a_start_addr,
+                      bool a_start_addr_relative_to_pc,
+                      size_t a_end_addr,
+                      bool a_end_addr_relative_to_pc,
+                      const DisassSlot &a_slot,
                       const UString &a_cookie);
 
+    void disassemble_lines (const UString &a_file_name,
+                            int a_line_num,
+                            int a_nb_disassembled_lines,
+                            const UString &a_cookie);
+
+    void disassemble_lines (const UString &a_file_name,
+                            int a_line_num,
+                            int a_nb_disassembled_lines,
+                            const DisassSlot &a_slot,
+                            const UString &a_cookie);
+
     void create_variable (const UString &a_name,
                           const UString &a_cookie="");
+
     void create_variable (const UString &a_name,
                           const ConstVariableSlot &a_s,
                           const UString &a_cookie="");
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index 6002c6f..a9f2efa 100644
--- a/src/dbgengine/nmv-gdbmi-parser.cc
+++ b/src/dbgengine/nmv-gdbmi-parser.cc
@@ -3978,8 +3978,7 @@ return false; \
     std::list<GDBMIValueSafePtr> vals;
     gdbmi_list->get_value_content (vals);
     std::list<GDBMIValueSafePtr>::const_iterator val_iter;
-    string addr, func_name, instr;
-    int offset = 0;
+    string addr, func_name, instr, offset;
     IDebugger::AsmInstr asm_instr;
     // Loop over the tuples contained in gdbmi_list.
     // Each tuple represents an asm instruction descriptor that has four
@@ -4009,7 +4008,7 @@ return false; \
             LOG_PARSING_ERROR2 (cur);
             ERROR_OUT;
         }
-        addr = val->get_string_content ();
+        addr = val->get_string_content ().raw ();
         LOG_DD ("addr: " << addr);
 
         // get func-name field
@@ -4031,8 +4030,8 @@ return false; \
             LOG_PARSING_ERROR2 (cur);
             ERROR_OUT;
         }
-        offset = atoi (val->get_string_content ().c_str ());
-        LOG_DD ("offset: " << (int) offset);
+        offset = val->get_string_content ().raw ();
+        LOG_DD ("offset: " << offset);
 
         // get instr field
         ++res_iter;
@@ -4044,8 +4043,7 @@ return false; \
         }
         instr = val->get_string_content ();
         LOG_DD ("instr: " << instr);
-        asm_instr = IDebugger::AsmInstr (UString::hexa_to_int (addr),
-                                         func_name, offset, instr);
+        asm_instr = IDebugger::AsmInstr (addr, func_name, offset, instr);
         a_asm_instrs.push_back (asm_instr);
     }
     a_to = cur;
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index 4f40a16..0747d77 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -773,21 +773,19 @@ public:
     /// starting from the beginning of the function, and the instruction
     /// itself, represented by a string.
     class AsmInstr {
-        size_t m_address;
+        string m_address;
         string m_func;
-        int m_offset;
+        string m_offset;
         string m_instr;
 
     public:
-        explicit AsmInstr ():
-            m_address (0),
-            m_offset (0)
+        explicit AsmInstr ()
         {
         }
 
-        AsmInstr (size_t a_address,
+        AsmInstr (string &a_address,
                   string &a_func,
-                  int a_offset,
+                  string &a_offset,
                   string &a_instr):
             m_address (a_address),
             m_func (a_func),
@@ -800,14 +798,14 @@ public:
         {
         }
 
-        size_t address () const {return m_address;}
-        void address (size_t a) {m_address = a;}
+        const string& address () const {return m_address;}
+        void address (string &a) {m_address = a;}
 
         const string& function () const {return m_func;}
         void function (const string &a_str) {m_func = a_str;}
 
-        int offset () const {return m_offset;}
-        void offset (int a_o) {m_offset = a_o;}
+        const string& offset () const {return m_offset;}
+        void offset (string &a_o) {m_offset = a_o;}
 
         const string& instruction () const {return m_instr;}
         void instruction (const string &a_instr) {m_instr = a_instr;}
@@ -818,13 +816,11 @@ public:
         // as we don't have any pointer member.
         UString m_function_name;
         UString m_file_name;
-        size_t m_start_address;
-        size_t m_end_address;
+        std::string m_start_address;
+        std::string m_end_address;
 
     public:
-        DisassembleInfo () :
-            m_start_address (0),
-            m_end_address (0)
+        DisassembleInfo ()
         {
         }
         ~DisassembleInfo ()
@@ -837,11 +833,11 @@ public:
         const UString& file_name () const {return m_file_name;}
         void file_name (const UString &a_name) {m_file_name = a_name;}
 
-        size_t start_address () const {return m_start_address;}
-        void start_address (size_t a) {m_start_address = a;}
+        const std::string& start_address () const {return m_start_address;}
+        void start_address (const std::string &a) {m_start_address = a;}
 
-        size_t end_address () const {return m_end_address;}
-        void end_address (size_t a) {m_end_address = a;}
+        const std::string& end_address () const {return m_end_address;}
+        void end_address (const std::string &a) {m_end_address = a;}
     };// end class DisassembleInfo
 
     virtual ~IDebugger () {}
@@ -1248,17 +1244,34 @@ public:
             const std::vector<uint8_t>& a_bytes,
             const UString& a_cookie="") = 0;
 
+    typedef sigc::slot<void,
+                       const IDebugger::DisassembleInfo&,
+                       const std::list<IDebugger::AsmInstr>& > DisassSlot;
+
     virtual void disassemble (size_t a_start_addr,
+                              bool a_start_addr_relative_to_pc,
                               size_t a_end_addr,
-                              bool a_start_addr_relative_to_pc = false,
-                              bool a_end_addr_relative_to_pc = false,
+                              bool a_end_addr_relative_to_pc,
                               const UString &a_cookie = "") = 0;
 
-    virtual void disassemble (const UString &a_file_name,
-                              int a_line_num,
-                              int a_nb_disassembled_lines,
+    virtual void disassemble (size_t a_start_addr,
+                              bool a_start_addr_relative_to_pc,
+                              size_t a_end_addr,
+                              bool a_end_addr_relative_to_pc,
+                              const DisassSlot &a_slot,
                               const UString &a_cookie = "") = 0;
 
+    virtual void disassemble_lines (const UString &a_file_name,
+                                    int a_line_num,
+                                    int a_nb_disassembled_lines,
+                                    const UString &a_cookie = "") = 0;
+
+    virtual void disassemble_lines (const UString &a_file_name,
+                                    int a_line_num,
+                                    int a_nb_disassembled_lines,
+                                    const DisassSlot &a_slot,
+                                    const UString &a_cookie = "") = 0;
+
     typedef sigc::slot<void, const VariableSafePtr> ConstVariableSlot;
     typedef sigc::slot<void, const VariableList> ConstVariableListSlot;
     typedef sigc::slot<void, const UString&> ConstUStringSlot;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 37fcdaf..a441e9c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -131,7 +131,6 @@ $(top_builddir)/src/common/libnemivercommon.la
 
 runtestdisassemble_SOURCES=test-disassemble.cc
 runtestdisassemble_LDADD= NEMIVERCOMMON_LIBS@ \
- BOOST_TEST_EXEC_MONITOR_LIB@ \
 $(top_builddir)/src/common/libnemivercommon.la
 
 docore_SOURCES=do-core.cc
diff --git a/tests/test-disassemble.cc b/tests/test-disassemble.cc
index 98d78fa..fe256ed 100644
--- a/tests/test-disassemble.cc
+++ b/tests/test-disassemble.cc
@@ -25,7 +25,6 @@
 
 #include <iostream>
 #include <iomanip>
-#include <boost/test/test_tools.hpp>
 #include <boost/test/minimal.hpp>
 #include <glibmm.h>
 #include "common/nmv-initializer.h"
@@ -42,11 +41,8 @@ Glib::RefPtr<Glib::MainLoop> loop =
 IDebuggerSafePtr debugger;
 
 static const char *PROG_TO_DEBUG = "./fooprog";
-static const char *DISASSEMBLE_COOKIE_1 =
-                                "disassemble-20-instructions-after-pc";
-static const char *DISASSEMBLE_COOKIE_2 = "disassemble-20-lines-in-main";
-static bool seen_disassemble_cookie_1;
-static bool seen_disassemble_cookie_2;
+static char counter1 = 0;
+static char counter2 = 0;
 
 void
 on_engine_died_signal ()
@@ -60,14 +56,51 @@ on_program_finished_signal ()
 {
     MESSAGE ("program finished");
     loop->quit ();
-    BOOST_REQUIRE_MESSAGE (seen_disassemble_cookie_1,
-                           "seen_disassemble_cookie_1"
-                           << seen_disassemble_cookie_1);
-    BOOST_REQUIRE_MESSAGE (seen_disassemble_cookie_2,
-                           "seen_disassemble_cookie_2"
-                           << seen_disassemble_cookie_2);
+    BOOST_REQUIRE (counter1 == 2);
+    BOOST_REQUIRE (counter2 == 3);
 }
 
+typedef list<IDebugger::AsmInstr> AsmInstrs;
+
+void
+on_instructions_disassembled_signal0 (const IDebugger::DisassembleInfo &a_info,
+                                      const AsmInstrs &a_instrs,
+                                      const UString &/*a_cookie*/);
+void
+on_instructions_disassembled_signal1 (const IDebugger::DisassembleInfo &,
+                                      const AsmInstrs &a_instrs);
+
+void
+on_instructions_disassembled_signal0 (const IDebugger::DisassembleInfo &a_info,
+                                      const AsmInstrs &a_instrs,
+                                      const UString &/*a_cookie*/)
+{
+    on_instructions_disassembled_signal1 (a_info, a_instrs);
+    ++counter1;
+}
+
+void
+on_instructions_disassembled_signal1 (const IDebugger::DisassembleInfo &,
+                                      const AsmInstrs &a_instrs)
+{
+    cout << "<AssemblyInstructionList nb='" << a_instrs.size ()
+         << "'>" << endl;
+    for (AsmInstrs::const_iterator it = a_instrs.begin ();
+         it != a_instrs.end ();
+         ++it) {
+        cout << " <instruction>" << endl;
+        cout << "  @" << setbase (16) << it->address ()
+             << setbase (10) << endl;
+        cout << "  func: " << it->function () << endl;
+        cout << "  offset: " << it->offset () << endl;
+        cout << "  instr: " << it->instruction () << endl;
+        cout << " </instruction>\n";
+    }
+    cout << "</AssemblyInstructionList>" << endl;
+    ++counter2;
+}
+
+
 void
 on_stopped_signal (IDebugger::StopReason a_reason,
                    bool a_has_frame,
@@ -88,40 +121,12 @@ on_stopped_signal (IDebugger::StopReason a_reason,
 
     BOOST_REQUIRE (debugger);
 
-    debugger->disassemble (0, 20, true, true, DISASSEMBLE_COOKIE_1);
-    debugger->disassemble (a_frame.file_name (), a_frame.line (),
-                           20, DISASSEMBLE_COOKIE_2);
+    debugger->disassemble (0, true, 20, true);
+    debugger->disassemble_lines (a_frame.file_name (), a_frame.line (),
+                                 20, &on_instructions_disassembled_signal1);
     debugger->do_continue ();
 }
 
-typedef list<IDebugger::AsmInstr> AsmInstrs;
-
-void
-on_instructions_disassembled_signal (IDebugger::DisassembleInfo &/*a_info*/,
-                                     const AsmInstrs &a_instrs,
-                                     const UString &a_cookie)
-{
-    if (a_cookie == DISASSEMBLE_COOKIE_1)
-        seen_disassemble_cookie_1 = true;
-    if (a_cookie == DISASSEMBLE_COOKIE_2)
-        seen_disassemble_cookie_2 = true;
-
-    cout << "<AssemblyInstructionList nb='" << a_instrs.size ()
-         << "'>" << endl;
-    for (AsmInstrs::const_iterator it = a_instrs.begin ();
-         it != a_instrs.end ();
-         ++it) {
-        cout << " <instruction>" << endl;
-        cout << "  @" << setbase (16) << it->address ()
-             << setbase (10) << endl;
-        cout << "  func: " << it->function () << endl;
-        cout << "  offset: " << it->offset () << endl;
-        cout << "  instr: " << it->instruction () << endl;
-        cout << " </instruction>\n";
-    }
-    cout << "</AssemblyInstructionList>" << endl;
-}
-
 NEMIVER_API int
 test_main (int, char**)
 {
@@ -146,7 +151,7 @@ test_main (int, char**)
                                     (&on_program_finished_signal);
     debugger->stopped_signal ().connect (&on_stopped_signal);
     debugger->instructions_disassembled_signal ().connect
-                                    (&on_instructions_disassembled_signal);
+                                    (&on_instructions_disassembled_signal0);
 
     //*****************************
     //</connect to IDebugger events>



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