* [PATCH 2/2] gdb: Change a VEC to std::vector in btrace.{c,h}
2019-09-23 22:09 ` [PATCH 0/2] Remove 2 uses of VEC from gdb Andrew Burgess
@ 2019-09-23 22:09 ` 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
` (4 subsequent siblings)
5 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-23 22:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
Replace a VEC with a std::vector in btrace.h, and update btrace.c to
match. This code is currently untested, so I've been quite
conservative with the changes - where previously we used VEC_safe_push
which would allocate the vector if it isn't already allocated - I now
check and allocate the std::vector using 'new' before pushing to the
vector.
As the new vector is inside a union I've currently used a pointer to
vector, which makes the code slightly uglier than it might otherwise
be, but again, due to lack of testing I'm reluctant to start
refactoring the code in a big way.
gdb/ChangeLog:
* btrace.c (btrace_maint_clear): Update to handle change from VEC
to std::vector.
(btrace_maint_decode_pt): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Remove 'vec.h' header include and use of DEF_VEC_O.
(struct btrace_maint_info) <packets>: Change fromm VEC to
std::vector.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/btrace.c | 37 +++++++++++++++++++------------------
gdb/btrace.h | 4 +---
3 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 5013b568a45..59e2a49bcd8 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1828,7 +1828,7 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- xfree (btinfo->maint.variant.pt.packets);
+ delete (btinfo->maint.variant.pt.packets);
btinfo->maint.variant.pt.packets = NULL;
btinfo->maint.variant.pt.packet_history.begin = 0;
@@ -2987,8 +2987,10 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
{
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets
+ = new std::vector <btrace_pt_packet_s>;
+ maint->variant.pt.packets->push_back (packet);
}
}
@@ -2996,8 +2998,10 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
break;
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets
+ = new std::vector <btrace_pt_packet_s>;
+ maint->variant.pt.packets->push_back (packet);
warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
packet.offset, pt_errstr (packet.errcode));
@@ -3098,11 +3102,11 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
+ if (btinfo->maint.variant.pt.packets->empty ())
btrace_maint_update_pt_packets (btinfo);
*begin = 0;
- *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
+ *end = btinfo->maint.variant.pt.packets->size ();
*from = btinfo->maint.variant.pt.packet_history.begin;
*to = btinfo->maint.variant.pt.packet_history.end;
break;
@@ -3145,23 +3149,21 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
{
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet_s> *packets;
unsigned int pkt;
packets = btinfo->maint.variant.pt.packets;
for (pkt = begin; pkt < end; ++pkt)
{
- const struct btrace_pt_packet *packet;
-
- packet = VEC_index (btrace_pt_packet_s, packets, pkt);
+ const struct btrace_pt_packet &packet = packets->at (pkt);
printf_unfiltered ("%u\t", pkt);
- printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
+ printf_unfiltered ("0x%" PRIx64 "\t", packet.offset);
- if (packet->errcode == pte_ok)
- pt_print_packet (&packet->packet);
+ if (packet.errcode == pte_ok)
+ pt_print_packet (&packet.packet);
else
- printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
+ printf_unfiltered ("[error: %s]", pt_errstr (packet.errcode));
printf_unfiltered ("\n");
}
@@ -3452,9 +3454,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
version.ext != NULL ? version.ext : "");
btrace_maint_update_pt_packets (btinfo);
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_pt_packet_s,
- btinfo->maint.variant.pt.packets));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->maint.variant.pt.packets->size ());
}
break;
#endif /* defined (HAVE_LIBIPT) */
diff --git a/gdb/btrace.h b/gdb/btrace.h
index d09c424804b..cea8cd9ad6a 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -29,7 +29,6 @@
#include "gdbsupport/btrace-common.h"
#include "target/waitstatus.h" /* For enum target_stop_reason. */
#include "gdbsupport/enum-flags.h"
-#include "gdbsupport/vec.h"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
@@ -267,7 +266,6 @@ struct btrace_pt_packet
/* Define functions operating on a vector of packets. */
typedef struct btrace_pt_packet btrace_pt_packet_s;
-DEF_VEC_O (btrace_pt_packet_s);
#endif /* defined (HAVE_LIBIPT) */
/* Branch trace iteration state for "maintenance btrace packet-history". */
@@ -301,7 +299,7 @@ struct btrace_maint_info
struct
{
/* A vector of decoded packets. */
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet_s> *packets;
/* The packet history iterator.
We are iterating over the above PACKETS vector. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 2/2] gdb: Change a VEC to std::vector in btrace.{c,h}
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
0 siblings, 0 replies; 35+ messages in thread
From: Simon Marchi @ 2019-09-24 2:19 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches
On 2019-09-23 6:09 p.m., Andrew Burgess wrote:
> Replace a VEC with a std::vector in btrace.h, and update btrace.c to
> match. This code is currently untested, so I've been quite
> conservative with the changes - where previously we used VEC_safe_push
> which would allocate the vector if it isn't already allocated - I now
> check and allocate the std::vector using 'new' before pushing to the
> vector.
>
> As the new vector is inside a union I've currently used a pointer to
> vector, which makes the code slightly uglier than it might otherwise
> be, but again, due to lack of testing I'm reluctant to start
> refactoring the code in a big way.
Hi Andrew,
Looks fine to me, just a few nits:
> diff --git a/gdb/btrace.c b/gdb/btrace.c
> index 5013b568a45..59e2a49bcd8 100644
> --- a/gdb/btrace.c
> +++ b/gdb/btrace.c
> @@ -1828,7 +1828,7 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)
>
> #if defined (HAVE_LIBIPT)
> case BTRACE_FORMAT_PT:
> - xfree (btinfo->maint.variant.pt.packets);
> + delete (btinfo->maint.variant.pt.packets);
You can remove the parenthesis.
>
> btinfo->maint.variant.pt.packets = NULL;
> btinfo->maint.variant.pt.packet_history.begin = 0;
> @@ -2987,8 +2987,10 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
> if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
> {
> packet.errcode = pt_errcode (errcode);
> - VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
> - &packet);
> + if (maint->variant.pt.packets == NULL)
> + maint->variant.pt.packets
> + = new std::vector <btrace_pt_packet_s>;
This will fit on a single line once you remove the `_s` :).
> --- a/gdb/btrace.h
> +++ b/gdb/btrace.h
> @@ -29,7 +29,6 @@
> #include "gdbsupport/btrace-common.h"
> #include "target/waitstatus.h" /* For enum target_stop_reason. */
> #include "gdbsupport/enum-flags.h"
> -#include "gdbsupport/vec.h"
>
> #if defined (HAVE_LIBIPT)
> # include <intel-pt.h>
> @@ -267,7 +266,6 @@ struct btrace_pt_packet
>
> /* Define functions operating on a vector of packets. */
> typedef struct btrace_pt_packet btrace_pt_packet_s;
> -DEF_VEC_O (btrace_pt_packet_s);
Like in the previous patch, you can drop this typedef. It was only useful to define the VEC.
Simon
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 1/2] gdb: Remove a VEC from gdbsupport/btrace-common.h
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-23 22:09 ` 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
` (3 subsequent siblings)
5 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-23 22:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
Converts a VEC into a std::vector in gdbsupport/btrace-common.h. This
commit just performs a mechanical conversion and doesn't do any
refactoring. One consequence of this is that the std::vector must
actually be a pointer to std::vector as it is placed within a union.
It might be possible in future to refactor to a class hierarchy and
remove the need for a union, but I'd rather have that be a separate
change to make it easier to see the evolution of the code.
gdb/ChangeLog:
* btrace.c (btrace_compute_ftrace_bts): Update for std::vector.
(btrace_add_pc): Likewise.
(btrace_stitch_bts): Likewise.
(parse_xml_btrace_block): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Add 'gdbsupport/vec.h' include.
* gdbsupport/btrace-common.c (btrace_data::fini): Likewise.
(btrace_data::empty): Likewise.
(btrace_data_append): Likewise.
* gdbsupport/btrace-common.h: Remove 'vec.h' include.
(struct btrace_block): Add constructor, and delete default
constructor.
(struct btrace_data_bts) <blocks>: Change to std::vector.
* nat/linux-btrace.c (perf_event_read_bts): Update for
std::vector.
(linux_read_bts): Likewise.
gdb/gdbserver/ChangeLog:
* linux-low.c (linux_low_read_btrace): Update for change to
std::vector.
---
gdb/ChangeLog | 21 +++++++++++++++++++
gdb/btrace.c | 47 ++++++++++++++++++------------------------
gdb/btrace.h | 1 +
gdb/gdbserver/ChangeLog | 5 +++++
gdb/gdbserver/linux-low.c | 8 ++-----
gdb/gdbsupport/btrace-common.c | 17 +++++++--------
gdb/gdbsupport/btrace-common.h | 20 +++++++++++++-----
gdb/nat/linux-btrace.c | 14 ++++++-------
8 files changed, 78 insertions(+), 55 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 1b809fb5c08..5013b568a45 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -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;
@@ -1073,7 +1073,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
blk -= 1;
- block = VEC_index (btrace_block_s, btrace->blocks, blk);
+ block = &btrace->blocks->at (blk);
pc = block->begin;
for (;;)
@@ -1573,7 +1573,6 @@ static void
btrace_add_pc (struct thread_info *tp)
{
struct btrace_data btrace;
- struct btrace_block *block;
struct regcache *regcache;
CORE_ADDR pc;
@@ -1581,11 +1580,10 @@ btrace_add_pc (struct thread_info *tp)
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
- btrace.variant.bts.blocks = NULL;
+ btrace.variant.bts.blocks = new std::vector <btrace_block_s>;
- block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
- block->begin = pc;
- block->end = pc;
+ btrace_block block (pc, pc);
+ btrace.variant.bts.blocks->push_back (block);
btrace_compute_ftrace (tp, &btrace, NULL);
}
@@ -1696,7 +1694,7 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
btinfo = &tp->btrace;
gdb_assert (!btinfo->functions.empty ());
- gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
+ gdb_assert (!btrace->blocks->empty ());
last_bfun = &btinfo->functions.back ();
@@ -1705,14 +1703,14 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
of the new trace, though, since we can't fill in the start address.*/
if (last_bfun->insn.empty ())
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
/* Beware that block trace starts with the most recent block, so the
chronologically first block in the new trace is the last block in
the new trace's block vector. */
- first_new_block = VEC_last (btrace_block_s, btrace->blocks);
+ first_new_block = &btrace->blocks->back ();
const btrace_insn &last_insn = last_bfun->insn.back ();
/* If the current PC at the end of the block is the same as in our current
@@ -1724,9 +1722,9 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
In the second case, the delta trace vector should contain exactly one
entry for the partial block containing the current PC. Remove it. */
if (first_new_block->end == last_insn.pc
- && VEC_length (btrace_block_s, btrace->blocks) == 1)
+ && btrace->blocks->size () == 1)
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
@@ -2030,7 +2028,6 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
- struct btrace_block *block;
ULONGEST *begin, *end;
btrace = (struct btrace_data *) user_data;
@@ -2042,7 +2039,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
case BTRACE_FORMAT_NONE:
btrace->format = BTRACE_FORMAT_BTS;
- btrace->variant.bts.blocks = NULL;
+ btrace->variant.bts.blocks = new std::vector <btrace_block_s>;
break;
default:
@@ -2052,9 +2049,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
- block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
- block->begin = *begin;
- block->end = *end;
+ btrace_block block (*begin, *end);
+ btrace->variant.bts.blocks->push_back (block);
}
/* Parse a "raw" xml record. */
@@ -3095,7 +3091,7 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
/* Nothing to do - we operate directly on BTINFO->DATA. */
*begin = 0;
- *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
+ *end = btinfo->data.variant.bts.blocks->size ();
*from = btinfo->maint.variant.bts.packet_history.begin;
*to = btinfo->maint.variant.bts.packet_history.end;
break;
@@ -3128,19 +3124,17 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
{
- VEC (btrace_block_s) *blocks;
+ std::vector <btrace_block_s> *blocks;
unsigned int blk;
blocks = btinfo->data.variant.bts.blocks;
for (blk = begin; blk < end; ++blk)
{
- const btrace_block_s *block;
-
- block = VEC_index (btrace_block_s, blocks, blk);
+ const btrace_block_s &block = blocks->at (blk);
printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
- core_addr_to_string_nz (block->begin),
- core_addr_to_string_nz (block->end));
+ core_addr_to_string_nz (block.begin),
+ core_addr_to_string_nz (block.end));
}
btinfo->maint.variant.bts.packet_history.begin = begin;
@@ -3443,9 +3437,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
break;
case BTRACE_FORMAT_BTS:
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_block_s,
- btinfo->data.variant.bts.blocks));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->data.variant.bts.blocks->size ());
break;
#if defined (HAVE_LIBIPT)
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"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index d64c3641ffb..ec2731b12a9 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7115,9 +7115,7 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
enum btrace_read_type type)
{
struct btrace_data btrace;
- struct btrace_block *block;
enum btrace_error err;
- int i;
err = linux_read_btrace (&btrace, tinfo, type);
if (err != BTRACE_ERR_NONE)
@@ -7140,11 +7138,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
- for (i = 0;
- VEC_iterate (btrace_block_s, btrace.variant.bts.blocks, i, block);
- i++)
+ for (const struct btrace_block &block : *btrace.variant.bts.blocks)
buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
- paddress (block->begin), paddress (block->end));
+ paddress (block.begin), paddress (block.end));
buffer_grow_str0 (buffer, "</btrace>\n");
break;
diff --git a/gdb/gdbsupport/btrace-common.c b/gdb/gdbsupport/btrace-common.c
index 13f1f1a0fdd..337ac1479c4 100644
--- a/gdb/gdbsupport/btrace-common.c
+++ b/gdb/gdbsupport/btrace-common.c
@@ -73,7 +73,7 @@ btrace_data::fini ()
return;
case BTRACE_FORMAT_BTS:
- VEC_free (btrace_block_s, variant.bts.blocks);
+ delete variant.bts.blocks;
return;
case BTRACE_FORMAT_PT:
@@ -95,7 +95,7 @@ btrace_data::empty () const
return true;
case BTRACE_FORMAT_BTS:
- return VEC_empty (btrace_block_s, variant.bts.blocks);
+ return variant.bts.blocks->empty ();
case BTRACE_FORMAT_PT:
return (variant.pt.size == 0);
@@ -132,7 +132,7 @@ btrace_data_append (struct btrace_data *dst,
case BTRACE_FORMAT_NONE:
dst->format = BTRACE_FORMAT_BTS;
- dst->variant.bts.blocks = NULL;
+ dst->variant.bts.blocks = new std::vector <btrace_block_s>;
/* Fall-through. */
case BTRACE_FORMAT_BTS:
@@ -141,15 +141,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);
+ btrace_block_s block
+ = src->variant.bts.blocks->at (--blk);
+ dst->variant.bts.blocks->push_back (block);
}
}
}
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 0b18924882c..cb8d1ba387a 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -26,8 +26,6 @@
inferior. For presentation purposes, the branch trace is represented as a
list of sequential control-flow blocks, one such list per thread. */
-#include "vec.h"
-
/* A branch trace block.
This represents a block of sequential control-flow. Adjacent blocks will be
@@ -43,11 +41,22 @@ struct btrace_block
/* The address of the first byte of the last instruction in the block. */
CORE_ADDR end;
+
+ /* Simple constructor. */
+ btrace_block (CORE_ADDR begin, CORE_ADDR end)
+ : begin (begin),
+ end (end)
+ {
+ /* Nothing. */
+ }
+
+private:
+ /* Don't create blocks without initialization. */
+ btrace_block () = delete;
};
/* Define functions operating on a vector of branch trace blocks. */
typedef struct btrace_block btrace_block_s;
-DEF_VEC_O (btrace_block_s);
/* Enumeration of btrace formats. */
@@ -137,8 +146,9 @@ 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_s> *blocks;
};
/* Configuration information to go with the trace data. */
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 8625291cce9..e1da4a1645b 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
In case the buffer overflows during sampling, one sample may have its lower
part at the end and its upper part at the beginning of the buffer. */
-static VEC (btrace_block_s) *
+static std::vector <btrace_block_s> *
perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
const uint8_t *end, const uint8_t *start, size_t size)
{
- VEC (btrace_block_s) *btrace = NULL;
+ std::vector <btrace_block_s> *btrace = new std::vector <btrace_block_s> ();
struct perf_event_sample sample;
size_t read = 0;
struct btrace_block block = { 0, 0 };
@@ -343,7 +343,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
/* We found a valid sample, so we can complete the current block. */
block.begin = psample->bts.to;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
/* Start the next block. */
block.end = psample->bts.from;
@@ -354,7 +354,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
reading delta trace, we can fill in the start address later on.
Otherwise we will prune it. */
block.begin = 0;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
return btrace;
}
@@ -785,7 +785,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
data_head = *pevent->data_head;
/* Delete any leftover trace from the previous iteration. */
- VEC_free (btrace_block_s, btrace->blocks);
+ delete (btrace->blocks);
if (type == BTRACE_READ_DELTA)
{
@@ -843,9 +843,9 @@ linux_read_bts (struct btrace_data_bts *btrace,
/* Prune the incomplete last block (i.e. the first one of inferior execution)
if we're not doing a delta read. There is no way of filling in its zeroed
BEGIN element. */
- if (!VEC_empty (btrace_block_s, btrace->blocks)
+ if (!btrace->blocks->empty ()
&& type != BTRACE_READ_DELTA)
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return BTRACE_ERR_NONE;
}
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/2] gdb: Remove a VEC from gdbsupport/btrace-common.h
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
0 siblings, 0 replies; 35+ messages in thread
From: Simon Marchi @ 2019-09-24 2:09 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches
On 2019-09-23 6:09 p.m., Andrew Burgess wrote:
> Converts a VEC into a std::vector in gdbsupport/btrace-common.h. This
> commit just performs a mechanical conversion and doesn't do any
> refactoring. One consequence of this is that the std::vector must
> actually be a pointer to std::vector as it is placed within a union.
> It might be possible in future to refactor to a class hierarchy and
> remove the need for a union, but I'd rather have that be a separate
> change to make it easier to see the evolution of the code.
Hi Andrew,
I think this is a good approach for incremental progress.
I noted a few things I would change, but nothing looked wrong to me in the patch.
> @@ -1073,7 +1073,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
>
> blk -= 1;
>
> - block = VEC_index (btrace_block_s, btrace->blocks, blk);
> + block = &btrace->blocks->at (blk);
Can you take the opportunity to make `block` a pointer to const? The `btrace`
object it comes from is const, so if we had proper accessors to get the data
out of it, the returned pointer would be const.
> @@ -1581,11 +1580,10 @@ btrace_add_pc (struct thread_info *tp)
> pc = regcache_read_pc (regcache);
>
> btrace.format = BTRACE_FORMAT_BTS;
> - btrace.variant.bts.blocks = NULL;
> + btrace.variant.bts.blocks = new std::vector <btrace_block_s>;
>
> - block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
> - block->begin = pc;
> - block->end = pc;
> + btrace_block block (pc, pc);
> + btrace.variant.bts.blocks->push_back (block);
The impact here would be minimal since the size of btrace_block is very small,
but the idiomatic thing to do there would be to construct the object directly
in the vector using emplace_back:
> @@ -1724,9 +1722,9 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
> In the second case, the delta trace vector should contain exactly one
> entry for the partial block containing the current PC. Remove it. */
> if (first_new_block->end == last_insn.pc
> - && VEC_length (btrace_block_s, btrace->blocks) == 1)
> + && btrace->blocks->size () == 1)
This fits on a single line.
> @@ -2052,9 +2049,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
> begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
> end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
>
> - block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
> - block->begin = *begin;
> - block->end = *end;
> + btrace_block block (*begin, *end);
> + btrace->variant.bts.blocks->push_back (block);
I suggest using emplace_back here too.
> @@ -141,15 +141,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);
> + btrace_block_s block
> + = src->variant.bts.blocks->at (--blk);
This fits on a single line.
Also, I don't know if it would make a difference at all (or if it would even make things
worse, since btrace_data is such a small structure), but I would instinctively have made
`block` a const reference to avoid a copy.
> @@ -43,11 +41,22 @@ struct btrace_block
>
> /* The address of the first byte of the last instruction in the block. */
> CORE_ADDR end;
> +
> + /* Simple constructor. */
> + btrace_block (CORE_ADDR begin, CORE_ADDR end)
> + : begin (begin),
> + end (end)
> + {
> + /* Nothing. */
> + }
> +
> +private:
> + /* Don't create blocks without initialization. */
> + btrace_block () = delete;
Is this explicit deletion needed? When you have a user-defined constructor, the
compiler won't generate an implicit default contructor. It's the opposite, if we
wanted it, we would need to do:
btrace_block () = default;
Also, if you need to delete some otherwise implicitly generated constructor or
operator, you don't need to put it private, just the "= delete" is enough.
> };
>
> /* Define functions operating on a vector of branch trace blocks. */
> typedef struct btrace_block btrace_block_s;
> -DEF_VEC_O (btrace_block_s);
You can get rid of the typedef too, and just use `btrace_block` everywhere.
> diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
> index 8625291cce9..e1da4a1645b 100644
> --- a/gdb/nat/linux-btrace.c
> +++ b/gdb/nat/linux-btrace.c
> @@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
> In case the buffer overflows during sampling, one sample may have its lower
> part at the end and its upper part at the beginning of the buffer. */
>
> -static VEC (btrace_block_s) *
> +static std::vector <btrace_block_s> *
> perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
> const uint8_t *end, const uint8_t *start, size_t size)
> {
> - VEC (btrace_block_s) *btrace = NULL;
> + std::vector <btrace_block_s> *btrace = new std::vector <btrace_block_s> ();
You can omit the parenthesis. I just mention this because you have omitted them
elsewhere in the patch, so I thought, let's be consistent!
> @@ -785,7 +785,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
> data_head = *pevent->data_head;
>
> /* Delete any leftover trace from the previous iteration. */
> - VEC_free (btrace_block_s, btrace->blocks);
> + delete (btrace->blocks);
You can remove the parenthesis here.
>
> if (type == BTRACE_READ_DELTA)
> {
> @@ -843,9 +843,9 @@ linux_read_bts (struct btrace_data_bts *btrace,
> /* Prune the incomplete last block (i.e. the first one of inferior execution)
> if we're not doing a delta read. There is no way of filling in its zeroed
> BEGIN element. */
> - if (!VEC_empty (btrace_block_s, btrace->blocks)
> + if (!btrace->blocks->empty ()
> && type != BTRACE_READ_DELTA)
This could fit one a single line.
Simon
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 0/2] Remove 2 uses of VEC from gdb
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-23 22:09 ` [PATCH 1/2] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
@ 2019-09-24 19:54 ` Tom Tromey
2019-09-25 15:54 ` [PATCHv2 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
` (2 subsequent siblings)
5 siblings, 0 replies; 35+ messages in thread
From: Tom Tromey @ 2019-09-24 19:54 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
Andrew> I don't know if people would prefer a redesign of the code at the same
Andrew> time, or if we're happy to just be rid of some more uses of VEC for
Andrew> now, and leave any redesign for later (probably not me though).
I think the approach you took is fine.
I looked at the patches but didn't have any comments that Simon didn't
already make.
thanks,
Tom
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv2 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
2019-09-23 22:09 ` [PATCH 0/2] Remove 2 uses of VEC from gdb Andrew Burgess
` (2 preceding siblings ...)
2019-09-24 19:54 ` [PATCH 0/2] Remove 2 uses of VEC from gdb Tom Tromey
@ 2019-09-25 15:54 ` 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
5 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-25 15:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Replace a VEC with a std::vector in btrace.h, and update btrace.c to
match. This code is currently untested, so I've been quite
conservative with the changes - where previously we used VEC_safe_push
which would allocate the vector if it isn't already allocated - I now
check and allocate the std::vector using 'new' before pushing to the
vector.
As the new vector is inside a union I've currently used a pointer to
vector, which makes the code slightly uglier than it might otherwise
be, but again, due to lack of testing I'm reluctant to start
refactoring the code in a big way.
gdb/ChangeLog:
* btrace.c (btrace_maint_clear): Update to handle change from VEC
to std::vector.
(btrace_maint_decode_pt): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Remove 'vec.h' header include and use of DEF_VEC_O.
(typedef btrace_pt_packet_s): Delete.
(struct btrace_maint_info) <packets>: Change fromm VEC to
std::vector.
---
gdb/ChangeLog | 13 +++++++++++++
gdb/btrace.c | 36 ++++++++++++++++++------------------
gdb/btrace.h | 6 +-----
3 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 0b5886c0ca6..cf92753b9d2 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1825,7 +1825,7 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- xfree (btinfo->maint.variant.pt.packets);
+ delete btinfo->maint.variant.pt.packets;
btinfo->maint.variant.pt.packets = NULL;
btinfo->maint.variant.pt.packet_history.begin = 0;
@@ -2983,8 +2983,10 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
{
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets
+ = new std::vector <btrace_pt_packet>;
+ maint->variant.pt.packets->push_back (packet);
}
}
@@ -2992,8 +2994,9 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
break;
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets = new std::vector <btrace_pt_packet>;
+ maint->variant.pt.packets->push_back (packet);
warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
packet.offset, pt_errstr (packet.errcode));
@@ -3094,11 +3097,11 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
+ if (btinfo->maint.variant.pt.packets->empty ())
btrace_maint_update_pt_packets (btinfo);
*begin = 0;
- *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
+ *end = btinfo->maint.variant.pt.packets->size ();
*from = btinfo->maint.variant.pt.packet_history.begin;
*to = btinfo->maint.variant.pt.packet_history.end;
break;
@@ -3141,23 +3144,21 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
{
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet> *packets;
unsigned int pkt;
packets = btinfo->maint.variant.pt.packets;
for (pkt = begin; pkt < end; ++pkt)
{
- const struct btrace_pt_packet *packet;
-
- packet = VEC_index (btrace_pt_packet_s, packets, pkt);
+ const struct btrace_pt_packet &packet = packets->at (pkt);
printf_unfiltered ("%u\t", pkt);
- printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
+ printf_unfiltered ("0x%" PRIx64 "\t", packet.offset);
- if (packet->errcode == pte_ok)
- pt_print_packet (&packet->packet);
+ if (packet.errcode == pte_ok)
+ pt_print_packet (&packet.packet);
else
- printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
+ printf_unfiltered ("[error: %s]", pt_errstr (packet.errcode));
printf_unfiltered ("\n");
}
@@ -3448,9 +3449,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
version.ext != NULL ? version.ext : "");
btrace_maint_update_pt_packets (btinfo);
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_pt_packet_s,
- btinfo->maint.variant.pt.packets));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->maint.variant.pt.packets->size ());
}
break;
#endif /* defined (HAVE_LIBIPT) */
diff --git a/gdb/btrace.h b/gdb/btrace.h
index d09c424804b..208c089fa7c 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -29,7 +29,6 @@
#include "gdbsupport/btrace-common.h"
#include "target/waitstatus.h" /* For enum target_stop_reason. */
#include "gdbsupport/enum-flags.h"
-#include "gdbsupport/vec.h"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
@@ -265,9 +264,6 @@ struct btrace_pt_packet
struct pt_packet packet;
};
-/* Define functions operating on a vector of packets. */
-typedef struct btrace_pt_packet btrace_pt_packet_s;
-DEF_VEC_O (btrace_pt_packet_s);
#endif /* defined (HAVE_LIBIPT) */
/* Branch trace iteration state for "maintenance btrace packet-history". */
@@ -301,7 +297,7 @@ struct btrace_maint_info
struct
{
/* A vector of decoded packets. */
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet> *packets;
/* The packet history iterator.
We are iterating over the above PACKETS vector. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv2 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
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
0 siblings, 0 replies; 35+ messages in thread
From: Simon Marchi @ 2019-09-26 2:35 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Tom Tromey
On 2019-09-25 11:54 a.m., Andrew Burgess wrote:
> @@ -2983,8 +2983,10 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
> if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
> {
> packet.errcode = pt_errcode (errcode);
> - VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
> - &packet);
> + if (maint->variant.pt.packets == NULL)
> + maint->variant.pt.packets
> + = new std::vector <btrace_pt_packet>;
This line fits on a single line as well.
Otherwise, patches 1 and 2 LGTM.
Thanks,
Simon
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCHv2 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
2019-09-23 22:09 ` [PATCH 0/2] Remove 2 uses of VEC from gdb Andrew Burgess
` (3 preceding siblings ...)
2019-09-25 15:54 ` [PATCHv2 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
@ 2019-09-25 15:54 ` Andrew Burgess
2019-09-25 15:54 ` [PATCHv2 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
5 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-25 15:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Converts a VEC into a std::vector in gdbsupport/btrace-common.h. This
commit just performs a mechanical conversion and doesn't do any
refactoring. One consequence of this is that the std::vector must
actually be a pointer to std::vector as it is placed within a union.
It might be possible in future to refactor to a class hierarchy and
remove the need for a union, but I'd rather have that be a separate
change to make it easier to see the evolution of the code.
gdb/ChangeLog:
* btrace.c (btrace_compute_ftrace_bts): Update for std::vector,
make accesses into the vector constant references.
(btrace_add_pc): Update for std::vector.
(btrace_stitch_bts): Likewise.
(parse_xml_btrace_block): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Add 'gdbsupport/vec.h' include.
* gdbsupport/btrace-common.c (btrace_data::fini): Update for
std::vector.
(btrace_data::empty): Likewise.
(btrace_data_append): Likewise.
* gdbsupport/btrace-common.h: Remove 'vec.h' include and use of
DEF_VEC_O.
(typedef btrace_block_s): Delete.
(struct btrace_block): Add constructor.
(struct btrace_data_bts) <blocks>: Change to std::vector.
* nat/linux-btrace.c (perf_event_read_bts): Update for
std::vector.
(linux_read_bts): Likewise.
gdb/gdbserver/ChangeLog:
* linux-low.c (linux_low_read_btrace): Update for change to
std::vector.
---
gdb/ChangeLog | 24 ++++++++++++++++++
gdb/btrace.c | 55 +++++++++++++++++-------------------------
gdb/btrace.h | 1 +
gdb/gdbserver/ChangeLog | 5 ++++
gdb/gdbserver/linux-low.c | 8 ++----
gdb/gdbsupport/btrace-common.c | 17 ++++++-------
gdb/gdbsupport/btrace-common.h | 19 +++++++++------
gdb/nat/linux-btrace.c | 15 ++++++------
8 files changed, 79 insertions(+), 65 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 1b809fb5c08..0b5886c0ca6 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -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;
@@ -1068,13 +1068,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
while (blk != 0)
{
- btrace_block_s *block;
CORE_ADDR pc;
blk -= 1;
- block = VEC_index (btrace_block_s, btrace->blocks, blk);
- pc = block->begin;
+ const btrace_block &block = btrace->blocks->at (blk);
+ pc = block.begin;
for (;;)
{
@@ -1083,7 +1082,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
int size;
/* We should hit the end of the block. Warn if we went too far. */
- if (block->end < pc)
+ if (block.end < pc)
{
/* Indicate the gap in the trace. */
bfun = ftrace_new_gap (btinfo, BDE_BTS_OVERFLOW, gaps);
@@ -1119,7 +1118,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
ftrace_update_insns (bfun, insn);
/* We're done once we pushed the instruction at the end. */
- if (block->end == pc)
+ if (block.end == pc)
break;
/* We can't continue if we fail to compute the size. */
@@ -1573,7 +1572,6 @@ static void
btrace_add_pc (struct thread_info *tp)
{
struct btrace_data btrace;
- struct btrace_block *block;
struct regcache *regcache;
CORE_ADDR pc;
@@ -1581,11 +1579,9 @@ btrace_add_pc (struct thread_info *tp)
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
- btrace.variant.bts.blocks = NULL;
+ btrace.variant.bts.blocks = new std::vector <btrace_block>;
- block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
- block->begin = pc;
- block->end = pc;
+ btrace.variant.bts.blocks->emplace_back (pc, pc);
btrace_compute_ftrace (tp, &btrace, NULL);
}
@@ -1692,11 +1688,11 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
{
struct btrace_thread_info *btinfo;
struct btrace_function *last_bfun;
- btrace_block_s *first_new_block;
+ btrace_block *first_new_block;
btinfo = &tp->btrace;
gdb_assert (!btinfo->functions.empty ());
- gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
+ gdb_assert (!btrace->blocks->empty ());
last_bfun = &btinfo->functions.back ();
@@ -1705,14 +1701,14 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
of the new trace, though, since we can't fill in the start address.*/
if (last_bfun->insn.empty ())
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
/* Beware that block trace starts with the most recent block, so the
chronologically first block in the new trace is the last block in
the new trace's block vector. */
- first_new_block = VEC_last (btrace_block_s, btrace->blocks);
+ first_new_block = &btrace->blocks->back ();
const btrace_insn &last_insn = last_bfun->insn.back ();
/* If the current PC at the end of the block is the same as in our current
@@ -1723,10 +1719,9 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
entries.
In the second case, the delta trace vector should contain exactly one
entry for the partial block containing the current PC. Remove it. */
- if (first_new_block->end == last_insn.pc
- && VEC_length (btrace_block_s, btrace->blocks) == 1)
+ if (first_new_block->end == last_insn.pc && btrace->blocks->size () == 1)
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
@@ -2030,7 +2025,6 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
- struct btrace_block *block;
ULONGEST *begin, *end;
btrace = (struct btrace_data *) user_data;
@@ -2042,7 +2036,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
case BTRACE_FORMAT_NONE:
btrace->format = BTRACE_FORMAT_BTS;
- btrace->variant.bts.blocks = NULL;
+ btrace->variant.bts.blocks = new std::vector <btrace_block>;
break;
default:
@@ -2052,9 +2046,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
- block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
- block->begin = *begin;
- block->end = *end;
+ btrace->variant.bts.blocks->emplace_back (*begin, *end);
}
/* Parse a "raw" xml record. */
@@ -3095,7 +3087,7 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
/* Nothing to do - we operate directly on BTINFO->DATA. */
*begin = 0;
- *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
+ *end = btinfo->data.variant.bts.blocks->size ();
*from = btinfo->maint.variant.bts.packet_history.begin;
*to = btinfo->maint.variant.bts.packet_history.end;
break;
@@ -3128,19 +3120,17 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
{
- VEC (btrace_block_s) *blocks;
+ std::vector <btrace_block> *blocks;
unsigned int blk;
blocks = btinfo->data.variant.bts.blocks;
for (blk = begin; blk < end; ++blk)
{
- const btrace_block_s *block;
-
- block = VEC_index (btrace_block_s, blocks, blk);
+ const btrace_block &block = blocks->at (blk);
printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
- core_addr_to_string_nz (block->begin),
- core_addr_to_string_nz (block->end));
+ core_addr_to_string_nz (block.begin),
+ core_addr_to_string_nz (block.end));
}
btinfo->maint.variant.bts.packet_history.begin = begin;
@@ -3443,9 +3433,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
break;
case BTRACE_FORMAT_BTS:
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_block_s,
- btinfo->data.variant.bts.blocks));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->data.variant.bts.blocks->size ());
break;
#if defined (HAVE_LIBIPT)
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"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index d64c3641ffb..0e4b14e3655 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7115,9 +7115,7 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
enum btrace_read_type type)
{
struct btrace_data btrace;
- struct btrace_block *block;
enum btrace_error err;
- int i;
err = linux_read_btrace (&btrace, tinfo, type);
if (err != BTRACE_ERR_NONE)
@@ -7140,11 +7138,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
- for (i = 0;
- VEC_iterate (btrace_block_s, btrace.variant.bts.blocks, i, block);
- i++)
+ for (const btrace_block &block : *btrace.variant.bts.blocks)
buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
- paddress (block->begin), paddress (block->end));
+ paddress (block.begin), paddress (block.end));
buffer_grow_str0 (buffer, "</btrace>\n");
break;
diff --git a/gdb/gdbsupport/btrace-common.c b/gdb/gdbsupport/btrace-common.c
index 13f1f1a0fdd..eaacb1161e9 100644
--- a/gdb/gdbsupport/btrace-common.c
+++ b/gdb/gdbsupport/btrace-common.c
@@ -73,7 +73,7 @@ btrace_data::fini ()
return;
case BTRACE_FORMAT_BTS:
- VEC_free (btrace_block_s, variant.bts.blocks);
+ delete variant.bts.blocks;
return;
case BTRACE_FORMAT_PT:
@@ -95,7 +95,7 @@ btrace_data::empty () const
return true;
case BTRACE_FORMAT_BTS:
- return VEC_empty (btrace_block_s, variant.bts.blocks);
+ return variant.bts.blocks->empty ();
case BTRACE_FORMAT_PT:
return (variant.pt.size == 0);
@@ -132,7 +132,7 @@ btrace_data_append (struct btrace_data *dst,
case BTRACE_FORMAT_NONE:
dst->format = BTRACE_FORMAT_BTS;
- dst->variant.bts.blocks = NULL;
+ dst->variant.bts.blocks = new std::vector <btrace_block>;
/* Fall-through. */
case BTRACE_FORMAT_BTS:
@@ -141,15 +141,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);
+ dst->variant.bts.blocks->push_back (block);
}
}
}
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 0b18924882c..166d7b18700 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -26,8 +26,6 @@
inferior. For presentation purposes, the branch trace is represented as a
list of sequential control-flow blocks, one such list per thread. */
-#include "vec.h"
-
/* A branch trace block.
This represents a block of sequential control-flow. Adjacent blocks will be
@@ -43,11 +41,15 @@ struct btrace_block
/* The address of the first byte of the last instruction in the block. */
CORE_ADDR end;
-};
-/* Define functions operating on a vector of branch trace blocks. */
-typedef struct btrace_block btrace_block_s;
-DEF_VEC_O (btrace_block_s);
+ /* Simple constructor. */
+ btrace_block (CORE_ADDR begin, CORE_ADDR end)
+ : begin (begin),
+ end (end)
+ {
+ /* Nothing. */
+ }
+};
/* Enumeration of btrace formats. */
@@ -137,8 +139,9 @@ 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;
};
/* Configuration information to go with the trace data. */
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 8625291cce9..6a369496deb 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
In case the buffer overflows during sampling, one sample may have its lower
part at the end and its upper part at the beginning of the buffer. */
-static VEC (btrace_block_s) *
+static std::vector <btrace_block> *
perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
const uint8_t *end, const uint8_t *start, size_t size)
{
- VEC (btrace_block_s) *btrace = NULL;
+ std::vector <btrace_block> *btrace = new std::vector <btrace_block>;
struct perf_event_sample sample;
size_t read = 0;
struct btrace_block block = { 0, 0 };
@@ -343,7 +343,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
/* We found a valid sample, so we can complete the current block. */
block.begin = psample->bts.to;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
/* Start the next block. */
block.end = psample->bts.from;
@@ -354,7 +354,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
reading delta trace, we can fill in the start address later on.
Otherwise we will prune it. */
block.begin = 0;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
return btrace;
}
@@ -785,7 +785,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
data_head = *pevent->data_head;
/* Delete any leftover trace from the previous iteration. */
- VEC_free (btrace_block_s, btrace->blocks);
+ delete btrace->blocks;
if (type == BTRACE_READ_DELTA)
{
@@ -843,9 +843,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
/* Prune the incomplete last block (i.e. the first one of inferior execution)
if we're not doing a delta read. There is no way of filling in its zeroed
BEGIN element. */
- if (!VEC_empty (btrace_block_s, btrace->blocks)
- && type != BTRACE_READ_DELTA)
- VEC_pop (btrace_block_s, btrace->blocks);
+ if (!btrace->blocks->empty () && type != BTRACE_READ_DELTA)
+ btrace->blocks->pop_back ();
return BTRACE_ERR_NONE;
}
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv2 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
2019-09-23 22:09 ` [PATCH 0/2] Remove 2 uses of VEC from gdb Andrew Burgess
` (4 preceding siblings ...)
2019-09-25 15:54 ` [PATCHv2 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
@ 2019-09-25 15:54 ` Andrew Burgess
2019-09-25 22:08 ` Tom Tromey
5 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-25 15:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Removes a use of VEC from dwarf2read.{c,h} and replaces it with
std::vector. As far as possible this is a like for like replacement
with minimal refactoring.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* dwarf2read.c (struct type_unit_group) <tus>: Convert to
std::vector.
(build_type_psymtabs_reader): Update for std::vector.
(build_type_psymtab_dependencies): Likewise.
* dwarf2read.h: Remove use of DEF_VEC_P.
(typedef sig_type_ptr): Delete.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2read.c | 16 ++++++++--------
gdb/dwarf2read.h | 3 ---
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1052501c351..7cc0dc3c92d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -620,7 +620,7 @@ struct type_unit_group
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- VEC (sig_type_ptr) *tus;
+ std::vector <signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
@@ -8184,7 +8184,9 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
tu_group = get_type_unit_group (cu, attr);
- VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
+ if (tu_group->tus == nullptr)
+ tu_group->tus = new std::vector <signatured_type *>;
+ tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
pst = create_partial_symtab (per_cu, "");
@@ -8341,8 +8343,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
struct partial_symtab *pst = per_cu->v.psymtab;
- int len = VEC_length (sig_type_ptr, tu_group->tus);
- struct signatured_type *iter;
+ int len = tu_group->tus->size ();
int i;
gdb_assert (len > 0);
@@ -8350,16 +8351,15 @@ build_type_psymtab_dependencies (void **slot, void *info)
pst->number_of_dependencies = len;
pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
- for (i = 0;
- VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
- ++i)
+ for (i = 0; i < tu_group->tus->size (); ++i)
{
+ struct signatured_type *iter = tu_group->tus->at (i);
gdb_assert (iter->per_cu.is_debug_types);
pst->dependencies[i] = iter->per_cu.v.psymtab;
iter->type_unit_group = tu_group;
}
- VEC_free (sig_type_ptr, tu_group->tus);
+ delete tu_group->tus;
return 1;
}
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index d5a02990d41..aee8742a79c 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -401,9 +401,6 @@ struct signatured_type
struct dwo_unit *dwo_unit;
};
-typedef struct signatured_type *sig_type_ptr;
-DEF_VEC_P (sig_type_ptr);
-
ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
/* This represents a '.dwz' file. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv2 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
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
` (3 more replies)
0 siblings, 4 replies; 35+ messages in thread
From: Tom Tromey @ 2019-09-25 22:08 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches, Simon Marchi, Tom Tromey
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
Andrew> Removes a use of VEC from dwarf2read.{c,h} and replaces it with
Andrew> std::vector. As far as possible this is a like for like replacement
Andrew> with minimal refactoring.
Andrew> + if (tu_group->tus == nullptr)
Andrew> + tu_group->tus = new std::vector <signatured_type *>;
Andrew> + tu_group->tus->push_back (sig_type);
Andrew> + int len = tu_group->tus->size ();
Is it possible to reach here with tus==nullptr?
Andrew> + for (i = 0; i < tu_group->tus->size (); ++i)
Likewise.
Andrew> - VEC_free (sig_type_ptr, tu_group->tus);
Andrew> + delete tu_group->tus;
VEC_free resets tus to nullptr, but I don't know whether or not that's
important.
Tom
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv3 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
2019-09-25 22:08 ` Tom Tromey
@ 2019-09-26 0:00 ` Andrew Burgess
2019-09-26 8:47 ` Metzger, Markus T
2019-09-26 0:00 ` [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
` (2 subsequent siblings)
3 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 0:00 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Converts a VEC into a std::vector in gdbsupport/btrace-common.h. This
commit just performs a mechanical conversion and doesn't do any
refactoring. One consequence of this is that the std::vector must
actually be a pointer to std::vector as it is placed within a union.
It might be possible in future to refactor to a class hierarchy and
remove the need for a union, but I'd rather have that be a separate
change to make it easier to see the evolution of the code.
gdb/ChangeLog:
* btrace.c (btrace_compute_ftrace_bts): Update for std::vector,
make accesses into the vector constant references.
(btrace_add_pc): Update for std::vector.
(btrace_stitch_bts): Likewise.
(parse_xml_btrace_block): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Add 'gdbsupport/vec.h' include.
* gdbsupport/btrace-common.c (btrace_data::fini): Update for
std::vector.
(btrace_data::empty): Likewise.
(btrace_data_append): Likewise.
* gdbsupport/btrace-common.h: Remove 'vec.h' include and use of
DEF_VEC_O.
(typedef btrace_block_s): Delete.
(struct btrace_block): Add constructor.
(struct btrace_data_bts) <blocks>: Change to std::vector.
* nat/linux-btrace.c (perf_event_read_bts): Update for
std::vector.
(linux_read_bts): Likewise.
gdb/gdbserver/ChangeLog:
* linux-low.c (linux_low_read_btrace): Update for change to
std::vector.
---
gdb/ChangeLog | 24 +++++++++++++++++
gdb/btrace.c | 59 +++++++++++++++++++-----------------------
gdb/btrace.h | 1 +
gdb/gdbserver/ChangeLog | 5 ++++
gdb/gdbserver/linux-low.c | 8 ++----
gdb/gdbsupport/btrace-common.c | 20 +++++++-------
gdb/gdbsupport/btrace-common.h | 19 ++++++++------
gdb/nat/linux-btrace.c | 16 ++++++------
8 files changed, 87 insertions(+), 65 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 1b809fb5c08..e3cf5d88f53 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1059,7 +1059,8 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
gdbarch = target_gdbarch ();
btinfo = &tp->btrace;
- blk = VEC_length (btrace_block_s, btrace->blocks);
+ gdb_assert (btrace->blocks != nullptr);
+ blk = btrace->blocks->size ();
if (btinfo->functions.empty ())
level = INT_MAX;
@@ -1068,13 +1069,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
while (blk != 0)
{
- btrace_block_s *block;
CORE_ADDR pc;
blk -= 1;
- block = VEC_index (btrace_block_s, btrace->blocks, blk);
- pc = block->begin;
+ const btrace_block &block = btrace->blocks->at (blk);
+ pc = block.begin;
for (;;)
{
@@ -1083,7 +1083,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
int size;
/* We should hit the end of the block. Warn if we went too far. */
- if (block->end < pc)
+ if (block.end < pc)
{
/* Indicate the gap in the trace. */
bfun = ftrace_new_gap (btinfo, BDE_BTS_OVERFLOW, gaps);
@@ -1119,7 +1119,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
ftrace_update_insns (bfun, insn);
/* We're done once we pushed the instruction at the end. */
- if (block->end == pc)
+ if (block.end == pc)
break;
/* We can't continue if we fail to compute the size. */
@@ -1573,7 +1573,6 @@ static void
btrace_add_pc (struct thread_info *tp)
{
struct btrace_data btrace;
- struct btrace_block *block;
struct regcache *regcache;
CORE_ADDR pc;
@@ -1581,11 +1580,9 @@ btrace_add_pc (struct thread_info *tp)
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
- btrace.variant.bts.blocks = NULL;
+ btrace.variant.bts.blocks = new std::vector <btrace_block>;
- block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
- block->begin = pc;
- block->end = pc;
+ btrace.variant.bts.blocks->emplace_back (pc, pc);
btrace_compute_ftrace (tp, &btrace, NULL);
}
@@ -1692,11 +1689,12 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
{
struct btrace_thread_info *btinfo;
struct btrace_function *last_bfun;
- btrace_block_s *first_new_block;
+ btrace_block *first_new_block;
btinfo = &tp->btrace;
gdb_assert (!btinfo->functions.empty ());
- gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
+ gdb_assert (btrace->blocks != nullptr);
+ gdb_assert (!btrace->blocks->empty ());
last_bfun = &btinfo->functions.back ();
@@ -1705,14 +1703,14 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
of the new trace, though, since we can't fill in the start address.*/
if (last_bfun->insn.empty ())
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
/* Beware that block trace starts with the most recent block, so the
chronologically first block in the new trace is the last block in
the new trace's block vector. */
- first_new_block = VEC_last (btrace_block_s, btrace->blocks);
+ first_new_block = &btrace->blocks->back ();
const btrace_insn &last_insn = last_bfun->insn.back ();
/* If the current PC at the end of the block is the same as in our current
@@ -1723,10 +1721,9 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
entries.
In the second case, the delta trace vector should contain exactly one
entry for the partial block containing the current PC. Remove it. */
- if (first_new_block->end == last_insn.pc
- && VEC_length (btrace_block_s, btrace->blocks) == 1)
+ if (first_new_block->end == last_insn.pc && btrace->blocks->size () == 1)
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
@@ -2030,7 +2027,6 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
- struct btrace_block *block;
ULONGEST *begin, *end;
btrace = (struct btrace_data *) user_data;
@@ -2042,7 +2038,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
case BTRACE_FORMAT_NONE:
btrace->format = BTRACE_FORMAT_BTS;
- btrace->variant.bts.blocks = NULL;
+ btrace->variant.bts.blocks = new std::vector <btrace_block>;
break;
default:
@@ -2052,9 +2048,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
- block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
- block->begin = *begin;
- block->end = *end;
+ gdb_assert (btrace->variant.bts.blocks != nullptr);
+ btrace->variant.bts.blocks->emplace_back (*begin, *end);
}
/* Parse a "raw" xml record. */
@@ -3095,7 +3090,8 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
/* Nothing to do - we operate directly on BTINFO->DATA. */
*begin = 0;
- *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
+ gdb_assert (btinfo->data.variant.bts.blocks != nullptr);
+ *end = btinfo->data.variant.bts.blocks->size ();
*from = btinfo->maint.variant.bts.packet_history.begin;
*to = btinfo->maint.variant.bts.packet_history.end;
break;
@@ -3128,19 +3124,17 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
{
- VEC (btrace_block_s) *blocks;
+ std::vector <btrace_block> *blocks;
unsigned int blk;
blocks = btinfo->data.variant.bts.blocks;
for (blk = begin; blk < end; ++blk)
{
- const btrace_block_s *block;
-
- block = VEC_index (btrace_block_s, blocks, blk);
+ const btrace_block &block = blocks->at (blk);
printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
- core_addr_to_string_nz (block->begin),
- core_addr_to_string_nz (block->end));
+ core_addr_to_string_nz (block.begin),
+ core_addr_to_string_nz (block.end));
}
btinfo->maint.variant.bts.packet_history.begin = begin;
@@ -3443,9 +3437,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
break;
case BTRACE_FORMAT_BTS:
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_block_s,
- btinfo->data.variant.bts.blocks));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->data.variant.bts.blocks->size ());
break;
#if defined (HAVE_LIBIPT)
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"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index d64c3641ffb..0e4b14e3655 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7115,9 +7115,7 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
enum btrace_read_type type)
{
struct btrace_data btrace;
- struct btrace_block *block;
enum btrace_error err;
- int i;
err = linux_read_btrace (&btrace, tinfo, type);
if (err != BTRACE_ERR_NONE)
@@ -7140,11 +7138,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
- for (i = 0;
- VEC_iterate (btrace_block_s, btrace.variant.bts.blocks, i, block);
- i++)
+ for (const btrace_block &block : *btrace.variant.bts.blocks)
buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
- paddress (block->begin), paddress (block->end));
+ paddress (block.begin), paddress (block.end));
buffer_grow_str0 (buffer, "</btrace>\n");
break;
diff --git a/gdb/gdbsupport/btrace-common.c b/gdb/gdbsupport/btrace-common.c
index 13f1f1a0fdd..dda9638bcd4 100644
--- a/gdb/gdbsupport/btrace-common.c
+++ b/gdb/gdbsupport/btrace-common.c
@@ -73,7 +73,8 @@ btrace_data::fini ()
return;
case BTRACE_FORMAT_BTS:
- VEC_free (btrace_block_s, variant.bts.blocks);
+ delete variant.bts.blocks;
+ variant.bts.blocks = nullptr;
return;
case BTRACE_FORMAT_PT:
@@ -95,7 +96,8 @@ btrace_data::empty () const
return true;
case BTRACE_FORMAT_BTS:
- return VEC_empty (btrace_block_s, variant.bts.blocks);
+ gdb_assert (variant.bts.blocks != nullptr);
+ return variant.bts.blocks->empty ();
case BTRACE_FORMAT_PT:
return (variant.pt.size == 0);
@@ -132,7 +134,7 @@ btrace_data_append (struct btrace_data *dst,
case BTRACE_FORMAT_NONE:
dst->format = BTRACE_FORMAT_BTS;
- dst->variant.bts.blocks = NULL;
+ dst->variant.bts.blocks = new std::vector <btrace_block>;
/* Fall-through. */
case BTRACE_FORMAT_BTS:
@@ -141,15 +143,13 @@ 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);
+ gdb_assert (src->variant.bts.blocks != nullptr);
+ 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);
+ dst->variant.bts.blocks->push_back (block);
}
}
}
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 0b18924882c..166d7b18700 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -26,8 +26,6 @@
inferior. For presentation purposes, the branch trace is represented as a
list of sequential control-flow blocks, one such list per thread. */
-#include "vec.h"
-
/* A branch trace block.
This represents a block of sequential control-flow. Adjacent blocks will be
@@ -43,11 +41,15 @@ struct btrace_block
/* The address of the first byte of the last instruction in the block. */
CORE_ADDR end;
-};
-/* Define functions operating on a vector of branch trace blocks. */
-typedef struct btrace_block btrace_block_s;
-DEF_VEC_O (btrace_block_s);
+ /* Simple constructor. */
+ btrace_block (CORE_ADDR begin, CORE_ADDR end)
+ : begin (begin),
+ end (end)
+ {
+ /* Nothing. */
+ }
+};
/* Enumeration of btrace formats. */
@@ -137,8 +139,9 @@ 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;
};
/* Configuration information to go with the trace data. */
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 8625291cce9..a63973d569d 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
In case the buffer overflows during sampling, one sample may have its lower
part at the end and its upper part at the beginning of the buffer. */
-static VEC (btrace_block_s) *
+static std::vector <btrace_block> *
perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
const uint8_t *end, const uint8_t *start, size_t size)
{
- VEC (btrace_block_s) *btrace = NULL;
+ std::vector <btrace_block> *btrace = new std::vector <btrace_block>;
struct perf_event_sample sample;
size_t read = 0;
struct btrace_block block = { 0, 0 };
@@ -343,7 +343,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
/* We found a valid sample, so we can complete the current block. */
block.begin = psample->bts.to;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
/* Start the next block. */
block.end = psample->bts.from;
@@ -354,7 +354,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
reading delta trace, we can fill in the start address later on.
Otherwise we will prune it. */
block.begin = 0;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
return btrace;
}
@@ -785,7 +785,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
data_head = *pevent->data_head;
/* Delete any leftover trace from the previous iteration. */
- VEC_free (btrace_block_s, btrace->blocks);
+ delete btrace->blocks;
+ btrace->blocks = nullptr;
if (type == BTRACE_READ_DELTA)
{
@@ -843,9 +844,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
/* Prune the incomplete last block (i.e. the first one of inferior execution)
if we're not doing a delta read. There is no way of filling in its zeroed
BEGIN element. */
- if (!VEC_empty (btrace_block_s, btrace->blocks)
- && type != BTRACE_READ_DELTA)
- VEC_pop (btrace_block_s, btrace->blocks);
+ if (!btrace->blocks->empty () && type != BTRACE_READ_DELTA)
+ btrace->blocks->pop_back ();
return BTRACE_ERR_NONE;
}
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* RE: [PATCHv3 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
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
0 siblings, 1 reply; 35+ messages in thread
From: Metzger, Markus T @ 2019-09-26 8:47 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Simon Marchi, Tom Tromey
Hello Andrew,
I can help you run the gdb.btrace suite. Do you have a user branch with these patches?
> @@ -1068,13 +1069,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
>
> while (blk != 0)
> {
> - btrace_block_s *block;
> CORE_ADDR pc;
>
> blk -= 1;
>
> - block = VEC_index (btrace_block_s, btrace->blocks, blk);
> - pc = block->begin;
> + const btrace_block &block = btrace->blocks->at (blk);
> + pc = block.begin;
We could also turn BTRACE->BLOCKS into a const & outside the loop.
> @@ -1581,11 +1580,9 @@ btrace_add_pc (struct thread_info *tp)
> pc = regcache_read_pc (regcache);
>
> btrace.format = BTRACE_FORMAT_BTS;
> - btrace.variant.bts.blocks = NULL;
> + btrace.variant.bts.blocks = new std::vector <btrace_block>;
A stack-allocated vector should do. Looks like we leaked the one-entry
vector before.
> @@ -2052,9 +2048,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
> begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
> end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
>
> - block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
> - block->begin = *begin;
> - block->end = *end;
> + gdb_assert (btrace->variant.bts.blocks != nullptr);
We don't check most pointers in GDB. Besides, we just allocated the vector.
The invariant is that if BTRACE->FORMAT == BTRACE_FORMAT_BTS, the vector
is non-null.
> @@ -3095,7 +3090,8 @@ btrace_maint_update_packets (struct btrace_thread_info
> *btinfo,
> case BTRACE_FORMAT_BTS:
> /* Nothing to do - we operate directly on BTINFO->DATA. */
> *begin = 0;
> - *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
> + gdb_assert (btinfo->data.variant.bts.blocks != nullptr);
See above. More below.
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
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv3 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
2019-09-26 8:47 ` Metzger, Markus T
@ 2019-09-26 11:32 ` Andrew Burgess
2019-09-26 13:07 ` Metzger, Markus T
0 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 11:32 UTC (permalink / raw)
To: Metzger, Markus T; +Cc: gdb-patches, Simon Marchi, Tom Tromey
* Metzger, Markus T <markus.t.metzger@intel.com> [2019-09-26 08:47:23 +0000]:
> Hello Andrew,
>
> I can help you run the gdb.btrace suite. Do you have a user branch
> with these patches?
You can find this branch here:
https://github.com/T-J-Teru/binutils-gdb/tree/gdb-remove-vec
Any additional testing is always welcome, though from Simon's feedback
I believe that I should be testing this OK - I'm running on a
post-Broadwell Intel CPU, and I am linking GDB against libipt, and see
no regressions over the entire testsuite.
>
>
> > @@ -1068,13 +1069,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
> >
> > while (blk != 0)
> > {
> > - btrace_block_s *block;
> > CORE_ADDR pc;
> >
> > blk -= 1;
> >
> > - block = VEC_index (btrace_block_s, btrace->blocks, blk);
> > - pc = block->begin;
> > + const btrace_block &block = btrace->blocks->at (blk);
> > + pc = block.begin;
>
> We could also turn BTRACE->BLOCKS into a const & outside the loop.
I was worried about the case where we get here and btrace->blocks ==
nullptr. I don't know if such a path is possible, I had a little
through the code and my conclusion was that the answer is not
obvious. So ideally I'd leave the code as close to the original as
possible to avoid introducing bugs.
>
>
> > @@ -1581,11 +1580,9 @@ btrace_add_pc (struct thread_info *tp)
> > pc = regcache_read_pc (regcache);
> >
> > btrace.format = BTRACE_FORMAT_BTS;
> > - btrace.variant.bts.blocks = NULL;
> > + btrace.variant.bts.blocks = new std::vector <btrace_block>;
>
> A stack-allocated vector should do. Looks like we leaked the one-entry
> vector before.
Nope the btrace object is stack local, and its destructor deletes the
vector, so its easier if this just stays being new'd for now.
>
>
> > @@ -2052,9 +2048,8 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
> > begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
> > end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
> >
> > - block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
> > - block->begin = *begin;
> > - block->end = *end;
> > + gdb_assert (btrace->variant.bts.blocks != nullptr);
>
> We don't check most pointers in GDB. Besides, we just allocated the vector.
> The invariant is that if BTRACE->FORMAT == BTRACE_FORMAT_BTS, the vector
> is non-null.
You are correct. Thanks. I've removed this assertion.
>
>
> > @@ -3095,7 +3090,8 @@ btrace_maint_update_packets (struct btrace_thread_info
> > *btinfo,
> > case BTRACE_FORMAT_BTS:
> > /* Nothing to do - we operate directly on BTINFO->DATA. */
> > *begin = 0;
> > - *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
> > + gdb_assert (btinfo->data.variant.bts.blocks != nullptr);
>
> See above. More below.
I think you've convinced me that having all of these assertions around
isn't great. So I've taken a slightly different approach. I'll post
another iteration soon.
Thanks,
Andrew
^ permalink raw reply [flat|nested] 35+ messages in thread* RE: [PATCHv3 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
2019-09-26 11:32 ` Andrew Burgess
@ 2019-09-26 13:07 ` Metzger, Markus T
0 siblings, 0 replies; 35+ messages in thread
From: Metzger, Markus T @ 2019-09-26 13:07 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches, Simon Marchi, Tom Tromey
Hello Andrew,
> Any additional testing is always welcome, though from Simon's feedback I believe
> that I should be testing this OK - I'm running on a post-Broadwell Intel CPU, and I
> am linking GDB against libipt, and see no regressions over the entire testsuite.
That should suffice. I wasn't sure if you had access to a suitable system.
> > > @@ -1068,13 +1069,12 @@ btrace_compute_ftrace_bts (struct
> > > thread_info *tp,
> > >
> > > while (blk != 0)
> > > {
> > > - btrace_block_s *block;
> > > CORE_ADDR pc;
> > >
> > > blk -= 1;
> > >
> > > - block = VEC_index (btrace_block_s, btrace->blocks, blk);
> > > - pc = block->begin;
> > > + const btrace_block &block = btrace->blocks->at (blk);
> > > + pc = block.begin;
> >
> > We could also turn BTRACE->BLOCKS into a const & outside the loop.
>
> I was worried about the case where we get here and btrace->blocks == nullptr. I
> don't know if such a path is possible, I had a little through the code and my
> conclusion was that the answer is not obvious. So ideally I'd leave the code as close
> to the original as possible to avoid introducing bugs.
We wouldn't get into this loop if BTRACE->BLOCKS == nullptr. BLK is initialized to
BTRACE->BLOCKS->size () (or zero with your latest version) so we'd skip this if we
ever had BTRACE->BLOCKS == nullptr.
> > > @@ -1581,11 +1580,9 @@ btrace_add_pc (struct thread_info *tp)
> > > pc = regcache_read_pc (regcache);
> > >
> > > btrace.format = BTRACE_FORMAT_BTS;
> > > - btrace.variant.bts.blocks = NULL;
> > > + btrace.variant.bts.blocks = new std::vector <btrace_block>;
> >
> > A stack-allocated vector should do. Looks like we leaked the
> > one-entry vector before.
>
> Nope the btrace object is stack local, and its destructor deletes the vector, so its
> easier if this just stays being new'd for now.
Thanks. We could clear it again but it's probably not worth the added complexity.
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
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
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 0:00 ` Andrew Burgess
2019-09-26 8:47 ` 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 0/3] Remove some uses of VEC Andrew Burgess
3 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 0:00 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Replace a VEC with a std::vector in btrace.h, and update btrace.c to
match. This code is currently untested, so I've been quite
conservative with the changes - where previously we used VEC_safe_push
which would allocate the vector if it isn't already allocated - I now
check and allocate the std::vector using 'new' before pushing to the
vector.
As the new vector is inside a union I've currently used a pointer to
vector, which makes the code slightly uglier than it might otherwise
be, but again, due to lack of testing I'm reluctant to start
refactoring the code in a big way.
gdb/ChangeLog:
* btrace.c (btrace_maint_clear): Update to handle change from VEC
to std::vector.
(btrace_maint_decode_pt): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Remove 'vec.h' header include and use of DEF_VEC_O.
(typedef btrace_pt_packet_s): Delete.
(struct btrace_maint_info) <packets>: Change fromm VEC to
std::vector.
---
gdb/ChangeLog | 13 +++++++++++++
gdb/btrace.c | 39 +++++++++++++++++++++------------------
gdb/btrace.h | 6 +-----
3 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index e3cf5d88f53..349e609addb 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1827,7 +1827,7 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- xfree (btinfo->maint.variant.pt.packets);
+ delete btinfo->maint.variant.pt.packets;
btinfo->maint.variant.pt.packets = NULL;
btinfo->maint.variant.pt.packet_history.begin = 0;
@@ -2986,8 +2986,10 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
{
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets
+ = new std::vector <btrace_pt_packet>;
+ maint->variant.pt.packets->push_back (packet);
}
}
@@ -2995,8 +2997,9 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
break;
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets = new std::vector <btrace_pt_packet>;
+ maint->variant.pt.packets->push_back (packet);
warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
packet.offset, pt_errstr (packet.errcode));
@@ -3098,11 +3101,13 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
+ if (btinfo->maint.variant.pt.packets == nullptr
+ || btinfo->maint.variant.pt.packets->empty ())
btrace_maint_update_pt_packets (btinfo);
*begin = 0;
- *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
+ *end = ((btinfo->maint.variant.pt.packets == nullptr)
+ ? 0 : btinfo->maint.variant.pt.packets->size ());
*from = btinfo->maint.variant.pt.packet_history.begin;
*to = btinfo->maint.variant.pt.packet_history.end;
break;
@@ -3145,23 +3150,21 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
{
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet> *packets;
unsigned int pkt;
packets = btinfo->maint.variant.pt.packets;
for (pkt = begin; pkt < end; ++pkt)
{
- const struct btrace_pt_packet *packet;
-
- packet = VEC_index (btrace_pt_packet_s, packets, pkt);
+ const struct btrace_pt_packet &packet = packets->at (pkt);
printf_unfiltered ("%u\t", pkt);
- printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
+ printf_unfiltered ("0x%" PRIx64 "\t", packet.offset);
- if (packet->errcode == pte_ok)
- pt_print_packet (&packet->packet);
+ if (packet.errcode == pte_ok)
+ pt_print_packet (&packet.packet);
else
- printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
+ printf_unfiltered ("[error: %s]", pt_errstr (packet.errcode));
printf_unfiltered ("\n");
}
@@ -3452,9 +3455,9 @@ maint_info_btrace_cmd (const char *args, int from_tty)
version.ext != NULL ? version.ext : "");
btrace_maint_update_pt_packets (btinfo);
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_pt_packet_s,
- btinfo->maint.variant.pt.packets));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ ((btinfo->maint.variant.pt.packets == nullptr)
+ ? 0 : btinfo->maint.variant.pt.packets->size ()));
}
break;
#endif /* defined (HAVE_LIBIPT) */
diff --git a/gdb/btrace.h b/gdb/btrace.h
index d09c424804b..208c089fa7c 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -29,7 +29,6 @@
#include "gdbsupport/btrace-common.h"
#include "target/waitstatus.h" /* For enum target_stop_reason. */
#include "gdbsupport/enum-flags.h"
-#include "gdbsupport/vec.h"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
@@ -265,9 +264,6 @@ struct btrace_pt_packet
struct pt_packet packet;
};
-/* Define functions operating on a vector of packets. */
-typedef struct btrace_pt_packet btrace_pt_packet_s;
-DEF_VEC_O (btrace_pt_packet_s);
#endif /* defined (HAVE_LIBIPT) */
/* Branch trace iteration state for "maintenance btrace packet-history". */
@@ -301,7 +297,7 @@ struct btrace_maint_info
struct
{
/* A vector of decoded packets. */
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet> *packets;
/* The packet history iterator.
We are iterating over the above PACKETS vector. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* RE: [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
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
0 siblings, 1 reply; 35+ messages in thread
From: Metzger, Markus T @ 2019-09-26 8:47 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Simon Marchi, Tom Tromey
Hello Andrew,
> @@ -2986,8 +2986,10 @@ btrace_maint_decode_pt (struct btrace_maint_info
> *maint,
> if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
> {
> packet.errcode = pt_errcode (errcode);
> - VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
> - &packet);
> + if (maint->variant.pt.packets == NULL)
> + maint->variant.pt.packets
> + = new std::vector <btrace_pt_packet>;
> + maint->variant.pt.packets->push_back (packet);
We shouldn't do that check inside the loop. I used VEC_safe_push for the realloc aspect.
> @@ -3098,11 +3101,13 @@ btrace_maint_update_packets (struct
> btrace_thread_info *btinfo,
>
> #if defined (HAVE_LIBIPT)
> case BTRACE_FORMAT_PT:
> - if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
> + if (btinfo->maint.variant.pt.packets == nullptr
> + || btinfo->maint.variant.pt.packets->empty ())
> btrace_maint_update_pt_packets (btinfo);
Here, I'd check for nullptr in order to allocate the vector and call
btrace_maint_update_pt_packets. Afterwards, I'd check for emptiness and delete
the vector again if there are no packets.
We can also leave an empty vector if you prefer that.
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
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
2019-09-26 8:47 ` Metzger, Markus T
@ 2019-09-26 11:33 ` Andrew Burgess
0 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 11:33 UTC (permalink / raw)
To: Metzger, Markus T; +Cc: gdb-patches, Simon Marchi, Tom Tromey
* Metzger, Markus T <markus.t.metzger@intel.com> [2019-09-26 08:47:28 +0000]:
> Hello Andrew,
>
> > @@ -2986,8 +2986,10 @@ btrace_maint_decode_pt (struct btrace_maint_info
> > *maint,
> > if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
> > {
> > packet.errcode = pt_errcode (errcode);
> > - VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
> > - &packet);
> > + if (maint->variant.pt.packets == NULL)
> > + maint->variant.pt.packets
> > + = new std::vector <btrace_pt_packet>;
> > + maint->variant.pt.packets->push_back (packet);
>
> We shouldn't do that check inside the loop. I used VEC_safe_push
> for the realloc aspect.
Thanks, I pushed the vector allocation out of the loop.
>
>
> > @@ -3098,11 +3101,13 @@ btrace_maint_update_packets (struct
> > btrace_thread_info *btinfo,
> >
> > #if defined (HAVE_LIBIPT)
> > case BTRACE_FORMAT_PT:
> > - if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
> > + if (btinfo->maint.variant.pt.packets == nullptr
> > + || btinfo->maint.variant.pt.packets->empty ())
> > btrace_maint_update_pt_packets (btinfo);
>
> Here, I'd check for nullptr in order to allocate the vector and call
> btrace_maint_update_pt_packets. Afterwards, I'd check for emptiness and delete
> the vector again if there are no packets.
>
> We can also leave an empty vector if you prefer that.
I hope I've interpreted your suggestion correctly. Please do check my
next version and correct me if I've not understood you.
Thanks,
Andrew
>
> 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
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCHv3 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
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 0:00 ` [PATCHv3 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
@ 2019-09-26 0:00 ` Andrew Burgess
2019-09-26 0:00 ` [PATCHv3 0/3] Remove some uses of VEC Andrew Burgess
3 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 0:00 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Removes a use of VEC from dwarf2read.{c,h} and replaces it with
std::vector. As far as possible this is a like for like replacement
with minimal refactoring.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* dwarf2read.c (struct type_unit_group) <tus>: Convert to
std::vector.
(build_type_psymtabs_reader): Update for std::vector.
(build_type_psymtab_dependencies): Likewise.
* dwarf2read.h: Remove use of DEF_VEC_P.
(typedef sig_type_ptr): Delete.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2read.c | 17 +++++++++--------
gdb/dwarf2read.h | 3 ---
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1052501c351..e2aa1a1f903 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -620,7 +620,7 @@ struct type_unit_group
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- VEC (sig_type_ptr) *tus;
+ std::vector <signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
@@ -8184,7 +8184,9 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
tu_group = get_type_unit_group (cu, attr);
- VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
+ if (tu_group->tus == nullptr)
+ tu_group->tus = new std::vector <signatured_type *>;
+ tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
pst = create_partial_symtab (per_cu, "");
@@ -8341,8 +8343,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
struct partial_symtab *pst = per_cu->v.psymtab;
- int len = VEC_length (sig_type_ptr, tu_group->tus);
- struct signatured_type *iter;
+ int len = (tu_group->tus == nullptr) ? 0 : tu_group->tus->size ();
int i;
gdb_assert (len > 0);
@@ -8350,16 +8351,16 @@ build_type_psymtab_dependencies (void **slot, void *info)
pst->number_of_dependencies = len;
pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
- for (i = 0;
- VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
- ++i)
+ for (i = 0; i < len; ++i)
{
+ struct signatured_type *iter = tu_group->tus->at (i);
gdb_assert (iter->per_cu.is_debug_types);
pst->dependencies[i] = iter->per_cu.v.psymtab;
iter->type_unit_group = tu_group;
}
- VEC_free (sig_type_ptr, tu_group->tus);
+ delete tu_group->tus;
+ tu_group->tus = nullptr;
return 1;
}
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index d5a02990d41..aee8742a79c 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -401,9 +401,6 @@ struct signatured_type
struct dwo_unit *dwo_unit;
};
-typedef struct signatured_type *sig_type_ptr;
-DEF_VEC_P (sig_type_ptr);
-
ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
/* This represents a '.dwz' file. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv3 0/3] Remove some uses of VEC
2019-09-25 22:08 ` Tom Tromey
` (2 preceding siblings ...)
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 ` Andrew Burgess
2019-09-26 2:52 ` Simon Marchi
` (4 more replies)
3 siblings, 5 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 0:00 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, Andrew Burgess
Tom raised some good points about patch #3, specifically that some of
the query functions like VEC_length and VEC_empty will return a sane
answer even when the vector pointer is NULL. He also pointed out that
VEC_free resets theh vector pointer back to NULL.
This revision of the series is a little more defensive about checking
for the std::vector pointer being null before dereferencing it. In
places where I'm reasonably sure the vector pointer won't be NULL I've
added an assert - then at least if I'm wrong we'll get a nice error
rather than a random crash.
Thanks,
Andrew
---
Andrew Burgess (3):
gdb: Remove a VEC from gdbsupport/btrace-common.h
gdb: Change a VEC to std::vector in btrace.{c,h}
gdb: Remove a use of VEC from dwarf2read.{c,h}
gdb/ChangeLog | 46 ++++++++++++++++++++
gdb/btrace.c | 98 ++++++++++++++++++++----------------------
gdb/btrace.h | 5 +--
gdb/dwarf2read.c | 17 ++++----
gdb/dwarf2read.h | 3 --
gdb/gdbserver/ChangeLog | 5 +++
gdb/gdbserver/linux-low.c | 8 +---
gdb/gdbsupport/btrace-common.c | 20 ++++-----
gdb/gdbsupport/btrace-common.h | 19 ++++----
gdb/nat/linux-btrace.c | 16 +++----
10 files changed, 139 insertions(+), 98 deletions(-)
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv3 0/3] Remove some uses of VEC
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 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
` (3 subsequent siblings)
4 siblings, 0 replies; 35+ messages in thread
From: Simon Marchi @ 2019-09-26 2:52 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Tom Tromey
On 2019-09-25 7:59 p.m., Andrew Burgess wrote:
> Tom raised some good points about patch #3, specifically that some of
> the query functions like VEC_length and VEC_empty will return a sane
> answer even when the vector pointer is NULL. He also pointed out that
> VEC_free resets theh vector pointer back to NULL.
>
> This revision of the series is a little more defensive about checking
> for the std::vector pointer being null before dereferencing it. In
> places where I'm reasonably sure the vector pointer won't be NULL I've
> added an assert - then at least if I'm wrong we'll get a nice error
> rather than a random crash.
Oh, that's a good point. I gave a quick look at patches 1 and 2, and
they seem good with the extra checks.
About testing, the testsuite contains a bunch of btrace tests in gdb.btrace,
and some more in gdb.python. It would be good to run those tests on a CPU
that supports Intel BTS and PT (which would mean any Broadwell or more recent
CPU) and a GDB linked against libipt. I can give it a try if you are unable
to do it for some reason.
Simon
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv4 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
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 ` Andrew Burgess
2019-09-26 13:40 ` Metzger, Markus T
2019-09-26 11:41 ` [PATCHv4 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
` (2 subsequent siblings)
4 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 11:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
Converts a VEC into a std::vector in gdbsupport/btrace-common.h. This
commit just performs a mechanical conversion and doesn't do any
refactoring. One consequence of this is that the std::vector must
actually be a pointer to std::vector as it is placed within a union.
It might be possible in future to refactor to a class hierarchy and
remove the need for a union, but I'd rather have that be a separate
change to make it easier to see the evolution of the code.
gdb/ChangeLog:
* btrace.c (btrace_compute_ftrace_bts): Update for std::vector,
make accesses into the vector constant references.
(btrace_add_pc): Update for std::vector.
(btrace_stitch_bts): Likewise.
(parse_xml_btrace_block): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Add 'gdbsupport/vec.h' include.
* gdbsupport/btrace-common.c (btrace_data::fini): Update for
std::vector.
(btrace_data::empty): Likewise.
(btrace_data_append): Likewise.
* gdbsupport/btrace-common.h: Remove 'vec.h' include and use of
DEF_VEC_O.
(typedef btrace_block_s): Delete.
(struct btrace_block): Add constructor.
(struct btrace_data_bts) <blocks>: Change to std::vector.
(struct btrace_data_bts) <blocks_size>: New function.
(struct btrace_data_bts) <blocks_empty>: New function.
* nat/linux-btrace.c (perf_event_read_bts): Update for
std::vector.
(linux_read_bts): Likewise.
gdb/gdbserver/ChangeLog:
* linux-low.c (linux_low_read_btrace): Update for change to
std::vector.
---
gdb/ChangeLog | 26 +++++++++++++++++++
gdb/btrace.c | 58 +++++++++++++++++-------------------------
gdb/btrace.h | 1 +
gdb/gdbserver/ChangeLog | 5 ++++
gdb/gdbserver/linux-low.c | 8 ++----
gdb/gdbsupport/btrace-common.c | 18 ++++++-------
gdb/gdbsupport/btrace-common.h | 38 +++++++++++++++++++++------
gdb/nat/linux-btrace.c | 16 ++++++------
8 files changed, 103 insertions(+), 67 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 1b809fb5c08..006cd740554 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -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;
@@ -1068,13 +1068,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
while (blk != 0)
{
- btrace_block_s *block;
CORE_ADDR pc;
blk -= 1;
- block = VEC_index (btrace_block_s, btrace->blocks, blk);
- pc = block->begin;
+ const btrace_block &block = btrace->blocks->at (blk);
+ pc = block.begin;
for (;;)
{
@@ -1083,7 +1082,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
int size;
/* We should hit the end of the block. Warn if we went too far. */
- if (block->end < pc)
+ if (block.end < pc)
{
/* Indicate the gap in the trace. */
bfun = ftrace_new_gap (btinfo, BDE_BTS_OVERFLOW, gaps);
@@ -1119,7 +1118,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
ftrace_update_insns (bfun, insn);
/* We're done once we pushed the instruction at the end. */
- if (block->end == pc)
+ if (block.end == pc)
break;
/* We can't continue if we fail to compute the size. */
@@ -1573,7 +1572,6 @@ static void
btrace_add_pc (struct thread_info *tp)
{
struct btrace_data btrace;
- struct btrace_block *block;
struct regcache *regcache;
CORE_ADDR pc;
@@ -1581,11 +1579,9 @@ btrace_add_pc (struct thread_info *tp)
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
- btrace.variant.bts.blocks = NULL;
+ btrace.variant.bts.blocks = new std::vector <btrace_block>;
- block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
- block->begin = pc;
- block->end = pc;
+ btrace.variant.bts.blocks->emplace_back (pc, pc);
btrace_compute_ftrace (tp, &btrace, NULL);
}
@@ -1692,11 +1688,11 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
{
struct btrace_thread_info *btinfo;
struct btrace_function *last_bfun;
- btrace_block_s *first_new_block;
+ btrace_block *first_new_block;
btinfo = &tp->btrace;
gdb_assert (!btinfo->functions.empty ());
- gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
+ gdb_assert (!btrace->blocks_empty ());
last_bfun = &btinfo->functions.back ();
@@ -1705,14 +1701,14 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
of the new trace, though, since we can't fill in the start address.*/
if (last_bfun->insn.empty ())
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
/* Beware that block trace starts with the most recent block, so the
chronologically first block in the new trace is the last block in
the new trace's block vector. */
- first_new_block = VEC_last (btrace_block_s, btrace->blocks);
+ first_new_block = &btrace->blocks->back ();
const btrace_insn &last_insn = last_bfun->insn.back ();
/* If the current PC at the end of the block is the same as in our current
@@ -1723,10 +1719,9 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
entries.
In the second case, the delta trace vector should contain exactly one
entry for the partial block containing the current PC. Remove it. */
- if (first_new_block->end == last_insn.pc
- && VEC_length (btrace_block_s, btrace->blocks) == 1)
+ if (first_new_block->end == last_insn.pc && btrace->blocks_size () == 1)
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
@@ -2030,7 +2025,6 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
- struct btrace_block *block;
ULONGEST *begin, *end;
btrace = (struct btrace_data *) user_data;
@@ -2042,7 +2036,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
case BTRACE_FORMAT_NONE:
btrace->format = BTRACE_FORMAT_BTS;
- btrace->variant.bts.blocks = NULL;
+ btrace->variant.bts.blocks = new std::vector <btrace_block>;
break;
default:
@@ -2051,10 +2045,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
-
- block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
- block->begin = *begin;
- block->end = *end;
+ btrace->variant.bts.blocks->emplace_back (*begin, *end);
}
/* Parse a "raw" xml record. */
@@ -3095,7 +3086,7 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
/* Nothing to do - we operate directly on BTINFO->DATA. */
*begin = 0;
- *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
+ *end = btinfo->data.variant.bts.blocks_size ();
*from = btinfo->maint.variant.bts.packet_history.begin;
*to = btinfo->maint.variant.bts.packet_history.end;
break;
@@ -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;
unsigned int blk;
- blocks = btinfo->data.variant.bts.blocks;
for (blk = begin; blk < end; ++blk)
{
- const btrace_block_s *block;
-
- block = VEC_index (btrace_block_s, blocks, blk);
+ const btrace_block &block = blocks.at (blk);
printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
- core_addr_to_string_nz (block->begin),
- core_addr_to_string_nz (block->end));
+ core_addr_to_string_nz (block.begin),
+ core_addr_to_string_nz (block.end));
}
btinfo->maint.variant.bts.packet_history.begin = begin;
@@ -3443,9 +3432,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
break;
case BTRACE_FORMAT_BTS:
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_block_s,
- btinfo->data.variant.bts.blocks));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->data.variant.bts.blocks_size ());
break;
#if defined (HAVE_LIBIPT)
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"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index d64c3641ffb..0e4b14e3655 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7115,9 +7115,7 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
enum btrace_read_type type)
{
struct btrace_data btrace;
- struct btrace_block *block;
enum btrace_error err;
- int i;
err = linux_read_btrace (&btrace, tinfo, type);
if (err != BTRACE_ERR_NONE)
@@ -7140,11 +7138,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
- for (i = 0;
- VEC_iterate (btrace_block_s, btrace.variant.bts.blocks, i, block);
- i++)
+ for (const btrace_block &block : *btrace.variant.bts.blocks)
buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
- paddress (block->begin), paddress (block->end));
+ paddress (block.begin), paddress (block.end));
buffer_grow_str0 (buffer, "</btrace>\n");
break;
diff --git a/gdb/gdbsupport/btrace-common.c b/gdb/gdbsupport/btrace-common.c
index 13f1f1a0fdd..d6e41173063 100644
--- a/gdb/gdbsupport/btrace-common.c
+++ b/gdb/gdbsupport/btrace-common.c
@@ -73,7 +73,8 @@ btrace_data::fini ()
return;
case BTRACE_FORMAT_BTS:
- VEC_free (btrace_block_s, variant.bts.blocks);
+ delete variant.bts.blocks;
+ variant.bts.blocks = nullptr;
return;
case BTRACE_FORMAT_PT:
@@ -95,7 +96,7 @@ btrace_data::empty () const
return true;
case BTRACE_FORMAT_BTS:
- return VEC_empty (btrace_block_s, variant.bts.blocks);
+ return variant.bts.blocks_empty ();
case BTRACE_FORMAT_PT:
return (variant.pt.size == 0);
@@ -132,7 +133,7 @@ btrace_data_append (struct btrace_data *dst,
case BTRACE_FORMAT_NONE:
dst->format = BTRACE_FORMAT_BTS;
- dst->variant.bts.blocks = NULL;
+ dst->variant.bts.blocks = new std::vector <btrace_block>;
/* Fall-through. */
case BTRACE_FORMAT_BTS:
@@ -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);
+ dst->variant.bts.blocks->push_back (block);
}
}
}
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 0b18924882c..3eb065ed03d 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -26,8 +26,6 @@
inferior. For presentation purposes, the branch trace is represented as a
list of sequential control-flow blocks, one such list per thread. */
-#include "vec.h"
-
/* A branch trace block.
This represents a block of sequential control-flow. Adjacent blocks will be
@@ -43,11 +41,15 @@ struct btrace_block
/* The address of the first byte of the last instruction in the block. */
CORE_ADDR end;
-};
-/* Define functions operating on a vector of branch trace blocks. */
-typedef struct btrace_block btrace_block_s;
-DEF_VEC_O (btrace_block_s);
+ /* Simple constructor. */
+ btrace_block (CORE_ADDR begin, CORE_ADDR end)
+ : begin (begin),
+ end (end)
+ {
+ /* Nothing. */
+ }
+};
/* Enumeration of btrace formats. */
@@ -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 ();
+ }
};
/* Configuration information to go with the trace data. */
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 8625291cce9..4fc68dca801 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
In case the buffer overflows during sampling, one sample may have its lower
part at the end and its upper part at the beginning of the buffer. */
-static VEC (btrace_block_s) *
+static std::vector <btrace_block> *
perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
const uint8_t *end, const uint8_t *start, size_t size)
{
- VEC (btrace_block_s) *btrace = NULL;
+ std::vector <btrace_block> *btrace = new std::vector <btrace_block>;
struct perf_event_sample sample;
size_t read = 0;
struct btrace_block block = { 0, 0 };
@@ -343,7 +343,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
/* We found a valid sample, so we can complete the current block. */
block.begin = psample->bts.to;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
/* Start the next block. */
block.end = psample->bts.from;
@@ -354,7 +354,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
reading delta trace, we can fill in the start address later on.
Otherwise we will prune it. */
block.begin = 0;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
return btrace;
}
@@ -785,7 +785,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
data_head = *pevent->data_head;
/* Delete any leftover trace from the previous iteration. */
- VEC_free (btrace_block_s, btrace->blocks);
+ delete btrace->blocks;
+ btrace->blocks = nullptr;
if (type == BTRACE_READ_DELTA)
{
@@ -843,9 +844,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
/* Prune the incomplete last block (i.e. the first one of inferior execution)
if we're not doing a delta read. There is no way of filling in its zeroed
BEGIN element. */
- if (!VEC_empty (btrace_block_s, btrace->blocks)
- && type != BTRACE_READ_DELTA)
- VEC_pop (btrace_block_s, btrace->blocks);
+ if (!btrace->blocks_empty () && type != BTRACE_READ_DELTA)
+ btrace->blocks->pop_back ();
return BTRACE_ERR_NONE;
}
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* RE: [PATCHv4 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
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
0 siblings, 0 replies; 35+ messages in thread
From: Metzger, Markus T @ 2019-09-26 13:40 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Simon Marchi, Tom Tromey
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
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCHv4 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
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 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
@ 2019-09-26 11:41 ` Andrew Burgess
2019-09-26 11:41 ` [PATCHv4 0/3] Remove some uses of VEC Andrew Burgess
2019-09-26 11:41 ` [PATCHv4 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
4 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 11:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
Removes a use of VEC from dwarf2read.{c,h} and replaces it with
std::vector. As far as possible this is a like for like replacement
with minimal refactoring.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* dwarf2read.c (struct type_unit_group) <tus>: Convert to
std::vector.
(build_type_psymtabs_reader): Update for std::vector.
(build_type_psymtab_dependencies): Likewise.
* dwarf2read.h: Remove use of DEF_VEC_P.
(typedef sig_type_ptr): Delete.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2read.c | 17 +++++++++--------
gdb/dwarf2read.h | 3 ---
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1052501c351..e2aa1a1f903 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -620,7 +620,7 @@ struct type_unit_group
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- VEC (sig_type_ptr) *tus;
+ std::vector <signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
@@ -8184,7 +8184,9 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
tu_group = get_type_unit_group (cu, attr);
- VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
+ if (tu_group->tus == nullptr)
+ tu_group->tus = new std::vector <signatured_type *>;
+ tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
pst = create_partial_symtab (per_cu, "");
@@ -8341,8 +8343,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
struct partial_symtab *pst = per_cu->v.psymtab;
- int len = VEC_length (sig_type_ptr, tu_group->tus);
- struct signatured_type *iter;
+ int len = (tu_group->tus == nullptr) ? 0 : tu_group->tus->size ();
int i;
gdb_assert (len > 0);
@@ -8350,16 +8351,16 @@ build_type_psymtab_dependencies (void **slot, void *info)
pst->number_of_dependencies = len;
pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
- for (i = 0;
- VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
- ++i)
+ for (i = 0; i < len; ++i)
{
+ struct signatured_type *iter = tu_group->tus->at (i);
gdb_assert (iter->per_cu.is_debug_types);
pst->dependencies[i] = iter->per_cu.v.psymtab;
iter->type_unit_group = tu_group;
}
- VEC_free (sig_type_ptr, tu_group->tus);
+ delete tu_group->tus;
+ tu_group->tus = nullptr;
return 1;
}
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index d5a02990d41..aee8742a79c 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -401,9 +401,6 @@ struct signatured_type
struct dwo_unit *dwo_unit;
};
-typedef struct signatured_type *sig_type_ptr;
-DEF_VEC_P (sig_type_ptr);
-
ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
/* This represents a '.dwz' file. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv4 0/3] Remove some uses of VEC
2019-09-26 0:00 ` [PATCHv3 0/3] Remove some uses of VEC Andrew Burgess
` (2 preceding siblings ...)
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 ` Andrew Burgess
2019-10-01 11:42 ` [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
` (3 more replies)
2019-09-26 11:41 ` [PATCHv4 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
4 siblings, 4 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 11:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
Only patches #1 and #2 have changed.
#1 - Update with Markus's feedback, and added new nullptr safe
methods to get the size and empty status of the new vector.
Use these throughout and remove lots of assertions.
#2 - Minor updates from Markus's feedback. Moves a vector
allocation out of a loop, and allocates the vector in
btrace_maint_update_packets.
The code is available for testing from here:
https://github.com/T-J-Teru/binutils-gdb/tree/gdb-remove-vec
Thanks,
Andrew
---
Andrew Burgess (3):
gdb: Remove a VEC from gdbsupport/btrace-common.h
gdb: Change a VEC to std::vector in btrace.{c,h}
gdb: Remove a use of VEC from dwarf2read.{c,h}
gdb/ChangeLog | 50 +++++++++++++++++++++
gdb/btrace.c | 98 +++++++++++++++++++-----------------------
gdb/btrace.h | 5 +--
gdb/dwarf2read.c | 17 ++++----
gdb/dwarf2read.h | 3 --
gdb/gdbserver/ChangeLog | 5 +++
gdb/gdbserver/linux-low.c | 8 +---
gdb/gdbsupport/btrace-common.c | 18 ++++----
gdb/gdbsupport/btrace-common.h | 38 ++++++++++++----
gdb/nat/linux-btrace.c | 16 +++----
10 files changed, 157 insertions(+), 101 deletions(-)
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
2019-09-26 11:41 ` [PATCHv4 0/3] Remove some uses of VEC Andrew Burgess
@ 2019-10-01 11:42 ` Andrew Burgess
2019-10-02 15:51 ` Pedro Alves
2019-10-01 11:42 ` [PATCHv5 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h Andrew Burgess
` (2 subsequent siblings)
3 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-10-01 11:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
Removes a use of VEC from dwarf2read.{c,h} and replaces it with
std::vector. As far as possible this is a like for like replacement
with minimal refactoring.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* dwarf2read.c (struct type_unit_group) <tus>: Convert to
std::vector.
(build_type_psymtabs_reader): Update for std::vector.
(build_type_psymtab_dependencies): Likewise.
* dwarf2read.h: Remove use of DEF_VEC_P.
(typedef sig_type_ptr): Delete.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2read.c | 17 +++++++++--------
gdb/dwarf2read.h | 3 ---
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 53e7393a7c9..30658b2d4f4 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -620,7 +620,7 @@ struct type_unit_group
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- VEC (sig_type_ptr) *tus;
+ std::vector <signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
@@ -8184,7 +8184,9 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
tu_group = get_type_unit_group (cu, attr);
- VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
+ if (tu_group->tus == nullptr)
+ tu_group->tus = new std::vector <signatured_type *>;
+ tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
pst = create_partial_symtab (per_cu, "");
@@ -8341,8 +8343,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
struct partial_symtab *pst = per_cu->v.psymtab;
- int len = VEC_length (sig_type_ptr, tu_group->tus);
- struct signatured_type *iter;
+ int len = (tu_group->tus == nullptr) ? 0 : tu_group->tus->size ();
int i;
gdb_assert (len > 0);
@@ -8350,16 +8351,16 @@ build_type_psymtab_dependencies (void **slot, void *info)
pst->number_of_dependencies = len;
pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
- for (i = 0;
- VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
- ++i)
+ for (i = 0; i < len; ++i)
{
+ struct signatured_type *iter = tu_group->tus->at (i);
gdb_assert (iter->per_cu.is_debug_types);
pst->dependencies[i] = iter->per_cu.v.psymtab;
iter->type_unit_group = tu_group;
}
- VEC_free (sig_type_ptr, tu_group->tus);
+ delete tu_group->tus;
+ tu_group->tus = nullptr;
return 1;
}
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index d5a02990d41..aee8742a79c 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -401,9 +401,6 @@ struct signatured_type
struct dwo_unit *dwo_unit;
};
-typedef struct signatured_type *sig_type_ptr;
-DEF_VEC_P (sig_type_ptr);
-
ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
/* This represents a '.dwz' file. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
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
0 siblings, 1 reply; 35+ messages in thread
From: Pedro Alves @ 2019-10-02 15:51 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger
Hi,
On 10/1/19 12:42 PM, Andrew Burgess wrote:
> - VEC (sig_type_ptr) *tus;
> + std::vector <signatured_type *> *tus;
I skimmed this quickly and noticed that throughout the series
you're putting a space in "vector <", which is not the prevailing
style.
(I've really not looked at the patches in any detail beyond that.)
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
2019-10-02 15:51 ` Pedro Alves
@ 2019-10-02 22:21 ` Andrew Burgess
2019-10-03 8:06 ` Pedro Alves
0 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-10-02 22:21 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, Simon Marchi, Tom Tromey, markus.t.metzger
* Pedro Alves <palves@redhat.com> [2019-10-02 16:50:57 +0100]:
> Hi,
>
> On 10/1/19 12:42 PM, Andrew Burgess wrote:
> > - VEC (sig_type_ptr) *tus;
> > + std::vector <signatured_type *> *tus;
>
> I skimmed this quickly and noticed that throughout the series
> you're putting a space in "vector <", which is not the prevailing
> style.
>
Sorry for this. I propose the below patch to address this mistake.
Thanks,
Andrew
--
From d686b9d504c338ac39b4ddbd7e0765b591e8bf04 Mon Sep 17 00:00:00 2001
From: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Wed, 2 Oct 2019 22:01:46 +0100
Subject: [PATCH] gdb: Remove whitespace in 'std::vector <...>'
In the following 3 commits:
commit df07e2c772dab40d268dc44c78bb087c4b75b3c6
Date: Wed Sep 25 16:10:50 2019 +0100
gdb: Remove a use of VEC from dwarf2read.{c,h}
commit 554ac434b02465f1fc925b0ae3393fb841e0d59c
Date: Thu Sep 19 13:17:59 2019 -0400
gdb: Change a VEC to std::vector in btrace.{c,h}
commit 46f29a9a260da1a03176682aff63bad03d8f2e8b
Date: Mon Sep 16 09:12:27 2019 -0400
gdb: Remove a VEC from gdbsupport/btrace-common.h
I incorrectly wrote 'std::vector <...>' instead of 'std::vector<...>',
this commit fixes this mistake. There should be no user visible
changes after this commit.
gdb/ChangeLog:
* btrace.c (btrace_add_pc): Remove whitespace before the template
parameter in 'std::vector <...>'.
(parse_xml_btrace_block): Likewise.
(btrace_maint_decode_pt): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
* btrace.h (struct btrace_maint_info): Likewise.
* dwarf2read.c (struct type_unit_group): Likewise.
(build_type_psymtabs_reader): Likewise.
* gdbsupport/btrace-common.c (btrace_data_append): Likewise.
* gdbsupport/btrace-common.h (struct btrace_data_bts): Likewise.
* nat/linux-btrace.c (perf_event_read_bts): Likewise.
---
gdb/ChangeLog | 15 +++++++++++++++
gdb/btrace.c | 12 ++++++------
gdb/btrace.h | 2 +-
gdb/dwarf2read.c | 4 ++--
gdb/gdbsupport/btrace-common.c | 2 +-
gdb/gdbsupport/btrace-common.h | 2 +-
gdb/nat/linux-btrace.c | 4 ++--
7 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 8bed31cdac0..e2443a2d234 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1579,7 +1579,7 @@ btrace_add_pc (struct thread_info *tp)
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
- btrace.variant.bts.blocks = new std::vector <btrace_block>;
+ btrace.variant.bts.blocks = new std::vector<btrace_block>;
btrace.variant.bts.blocks->emplace_back (pc, pc);
@@ -2036,7 +2036,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
case BTRACE_FORMAT_NONE:
btrace->format = BTRACE_FORMAT_BTS;
- btrace->variant.bts.blocks = new std::vector <btrace_block>;
+ btrace->variant.bts.blocks = new std::vector<btrace_block>;
break;
default:
@@ -2963,7 +2963,7 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
int errcode;
if (maint->variant.pt.packets == NULL)
- maint->variant.pt.packets = new std::vector <btrace_pt_packet>;
+ maint->variant.pt.packets = new std::vector<btrace_pt_packet>;
for (;;)
{
@@ -3095,7 +3095,7 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
if (btinfo->maint.variant.pt.packets == nullptr)
- btinfo->maint.variant.pt.packets = new std::vector <btrace_pt_packet>;
+ btinfo->maint.variant.pt.packets = new std::vector<btrace_pt_packet>;
if (btinfo->maint.variant.pt.packets->empty ())
btrace_maint_update_pt_packets (btinfo);
@@ -3123,7 +3123,7 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
{
- const std::vector <btrace_block> &blocks
+ const std::vector<btrace_block> &blocks
= *btinfo->data.variant.bts.blocks;
unsigned int blk;
@@ -3144,7 +3144,7 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
{
- const std::vector <btrace_pt_packet> &packets
+ const std::vector<btrace_pt_packet> &packets
= *btinfo->maint.variant.pt.packets;
unsigned int pkt;
diff --git a/gdb/btrace.h b/gdb/btrace.h
index 208c089fa7c..acde64a5122 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -297,7 +297,7 @@ struct btrace_maint_info
struct
{
/* A vector of decoded packets. */
- std::vector <btrace_pt_packet> *packets;
+ std::vector<btrace_pt_packet> *packets;
/* The packet history iterator.
We are iterating over the above PACKETS vector. */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index feac40ff95c..9d9dd6db709 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -620,7 +620,7 @@ struct type_unit_group
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- std::vector <signatured_type *> *tus;
+ std::vector<signatured_type *> *tus;
/* The compunit symtab.
Type units in a group needn't all be defined in the same source file,
@@ -8191,7 +8191,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
tu_group = get_type_unit_group (cu, attr);
if (tu_group->tus == nullptr)
- tu_group->tus = new std::vector <signatured_type *>;
+ tu_group->tus = new std::vector<signatured_type *>;
tu_group->tus->push_back (sig_type);
prepare_one_comp_unit (cu, type_unit_die, language_minimal);
diff --git a/gdb/gdbsupport/btrace-common.c b/gdb/gdbsupport/btrace-common.c
index d6d3ab50c9e..608506c34c9 100644
--- a/gdb/gdbsupport/btrace-common.c
+++ b/gdb/gdbsupport/btrace-common.c
@@ -133,7 +133,7 @@ btrace_data_append (struct btrace_data *dst,
case BTRACE_FORMAT_NONE:
dst->format = BTRACE_FORMAT_BTS;
- dst->variant.bts.blocks = new std::vector <btrace_block>;
+ dst->variant.bts.blocks = new std::vector<btrace_block>;
/* Fall-through. */
case BTRACE_FORMAT_BTS:
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 166d7b18700..09a90485cdc 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -141,7 +141,7 @@ struct btrace_data_bts
/* Branch trace is represented as a vector of branch trace blocks starting
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;
+ std::vector<btrace_block> *blocks;
};
/* Configuration information to go with the trace data. */
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index a63973d569d..850fa8df584 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
In case the buffer overflows during sampling, one sample may have its lower
part at the end and its upper part at the beginning of the buffer. */
-static std::vector <btrace_block> *
+static std::vector<btrace_block> *
perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
const uint8_t *end, const uint8_t *start, size_t size)
{
- std::vector <btrace_block> *btrace = new std::vector <btrace_block>;
+ std::vector<btrace_block> *btrace = new std::vector<btrace_block>;
struct perf_event_sample sample;
size_t read = 0;
struct btrace_block block = { 0, 0 };
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h}
2019-10-02 22:21 ` Andrew Burgess
@ 2019-10-03 8:06 ` Pedro Alves
0 siblings, 0 replies; 35+ messages in thread
From: Pedro Alves @ 2019-10-03 8:06 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches, Simon Marchi, Tom Tromey, markus.t.metzger
On 10/2/19 11:21 PM, Andrew Burgess wrote:
> * Pedro Alves <palves@redhat.com> [2019-10-02 16:50:57 +0100]:
>
>> Hi,
>>
>> On 10/1/19 12:42 PM, Andrew Burgess wrote:
>>> - VEC (sig_type_ptr) *tus;
>>> + std::vector <signatured_type *> *tus;
>>
>> I skimmed this quickly and noticed that throughout the series
>> you're putting a space in "vector <", which is not the prevailing
>> style.
>>
>
> Sorry for this. I propose the below patch to address this mistake.
Far from a big deal. :-) Thanks! Looks pretty obvious to me.
Pedro Alves
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCHv5 1/3] gdb: Remove a VEC from gdbsupport/btrace-common.h
2019-09-26 11:41 ` [PATCHv4 0/3] Remove some uses of VEC Andrew Burgess
2019-10-01 11:42 ` [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{c,h} Andrew Burgess
@ 2019-10-01 11:42 ` Andrew Burgess
2019-10-01 19:59 ` Tom Tromey
2019-10-01 11:42 ` [PATCHv5 2/3] gdb: Change a VEC to std::vector in btrace.{c,h} Andrew Burgess
[not found] ` <cover.1569929785.git.andrew.burgess@embecosm.com>
3 siblings, 1 reply; 35+ messages in thread
From: Andrew Burgess @ 2019-10-01 11:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
TODO: Update ChangeLogs
Converts a VEC into a std::vector in gdbsupport/btrace-common.h. This
commit just performs a mechanical conversion and doesn't do any
refactoring. One consequence of this is that the std::vector must
actually be a pointer to std::vector as it is placed within a union.
It might be possible in future to refactor to a class hierarchy and
remove the need for a union, but I'd rather have that be a separate
change to make it easier to see the evolution of the code.
gdb/ChangeLog:
* btrace.c (btrace_compute_ftrace_bts): Update for std::vector,
make accesses into the vector constant references.
(btrace_add_pc): Update for std::vector.
(btrace_stitch_bts): Likewise.
(parse_xml_btrace_block): Likewise.
(btrace_maint_update_packets): Likewise.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* gdbsupport/btrace-common.c (btrace_data::fini): Update for
std::vector.
(btrace_data::empty): Likewise.
(btrace_data_append): Likewise.
* gdbsupport/btrace-common.h: Remove use of DEF_VEC_O.
(typedef btrace_block_s): Delete.
(struct btrace_block): Add constructor.
(struct btrace_data_bts) <blocks>: Change to std::vector.
* nat/linux-btrace.c (perf_event_read_bts): Update for
std::vector.
(linux_read_bts): Likewise.
gdb/gdbserver/ChangeLog:
* linux-low.c (linux_low_read_btrace): Update for change to
std::vector.
---
gdb/ChangeLog | 22 ++++++++++++++++
gdb/btrace.c | 58 +++++++++++++++++-------------------------
gdb/gdbserver/ChangeLog | 5 ++++
gdb/gdbserver/linux-low.c | 8 ++----
gdb/gdbsupport/btrace-common.c | 18 ++++++-------
gdb/gdbsupport/btrace-common.h | 17 ++++++++-----
gdb/nat/linux-btrace.c | 16 ++++++------
7 files changed, 79 insertions(+), 65 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 1b809fb5c08..b6a11136444 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -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;
@@ -1068,13 +1068,12 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
while (blk != 0)
{
- btrace_block_s *block;
CORE_ADDR pc;
blk -= 1;
- block = VEC_index (btrace_block_s, btrace->blocks, blk);
- pc = block->begin;
+ const btrace_block &block = btrace->blocks->at (blk);
+ pc = block.begin;
for (;;)
{
@@ -1083,7 +1082,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
int size;
/* We should hit the end of the block. Warn if we went too far. */
- if (block->end < pc)
+ if (block.end < pc)
{
/* Indicate the gap in the trace. */
bfun = ftrace_new_gap (btinfo, BDE_BTS_OVERFLOW, gaps);
@@ -1119,7 +1118,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
ftrace_update_insns (bfun, insn);
/* We're done once we pushed the instruction at the end. */
- if (block->end == pc)
+ if (block.end == pc)
break;
/* We can't continue if we fail to compute the size. */
@@ -1573,7 +1572,6 @@ static void
btrace_add_pc (struct thread_info *tp)
{
struct btrace_data btrace;
- struct btrace_block *block;
struct regcache *regcache;
CORE_ADDR pc;
@@ -1581,11 +1579,9 @@ btrace_add_pc (struct thread_info *tp)
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
- btrace.variant.bts.blocks = NULL;
+ btrace.variant.bts.blocks = new std::vector <btrace_block>;
- block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
- block->begin = pc;
- block->end = pc;
+ btrace.variant.bts.blocks->emplace_back (pc, pc);
btrace_compute_ftrace (tp, &btrace, NULL);
}
@@ -1692,11 +1688,11 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
{
struct btrace_thread_info *btinfo;
struct btrace_function *last_bfun;
- btrace_block_s *first_new_block;
+ btrace_block *first_new_block;
btinfo = &tp->btrace;
gdb_assert (!btinfo->functions.empty ());
- gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
+ gdb_assert (!btrace->blocks->empty ());
last_bfun = &btinfo->functions.back ();
@@ -1705,14 +1701,14 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
of the new trace, though, since we can't fill in the start address.*/
if (last_bfun->insn.empty ())
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
/* Beware that block trace starts with the most recent block, so the
chronologically first block in the new trace is the last block in
the new trace's block vector. */
- first_new_block = VEC_last (btrace_block_s, btrace->blocks);
+ first_new_block = &btrace->blocks->back ();
const btrace_insn &last_insn = last_bfun->insn.back ();
/* If the current PC at the end of the block is the same as in our current
@@ -1723,10 +1719,9 @@ btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
entries.
In the second case, the delta trace vector should contain exactly one
entry for the partial block containing the current PC. Remove it. */
- if (first_new_block->end == last_insn.pc
- && VEC_length (btrace_block_s, btrace->blocks) == 1)
+ if (first_new_block->end == last_insn.pc && btrace->blocks->size () == 1)
{
- VEC_pop (btrace_block_s, btrace->blocks);
+ btrace->blocks->pop_back ();
return 0;
}
@@ -2030,7 +2025,6 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
std::vector<gdb_xml_value> &attributes)
{
struct btrace_data *btrace;
- struct btrace_block *block;
ULONGEST *begin, *end;
btrace = (struct btrace_data *) user_data;
@@ -2042,7 +2036,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
case BTRACE_FORMAT_NONE:
btrace->format = BTRACE_FORMAT_BTS;
- btrace->variant.bts.blocks = NULL;
+ btrace->variant.bts.blocks = new std::vector <btrace_block>;
break;
default:
@@ -2051,10 +2045,7 @@ parse_xml_btrace_block (struct gdb_xml_parser *parser,
begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value.get ();
end = (ULONGEST *) xml_find_attribute (attributes, "end")->value.get ();
-
- block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
- block->begin = *begin;
- block->end = *end;
+ btrace->variant.bts.blocks->emplace_back (*begin, *end);
}
/* Parse a "raw" xml record. */
@@ -3095,7 +3086,7 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
case BTRACE_FORMAT_BTS:
/* Nothing to do - we operate directly on BTINFO->DATA. */
*begin = 0;
- *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
+ *end = btinfo->data.variant.bts.blocks->size ();
*from = btinfo->maint.variant.bts.packet_history.begin;
*to = btinfo->maint.variant.bts.packet_history.end;
break;
@@ -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;
unsigned int blk;
- blocks = btinfo->data.variant.bts.blocks;
for (blk = begin; blk < end; ++blk)
{
- const btrace_block_s *block;
-
- block = VEC_index (btrace_block_s, blocks, blk);
+ const btrace_block &block = blocks.at (blk);
printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
- core_addr_to_string_nz (block->begin),
- core_addr_to_string_nz (block->end));
+ core_addr_to_string_nz (block.begin),
+ core_addr_to_string_nz (block.end));
}
btinfo->maint.variant.bts.packet_history.begin = begin;
@@ -3443,9 +3432,8 @@ maint_info_btrace_cmd (const char *args, int from_tty)
break;
case BTRACE_FORMAT_BTS:
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_block_s,
- btinfo->data.variant.bts.blocks));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ btinfo->data.variant.bts.blocks->size ());
break;
#if defined (HAVE_LIBIPT)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index d64c3641ffb..0e4b14e3655 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -7115,9 +7115,7 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
enum btrace_read_type type)
{
struct btrace_data btrace;
- struct btrace_block *block;
enum btrace_error err;
- int i;
err = linux_read_btrace (&btrace, tinfo, type);
if (err != BTRACE_ERR_NONE)
@@ -7140,11 +7138,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
- for (i = 0;
- VEC_iterate (btrace_block_s, btrace.variant.bts.blocks, i, block);
- i++)
+ for (const btrace_block &block : *btrace.variant.bts.blocks)
buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
- paddress (block->begin), paddress (block->end));
+ paddress (block.begin), paddress (block.end));
buffer_grow_str0 (buffer, "</btrace>\n");
break;
diff --git a/gdb/gdbsupport/btrace-common.c b/gdb/gdbsupport/btrace-common.c
index 13f1f1a0fdd..d6d3ab50c9e 100644
--- a/gdb/gdbsupport/btrace-common.c
+++ b/gdb/gdbsupport/btrace-common.c
@@ -73,7 +73,8 @@ btrace_data::fini ()
return;
case BTRACE_FORMAT_BTS:
- VEC_free (btrace_block_s, variant.bts.blocks);
+ delete variant.bts.blocks;
+ variant.bts.blocks = nullptr;
return;
case BTRACE_FORMAT_PT:
@@ -95,7 +96,7 @@ btrace_data::empty () const
return true;
case BTRACE_FORMAT_BTS:
- return VEC_empty (btrace_block_s, variant.bts.blocks);
+ return variant.bts.blocks->empty ();
case BTRACE_FORMAT_PT:
return (variant.pt.size == 0);
@@ -132,7 +133,7 @@ btrace_data_append (struct btrace_data *dst,
case BTRACE_FORMAT_NONE:
dst->format = BTRACE_FORMAT_BTS;
- dst->variant.bts.blocks = NULL;
+ dst->variant.bts.blocks = new std::vector <btrace_block>;
/* Fall-through. */
case BTRACE_FORMAT_BTS:
@@ -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);
+ dst->variant.bts.blocks->push_back (block);
}
}
}
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 0b18924882c..9c57645ffb1 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -43,11 +43,15 @@ struct btrace_block
/* The address of the first byte of the last instruction in the block. */
CORE_ADDR end;
-};
-/* Define functions operating on a vector of branch trace blocks. */
-typedef struct btrace_block btrace_block_s;
-DEF_VEC_O (btrace_block_s);
+ /* Simple constructor. */
+ btrace_block (CORE_ADDR begin, CORE_ADDR end)
+ : begin (begin),
+ end (end)
+ {
+ /* Nothing. */
+ }
+};
/* Enumeration of btrace formats. */
@@ -137,8 +141,9 @@ 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;
};
/* Configuration information to go with the trace data. */
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 8625291cce9..a63973d569d 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -271,11 +271,11 @@ perf_event_sample_ok (const struct perf_event_sample *sample)
In case the buffer overflows during sampling, one sample may have its lower
part at the end and its upper part at the beginning of the buffer. */
-static VEC (btrace_block_s) *
+static std::vector <btrace_block> *
perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
const uint8_t *end, const uint8_t *start, size_t size)
{
- VEC (btrace_block_s) *btrace = NULL;
+ std::vector <btrace_block> *btrace = new std::vector <btrace_block>;
struct perf_event_sample sample;
size_t read = 0;
struct btrace_block block = { 0, 0 };
@@ -343,7 +343,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
/* We found a valid sample, so we can complete the current block. */
block.begin = psample->bts.to;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
/* Start the next block. */
block.end = psample->bts.from;
@@ -354,7 +354,7 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
reading delta trace, we can fill in the start address later on.
Otherwise we will prune it. */
block.begin = 0;
- VEC_safe_push (btrace_block_s, btrace, &block);
+ btrace->push_back (block);
return btrace;
}
@@ -785,7 +785,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
data_head = *pevent->data_head;
/* Delete any leftover trace from the previous iteration. */
- VEC_free (btrace_block_s, btrace->blocks);
+ delete btrace->blocks;
+ btrace->blocks = nullptr;
if (type == BTRACE_READ_DELTA)
{
@@ -843,9 +844,8 @@ linux_read_bts (struct btrace_data_bts *btrace,
/* Prune the incomplete last block (i.e. the first one of inferior execution)
if we're not doing a delta read. There is no way of filling in its zeroed
BEGIN element. */
- if (!VEC_empty (btrace_block_s, btrace->blocks)
- && type != BTRACE_READ_DELTA)
- VEC_pop (btrace_block_s, btrace->blocks);
+ if (!btrace->blocks->empty () && type != BTRACE_READ_DELTA)
+ btrace->blocks->pop_back ();
return BTRACE_ERR_NONE;
}
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCHv5 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
2019-09-26 11:41 ` [PATCHv4 0/3] Remove some uses of VEC Andrew Burgess
2019-10-01 11:42 ` [PATCHv5 3/3] gdb: Remove a use of VEC from dwarf2read.{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 11:42 ` Andrew Burgess
[not found] ` <cover.1569929785.git.andrew.burgess@embecosm.com>
3 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-10-01 11:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
Replace a VEC with a std::vector in btrace.h, and update btrace.c to
match. It is worth noting that this code appears to be currently
untested by the GDB testsuite. I've tried to do a like for like
replacement when moving to std::vector, with minimal refactoring to
try and avoid introducing any bugs.
As the new vector is inside a union I've currently used a pointer to
vector, which makes the code slightly uglier than it might otherwise
be, but again, due to lack of testing I'm reluctant to start
refactoring the code in a big way.
gdb/ChangeLog:
* btrace.c (btrace_maint_clear): Update to handle change from VEC
to std::vector.
(btrace_maint_decode_pt): Likewise, and move allocation of the
vector outside of the loop.
(btrace_maint_update_packets): Update to handle change from VEC to
std::vector.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Remove use of DEF_VEC_O.
(typedef btrace_pt_packet_s): Delete.
(struct btrace_maint_info) <packets>: Change fromm VEC to
std::vector.
* gdbsupport/btrace-common.h: Remove 'vec.h' include.
---
gdb/ChangeLog | 16 ++++++++++++++++
gdb/btrace.c | 40 +++++++++++++++++++++-------------------
gdb/btrace.h | 5 +----
gdb/gdbsupport/btrace-common.h | 2 --
4 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index b6a11136444..8bed31cdac0 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1825,7 +1825,7 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- xfree (btinfo->maint.variant.pt.packets);
+ delete btinfo->maint.variant.pt.packets;
btinfo->maint.variant.pt.packets = NULL;
btinfo->maint.variant.pt.packet_history.begin = 0;
@@ -2962,6 +2962,9 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
{
int errcode;
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets = new std::vector <btrace_pt_packet>;
+
for (;;)
{
struct btrace_pt_packet packet;
@@ -2982,8 +2985,7 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
{
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ maint->variant.pt.packets->push_back (packet);
}
}
@@ -2991,8 +2993,7 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
break;
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ maint->variant.pt.packets->push_back (packet);
warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
packet.offset, pt_errstr (packet.errcode));
@@ -3093,11 +3094,14 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
+ if (btinfo->maint.variant.pt.packets == nullptr)
+ btinfo->maint.variant.pt.packets = new std::vector <btrace_pt_packet>;
+
+ if (btinfo->maint.variant.pt.packets->empty ())
btrace_maint_update_pt_packets (btinfo);
*begin = 0;
- *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
+ *end = btinfo->maint.variant.pt.packets->size ();
*from = btinfo->maint.variant.pt.packet_history.begin;
*to = btinfo->maint.variant.pt.packet_history.end;
break;
@@ -3140,23 +3144,21 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
{
- VEC (btrace_pt_packet_s) *packets;
+ const std::vector <btrace_pt_packet> &packets
+ = *btinfo->maint.variant.pt.packets;
unsigned int pkt;
- packets = btinfo->maint.variant.pt.packets;
for (pkt = begin; pkt < end; ++pkt)
{
- const struct btrace_pt_packet *packet;
-
- packet = VEC_index (btrace_pt_packet_s, packets, pkt);
+ const struct btrace_pt_packet &packet = packets.at (pkt);
printf_unfiltered ("%u\t", pkt);
- printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
+ printf_unfiltered ("0x%" PRIx64 "\t", packet.offset);
- if (packet->errcode == pte_ok)
- pt_print_packet (&packet->packet);
+ if (packet.errcode == pte_ok)
+ pt_print_packet (&packet.packet);
else
- printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
+ printf_unfiltered ("[error: %s]", pt_errstr (packet.errcode));
printf_unfiltered ("\n");
}
@@ -3447,9 +3449,9 @@ maint_info_btrace_cmd (const char *args, int from_tty)
version.ext != NULL ? version.ext : "");
btrace_maint_update_pt_packets (btinfo);
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_pt_packet_s,
- btinfo->maint.variant.pt.packets));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ ((btinfo->maint.variant.pt.packets == nullptr)
+ ? 0 : btinfo->maint.variant.pt.packets->size ()));
}
break;
#endif /* defined (HAVE_LIBIPT) */
diff --git a/gdb/btrace.h b/gdb/btrace.h
index ba8d27c879c..208c089fa7c 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -264,9 +264,6 @@ struct btrace_pt_packet
struct pt_packet packet;
};
-/* Define functions operating on a vector of packets. */
-typedef struct btrace_pt_packet btrace_pt_packet_s;
-DEF_VEC_O (btrace_pt_packet_s);
#endif /* defined (HAVE_LIBIPT) */
/* Branch trace iteration state for "maintenance btrace packet-history". */
@@ -300,7 +297,7 @@ struct btrace_maint_info
struct
{
/* A vector of decoded packets. */
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet> *packets;
/* The packet history iterator.
We are iterating over the above PACKETS vector. */
diff --git a/gdb/gdbsupport/btrace-common.h b/gdb/gdbsupport/btrace-common.h
index 9c57645ffb1..166d7b18700 100644
--- a/gdb/gdbsupport/btrace-common.h
+++ b/gdb/gdbsupport/btrace-common.h
@@ -26,8 +26,6 @@
inferior. For presentation purposes, the branch trace is represented as a
list of sequential control-flow blocks, one such list per thread. */
-#include "vec.h"
-
/* A branch trace block.
This represents a block of sequential control-flow. Adjacent blocks will be
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread[parent not found: <cover.1569929785.git.andrew.burgess@embecosm.com>]
* RE: [PATCHv5 0/3] Remove some uses of VEC
[not found] ` <cover.1569929785.git.andrew.burgess@embecosm.com>
@ 2019-10-01 12:04 ` Metzger, Markus T
0 siblings, 0 replies; 35+ messages in thread
From: Metzger, Markus T @ 2019-10-01 12:04 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Simon Marchi, Tom Tromey
Hello Andrew,
> Andrew Burgess (3):
> gdb: Remove a VEC from gdbsupport/btrace-common.h
> gdb: Change a VEC to std::vector in btrace.{c,h}
> gdb: Remove a use of VEC from dwarf2read.{c,h}
>
> gdb/ChangeLog | 47 ++++++++++++++++++++
> gdb/btrace.c | 98 +++++++++++++++++++-----------------------
> gdb/btrace.h | 5 +--
> gdb/dwarf2read.c | 17 ++++----
> gdb/dwarf2read.h | 3 --
> gdb/gdbserver/ChangeLog | 5 +++
> gdb/gdbserver/linux-low.c | 8 +---
> gdb/gdbsupport/btrace-common.c | 18 ++++---- gdb/gdbsupport/btrace-
> common.h | 19 ++++----
> gdb/nat/linux-btrace.c | 16 +++----
> 10 files changed, 135 insertions(+), 101 deletions(-)
The btrace bits look good to me.
Thanks for your patches,
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
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCHv4 2/3] gdb: Change a VEC to std::vector in btrace.{c,h}
2019-09-26 0:00 ` [PATCHv3 0/3] Remove some uses of VEC Andrew Burgess
` (3 preceding siblings ...)
2019-09-26 11:41 ` [PATCHv4 0/3] Remove some uses of VEC Andrew Burgess
@ 2019-09-26 11:41 ` Andrew Burgess
4 siblings, 0 replies; 35+ messages in thread
From: Andrew Burgess @ 2019-09-26 11:41 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi, Tom Tromey, markus.t.metzger, Andrew Burgess
Replace a VEC with a std::vector in btrace.h, and update btrace.c to
match. This code is currently untested, so I've been quite
conservative with the changes - where previously we used VEC_safe_push
which would allocate the vector if it isn't already allocated - I now
check and allocate the std::vector using 'new' before pushing to the
vector.
As the new vector is inside a union I've currently used a pointer to
vector, which makes the code slightly uglier than it might otherwise
be, but again, due to lack of testing I'm reluctant to start
refactoring the code in a big way.
gdb/ChangeLog:
* btrace.c (btrace_maint_clear): Update to handle change from VEC
to std::vector.
(btrace_maint_decode_pt): Likewise, and move allocation of the
vector outside of the loop.
(btrace_maint_update_packets): Update to handle change from VEC to
std::vector.
(btrace_maint_print_packets): Likewise.
(maint_info_btrace_cmd): Likewise.
* btrace.h: Remove 'vec.h' header include and use of DEF_VEC_O.
(typedef btrace_pt_packet_s): Delete.
(struct btrace_maint_info) <packets>: Change fromm VEC to
std::vector.
---
gdb/ChangeLog | 15 +++++++++++++++
gdb/btrace.c | 40 +++++++++++++++++++++-------------------
gdb/btrace.h | 6 +-----
3 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 006cd740554..9fc95a35739 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1825,7 +1825,7 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- xfree (btinfo->maint.variant.pt.packets);
+ delete btinfo->maint.variant.pt.packets;
btinfo->maint.variant.pt.packets = NULL;
btinfo->maint.variant.pt.packet_history.begin = 0;
@@ -2962,6 +2962,9 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
{
int errcode;
+ if (maint->variant.pt.packets == NULL)
+ maint->variant.pt.packets = new std::vector <btrace_pt_packet>;
+
for (;;)
{
struct btrace_pt_packet packet;
@@ -2982,8 +2985,7 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
{
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ maint->variant.pt.packets->push_back (packet);
}
}
@@ -2991,8 +2993,7 @@ btrace_maint_decode_pt (struct btrace_maint_info *maint,
break;
packet.errcode = pt_errcode (errcode);
- VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
- &packet);
+ maint->variant.pt.packets->push_back (packet);
warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
packet.offset, pt_errstr (packet.errcode));
@@ -3093,11 +3094,14 @@ btrace_maint_update_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
- if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
+ if (btinfo->maint.variant.pt.packets == nullptr)
+ btinfo->maint.variant.pt.packets = new std::vector <btrace_pt_packet>;
+
+ if (btinfo->maint.variant.pt.packets->empty ())
btrace_maint_update_pt_packets (btinfo);
*begin = 0;
- *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
+ *end = btinfo->maint.variant.pt.packets->size ();
*from = btinfo->maint.variant.pt.packet_history.begin;
*to = btinfo->maint.variant.pt.packet_history.end;
break;
@@ -3140,23 +3144,21 @@ btrace_maint_print_packets (struct btrace_thread_info *btinfo,
#if defined (HAVE_LIBIPT)
case BTRACE_FORMAT_PT:
{
- VEC (btrace_pt_packet_s) *packets;
+ const std::vector <btrace_pt_packet> &packets
+ = *btinfo->maint.variant.pt.packets;
unsigned int pkt;
- packets = btinfo->maint.variant.pt.packets;
for (pkt = begin; pkt < end; ++pkt)
{
- const struct btrace_pt_packet *packet;
-
- packet = VEC_index (btrace_pt_packet_s, packets, pkt);
+ const struct btrace_pt_packet &packet = packets.at (pkt);
printf_unfiltered ("%u\t", pkt);
- printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
+ printf_unfiltered ("0x%" PRIx64 "\t", packet.offset);
- if (packet->errcode == pte_ok)
- pt_print_packet (&packet->packet);
+ if (packet.errcode == pte_ok)
+ pt_print_packet (&packet.packet);
else
- printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
+ printf_unfiltered ("[error: %s]", pt_errstr (packet.errcode));
printf_unfiltered ("\n");
}
@@ -3447,9 +3449,9 @@ maint_info_btrace_cmd (const char *args, int from_tty)
version.ext != NULL ? version.ext : "");
btrace_maint_update_pt_packets (btinfo);
- printf_unfiltered (_("Number of packets: %u.\n"),
- VEC_length (btrace_pt_packet_s,
- btinfo->maint.variant.pt.packets));
+ printf_unfiltered (_("Number of packets: %zu.\n"),
+ ((btinfo->maint.variant.pt.packets == nullptr)
+ ? 0 : btinfo->maint.variant.pt.packets->size ()));
}
break;
#endif /* defined (HAVE_LIBIPT) */
diff --git a/gdb/btrace.h b/gdb/btrace.h
index d09c424804b..208c089fa7c 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -29,7 +29,6 @@
#include "gdbsupport/btrace-common.h"
#include "target/waitstatus.h" /* For enum target_stop_reason. */
#include "gdbsupport/enum-flags.h"
-#include "gdbsupport/vec.h"
#if defined (HAVE_LIBIPT)
# include <intel-pt.h>
@@ -265,9 +264,6 @@ struct btrace_pt_packet
struct pt_packet packet;
};
-/* Define functions operating on a vector of packets. */
-typedef struct btrace_pt_packet btrace_pt_packet_s;
-DEF_VEC_O (btrace_pt_packet_s);
#endif /* defined (HAVE_LIBIPT) */
/* Branch trace iteration state for "maintenance btrace packet-history". */
@@ -301,7 +297,7 @@ struct btrace_maint_info
struct
{
/* A vector of decoded packets. */
- VEC (btrace_pt_packet_s) *packets;
+ std::vector <btrace_pt_packet> *packets;
/* The packet history iterator.
We are iterating over the above PACKETS vector. */
--
2.14.5
^ permalink raw reply [flat|nested] 35+ messages in thread