This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Broken cast in linux-thread-db


Casting a pointer to CORE_ADDR results in implementation defined behaviour
when the latter is wider than a pointer.  The implementation's behaviour
might be to sign extend which is not what we want here.  Tested on
i386-suse-linux with --enable-64-bit-bfd.

Andreas.

2005-10-12  Andreas Schwab  <schwab@suse.de>

	* linux-thread-db.c (enable_thread_event): Cast pointer to
	uintptr_t to avoid implementation defined behaviour.
	(thread_db_get_thread_local_address): Likewise.

--- gdb/linux-thread-db.c.~1.10.~	2005-09-12 11:04:57.000000000 +0200
+++ gdb/linux-thread-db.c	2005-10-12 15:16:06.000000000 +0200
@@ -505,9 +505,13 @@ enable_thread_event (td_thragent_t *thre
     return err;
 
   /* Set up the breakpoint.  */
-  (*bp) = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
-					      (CORE_ADDR) notify.u.bptaddr,
-					      &current_target);
+  (*bp) = (gdbarch_convert_from_func_ptr_addr
+	   (current_gdbarch,
+	    /* Don't cast directly to CORE_ADDR, which may be wider than a
+	       pointer and results in implementation defined
+	       behaviour.  */
+	    (uintptr_t) notify.u.bptaddr,
+	    &current_target));
   create_thread_event_breakpoint ((*bp));
 
   return TD_OK;
@@ -1277,7 +1281,10 @@ thread_db_get_thread_local_address (ptid
                      (("%s")), thread_db_err_str (err));
 
       /* Cast assuming host == target.  Joy.  */
-      return (CORE_ADDR) address;
+      /* Don't cast directly to CORE_ADDR, which may be wider than a
+	 pointer and results in implementation defined behaviour.  GCC
+	 would sign extend the value which is not what we want here.  */
+      return (uintptr_t) address;
     }
 
   if (target_beneath->to_get_thread_local_address)

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]