Skip to content

Commit f7e68e1

Browse files
EvgeniiDidinstephanosio
authored andcommitted
gdb/remote: make tid/pid type long in write_ptid
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. Signed-off-by: Evgeniy Didin <didin@synopsys.com> Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
1 parent 4102c45 commit f7e68e1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

gdb/remote.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,21 +3443,21 @@ static int remote_newthread_step (threadref *ref, void *context);
34433443
char *
34443444
remote_target::write_ptid (char *buf, const char *endbuf, ptid_t ptid)
34453445
{
3446-
int pid, tid;
3446+
long pid, tid;
34473447

34483448
if (m_features.remote_multi_process_p ())
34493449
{
34503450
pid = ptid.pid ();
34513451
if (pid < 0)
3452-
buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
3452+
buf += xsnprintf (buf, endbuf - buf, "p-%lx.", -pid);
34533453
else
3454-
buf += xsnprintf (buf, endbuf - buf, "p%x.", pid);
3454+
buf += xsnprintf (buf, endbuf - buf, "p%lx.", pid);
34553455
}
34563456
tid = ptid.lwp ();
34573457
if (tid < 0)
3458-
buf += xsnprintf (buf, endbuf - buf, "-%x", -tid);
3458+
buf += xsnprintf (buf, endbuf - buf, "-%lx", -tid);
34593459
else
3460-
buf += xsnprintf (buf, endbuf - buf, "%x", tid);
3460+
buf += xsnprintf (buf, endbuf - buf, "%lx", tid);
34613461

34623462
return buf;
34633463
}

0 commit comments

Comments
 (0)