From patchwork Wed Aug 8 14:11:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mangold, Kevin" X-Patchwork-Id: 28788 Received: (qmail 44996 invoked by alias); 8 Aug 2018 14:11:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 44986 invoked by uid 89); 8 Aug 2018 14:11:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HTML_MESSAGE, SPF_PASS autolearn=ham version=3.3.2 spammy=mozilla, Usage, replay, H*c:alternative X-HELO: gecko.sbs.de Received: from gecko.sbs.de (HELO gecko.sbs.de) (194.138.37.40) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Aug 2018 14:11:17 +0000 Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id w78EBEJn018870 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 8 Aug 2018 16:11:14 +0200 Received: from DEFTHW99ERKMSX.ww902.siemens.net (defthw99erkmsx.ww902.siemens.net [139.22.70.147]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTPS id w78EBEG5015345 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 8 Aug 2018 16:11:14 +0200 Received: from DEFTHW99EREMSX.ww902.siemens.net (139.22.70.66) by DEFTHW99ERKMSX.ww902.siemens.net (139.22.70.147) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 8 Aug 2018 16:11:13 +0200 Received: from DEFTHW99EH4MSX.ww902.siemens.net ([169.254.2.221]) by DEFTHW99EREMSX.ww902.siemens.net ([139.22.70.66]) with mapi id 14.03.0408.000; Wed, 8 Aug 2018 16:11:13 +0200 From: "Mangold, Kevin" To: "gdb-patches@sourceware.org" Subject: [PATCH] Patch eclipse error, when gdb is used with rr reverse-execution Date: Wed, 8 Aug 2018 14:11:12 +0000 Message-ID: MIME-Version: 1.0 From 40c56962b4b02bd487a8b40e38d14af756515ce6 Mon Sep 17 00:00:00 2001 From: Mangold 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(-) 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 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) {