This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Patch eclipse error, when gdb is used with rr reverse-execution


From 40c56962b4b02bd487a8b40e38d14af756515ce6 Mon Sep 17 00:00:00 2001
From: Mangold <kevin.mangold@siemens.com>
Date: Wed, 8 Aug 2018 15:33:28 +0200
Subject: [PATCH] When rr (https://github.com/mozilla/rr) is used with gdb and
eclipse reverse execution of a thread creation can cause an eclipse error, if
we continue and reverse-continue to fast over the thread creation. Eclipse
wants to update the stack-list-frames and therefore wants thread
infomrations. It's a bug in eclipse we can not fix, because reverse execution
with rr is not supported in eclipse. With this 'patch' we do not throw an
error, if eclipse is used with rr and gdb. For that to work, we must sent the
command 'reverse_execution_on_in_eclipse'. Then the find_thread_id and
find_thread_global_id function return a valid thread_info for eclipse, when
they want to update the stack-list-frames. If this patch gets merged, we
could add the next ability to track over the correct thread id's, when using
rr in eclipse.

gdb/Changelog

                        * thread.c: changed function find_global_thread_id
                        and find_thread_id to work with rr and eclipse.
                        Add command 'reverse_execution_on_in_eclipse' which
                        allows the rr interface to prepare gdb, when used
                        with rr and eclipse.
---
gdb/thread.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/gdb/thread.c b/gdb/thread.c
index 5071fdb27f..2b19d5be78 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -482,14 +482,29 @@ delete_thread_silent (thread_info *thread)
   delete_thread_1 (thread, true /* silent */);
}
+bool reverse_execution_on_in_eclipse = false;
+
struct thread_info *
find_thread_global_id (int global_id)
{
   struct thread_info *tp;
+  int thread_num = 0;
-  for (tp = thread_list; tp; tp = tp->next)
+  for (tp = thread_list; tp; tp = tp->next) {
     if (tp->global_num == global_id)
       return tp;
+    thread_num++;
+  }
+
+  // if we did not find any matching thread, it could be that
+  // we are using reverse debugging and reverse executed over
+  // a thread creation. We select then the thread with highest
+  // thread id as actual thread, so we do not throw any errors.
+  // If we can not find any threads, we return zero. We are
+  // doing this, only when reverse execution is enabled
+  if (reverse_execution_on_in_eclipse)
+          if (global_id > thread_num)
+      return find_thread_global_id(global_id - 1);
   return NULL;
}
@@ -498,10 +513,23 @@ static struct thread_info *
find_thread_id (struct inferior *inf, int thr_num)
{
   struct thread_info *tp;
+  int thread_num = 0;
-  for (tp = thread_list; tp; tp = tp->next)
+  for (tp = thread_list; tp; tp = tp->next) {
     if (tp->inf == inf && tp->per_inf_num == thr_num)
       return tp;
+    thread_num++;
+  }
+
+  // if we did not find any matching thread, it could be that
+  // we are using reverse debugging and reverse executed over
+  // a thread creation. We select then the thread with highest
+  // thread id as actual thread, so we do not throw any errors.
+  // If we can not find any threads, we return zero. We are
+  // doing this, only when reverse execution is enabled
+  if (reverse_execution_on_in_eclipse)
+    if (thr_num > thread_num)
+      return find_thread_global_id(thr_num - 1);
   return NULL;
}
@@ -2058,6 +2086,12 @@ global_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
   return thread_num_make_value_helper (gdbarch, 1);
}
+static void
+set_reverse_execution_on_in_eclipse (const char *arg, int from_tty)
+{
+          reverse_execution_on_in_eclipse = true;
+}
+
/* Commands with a prefix of `thread'.  */
struct cmd_list_element *thread_cmd_list = NULL;
@@ -2144,6 +2178,14 @@ Usage: thread find REGEXP\n\
Will display thread ids whose name, target ID, or extra info matches REGEXP."),
              &thread_cmd_list);
+  add_cmd ("reverse_execution_on_in_eclipse", class_run,
+set_reverse_execution_on_in_eclipse, _("\
+Call this function, when the debugger is used with rr \n\
+(record/replay from https://github.com/mozilla/rr ).\n\
+rr calls this function automated, when used correct with eclipse, \n\
+more Information: https://github.com/mozilla/rr/wiki/Using-rr-in-an-IDE \n\
+Do not use this function manual!"), &cmdlist);
+
   add_com_alias ("t", "thread", class_run, 1);
   add_setshow_boolean_cmd ("thread-events", no_class,
--
2.17.1.windows.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]