From patchwork Wed Nov 6 10:37:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Didin X-Patchwork-Id: 35668 Received: (qmail 125075 invoked by alias); 6 Nov 2019 10:38:24 -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 125064 invoked by uid 89); 6 Nov 2019 10:38:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=U*claziss, Miranda, claziss@synopsys.com, clazisssynopsyscom X-HELO: smtprelay-out1.synopsys.com Received: from smtprelay-out1.synopsys.com (HELO smtprelay-out1.synopsys.com) (198.182.47.102) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Nov 2019 10:38:22 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 43AEEC0F34; Wed, 6 Nov 2019 10:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1573036701; bh=dr9R5HUDFEcK0T0CTPq86iG4DKgDDwdb9YPkFD1McnY=; h=From:To:Cc:Subject:Date:From; b=Jj7qlQV59SxIx1Mw6wUOiOMjQOs+nlGCk78Nl+nb7kMYrpdXqXuDAcYbhpwFG3KnK kCQ8B9lGUzFLI5dqiiitwefAxTkzxLoMkuyM9QzYpGputB22aoMs+ozqrx/Lsu/imv SB+ZhRIDzVBz1InkC2joMiCkRHeSWxBTJpcektfo9xJDcJZIBEUF7PemZXlh1JXGk/ xOQudpppQsk26J3JZaf94qyl94cDs2tvAc1X2XEu/BJ3lpS8nL44P3/s1bZQDF4exc hvB+hwOBFuQJTDyMowmCeQZgzRYXNN2q6OvEk7wPZ0NaRTSFD7OZ4J9N0ifmIxg6G4 OW56acWcn54ug== Received: from didin-7490l.internal.synopsys.com (didin-7490l.internal.synopsys.com [10.121.3.58]) by mailhost.synopsys.com (Postfix) with ESMTP id 38049A0071; Wed, 6 Nov 2019 10:38:09 +0000 (UTC) From: Evgeniy Didin To: gdb-patches@sourceware.org Cc: Evgeniy Didin , Alexey Brodkin , Claudiu Zissulescu , Cupertino Miranda , Vineet Gupta , Shahab Vahedi , linux-snps-arc@lists.infradead.org Subject: [PATCH] gdb/remote: Remove negative tid/pid handling in wite_ptid Date: Wed, 6 Nov 2019 13:37:56 +0300 Message-Id: <20191106103756.1066-1-didin@synopsys.com> Actually thread and process ID's are positive values. Accorting to http://man7.org/linux/man-pages/man7/pthreads.7.html threads are creating using "clone" syscall, so the ID generation mechanism is similar for threads and processes. According to Linux source code there is a function call tree, which allocates PID[TID]: clone |->_do_fork |->copy_process |->alloc_pid |->idr_alloc_cyclic |->idr_alloc_u32(idr, ptr, &id, max, gfp); And in idr_alloc_u32() "id" is u32 value, which means positiveness. Also according to: https://elixir.bootlin.com/linux/latest/source/kernel/pid.c#L177 PID cannot be less than 1. In Zephyr RTOS the k_thread_create function returns thread ID which is actually pointer to k_thread structure. If the memory addressing starts from 0x80000000, passing such big values to write_ptid() leads to overflow of "int tid" variable and thread ID becomes negative. So lets remove the code, which handles negative tid/pid values. gdb/ChangeLog: 2019-11-06 Evgeniy Didin * remote.c (remote_target::write_ptid): Remove handling negative tid,pid. Change "int" to uint32_t for pid/tid. Signed-off-by: Evgeniy Didin Cc: Alexey Brodkin Cc: Claudiu Zissulescu Cc: Cupertino Miranda Cc: Vineet Gupta Cc: Shahab Vahedi Cc: linux-snps-arc@lists.infradead.org Signed-off-by: Evgeniy Didin --- gdb/ChangeLog | 6 ++++++ gdb/remote.c | 12 +++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e886480d62..0011d064e9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-11-06 Evgeniy Didin + + * remote.c (remote_target::write_ptid): Remove handling + negative tid,pid. Change "int" to uint32_t for pid/tid. + + 2019-11-05 Tom Tromey * tui/tui-disasm.c (struct tui_asm_line) : New member. diff --git a/gdb/remote.c b/gdb/remote.c index 8ea52d355a..2c119fad1a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2909,22 +2909,16 @@ static int remote_newthread_step (threadref *ref, void *context); char * remote_target::write_ptid (char *buf, const char *endbuf, ptid_t ptid) { - int pid, tid; + uint32_t pid, tid; struct remote_state *rs = get_remote_state (); if (remote_multi_process_p (rs)) { pid = ptid.pid (); - if (pid < 0) - buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid); - else - buf += xsnprintf (buf, endbuf - buf, "p%x.", pid); + buf += xsnprintf (buf, endbuf - buf, "p%x.", pid); } tid = ptid.lwp (); - if (tid < 0) - buf += xsnprintf (buf, endbuf - buf, "-%x", -tid); - else - buf += xsnprintf (buf, endbuf - buf, "%x", tid); + buf += xsnprintf (buf, endbuf - buf, "%x", tid); return buf; }