From patchwork Fri Aug 10 18:11:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Franco de Carvalho X-Patchwork-Id: 28842 Received: (qmail 126714 invoked by alias); 10 Aug 2018 18:11:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 126689 invoked by uid 89); 10 Aug 2018 18:11:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=H*MI:vnet X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Aug 2018 18:11:28 +0000 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7AI9Nwj080876 for ; Fri, 10 Aug 2018 14:11:27 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ksccr7v9d-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Aug 2018 14:11:26 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Aug 2018 12:11:25 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 10 Aug 2018 12:11:23 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7AIBMRd7602648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 10 Aug 2018 11:11:22 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5BAA0BE053; Fri, 10 Aug 2018 12:11:22 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1BF96BE04F; Fri, 10 Aug 2018 12:11:22 -0600 (MDT) Received: from pedro.localdomain (unknown [9.85.205.203]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 10 Aug 2018 12:11:21 -0600 (MDT) Received: by pedro.localdomain (Postfix, from userid 1000) id 1FCE03C0472; Fri, 10 Aug 2018 15:11:19 -0300 (-03) From: Pedro Franco de Carvalho To: Tom Tromey Cc: gdb-patches@sourceware.org, uweigand@de.ibm.com, edjunior@gmail.com Subject: Re: [PATCH v2 01/12] Zero-initialize linux note sections In-Reply-To: <87bmaa5hdt.fsf@tromey.com> References: <20180810025210.6942-1-pedromfc@linux.ibm.com> <20180810025210.6942-2-pedromfc@linux.ibm.com> <87bmaa5hdt.fsf@tromey.com> Date: Fri, 10 Aug 2018 15:11:19 -0300 MIME-Version: 1.0 x-cbid: 18081018-0020-0000-0000-00000E4DF22C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009519; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01071735; UDB=6.00551975; IPR=6.00851530; MB=3.00022639; MTD=3.00000008; XFM=3.00000015; UTC=2018-08-10 18:11:25 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18081018-0021-0000-0000-000062A1BD1D Message-Id: <87ftzmhz20.fsf@linux.vnet.ibm.com> X-IsSubscribed: yes Tom Tromey writes: > It might be nice for future developers if there were a comment here > explaining that this is intentionally zero-initialized. Other spots in > gdb use gdb::def_vector and perhaps someone might think that would be a > worthwhile micro-optimization. > > Tom Ok! I'll add the comment below. Thanks! diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 3cfa2a5aa4..2bcd2390c5 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1583,7 +1583,9 @@ linux_collect_regset_section_cb (const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data) { - char *buf; + /* This is intentionally zero-initialized by using std::vector, so + that any padding bytes in the core file will show as 0. */ + std::vector buf (size); struct linux_collect_regset_section_cb_data *data = (struct linux_collect_regset_section_cb_data *) cb_data; @@ -1592,19 +1594,17 @@ linux_collect_regset_section_cb (const char *sect_name, int size, gdb_assert (regset && regset->collect_regset); - buf = (char *) xmalloc (size); - regset->collect_regset (regset, data->regcache, -1, buf, size); + regset->collect_regset (regset, data->regcache, -1, buf.data (), size); /* PRSTATUS still needs to be treated specially. */ if (strcmp (sect_name, ".reg") == 0) data->note_data = (char *) elfcore_write_prstatus (data->obfd, data->note_data, data->note_size, data->lwp, - gdb_signal_to_host (data->stop_signal), buf); + gdb_signal_to_host (data->stop_signal), buf.data ()); else data->note_data = (char *) elfcore_write_register_note (data->obfd, data->note_data, data->note_size, - sect_name, buf, size); - xfree (buf); + sect_name, buf.data (), size); if (data->note_data == NULL) data->abort_iteration = 1;