[nemiver/follow-fork-mode: 18/35] Add proper streaming operators for asm insns



commit bcad3811e174314ed56c5fbccfb1519c8f1d14c0
Author: Dodji Seketeli <dodji redhat com>
Date:   Sun Apr 25 10:21:18 2010 +0200

    Add proper streaming operators for asm insns
    
    	* src/dbgengine/nmv-asm-utils.h: New file.
    	* src/dbgengine/Makefile.am: Add it to build system.
    	* src/dbgengine/nmv-gdbmi-parser.cc
    	(operator<<(std::ostream&, const IDebugger::AsmInstr&)): Remove
    	because a template of this is now available in the newly added
    	nmv-asm-utils.h above.

 src/dbgengine/Makefile.am         |    2 +-
 src/dbgengine/nmv-asm-utils.h     |   91 +++++++++++++++++++++++++++++++++++++
 src/dbgengine/nmv-gdbmi-parser.cc |   14 +-----
 src/dbgengine/nmv-gdbmi-parser.h  |    4 --
 4 files changed, 93 insertions(+), 18 deletions(-)
---
diff --git a/src/dbgengine/Makefile.am b/src/dbgengine/Makefile.am
index c4e73cd..439c441 100644
--- a/src/dbgengine/Makefile.am
+++ b/src/dbgengine/Makefile.am
@@ -23,7 +23,7 @@ libdebuggerutils.la \
 libgdbengine.la
 
 idebuggerheaders= \
-nmv-i-debugger.h
+nmv-i-debugger.h nmv-asm-utils.h
 
 ivarlistheaders= \
 nmv-i-var-list.h
diff --git a/src/dbgengine/nmv-asm-utils.h b/src/dbgengine/nmv-asm-utils.h
new file mode 100644
index 0000000..7a17df2
--- /dev/null
+++ b/src/dbgengine/nmv-asm-utils.h
@@ -0,0 +1,91 @@
+/*
+ *This file is part of the Nemiver project
+ *
+ *Nemiver is free software; you can redistribute
+ *it and/or modify it under the terms of
+ *the GNU General Public License as published by the
+ *Free Software Foundation; either version 2,
+ *or (at your option) any later version.
+ *
+ *Nemiver is distributed in the hope that it will
+ *be useful, but WITHOUT ANY WARRANTY;
+ *without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *See the GNU General Public License for more details.
+ *
+ *You should have received a copy of the
+ *GNU General Public License along with Nemiver;
+ *see the file COPYING.
+ *If not, write to the Free Software Foundation,
+ *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *See COPYRIGHT file copyright information.
+ */
+// Author: Dodji Seketeli
+
+#ifndef __NEMIVER_ASM_UTILS_H__
+#define __NEMIVER_ASM_UTILS_H__
+
+#include "nmv-i-debugger.h"
+
+NEMIVER_BEGIN_NAMESPACE (nemiver)
+
+template<class Stream>
+Stream&
+operator<< (Stream &a_out, const IDebugger::AsmInstr &a_instr)
+{
+    a_out << "<asm-instr>\n"
+          << " <addr>" <<  a_instr.address () << "</addr>\n"
+          << " <function-name>" << a_instr.function () << "</function-name>\n"
+          << " <offset>" << a_instr.offset () << "</offset>\n"
+          << " <instr>" << a_instr.instruction () << "</instr>\n"
+          << "</asm-instr>\n";
+    return a_out;
+}
+
+template<class Stream>
+Stream&
+operator<< (Stream &a_out, const IDebugger::MixedAsmInstr &a_instr)
+{
+    a_out << "<asm-mixed-instr>\n"
+          << " <line>" << a_instr.line_number () << "</line>\n"
+          << " <path>" << a_instr.file_path ()   << "</path>\n";
+
+    list<IDebugger::AsmInstr>::const_iterator it;
+    a_out << " <asm-instr-list>";
+    for (it = a_instr.instrs ().begin ();
+         it != a_instr.instrs ().end ();
+         ++it) {
+        a_out << "  <asm-instr>\n"
+              << "   <addr>" <<  it->address () << "</addr>\n"
+              << "   <function-name>" << it->function ()
+                                      << "</function-name>\n"
+              << "   <offset>" << it->offset ()      << "</offset>\n"
+              << "   <instr>" <<  it->instruction () << "</instr>\n"
+              << "  </asm-instr>\n";
+    }
+    a_out << " </asm-instr-list>"
+          << "</asm-mixed-instr>\n";
+
+    return a_out;
+}
+
+template<class Stream>
+Stream&
+operator<< (Stream &a_out, const IDebugger::Asm &a_asm)
+{
+    switch (a_asm.which ()) {
+        case IDebugger::Asm::TYPE_PURE:
+            a_out << a_asm.instr ();
+            break;
+        case IDebugger::Asm::TYPE_MIXED:
+            a_out << a_asm.mixed_instr ();
+            break;
+        default:
+            THROW ("reached unreachable");
+    }
+    return a_out;
+}
+
+NEMIVER_END_NAMESPACE (nemiver)
+#endif // __NEMIVER_ASM_UTILS_H__ 
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index 552b2f0..46f90d4 100644
--- a/src/dbgengine/nmv-gdbmi-parser.cc
+++ b/src/dbgengine/nmv-gdbmi-parser.cc
@@ -26,6 +26,7 @@
 #include <sstream>
 #include "common/nmv-str-utils.h"
 #include "nmv-gdbmi-parser.h"
+#include "nmv-asm-utils.h"
 
 using nemiver::common::UString;
 
@@ -192,19 +193,6 @@ const char* PREFIX_PATH_EXPR = "path_expr=";
 const char* PATH_EXPR = "path_expr";
 static const char* PREFIX_ASM_INSTRUCTIONS= "asm_insns=";
 
-std::ostream&
-operator<< (std::ostream &a_out, const IDebugger::AsmInstr &a_instr)
-{
-    a_out << "<asm-instr>\n"
-          << " <addr>" <<  a_instr.address () << "</addr>\n"
-          << " <function-name>" << a_instr.function () << "</function-name>\n"
-          << " <offset>" << a_instr.offset () << "</offset>\n"
-          << " <instr>" << a_instr.instruction () << "</instr>\n"
-          << "</asm-instr>\n";
-    return a_out;
-}
-
-
 static bool
 is_string_start (gunichar a_c)
 {
diff --git a/src/dbgengine/nmv-gdbmi-parser.h b/src/dbgengine/nmv-gdbmi-parser.h
index 1b04c5d..ef9b207 100644
--- a/src/dbgengine/nmv-gdbmi-parser.h
+++ b/src/dbgengine/nmv-gdbmi-parser.h
@@ -302,10 +302,6 @@ operator<< (ostream &a_out, const GDBMIValueSafePtr &a_val);
 std::ostream&
 operator<< (std::ostream &a_out, const IDebugger::Variable &a_var);
 
-std::ostream&
-operator<< (std::ostream &a_out, const IDebugger::AsmInstr &a_inst);
-
-
 //******************************************
 //</gdbmi datastructure streaming operators>
 //******************************************



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