Message ID | 20191106132732.11034-1-didin@synopsys.com |
---|---|
State | New |
Headers | show |
Series | [v2] gdb/remote: Remove negative tid/pid handling in wite_ptid | expand |
On 11/6/19 1:27 PM, Evgeniy Didin wrote: > 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. Sure for Linux. But negative numbers have meaning in the remote protocol: https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#thread_002did-syntax Thanks, Pedro Alves
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e886480d62..cd55d65ced 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 "unsigned int" 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..ea12d738c8 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; + unsigned int 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; }