From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10495 invoked by alias); 15 Jul 2002 20:09:39 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 10425 invoked from network); 15 Jul 2002 20:09:37 -0000 Received: from unknown (HELO potter.sfbay.redhat.com) (205.180.83.107) by sources.redhat.com with SMTP; 15 Jul 2002 20:09:37 -0000 Received: from romulus.sfbay.redhat.com (remus.sfbay.redhat.com [172.16.27.252]) by potter.sfbay.redhat.com (8.11.6/8.11.6) with ESMTP id g6FKAFQ16680 for ; Mon, 15 Jul 2002 13:10:15 -0700 Received: (from kev@localhost) by romulus.sfbay.redhat.com (8.11.6/8.11.6) id g6FK9YR05452 for gdb-patches@sources.redhat.com; Mon, 15 Jul 2002 13:09:34 -0700 Date: Mon, 15 Jul 2002 13:23:00 -0000 From: Kevin Buettner Message-Id: <1020715200934.ZM5451@localhost.localdomain> To: gdb-patches@sources.redhat.com Subject: [PATCH] aix-thread.c: Eliminate goto statements / fix array overrun MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-07/txt/msg00340.txt.bz2 I've just committed the following patch... * aix-thread.c (ptrace_check): Eliminate goto. (sync_threadlists): Eliminate gotos. Also, fix array overrun problem. Index: aix-thread.c =================================================================== RCS file: /cvs/src/src/gdb/aix-thread.c,v retrieving revision 1.2 diff -u -p -r1.2 aix-thread.c --- aix-thread.c 15 Jul 2002 18:55:04 -0000 1.2 +++ aix-thread.c 15 Jul 2002 20:03:05 -0000 @@ -249,17 +249,17 @@ ptrace_check (int req, int id, int ret) case PTT_READ_FPRS: case PTT_READ_SPRS: if (ret == -1 && errno == EPERM) - goto strange; + { + if (debug_aix_thread) + fprintf_unfiltered (gdb_stdlog, "ptrace (%d, %d) = %d (errno = %d)", + req, id, ret, errno); + return ret == -1 ? 0 : 1; + } break; } error ("aix-thread: ptrace (%d, %d) returned %d (errno = %d %s)", req, id, ret, errno, strerror (errno)); - - strange: - if (debug_aix_thread) - fprintf_unfiltered (gdb_stdlog, "ptrace (%d, %d) = %d (errno = %d)", - req, id, ret, errno); - return ret == -1 ? 0 : 1; + return 0; /* not reached. */ } /* Call ptracex(REQ, ID, ADDR, DATA, BUF). Return success. */ @@ -643,7 +643,6 @@ sync_threadlists (void) pthdb_pthread_t pdtid; pthread_t pthid; pthdb_tid_t tid; - ptid_t pptid, gptid; /* Accumulate an array of libpthdebug threads sorted by pthread id. */ @@ -694,39 +693,52 @@ sync_threadlists (void) infpid = PIDGET (inferior_ptid); for (pi = gi = 0; pi < pcount || gi < gcount;) { - pptid = BUILD_THREAD (pbuf[pi].pthid, infpid); - gptid = gbuf[gi]->ptid; - pdtid = pbuf[pi].pdtid; - tid = pbuf[pi].tid; - if (pi == pcount) - goto del; - if (gi == gcount) - goto add; - - if (ptid_equal (pptid, gptid)) { - gbuf[gi]->private->pdtid = pdtid; - gbuf[gi]->private->tid = tid; - pi++; + delete_thread (gbuf[gi]->ptid); gi++; } - else if (ptid_cmp (pptid, gptid) > 0) - { - del: - delete_thread (gptid); - gi++; - } - else + else if (gi == gcount) { - add: - thread = add_thread (pptid); + thread = add_thread (BUILD_THREAD (pbuf[pi].pthid, infpid)); thread->private = xmalloc (sizeof (struct private_thread_info)); - thread->private->pdtid = pdtid; - thread->private->tid = tid; + 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); + gptid = gbuf[gi]->ptid; + pdtid = pbuf[pi].pdtid; + tid = pbuf[pi].tid; + cmp_result = ptid_cmp (pptid, gptid); + + if (cmp_result == 0) + { + gbuf[gi]->private->pdtid = pdtid; + gbuf[gi]->private->tid = tid; + pi++; + gi++; + } + else if (cmp_result > 0) + { + delete_thread (gptid); + gi++; + } + else + { + thread = add_thread (pptid); + thread->private = xmalloc (sizeof (struct private_thread_info)); + thread->private->pdtid = pdtid; + thread->private->tid = tid; + pi++; + } + } } xfree (pbuf);