This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Use std::vector for traceframe_info::tvars
- From: Simon Marchi <simark at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 14 Oct 2017 12:52:27 -0000
- Subject: [binutils-gdb] Use std::vector for traceframe_info::tvars
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d0d292a27402ee2d3f91d541371f134f91730373
commit d0d292a27402ee2d3f91d541371f134f91730373
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date: Sat Oct 14 08:42:23 2017 -0400
Use std::vector for traceframe_info::tvars
Straightforward change to get rid of a VEC. We need to new/delete
traceframe_info instead of malloc/free it. I found three places that
allocate a traceframe_info (ctf_traceframe_info, tfile_traceframe_info
and parse_traceframe_info) and only one that frees it
(free_traceframe_info).
gdb/ChangeLog:
* tracepoint.h (struct traceframe_info) <tvars>: Change type to
std::vector<int>.
* tracepoint.c (free_traceframe_info): Deallocate with delete.
(traceframe_info_start_tvar): Adjust to vector change.
(parse_traceframe_info): Allocate with new.
* ctf.c (ctf_traceframe_info): Allocate with new, adjust to
vector change.
* tracefile-tfile.c (build_traceframe_info): Adjust to vector
change.
tfile_traceframe_info): Allocate with new.
* mi/mi-main.c (mi_cmd_trace_frame_collected): Adjust to vector
change.
Diff:
---
gdb/ChangeLog | 15 +++++++++++++++
gdb/ctf.c | 4 ++--
gdb/mi/mi-main.c | 5 +----
gdb/tracefile-tfile.c | 4 ++--
gdb/tracepoint.c | 8 +++-----
gdb/tracepoint.h | 4 ++--
6 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 773c828..51f37c3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,20 @@
2017-10-14 Simon Marchi <simon.marchi@polymtl.ca>
+ * tracepoint.h (struct traceframe_info) <tvars>: Change type to
+ std::vector<int>.
+ * tracepoint.c (free_traceframe_info): Deallocate with delete.
+ (traceframe_info_start_tvar): Adjust to vector change.
+ (parse_traceframe_info): Allocate with new.
+ * ctf.c (ctf_traceframe_info): Allocate with new, adjust to
+ vector change.
+ * tracefile-tfile.c (build_traceframe_info): Adjust to vector
+ change.
+ tfile_traceframe_info): Allocate with new.
+ * mi/mi-main.c (mi_cmd_trace_frame_collected): Adjust to vector
+ change.
+
+2017-10-14 Simon Marchi <simon.marchi@polymtl.ca>
+
* tracepoint.c (traceframe_info): Rename to...
(current_traceframe_info): ...this.
(clear_traceframe_info): Adjust.
diff --git a/gdb/ctf.c b/gdb/ctf.c
index d719163..183ee34 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -1638,7 +1638,7 @@ ctf_trace_find (struct target_ops *self, enum trace_find_type type, int num,
static struct traceframe_info *
ctf_traceframe_info (struct target_ops *self)
{
- struct traceframe_info *info = XCNEW (struct traceframe_info);
+ traceframe_info *info = new traceframe_info;
const char *name;
struct bt_iter_pos *pos;
@@ -1682,7 +1682,7 @@ ctf_traceframe_info (struct target_ops *self)
def = bt_ctf_get_field (event, scope, "num");
vnum = (int) bt_ctf_get_uint64 (def);
- VEC_safe_push (int, info->tvars, vnum);
+ info->tvars.push_back (vnum);
}
else
{
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 5057f94..a94e329 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2724,12 +2724,9 @@ mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
/* Trace state variables. */
{
- int tvar;
- int i;
-
ui_out_emit_list list_emitter (uiout, "tvars");
- for (i = 0; VEC_iterate (int, tinfo->tvars, i, tvar); i++)
+ for (int tvar : tinfo->tvars)
{
struct trace_state_variable *tsv;
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 7288e7c..0075581 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -1075,7 +1075,7 @@ build_traceframe_info (char blocktype, void *data)
int vnum;
tfile_read ((gdb_byte *) &vnum, 4);
- VEC_safe_push (int, info->tvars, vnum);
+ info->tvars.push_back (vnum);
}
case 'R':
case 'S':
@@ -1095,7 +1095,7 @@ build_traceframe_info (char blocktype, void *data)
static struct traceframe_info *
tfile_traceframe_info (struct target_ops *self)
{
- struct traceframe_info *info = XCNEW (struct traceframe_info);
+ traceframe_info *info = new traceframe_info;
traceframe_walk_blocks (build_traceframe_info, 0, info);
return info;
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index bbfc2ce..2605c0a 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -199,9 +199,8 @@ free_traceframe_info (struct traceframe_info *info)
if (info != NULL)
{
VEC_free (mem_range_s, info->memory);
- VEC_free (int, info->tvars);
- xfree (info);
+ delete info;
}
}
@@ -4025,7 +4024,7 @@ traceframe_info_start_tvar (struct gdb_xml_parser *parser,
= (const char *) xml_find_attribute (attributes, "id")->value;
int id = gdb_xml_parse_ulongest (parser, id_attrib);
- VEC_safe_push (int, info->tvars, id);
+ info->tvars.push_back (id);
}
/* Discard the constructed trace frame info (if an error occurs). */
@@ -4072,10 +4071,9 @@ static const struct gdb_xml_element traceframe_info_elements[] = {
struct traceframe_info *
parse_traceframe_info (const char *tframe_info)
{
- struct traceframe_info *result;
+ traceframe_info *result = new traceframe_info;
struct cleanup *back_to;
- result = XCNEW (struct traceframe_info);
back_to = make_cleanup (free_result, result);
if (gdb_xml_parse_quick (_("trace frame info"),
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index ffa645b..625415c 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -32,10 +32,10 @@
struct traceframe_info
{
/* Collected memory. */
- VEC(mem_range_s) *memory;
+ VEC(mem_range_s) *memory = NULL;
/* Collected trace state variables. */
- VEC(int) *tvars;
+ std::vector<int> tvars;
};
/* A trace state variable is a value managed by a target being