From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9493 invoked by alias); 16 Sep 2011 22:44:12 -0000 Received: (qmail 9484 invoked by uid 22791); 16 Sep 2011 22:44:10 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from barfooze.de (HELO barfooze.de) (78.46.117.212) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Sep 2011 22:43:52 +0000 Received: from xdsl-188-155-204-78.adslplus.ch ([188.155.204.78] helo=[172.16.0.230]) by barfooze.de with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.76) (envelope-from ) id 1R4h8H-0005gh-KV for gdb-patches@sourceware.org; Sat, 17 Sep 2011 00:43:51 +0200 Message-ID: <4E73D06F.603@barfooze.de> Date: Fri, 16 Sep 2011 23:01:00 -0000 From: John Spencer User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Mail/1.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: wrong assumptions about pthread_t being numeric Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-09/txt/msg00329.txt.bz2 there are a couple of spots in thread handling which assume that thread_t (typedef of pthread_t) is of a numeric type. according to POSIX http://pubs.opengroup.org/onlinepubs/007904875/basedefs/sys/types.h.html pthread_t is a non-arithmetic type. thus whenever a "thread id" of type pthread_t is used in a numeric context, it invokes undefined behaviour, since pthread_t could be a struct, a pointer, etc. for example, it is implemented as a pointer to a struct in musl libc for efficiency. i basically wanted to fix my compile error and send a patch, but i think this should be discussed first. thread-db.c: In function 'find_one_thread': thread-db.c:295:7: error: format '%ld' expects type 'long int', but argument 3 has type 'thread_t' thread-db.c: In function 'attach_thread': thread-db.c:335:7: error: format '%ld' expects type 'long int', but argument 3 has type 'thread_t' thread-db.c:341:9: error: format '%ld' expects type 'long int', but argument 2 has type 'thread_t' $ grep ti_tid `find gdb-7.3.1 -name '*.c'` gdb-7.3.1/gdb/sol-thread.c: return BUILD_THREAD (ti.ti_tid, PIDGET (lwp)); gdb-7.3.1/gdb/sol-thread.c: ptid = BUILD_THREAD (ti.ti_tid, PIDGET (inferior_ptid)); gdb-7.3.1/gdb/sol-thread.c: ti.ti_tid, ti.ti_lid); gdb-7.3.1/gdb/linux-thread-db.c: gdb_assert (ti_p->ti_tid != 0); gdb-7.3.1/gdb/linux-thread-db.c: private->tid = ti_p->ti_tid; gdb-7.3.1/gdb/linux-thread-db.c: if (ti.ti_tid == 0 && target_has_execution) gdb-7.3.1/gdb/gdbserver/thread-db.c: ti.ti_tid, ti.ti_lid); gdb-7.3.1/gdb/gdbserver/thread-db.c: if (ti.ti_tid == 0) gdb-7.3.1/gdb/gdbserver/thread-db.c: ti_p->ti_tid, ti_p->ti_lid); gdb-7.3.1/gdb/gdbserver/thread-db.c: ti_p->ti_tid, ti_p->ti_lid); gdb-7.3.1/gdb/aix-thread.c: return thrinf.ti_tid; -- JS