From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21657 invoked by alias); 14 Feb 2013 18:38:12 -0000 Received: (qmail 21553 invoked by uid 22791); 14 Feb 2013 18:38:10 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_EG X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Feb 2013 18:38:02 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1EIc20k031161 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Feb 2013 13:38:02 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1EIc0ik018972 for ; Thu, 14 Feb 2013 13:38:01 -0500 Subject: [RFC PATCH] Appease Valgrind over ptrace calls. To: gdb-patches@sourceware.org From: Pedro Alves Date: Thu, 14 Feb 2013 18:38:00 -0000 Message-ID: <20130214183800.4809.80774.stgit@brno.lan> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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: 2013-02/txt/msg00371.txt.bz2 Trying out Valgrind on gdbserver, on x86_64, I get these annoying warnings: ==3987== Conditional jump or move depends on uninitialised value(s) ==3987== at 0x430FB2: x86_linux_update_xmltarget (linux-x86-low.c:1250) ==3987== by 0x4310F7: x86_linux_process_qsupported (linux-x86-low.c:1304) ==3987== by 0x42BD07: linux_process_qsupported (linux-low.c:5253) ==3987== by 0x40CF75: handle_query (server.c:1571) ==3987== by 0x41045E: process_serial_event (server.c:2930) ==3987== by 0x41154C: handle_serial_event (server.c:3364) ==3987== by 0x4170BA: handle_file_event (event-loop.c:436) ==3987== by 0x416847: process_event (event-loop.c:191) ==3987== by 0x41762E: start_event_loop (event-loop.c:554) ==3987== by 0x410137: main (server.c:2781) ==3987== ==3987== Conditional jump or move depends on uninitialised value(s) ==3987== at 0x431009: x86_linux_update_xmltarget (linux-x86-low.c:1258) ==3987== by 0x4310F7: x86_linux_process_qsupported (linux-x86-low.c:1304) ==3987== by 0x42BD07: linux_process_qsupported (linux-low.c:5253) ==3987== by 0x40CF75: handle_query (server.c:1571) ==3987== by 0x41045E: process_serial_event (server.c:2930) ==3987== by 0x41154C: handle_serial_event (server.c:3364) ==3987== by 0x4170BA: handle_file_event (event-loop.c:436) ==3987== by 0x416847: process_event (event-loop.c:191) ==3987== by 0x41762E: start_event_loop (event-loop.c:554) ==3987== by 0x410137: main (server.c:2781) ==3987== ==3987== Conditional jump or move depends on uninitialised value(s) ==3987== at 0x435AD9: i387_xsave_to_cache (i387-fp.c:477) ==3987== by 0x42FD67: x86_store_xstateregset (linux-x86-low.c:353) ==3987== by 0x42A01C: regsets_fetch_inferior_registers (linux-low.c:4063) ==3987== by 0x42A7FC: linux_fetch_registers (linux-low.c:4355) ==3987== by 0x40675B: get_thread_regcache (regcache.c:50) ==3987== by 0x408D0F: prepare_resume_reply (remote-utils.c:1337) ==3987== by 0x40F5CC: handle_status (server.c:2372) ==3987== by 0x41077F: process_serial_event (server.c:3029) ==3987== by 0x41154C: handle_serial_event (server.c:3364) ==3987== by 0x4170BA: handle_file_event (event-loop.c:436) ==3987== by 0x416847: process_event (event-loop.c:191) ==3987== by 0x41762E: start_event_loop (event-loop.c:554) It seems like Valgrind doesn't understand that ptrace writes to the buffers in question, so throws out false positives. Valgrind on GDB spews out equivalent warnings. This patch works around it in gdbserver. Is there a better way to do this perhaps? Hmm, nut, I'm now wondering why we don't see many more ptrace-related warnings in other cases. Maybe Valgrind does know about ptrace, but not about PTRACE_GETREGSET? gdb/gdbserver/ 2013-02-14 Pedro Alves * linux-low.c (regsets_fetch_inferior_registers) --- gdb/gdbserver/linux-low.c | 6 ++++-- gdb/gdbserver/linux-x86-low.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index c52cd2e..00214da 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -4022,7 +4022,8 @@ regsets_fetch_inferior_registers (struct regcache *regcache) continue; } - buf = xmalloc (regset->size); + /* Zero out the buffer to appease Valgrind. */ + buf = xcalloc (1, regset->size); nt_type = regset->nt_type; if (nt_type) @@ -4092,7 +4093,8 @@ regsets_store_inferior_registers (struct regcache *regcache) continue; } - buf = xmalloc (regset->size); + /* Zero out the buffer to appease Valgrind. */ + buf = xcalloc (1, regset->size); /* First fill the buffer with the current register set contents, in case there are any items in the kernel's regset that are diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c index 31657d3..604ecd6 100644 --- a/gdb/gdbserver/linux-x86-low.c +++ b/gdb/gdbserver/linux-x86-low.c @@ -1224,7 +1224,9 @@ x86_linux_update_xmltarget (void) /* Check if XSAVE extended state is supported. */ if (have_ptrace_getregset == -1) { - unsigned long long xstateregs[I386_XSTATE_SSE_SIZE / sizeof (long long)]; + /* Zeroed out to appease Valgrind. */ + unsigned long long + xstateregs[I386_XSTATE_SSE_SIZE / sizeof (long long)] = {0}; struct iovec iov; iov.iov_base = xstateregs;