From patchwork Tue Nov 21 22:29:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 24435 Received: (qmail 39205 invoked by alias); 21 Nov 2017 22:29:34 -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 39169 invoked by uid 89); 21 Nov 2017 22:29:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=remotes, tar, Upon, our 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, 21 Nov 2017 22:29:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 93F96116523; Tue, 21 Nov 2017 17:29:31 -0500 (EST) 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 fLczFjvO9Lr7; Tue, 21 Nov 2017 17:29:31 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 6508C116505; Tue, 21 Nov 2017 17:29:31 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id ACA7D87459; Tue, 21 Nov 2017 14:29:29 -0800 (PST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Xavier Roirand Subject: [Ada 5/6] (Ada) crash connecting to TSIM simulator Date: Tue, 21 Nov 2017 14:29:22 -0800 Message-Id: <20171121222923.8951-6-brobecker@adacore.com> In-Reply-To: <20171121222923.8951-1-brobecker@adacore.com> References: <20171121222923.8951-1-brobecker@adacore.com> Connecting to a TSIM simulator over the remote protocol causes GDB to crash with the following failed assertion: (gdb) tar remote :1234 Remote debugging using :1234 /[...]/gdb/ravenscar-thread.c:182: internal-error: ravenscar_update_inferior_ptid: Assertion `!is_ravenscar_task (inferior_ptid)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) y What happens is the following. Upon connection to the target, GDB sends a 'qfThreadInfo' query, which is the query asking the target for the ID of the first thread, and TSIM replies 'm0': Sending packet: $qfThreadInfo#bb...Ack Packet received: m0 As a result of this, GDB takes the '0' as the TID, and because of it, constructs a ptid whose value is {42000, 0, 0}. This trips our !is_ravenscar_task check, because all it does to identify threads corresponding to ravenscar tasks is that their lwp is null, because that's how we construct their ptid. But this is unfortunatly not sufficient when debugging with TSIM, because the thread ID that TSIM returns causes the creation of a ptid whose lwp is zero, which matches the current identification scheme and yet is clearly not a ravenscar task. The fix is to also make sure that the ptid's tid field is nonzero. gdb/ChangeLog: * ravenscar-thread.c (is_ravenscar_task): Also verify that the ptid's TID is nonzero. --- gdb/ravenscar-thread.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index e7922277ce..00593b84db 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -101,8 +101,14 @@ static void ravenscar_inferior_created (struct target_ops *target, static int is_ravenscar_task (ptid_t ptid) { - /* By construction, ravenscar tasks have their LWP set to zero. */ - return ptid_get_lwp (ptid) == 0; + /* By construction, ravenscar tasks have their LWP set to zero. + Also make sure that the TID is nonzero, as some remotes, when + asked for the list of threads, will return the first thread + as having its TID set to zero. For instance, TSIM version + 2.0.48 for LEON3 sends 'm0' as a reply to the 'qfThreadInfo' + query, which the remote protocol layer then treats as a thread + whose TID is 0. This is obviously not a ravenscar task. */ + return ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) != 0; } /* Given PTID, which can be either a ravenscar task or a CPU thread,