[PATCH 1/3] Fix IDebugger state after loading a program



    * src/dbgengine/nmv-gdb-engine.cc
    (GDBEngine::load_program): After loading a program set
    the IDebugger state to INFERIOR_LOADED instead of RUNNING.
    * tests/test-dbg-states.cc: Test that the IDebugger has the following state:
    NOT_STARTED at initilization,
    INFERIOR_LOADED after an inferior has been loaded.
    * tests/Makefile.am: Add new test program
---
 src/dbgengine/nmv-gdb-engine.cc |  1 +
 tests/Makefile.am               |  7 +++-
 tests/test-dbg-states.cc        | 79 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-dbg-states.cc

diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index 68e181f..b325385 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -3383,6 +3383,7 @@ GDBEngine::load_program (const UString &a_prog,
         }
     }
     m_priv->set_tty_path (a_slave_tty_path, "load-program");
+    set_state(IDebugger::INFERIOR_LOADED);
     return true;
 }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f4de79..b28b1c5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,7 +18,7 @@ runtestcppparser runtestvarpathexpr \
 runtestlibtoolwrapperdetection \
 runtesttypes runtestdisassemble \
 runtestvariableformat runtestprettyprint \
-runtestthreads
+runtestthreads runtestdbgstates
 
 else
 
@@ -59,6 +59,11 @@ forkchild_LDADD=
 prettyprint_SOURCES=$(h)/pretty-print.cc
 prettyprint_LDADD=
 
+runtestdbgstates_SOURCES=$(h)/test-dbg-states.cc
+runtestdbgstates_LDADD= NEMIVERCOMMON_LIBS@ \
+$(top_builddir)/src/common/libnemivercommon.la \
+$(top_builddir)/src/dbgengine/libdebuggerutils.la
+
 runtestbreakpoint_SOURCES=$(h)/test-breakpoint.cc
 runtestbreakpoint_LDADD= NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
diff --git a/tests/test-dbg-states.cc b/tests/test-dbg-states.cc
new file mode 100644
index 0000000..6b58549
--- /dev/null
+++ b/tests/test-dbg-states.cc
@@ -0,0 +1,79 @@
+#include "config.h"
+#include <iostream>
+#include <boost/test/minimal.hpp>
+#include <glibmm.h>
+#include "common/nmv-initializer.h"
+#include "common/nmv-safe-ptr-utils.h"
+#include "common/nmv-exception.h"
+#include "nmv-i-debugger.h"
+#include "nmv-debugger-utils.h"
+
+using namespace nemiver;
+using namespace nemiver::common;
+
+Glib::RefPtr<Glib::MainLoop> loop =
+    Glib::MainLoop::create (Glib::MainContext::get_default ());
+
+void
+on_engine_died_signal ()
+{
+    MESSAGE ("engine died");
+    loop->quit ();
+}
+
+void
+on_program_finished_signal (IDebuggerSafePtr a_debugger)
+{
+    MESSAGE ("program finished");
+    loop->quit ();
+
+    BOOST_REQUIRE (a_debugger);
+    BOOST_REQUIRE (a_debugger->get_state () == IDebugger::PROGRAM_EXITED);
+}
+
+void
+display_help ()
+{
+    MESSAGE ("test-basic <prog-to-debug>\n");
+}
+
+NEMIVER_API int
+test_main (int argc, char *argv[])
+{
+    if (argc || argv) {/*keep compiler happy*/}
+
+    NEMIVER_TRY;
+
+    Initializer::do_init ();
+
+    THROW_IF_FAIL (loop);
+
+    IDebuggerSafePtr debugger =
+        debugger_utils::load_debugger_iface_with_confmgr ();
+
+    debugger->set_event_loop_context (loop->get_context ());
+
+    //*****************************
+    //<connect to IDebugger events>
+    //*****************************
+    debugger->engine_died_signal ().connect (&on_engine_died_signal);
+    debugger->program_finished_signal ().connect
+        (sigc::bind<IDebuggerSafePtr> (&on_program_finished_signal, debugger));
+
+    std::vector<UString> args, source_search_dir;
+    debugger->enable_pretty_printing (false);
+    source_search_dir.push_back (".");
+
+    BOOST_REQUIRE (debugger->get_state () == IDebugger::NOT_STARTED);
+    debugger->load_program ("fooprog", args, ".",
+                            source_search_dir, "",
+                            false);
+    BOOST_REQUIRE (debugger->get_state () == IDebugger::INFERIOR_LOADED);
+
+    debugger->run ();
+    loop->run ();
+
+    NEMIVER_CATCH_NOX;
+
+    return 0;
+}
-- 
1.8.4.rc3



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