From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119068 invoked by alias); 26 Sep 2019 13:40:23 -0000 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 Received: (qmail 119060 invoked by uid 89); 26 Sep 2019 13:40:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=onto X-HELO: mga14.intel.com Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Sep 2019 13:40:21 +0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2019 06:40:18 -0700 Received: from irsmsx109.ger.corp.intel.com ([163.33.3.23]) by fmsmga004.fm.intel.com with ESMTP; 26 Sep 2019 06:40:18 -0700 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.103]) by IRSMSX109.ger.corp.intel.com ([169.254.13.29]) with mapi id 14.03.0439.000; Thu, 26 Sep 2019 14:40:17 +0100 From: "Metzger, Markus T" To: Andrew Burgess , gdb-patches CC: Simon Marchi , Tom Tromey Subject: RE: [PATCHv4 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Date: Thu, 26 Sep 2019 13:40:00 -0000 Message-ID: References: <4773109a57a82515f1f734abf794e8574f07488b.1569497661.git.andrew.burgess@embecosm.com> In-Reply-To: <4773109a57a82515f1f734abf794e8574f07488b.1569497661.git.andrew.burgess@embecosm.com> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00519.txt.bz2 Hello Andrew, > @@ -1059,7 +1059,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp, >=20 > gdbarch =3D target_gdbarch (); > btinfo =3D &tp->btrace; > - blk =3D VEC_length (btrace_block_s, btrace->blocks); > + blk =3D btrace->blocks_size (); >=20 > if (btinfo->functions.empty ()) > level =3D INT_MAX; We should be able to guarantee that BTRACE->BLOCKS !=3D nullptr. We only g= et here if the btrace format is set to BTRACE_FORMAT_BTS. The blocks vector m= ust be allocated whenever we set the format to BTRACE_FORMAT_BTS. > @@ -3128,19 +3119,17 @@ btrace_maint_print_packets (struct > btrace_thread_info *btinfo, >=20 > case BTRACE_FORMAT_BTS: > { > - VEC (btrace_block_s) *blocks; > + const std::vector &blocks > + =3D *btinfo->data.variant.bts.blocks; Would that fit onto a single line? > diff --git a/gdb/btrace.h b/gdb/btrace.h > index ba8d27c879c..d09c424804b 100644 > --- a/gdb/btrace.h > +++ b/gdb/btrace.h > @@ -29,6 +29,7 @@ > #include "gdbsupport/btrace-common.h" > #include "target/waitstatus.h" /* For enum target_stop_reason. */ > #include "gdbsupport/enum-flags.h" > +#include "gdbsupport/vec.h" Didn't you want to remove those includes? > @@ -141,15 +142,12 @@ btrace_data_append (struct btrace_data *dst, >=20 > /* We copy blocks in reverse order to have the oldest block at > index zero. */ > - blk =3D VEC_length (btrace_block_s, src->variant.bts.blocks); > + blk =3D src->variant.bts.blocks_size (); > while (blk !=3D 0) > { > - btrace_block_s *block; > - > - block =3D VEC_index (btrace_block_s, src->variant.bts.blocks, > - --blk); > - > - VEC_safe_push (btrace_block_s, dst->variant.bts.blocks, block); > + const btrace_block &block > + =3D src->variant.bts.blocks->at (--blk); Would this fit onto one line? =20 > @@ -137,8 +139,28 @@ struct btrace_config > struct btrace_data_bts > { > /* Branch trace is represented as a vector of branch trace blocks star= ting > - with the most recent block. */ > - VEC (btrace_block_s) *blocks; > + with the most recent block. This needs to be a pointer as we place > + btrace_data_bts into a union. */ > + std::vector *blocks; > + > + /* The BLOCKS vector used to be implemented using a C vector library. = A > + property of this library was that the size and empty functions could > + be called with a nullptr (to the vector) and still have a sensible > + answer return. > + > + When converting to C++ std::vector this method was added here to av= oid > + introducing errors if we ever did try to call size or empty on a > + nullptr. */ > + size_t blocks_size () const > + { > + return (blocks =3D=3D nullptr) ? 0 : blocks->size (); > + } > + > + /* See the comment for BLOCKS_SIZE above. */ > + bool blocks_empty () const > + { > + return (blocks =3D=3D nullptr) ? true : blocks->empty (); > + } These helpers shouldn't be necessary. If the format is set to BTRACE_FORMA= T_BTS, the blocks vector must have been allocated. And it must be freed when the = format is set to any other value - most likely BTRACE_FORMAT_NONE. Same for BTRACE_FORMAT_PT. Without trace, the format should be left at BTRACE_FORMAT_NONE. Regards, Markus. Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Gary Kershaw Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928