linux-snps-arc.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Evgeniy Didin <Evgeniy.Didin@synopsys.com>
To: gdb-patches@sourceware.org
Cc: Cupertino Miranda <Cupertino.Miranda@synopsys.com>,
	Vineet Gupta <Vineet.Gupta1@synopsys.com>,
	Alexey Brodkin <Alexey.Brodkin@synopsys.com>,
	Shahab Vahedi <Shahab.Vahedi@synopsys.com>,
	Evgeniy Didin <Evgeniy.Didin@synopsys.com>,
	linux-snps-arc@lists.infradead.org,
	Claudiu Zissulescu <Claudiu.Zissulescu@synopsys.com>
Subject: [PATCH] gdb/remote: Remove negative tid/pid handling in wite_ptid
Date: Wed,  6 Nov 2019 13:37:56 +0300	[thread overview]
Message-ID: <20191106103756.1066-1-didin@synopsys.com> (raw)

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 <didin@synopsys.com>

        * remote.c (remote_target::write_ptid):  Remove handling
         negative tid,pid. Change "int" to uint32_t for pid/tid.

Signed-off-by: Evgeniy Didin <didin@synopsys.com>
Cc: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Claudiu Zissulescu <claziss@synopsys.com>
Cc: Cupertino Miranda <cmiranda@synopsys.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Shahab Vahedi <shahab@synopsys.com>
Cc: linux-snps-arc@lists.infradead.org

Signed-off-by: Evgeniy Didin <didin@synopsys.com>
---
 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 <didin@synopsys.com>
+
+	* remote.c (remote_target::write_ptid):  Remove handling
+	negative tid,pid. Change "int" to uint32_t for pid/tid.
+
+
 2019-11-05  Tom Tromey  <tom@tromey.com>
 
 	* tui/tui-disasm.c (struct tui_asm_line) <addr_size>: 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;
 }
-- 
2.17.2


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

                 reply	other threads:[~2019-11-06 10:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191106103756.1066-1-didin@synopsys.com \
    --to=evgeniy.didin@synopsys.com \
    --cc=Alexey.Brodkin@synopsys.com \
    --cc=Claudiu.Zissulescu@synopsys.com \
    --cc=Cupertino.Miranda@synopsys.com \
    --cc=Shahab.Vahedi@synopsys.com \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=gdb-patches@sourceware.org \
    --cc=linux-snps-arc@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).