[nemiver] Update call stack on thread sel (Closes: #601199)



commit 8eb5cf3c4d71f4d5cf791e271bf7b28f265cc61e
Author: Dodji Seketeli <dodji redhat com>
Date:   Sun Nov 8 22:29:11 2009 +0100

    Update call stack on thread sel (Closes: #601199)
    
    	* src/persp/dbgperspective/nmv-call-stack.cc:
    	(CallStack::Priv::handle_update): Break out from
    	CallStack::Priv::on_debugger_stopped_signal.
    	(CallStack::Priv::on_thread_selected_signal): New signal handler.
    	Use the new CallStack::Priv::handle_update.
    	(CallStack::Priv::connect_debugger_signals): Update the call
    	stack when a new thread is selected.
    	(CallStack::Priv::on_debugger_stopped_signal): Use the new
    	CallStack::Priv::handle_update.
    	(finish_update_handling): Renamed finish_handling_debugger_stopped_event
    	into this.
    	(CallStack::Priv::on_expose_event_signal): Adjust.
    	* tests/threads.cc: New test.
    	* tests/Makefile.am: Add new test to build system.

 src/persp/dbgperspective/nmv-call-stack.cc |   43 ++++++++++++++-------
 tests/Makefile.am                          |    5 ++-
 tests/threads.cc                           |   56 ++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 15 deletions(-)
---
diff --git a/src/persp/dbgperspective/nmv-call-stack.cc b/src/persp/dbgperspective/nmv-call-stack.cc
index e140f3a..ec56ef5 100644
--- a/src/persp/dbgperspective/nmv-call-stack.cc
+++ b/src/persp/dbgperspective/nmv-call-stack.cc
@@ -240,12 +240,28 @@ struct CallStack::Priv {
         debugger->select_frame (cur_frame_index);
     }
 
-    void finish_handling_debugger_stopped_event ()
+    void finish_update_handling ()
     {
         THROW_IF_FAIL (debugger);
         debugger->list_frames (frame_low, frame_high);
     }
 
+    void handle_update (const UString &a_cookie)
+    {
+        if (a_cookie != COOKIE_CALL_STACK_IN_FRAME_PAGING_TRANS) {
+            // Restore the frame window, in case the user changed it by
+            // requesting more call stack frames.
+            frame_low = 0;
+            frame_high = nb_frames_expansion_chunk;
+        }
+
+        if (should_process_now ()) {
+            finish_update_handling ();
+        } else {
+            is_up2date = false;
+        }
+    }
+
     void on_debugger_stopped_signal (IDebugger::StopReason a_reason,
                                      bool /*a_has_frame*/,
                                      const IDebugger::Frame &/*a_frame*/,
@@ -264,22 +280,19 @@ struct CallStack::Priv {
             return;
         }
 
-        if (a_cookie != COOKIE_CALL_STACK_IN_FRAME_PAGING_TRANS) {
-            // Restore the frame window, in case the user changed it by
-            // requesting more call stack frames.
-            frame_low = 0;
-            frame_high = nb_frames_expansion_chunk;
-        }
-
-        if (should_process_now ()) {
-            finish_handling_debugger_stopped_event ();
-        } else {
-            is_up2date = false;
-        }
+        handle_update (a_cookie);
 
         NEMIVER_CATCH
     }
 
+    void on_thread_selected_signal (int /*a_thread_id*/,
+                                    const IDebugger::Frame* const /*a_frame*/,
+                                    const UString& a_cookie)
+    {
+        LOG_FUNCTION_SCOPE_NORMAL_DD;
+        handle_update (a_cookie);
+    }
+
     void on_frames_listed_signal (const vector<IDebugger::Frame> &a_stack,
                                   const UString &a_cookie)
     {
@@ -387,7 +400,7 @@ struct CallStack::Priv {
 
         NEMIVER_TRY
         if (!is_up2date) {
-            finish_handling_debugger_stopped_event ();
+            finish_update_handling ();
             is_up2date = true;
         }
         NEMIVER_CATCH
@@ -412,6 +425,8 @@ struct CallStack::Priv {
 
         debugger->stopped_signal ().connect (sigc::mem_fun
                     (*this, &CallStack::Priv::on_debugger_stopped_signal));
+        debugger->thread_selected_signal ().connect (sigc::mem_fun
+                     (*this, &CallStack::Priv::on_thread_selected_signal));
         debugger->frames_listed_signal ().connect (sigc::mem_fun
                     (*this, &CallStack::Priv::on_frames_listed_signal));
         debugger->frames_arguments_listed_signal ().connect (sigc::mem_fun
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b945170..919ff3c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,7 +24,7 @@ noinst_PROGRAMS= \
 $(TESTS) \
 runtestcore  runteststdout  docore inout \
 pointerderef fooprog templatedvar \
-gtkmmtest dostackoverflow bigvar
+gtkmmtest dostackoverflow bigvar threads
 
 runtestgdbmi_SOURCES=test-gdbmi.cc
 runtestgdbmi_LDADD= @NEMIVERCOMMON_LIBS@ \
@@ -150,6 +150,9 @@ dostackoverflow_LDADD= NEMIVERCOMMON_LIBS@
 bigvar_SOURCES=big-var.c
 bigvar_LDADD= NEMIVERCOMMON_LIBS@
 
+threads_SOURCES=threads.c
+threads_LDADD= NEMIVERCOMMON_LIBS@
+
 INCLUDES=-I$(top_srcdir)/src \
 -I$(top_srcdir)/src/confmgr \
 -I$(top_srcdir)/src/dbgengine \
diff --git a/tests/threads.cc b/tests/threads.cc
new file mode 100644
index 0000000..1d19e65
--- /dev/null
+++ b/tests/threads.cc
@@ -0,0 +1,56 @@
+#include <pthread.h>
+#include <cstdlib>
+#include <cassert>
+#include <string>
+#include <iostream>
+
+static const int NUM_ITER = 10000;
+static const int NUM_THREADS = 5;
+// pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+// pthread_cond_t c = PTHREAD_COND_INITIALIZER;
+
+
+struct thread_info
+{
+    pthread_t tid;
+    int tnum;
+
+    thread_info ()
+    : tid (0), tnum (0)
+    {
+    }
+};
+thread_info threads[NUM_THREADS];
+using namespace std;
+
+void*
+thread_func (void *arg)
+{
+    assert (arg != 0);
+    thread_info *ti = static_cast<thread_info*> (arg);
+    for (int i = 0; i < NUM_ITER; ++i) {
+        cout << "thread " << ti->tnum << ":iter:" << i << "\n";
+    }
+    cout << flush;
+    return NULL;
+}
+
+int
+main ()
+{
+    for (int i = 0; i < NUM_THREADS; ++i) {
+        threads[i].tnum = i;
+        if (pthread_create (&threads[i].tid,
+                            NULL,
+                            &thread_func,
+                            &threads[i])) {
+            cerr << "Failed to create thread id number: "<< i << endl;
+            exit (EXIT_FAILURE);
+        }
+    }
+    for (int i = 0; i < NUM_THREADS; ++i) {
+        pthread_join (threads[i].tid, NULL);
+    }
+    return 0;
+}
+



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