Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: Andrew Burgess <andrew.burgess@embecosm.com>,
	gdb-patches	<gdb-patches@sourceware.org>
Cc: Simon Marchi <simark@simark.ca>, Tom Tromey <tom@tromey.com>
Subject: RE: [PATCHv4 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
Date: Thu, 26 Sep 2019 13:40:00 -0000	[thread overview]
Message-ID: <A78C989F6D9628469189715575E55B236B4D926F@IRSMSX104.ger.corp.intel.com> (raw)
In-Reply-To: <4773109a57a82515f1f734abf794e8574f07488b.1569497661.git.andrew.burgess@embecosm.com>

Hello Andrew,

> @@ -1059,7 +1059,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
> 
>    gdbarch = target_gdbarch ();
>    btinfo = &tp->btrace;
> -  blk = VEC_length (btrace_block_s, btrace->blocks);
> +  blk = btrace->blocks_size ();
> 
>    if (btinfo->functions.empty ())
>      level = INT_MAX;

We should be able to guarantee that BTRACE->BLOCKS != nullptr.  We only get
here if the btrace format is set to BTRACE_FORMAT_BTS.  The blocks vector must
be allocated whenever we set the format to BTRACE_FORMAT_BTS.


> @@ -3128,19 +3119,17 @@ btrace_maint_print_packets (struct
> btrace_thread_info *btinfo,
> 
>      case BTRACE_FORMAT_BTS:
>        {
> -	VEC (btrace_block_s) *blocks;
> +	const std::vector <btrace_block> &blocks
> +	  = *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,
> 
>  	    /* We copy blocks in reverse order to have the oldest block at
>  	       index zero.  */
> -	    blk = VEC_length (btrace_block_s, src->variant.bts.blocks);
> +	    blk = src->variant.bts.blocks_size ();
>  	    while (blk != 0)
>  	      {
> -		btrace_block_s *block;
> -
> -		block = 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
> +		  = src->variant.bts.blocks->at (--blk);

Would this fit onto one line?

 
> @@ -137,8 +139,28 @@ struct btrace_config
>  struct btrace_data_bts
>  {
>    /* Branch trace is represented as a vector of branch trace blocks starting
> -     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 <btrace_block> *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 avoid
> +     introducing errors if we ever did try to call size or empty on a
> +     nullptr.  */
> +  size_t blocks_size () const
> +  {
> +    return (blocks == nullptr) ? 0 : blocks->size ();
> +  }
> +
> +  /* See the comment for BLOCKS_SIZE above.  */
> +  bool blocks_empty () const
> +  {
> +    return (blocks == nullptr) ? true : blocks->empty ();
> +  }

These helpers shouldn't be necessary.  If the format is set to BTRACE_FORMAT_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


      reply	other threads:[~2019-09-26 13:40 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 15:54 [PATCHv2 0/3] Remove some uses of VEC Andrew Burgess
2019-09-23 22:09 ` [PATCH 0/2] Remove 2 uses of VEC from gdb Andrew Burgess
2019-09-23 22:09   ` [PATCH 2/2] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
2019-09-24  2:19     ` Simon Marchi
2019-09-23 22:09   ` [PATCH 1/2] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
2019-09-24  2:09     ` Simon Marchi
2019-09-24 19:54   ` [PATCH 0/2] Remove 2 uses of VEC from gdb Tom Tromey
2019-09-25 15:54   ` [PATCHv2 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
2019-09-26  2:35     ` Simon Marchi
2019-09-25 15:54   ` [PATCHv2 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
2019-09-25 15:54   ` [PATCHv2 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
2019-09-25 22:08     ` Tom Tromey
2019-09-26  0:00       ` [PATCHv3 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
2019-09-26  8:47         ` Metzger, Markus T
2019-09-26 11:32           ` Andrew Burgess
2019-09-26 13:07             ` Metzger, Markus T
2019-09-26  0:00       ` [PATCHv3 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
2019-09-26  0:00       ` [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
2019-09-26  8:47         ` Metzger, Markus T
2019-09-26 11:33           ` Andrew Burgess
2019-09-26  0:00       ` [PATCHv3 0/3] Remove some uses of VEC Andrew Burgess
2019-09-26  2:52         ` Simon Marchi
2019-09-26 11:41         ` [PATCHv4 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
2019-09-26 11:41         ` [PATCHv4 0/3] Remove some uses of VEC Andrew Burgess
2019-10-01 11:42           ` [PATCHv5 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
2019-10-01 11:42           ` [PATCHv5 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
2019-10-01 19:59             ` Tom Tromey
2019-10-01 11:42           ` [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
2019-10-02 15:51             ` Pedro Alves
2019-10-02 22:21               ` Andrew Burgess
2019-10-03  8:06                 ` Pedro Alves
     [not found]           ` <cover.1569929785.git.andrew.burgess@embecosm.com>
2019-10-01 12:04             ` [PATCHv5 0/3] Remove some uses of VEC Metzger, Markus T
2019-09-26 11:41         ` [PATCHv4 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
2019-09-26 11:41         ` [PATCHv4 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
2019-09-26 13:40           ` Metzger, Markus T [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A78C989F6D9628469189715575E55B236B4D926F@IRSMSX104.ger.corp.intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox