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]

[patch] Fix valgrind-detected read-uninitialized-mem.


Greetings,

I've run 'make check' with GDB='valgrind ../gdb', and discovered one
more problem: several tests, e.g. 'gdb.threads/killed.exp' report:

==28543== Conditional jump or move depends on uninitialised value(s)
==28543==    at 0x6EBD725: td_thr_get_info (/build/buildd/eglibc-2.11.1/nptl_db/td_thr_get_info.c:35)
==28543==    by 0x4CD8EC: thread_get_info_callback (/home/src/gdb/linux-thread-db.c:396)
==28543==    by 0x4CDBE2: thread_from_lwp (/home/src/gdb/linux-thread-db.c:458)
==28543==    by 0x4CF80C: thread_db_wait (/home/src/gdb/linux-thread-db.c:1378)
==28543==    by 0x5EB6B4: target_wait (/home/src/gdb/target.c:2534)
==28543==    by 0x5AD8DB: wait_for_inferior (/home/src/gdb/infrun.c:2671)
==28543==    by 0x5ACCAD: proceed (/home/src/gdb/infrun.c:2236)
==28543==    by 0x5A55A7: run_command_1 (/home/src/gdb/infcmd.c:610)
==28543==    by 0x5A55E1: run_command (/home/src/gdb/infcmd.c:620)
==28543==    by 0x4FACFC: do_cfunc (/home/src/gdb/cli/cli-decode.c:67)
==28543==    by 0x4FDDC3: cmd_func (/home/src/gdb/cli/cli-decode.c:1777)
==28543==    by 0x476D75: execute_command (/home/src/gdb/top.c:442)
==28543==  Uninitialised value was created by a stack allocation
==28543==    at 0x4CDA7A: thread_from_lwp (/home/src/gdb/linux-thread-db.c:428)

AFAICT, this is a case of "don't care" -- th.th_unique is partially
initialized by ptrace (PTRACE_ARCH_PRCTL, ..., ARCH_GET_GS), and so the
comparison in td_thr_get_info:

  if (th->th_unique == 0)

is guaranteed to work correctly even though not all bytes of th_unique
have defined value.

Still, it would be nice to keep GDB valgrind-clean, and attached patch
squashes this error.

Thanks,

--
Paul Pluzhnikov

2011-07-23  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* linux-thread-db.c (thread_from_lwp): Initialize th.th_unique.


Index: linux-thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-thread-db.c,v
retrieving revision 1.87
diff -u -p -r1.87 linux-thread-db.c
--- linux-thread-db.c	18 May 2011 15:00:55 -0000	1.87
+++ linux-thread-db.c	23 Jul 2011 23:23:49 -0000
@@ -431,6 +431,9 @@ thread_from_lwp (ptid_t ptid)
   struct thread_db_info *info;
   struct thread_get_info_inout io = {0};
 
+  /* Just in case td_ta_map_lwp2thr doesn't initialize it completely.  */
+  th.th_unique = 0;
+
   /* This ptid comes from linux-nat.c, which should always fill in the
      LWP.  */
   gdb_assert (GET_LWP (ptid) != 0);


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