Author: Armin Rigo <ar...@tunes.org>
Branch: reverse-debugger
Changeset: r86160:e2ab29983fd5
Date: 2016-08-11 21:24 +0200
http://bitbucket.org/pypy/pypy/changeset/e2ab29983fd5/

Log:    During debugging, print a separator line when a thread switch occurs

diff --git a/rpython/translator/revdb/interact.py 
b/rpython/translator/revdb/interact.py
--- a/rpython/translator/revdb/interact.py
+++ b/rpython/translator/revdb/interact.py
@@ -37,10 +37,19 @@
     def interact(self):
         last_command = 'help'
         previous_time = None
+        previous_thread = 0
         while True:
             last_time = self.pgroup.get_current_time()
             if last_time != previous_time:
                 print
+                if self.pgroup.get_current_thread() != previous_thread:
+                    previous_thread = self.pgroup.get_current_thread()
+                    if previous_thread == 0:
+                        print ('-------------------- in the main thread '
+                               '--------------------')
+                    else:
+                        print ('-------------------- in non-main thread '
+                               '#%d --------------------' % (previous_thread,))
                 self.pgroup.update_watch_values()
                 last_time = self.pgroup.get_current_time()
             if self.print_extra_pending_info:
@@ -49,6 +58,7 @@
             if last_time != previous_time:
                 self.pgroup.show_backtrace(complete=0)
                 previous_time = last_time
+
             prompt = '(%d)$ ' % last_time
             try:
                 cmdline = raw_input(prompt).strip()
diff --git a/rpython/translator/revdb/process.py 
b/rpython/translator/revdb/process.py
--- a/rpython/translator/revdb/process.py
+++ b/rpython/translator/revdb/process.py
@@ -120,12 +120,13 @@
         return msg
 
     def expect_ready(self):
-        msg = self.expect(ANSWER_READY, Ellipsis, Ellipsis)
+        msg = self.expect(ANSWER_READY, Ellipsis, Ellipsis, Ellipsis)
         self.update_times(msg)
 
     def update_times(self, msg):
         self.current_time = msg.arg1
         self.currently_created_objects = msg.arg2
+        self.current_thread = msg.arg3
 
     def clone(self):
         """Fork this subprocess.  Returns a new ReplayProcess() that is
@@ -252,10 +253,13 @@
     def get_currently_created_objects(self):
         return self.active.currently_created_objects
 
+    def get_current_thread(self):
+        return self.active.current_thread
+
     def _check_current_time(self, time):
         assert self.get_current_time() == time
         self.active.send(Message(CMD_FORWARD, 0))
-        return self.active.expect(ANSWER_READY, time, Ellipsis)
+        return self.active.expect(ANSWER_READY, time, Ellipsis, Ellipsis)
 
     def get_max_time(self):
         return self.total_stop_points
diff --git a/rpython/translator/revdb/src-revdb/revdb.c 
b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -663,6 +663,7 @@
 static stacklet_thread_handle st_thread;
 static stacklet_handle st_outer_controller_h;
 static uint64_t current_thread_id, target_thread_id;
+static uint64_t current_thread_num, next_thread_num;
 static void *thread_tree_root;
 
 
@@ -672,7 +673,7 @@
     char **argv;
 };
 struct replay_thread_s {
-    uint64_t tid;
+    uint64_t tid, tnum;
     stacklet_handle h;
     struct pypy_threadlocal_s tloc;
 };
@@ -754,7 +755,9 @@
             struct replay_thread_s *node, **item, dummy;
 
             if (real_tloc == NULL) {
-                _OP_THREADLOCALREF_ADDR_SIGHANDLER(real_tloc);
+                char *p;
+                _OP_THREADLOCALREF_ADDR_SIGHANDLER(p);
+                real_tloc = (struct pypy_threadlocal_s *)p;
             }
 
             if (h == NULL)
@@ -767,6 +770,7 @@
                 if (!node)
                     goto out_of_memory;
                 node->tid = current_thread_id;
+                node->tnum = current_thread_num;
                 node->h = h;
                 /* save the thread-locals, if any */
                 if (real_tloc != NULL)
@@ -793,6 +797,7 @@
             item = tfind(&dummy, &thread_tree_root, compare_replay_thread);
             if (item == NULL) {
                 /* it's a new thread, start it now */
+                current_thread_num = next_thread_num++;
                 if (real_tloc != NULL)
                     memset(((char *)real_tloc) + RPY_TLOFSFIRST, 0,
                            sizeof(struct pypy_threadlocal_s) - RPY_TLOFSFIRST);
@@ -801,6 +806,7 @@
             else {
                 node = *item;
                 assert(node->tid == target_thread_id);
+                current_thread_num = node->tnum;
                 h = node->h;
                 tdelete(node, &thread_tree_root, compare_replay_thread);
                 if (real_tloc != NULL)
@@ -957,6 +963,8 @@
         exit(1);
     }
     current_thread_id = h.main_thread_id;
+    current_thread_num = 0;
+    next_thread_num = 1;
     if (h.ptr1 != &rpy_reverse_db_stop_point ||
         h.ptr2 != &rpy_revdb) {
         fprintf(stderr,
@@ -1389,7 +1397,7 @@
             write_answer(ANSWER_READY,
                          saved_state.stop_point_seen,
                          saved_state.unique_id_seen,
-                         0);
+                         current_thread_num);
             read_sock(&cmd, sizeof(cmd));
 
             char extra[cmd.extra_size + 1];
diff --git a/rpython/translator/revdb/test/test_thread.py 
b/rpython/translator/revdb/test/test_thread.py
--- a/rpython/translator/revdb/test/test_thread.py
+++ b/rpython/translator/revdb/test/test_thread.py
@@ -166,13 +166,14 @@
         child = self.replay()
         for i in range(2, 6):
             child.send(Message(CMD_FORWARD, 1))
-            child.expect(ANSWER_READY, i, Ellipsis)
+            child.expect(ANSWER_READY, i, Ellipsis,
+                         (i & 1) ^ 1)    # thread number: either 0 or 1 here
         child.send(Message(CMD_FORWARD, 1))
         child.expect(ANSWER_AT_END)
 
 
 class TestThreadLocal(InteractiveTests):
-    expected_stop_points = 1
+    expected_stop_points = 2
 
     def setup_class(cls):
         from rpython.translator.revdb.test.test_basic import compile, run
@@ -192,6 +193,7 @@
             rthread.gc_thread_die()
 
         def main(argv):
+            revdb.stop_point()
             ec = EC(12)
             raw_thread_local.set(ec)
             rthread.start_new_thread(bootstrap, ())
@@ -206,4 +208,6 @@
     def test_go_threadlocal(self):
         child = self.replay()
         child.send(Message(CMD_FORWARD, 1))
+        child.expect(ANSWER_READY, 2, Ellipsis, 1)
+        child.send(Message(CMD_FORWARD, 1))
         child.expect(ANSWER_AT_END)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to