gdb/remote: make tid/pid type long in wite_ptid
PATCH 1/1 gdb/remote: make tid/pid type long in wite_ptid
From: Evgeniy Didin <[email protected]>
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 make tid/pid variables type "long", this will prevent overflow and should not break any logic.
gdb/ChangeLog:
2019-11-09 Evgeniy Didin <[email protected]>
* remote.c (remote_target::write_ptid): Make tid,pid variables type "long" to prevent overflow.
Signed-off-by Evgeniy Didin <[email protected]>
--- gdb/ChangeLog | 5 +++++ gdb/remote.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-)
gdb/ChangeLog +5 -0
@@ -1,3 +1,8 @@ +2019-11-09 Evgeniy Didin <[email protected]> + + * remote.c (remote_target::write_ptid): Make tid,pid + variables type "long" to prevent overflow. + 2019-11-08 Tom Tromey <[email protected]> * top.c (read_command_file): Update.
gdb/remote.c +5 -5
@@ -2909,22 +2909,22 @@ 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; +long 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); + buf +=xsnprintf (buf, endbuf - buf,"p-%lx." , -pid);else - buf +=xsnprintf (buf, endbuf - buf,"p%x." , pid); + buf +=xsnprintf (buf, endbuf - buf,"p%lx." , pid); } tid = ptid.lwp ();if (tid <0 ) - buf +=xsnprintf (buf, endbuf - buf,"-%x" , -tid); + buf +=xsnprintf (buf, endbuf - buf,"-%lx" , -tid);else - buf +=xsnprintf (buf, endbuf - buf,"%x" , tid); + buf +=xsnprintf (buf, endbuf - buf,"%lx" , tid);return buf; }
Signature · 7 lines
2.16.2 _______________________________________________ linux-snps-arc mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-snps-arc