* aix-thread.c (ptrace_check): Eliminate goto.

(sync_threadlists): Eliminate gotos.  Also, fix array overrun
	problem.
This commit is contained in:
Kevin Buettner
2002-07-15 20:06:12 +00:00
parent 8e2c28d425
commit 42cc437fb0
2 changed files with 50 additions and 32 deletions

View File

@ -1,3 +1,9 @@
2002-07-15 Kevin Buettner <kevinb@redhat.com>
* aix-thread.c (ptrace_check): Eliminate goto.
(sync_threadlists): Eliminate gotos. Also, fix array overrun
problem.
2002-07-15 Kevin Buettner <kevinb@redhat.com> 2002-07-15 Kevin Buettner <kevinb@redhat.com>
* aix-thread.c (gdbcmd.h): Include. * aix-thread.c (gdbcmd.h): Include.

View File

@ -249,17 +249,17 @@ ptrace_check (int req, int id, int ret)
case PTT_READ_FPRS: case PTT_READ_FPRS:
case PTT_READ_SPRS: case PTT_READ_SPRS:
if (ret == -1 && errno == EPERM) if (ret == -1 && errno == EPERM)
goto strange; {
break;
}
error ("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)",
req, id, ret, errno, strerror (errno));
strange:
if (debug_aix_thread) if (debug_aix_thread)
fprintf_unfiltered (gdb_stdlog, "ptrace (%d, %d) = %d (errno = %d)", fprintf_unfiltered (gdb_stdlog, "ptrace (%d, %d) = %d (errno = %d)",
req, id, ret, errno); req, id, ret, errno);
return ret == -1 ? 0 : 1; return ret == -1 ? 0 : 1;
}
break;
}
error ("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)",
req, id, ret, errno, strerror (errno));
return 0; /* not reached. */
} }
/* Call ptracex(REQ, ID, ADDR, DATA, BUF). Return success. */ /* Call ptracex(REQ, ID, ADDR, DATA, BUF). Return success. */
@ -643,7 +643,6 @@ sync_threadlists (void)
pthdb_pthread_t pdtid; pthdb_pthread_t pdtid;
pthread_t pthid; pthread_t pthid;
pthdb_tid_t tid; pthdb_tid_t tid;
ptid_t pptid, gptid;
/* Accumulate an array of libpthdebug threads sorted by pthread id. */ /* Accumulate an array of libpthdebug threads sorted by pthread id. */
@ -694,39 +693,52 @@ sync_threadlists (void)
infpid = PIDGET (inferior_ptid); infpid = PIDGET (inferior_ptid);
for (pi = gi = 0; pi < pcount || gi < gcount;) for (pi = gi = 0; pi < pcount || gi < gcount;)
{ {
if (pi == pcount)
{
delete_thread (gbuf[gi]->ptid);
gi++;
}
else if (gi == gcount)
{
thread = add_thread (BUILD_THREAD (pbuf[pi].pthid, infpid));
thread->private = xmalloc (sizeof (struct private_thread_info));
thread->private->pdtid = pbuf[pi].pdtid;
thread->private->tid = pbuf[pi].tid;
pi++;
}
else
{
ptid_t pptid, gptid;
int cmp_result;
pptid = BUILD_THREAD (pbuf[pi].pthid, infpid); pptid = BUILD_THREAD (pbuf[pi].pthid, infpid);
gptid = gbuf[gi]->ptid; gptid = gbuf[gi]->ptid;
pdtid = pbuf[pi].pdtid; pdtid = pbuf[pi].pdtid;
tid = pbuf[pi].tid; tid = pbuf[pi].tid;
if (pi == pcount) cmp_result = ptid_cmp (pptid, gptid);
goto del;
if (gi == gcount)
goto add;
if (ptid_equal (pptid, gptid)) if (cmp_result == 0)
{ {
gbuf[gi]->private->pdtid = pdtid; gbuf[gi]->private->pdtid = pdtid;
gbuf[gi]->private->tid = tid; gbuf[gi]->private->tid = tid;
pi++; pi++;
gi++; gi++;
} }
else if (ptid_cmp (pptid, gptid) > 0) else if (cmp_result > 0)
{ {
del:
delete_thread (gptid); delete_thread (gptid);
gi++; gi++;
} }
else else
{ {
add:
thread = add_thread (pptid); thread = add_thread (pptid);
thread->private = xmalloc (sizeof (struct private_thread_info)); thread->private = xmalloc (sizeof (struct private_thread_info));
thread->private->pdtid = pdtid; thread->private->pdtid = pdtid;
thread->private->tid = tid; thread->private->tid = tid;
pi++; pi++;
} }
}
} }
xfree (pbuf); xfree (pbuf);