From patchwork Tue Mar 26 14:43:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31987 Received: (qmail 80862 invoked by alias); 26 Mar 2019 14:44:11 -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 79280 invoked by uid 89); 26 Mar 2019 14:44:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=1558, objfilesh, UD:objfiles.h, objfiles.h X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Mar 2019 14:44:08 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5A090116C6F; Tue, 26 Mar 2019 10:44:07 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id V5WWDPzyfsvj; Tue, 26 Mar 2019 10:44:07 -0400 (EDT) Received: from murgatroyd.Home (174-29-37-56.hlrn.qwest.net [174.29.37.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 06750116C5F; Tue, 26 Mar 2019 10:44:06 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/8] Handle case where Ada task is current but not listed Date: Tue, 26 Mar 2019 08:43:58 -0600 Message-Id: <20190326144404.6670-3-tromey@adacore.com> In-Reply-To: <20190326144404.6670-1-tromey@adacore.com> References: <20190326144404.6670-1-tromey@adacore.com> MIME-Version: 1.0 Currently, the ravenscar runtime can mark an Ada task as the current task, before adding it to the list of tasks that can be read by gdb. In this scenario, gdb can sometimes crash in ravenscar_get_thread_base_cpu with: ../../src/gdb/ravenscar-thread.c:167: internal-error: int ravenscar_get_thread_base_cpu(ptid_t): Assertion `task_info != NULL' failed. However, as ravenscar_get_thread_base_cpu is only called to find the base CPU, we can simply record this when registering the thread, and look this up later. gdb/ChangeLog 2019-03-26 Tom Tromey * ravenscar-thread.c (ravenscar_thread_target) : Now methods. : New member. (ravenscar_thread_target::get_thread_base_cpu): Rename from ravenscar_get_thread_base_cpu. Check cpu_map. (ravenscar_thread_target::task_is_currently_active): Update. (ravenscar_thread_target::get_base_thread_from_ravenscar_task): Now a method. (ravenscar_thread_target::update_inferior_ptid): Put initial thread into the cpu_map. --- gdb/ChangeLog | 13 +++++++++++++ gdb/ravenscar-thread.c | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index 225bffcb65a..a8f8ac8c440 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -30,6 +30,7 @@ #include "top.h" #include "regcache.h" #include "objfiles.h" +#include /* This module provides support for "Ravenscar" tasks (Ada) when debugging on bare-metal targets. @@ -132,6 +133,14 @@ private: ptid_t active_task (int cpu); bool task_is_currently_active (ptid_t ptid); bool runtime_initialized (); + int get_thread_base_cpu (ptid_t ptid); + ptid_t get_base_thread_from_ravenscar_task (ptid_t ptid); + + /* This maps a TID to the CPU on which it was running. This is + needed because sometimes the runtime will report an active task + that hasn't yet been put on the list of tasks that is read by + ada-tasks.c. */ + std::unordered_map cpu_map; }; /* Return true iff PTID corresponds to a ravenscar task. */ @@ -155,8 +164,8 @@ is_ravenscar_task (ptid_t ptid) This assume that PTID is a valid ptid_t. Otherwise, a gdb_assert will be triggered. */ -static int -ravenscar_get_thread_base_cpu (ptid_t ptid) +int +ravenscar_thread_target::get_thread_base_cpu (ptid_t ptid) { int base_cpu; @@ -164,8 +173,15 @@ ravenscar_get_thread_base_cpu (ptid_t ptid) { struct ada_task_info *task_info = ada_get_task_info_from_ptid (ptid); - gdb_assert (task_info != NULL); - base_cpu = task_info->base_cpu; + if (task_info != NULL) + base_cpu = task_info->base_cpu; + else + { + auto iter = cpu_map.find (ptid.tid ()); + + gdb_assert (iter != cpu_map.end ()); + base_cpu = iter->second; + } } else { @@ -189,8 +205,7 @@ ravenscar_get_thread_base_cpu (ptid_t ptid) bool ravenscar_thread_target::task_is_currently_active (ptid_t ptid) { - ptid_t active_task_ptid - = active_task (ravenscar_get_thread_base_cpu (ptid)); + ptid_t active_task_ptid = active_task (get_thread_base_cpu (ptid)); return ptid == active_task_ptid; } @@ -201,15 +216,15 @@ ravenscar_thread_target::task_is_currently_active (ptid_t ptid) This is the thread that corresponds to the CPU on which the task is running. */ -static ptid_t -get_base_thread_from_ravenscar_task (ptid_t ptid) +ptid_t +ravenscar_thread_target::get_base_thread_from_ravenscar_task (ptid_t ptid) { int base_cpu; if (!is_ravenscar_task (ptid)) return ptid; - base_cpu = ravenscar_get_thread_base_cpu (ptid); + base_cpu = get_thread_base_cpu (ptid); return ptid_t (ptid.pid (), base_cpu, 0); } @@ -224,7 +239,7 @@ ravenscar_thread_target::update_inferior_ptid () m_base_ptid = inferior_ptid; gdb_assert (!is_ravenscar_task (inferior_ptid)); - base_cpu = ravenscar_get_thread_base_cpu (m_base_ptid); + base_cpu = get_thread_base_cpu (m_base_ptid); /* If the runtime has not been initialized yet, the inferior_ptid is the only ptid that there is. */ @@ -240,7 +255,10 @@ ravenscar_thread_target::update_inferior_ptid () system.tasking.debug's list yet; so ravenscar_update_thread_list may not always add it to the thread list. Add it here. */ if (!find_thread_ptid (inferior_ptid)) - add_thread (inferior_ptid); + { + add_thread (inferior_ptid); + cpu_map[inferior_ptid.tid ()] = base_cpu; + } } /* The Ravenscar Runtime exports a symbol which contains the ID of