Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* wrong assumptions about pthread_t being numeric
@ 2011-09-16 23:01 John Spencer
  2011-09-16 23:16 ` Pedro Alves
  0 siblings, 1 reply; 19+ messages in thread
From: John Spencer @ 2011-09-16 23:01 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-10-05  8:02 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-16 23:01 wrong assumptions about pthread_t being numeric John Spencer
2011-09-16 23:16 ` Pedro Alves
2011-09-17  0:31   ` John Spencer
2011-09-17  1:05     ` Pedro Alves
2011-09-17  1:23       ` John Spencer
2011-09-17  2:29         ` Matt Rice
2011-09-17  6:47         ` Joel Brobecker
2011-09-18  0:11           ` John Spencer
2011-09-29  2:31             ` John Spencer
2011-09-29  8:39               ` Kai Tietz
2011-10-01  1:08                 ` John Spencer
2011-09-29 11:10               ` Pedro Alves
2011-09-17 15:29         ` Pedro Alves
2011-09-17 15:47           ` Pedro Alves
2011-10-01  1:02             ` John Spencer
2011-10-01  2:00               ` Pedro Alves
2011-10-01  9:00                 ` Mark Kettenis
2011-10-01  9:14                   ` Kevin Pouget
2011-10-05  8:02                 ` John Spencer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox