diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2018-03-22 00:27:19 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-03-22 00:27:19 -0400 |
commit | 5d9310c4b88f807c1a3f1a0b4d7b6c10925dcaf7 (patch) | |
tree | b78fb98efc2bdab7fd374e0098bf8b7a426f0d4c /gdb/tracepoint.c | |
parent | 62c222b6d9fcce8adf65f48fca2e528f777afeeb (diff) | |
download | gdb-5d9310c4b88f807c1a3f1a0b4d7b6c10925dcaf7.zip gdb-5d9310c4b88f807c1a3f1a0b4d7b6c10925dcaf7.tar.gz gdb-5d9310c4b88f807c1a3f1a0b4d7b6c10925dcaf7.tar.bz2 |
Get rid of VEC(static_tracepoint_marker_p)
This patch replaces VEC(static_tracepoint_marker_p) with std::vector,
and does some c++ification around that. I thought a new overload of
hex2str was useful, so I added it as well as corresponding unit tests.
I also added an overload of ui_out::field_string that takes an
std::string directly.
gdb/ChangeLog:
* tracepoint.h (struct static_tracepoint_marker): Initialize
fields, define default constructor, move constructor and move
assignment, disable the rest.
<str_id, extra>: Make std::string.
(release_static_tracepoint_marker): Remove.
(free_current_marker): Remove.
* tracepoint.c (free_current_marker): Remove.
(parse_static_tracepoint_marker_definition): Adjust to
std::string, use new hex2str overload.
(release_static_tracepoint_marker): Remove.
(print_one_static_tracepoint_marker): Get marker by reference
and adjust to std::string.
(info_static_tracepoint_markers_command): Adjust to std::vector
changes
* target.h (static_tracepoint_marker_p): Remove typedef.
(DEF_VEC_P(static_tracepoint_marker_p)): Remove.
(struct target_ops) <to_static_tracepoint_marker_at>: Return
bool.
<to_static_tracepoint_markers_by_strid>: Return std::vector.
* target-debug.h
(target_debug_print_VEC_static_tracepoint_marker_p_p): Remove.
(target_debug_print_std_vector_static_tracepoint_marker): New.
(target_debug_print_struct_static_tracepoint_marker_p): Rename
to...
(target_debug_print_static_tracepoint_marker_p): ... this.
* target-delegates.c: Re-generate.
* breakpoint.h (struct tracepoint) <static_trace_marker_id>:
Make std::string.
* breakpoint.c (init_breakpoint_sal): Adjust to std::string.
(decode_static_tracepoint_spec): Adjust to std::vector.
(tracepoint_print_one_detail): Adjust to std::string.
(strace_marker_decode_location): Adjust to std::string.
(update_static_tracepoint): Adjust to std::string, remove call
to release_static_tracepoint_marker.
* linux-nat.c (linux_child_static_tracepoint_markers_by_strid):
Adjust to std::vector.
* remote.c (remote_static_tracepoint_marker_at): Return bool.
(remote_static_tracepoint_markers_by_strid): Adjust to
std::vector.
* common/rsp-low.h (hex2str): New overload with explicit count
of bytes.
* common/rsp-low.c (hex2str): New overload with explicit count
of bytes.
* unittests/rsp-low-selftests.c (test_hex2str): New function.
(_initialize_rsp_low_selftests): Add test_hex2str test.
* unittests/tracepoint-selftests.c
(test_parse_static_tracepoint_marker_definition): Adjust to
std::string.
Diffstat (limited to 'gdb/tracepoint.c')
-rw-r--r-- | gdb/tracepoint.c | 82 |
1 files changed, 19 insertions, 63 deletions
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 8e779bc..965c236 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -3674,21 +3674,6 @@ parse_tsv_definition (const char *line, struct uploaded_tsv **utsvp) utsv->name = xstrdup (buf); } -void -free_current_marker (void *arg) -{ - struct static_tracepoint_marker **marker_p - = (struct static_tracepoint_marker **) arg; - - if (*marker_p != NULL) - { - release_static_tracepoint_marker (*marker_p); - xfree (*marker_p); - } - else - *marker_p = NULL; -} - /* Given a line of text defining a static tracepoint marker, parse it into a "static tracepoint marker" object. Throws an error is parsing fails. If PP is non-null, it points to one past the end of @@ -3696,11 +3681,10 @@ free_current_marker (void *arg) void parse_static_tracepoint_marker_definition (const char *line, const char **pp, - struct static_tracepoint_marker *marker) + static_tracepoint_marker *marker) { const char *p, *endp; ULONGEST addr; - int end; p = line; p = unpack_varlen_hex (p, &addr); @@ -3713,12 +3697,10 @@ parse_static_tracepoint_marker_definition (const char *line, const char **pp, if (endp == NULL) error (_("bad marker definition: %s"), line); - marker->str_id = (char *) xmalloc (endp - p + 1); - end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2); - marker->str_id[end] = '\0'; + marker->str_id = hex2str (p, (endp - p) / 2); - p += 2 * end; - p++; /* skip a colon */ + p = endp; + p++; /* skip a colon */ /* This definition may be followed by another one, separated by a comma. */ int hex_len; @@ -3728,30 +3710,17 @@ parse_static_tracepoint_marker_definition (const char *line, const char **pp, else hex_len = strlen (p); - marker->extra = (char *) xmalloc (hex_len / 2 + 1); - end = hex2bin (p, (gdb_byte *) marker->extra, hex_len / 2); - marker->extra[end] = '\0'; + marker->extra = hex2str (p, hex_len / 2); - if (pp) + if (pp != nullptr) *pp = p + hex_len; } -/* Release a static tracepoint marker's contents. Note that the - object itself isn't released here. There objects are usually on - the stack. */ - -void -release_static_tracepoint_marker (struct static_tracepoint_marker *marker) -{ - xfree (marker->str_id); - marker->str_id = NULL; -} - /* Print MARKER to gdb_stdout. */ static void print_one_static_tracepoint_marker (int count, - struct static_tracepoint_marker *marker) + const static_tracepoint_marker &marker) { struct symbol *sym; @@ -3761,9 +3730,9 @@ print_one_static_tracepoint_marker (int count, VEC(breakpoint_p) *tracepoints; symtab_and_line sal; - sal.pc = marker->address; + sal.pc = marker.address; - tracepoints = static_tracepoints_here (marker->address); + tracepoints = static_tracepoints_here (marker.address); ui_out_emit_tuple tuple_emitter (uiout, "marker"); @@ -3771,7 +3740,7 @@ print_one_static_tracepoint_marker (int count, identifier! */ uiout->field_int ("count", count); - uiout->field_string ("marker-id", marker->str_id); + uiout->field_string ("marker-id", marker.str_id.c_str ()); uiout->field_fmt ("enabled", "%c", !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n'); @@ -3779,17 +3748,17 @@ print_one_static_tracepoint_marker (int count, strcpy (wrap_indent, " "); - if (gdbarch_addr_bit (marker->gdbarch) <= 32) + if (gdbarch_addr_bit (marker.gdbarch) <= 32) strcat (wrap_indent, " "); else strcat (wrap_indent, " "); strcpy (extra_field_indent, " "); - uiout->field_core_addr ("addr", marker->gdbarch, marker->address); + uiout->field_core_addr ("addr", marker.gdbarch, marker.address); - sal = find_pc_line (marker->address, 0); - sym = find_pc_sect_function (marker->address, NULL); + sal = find_pc_line (marker.address, 0); + sym = find_pc_sect_function (marker.address, NULL); if (sym) { uiout->text ("in "); @@ -3827,7 +3796,7 @@ print_one_static_tracepoint_marker (int count, uiout->text ("\n"); uiout->text (extra_field_indent); uiout->text (_("Data: \"")); - uiout->field_string ("extra-data", marker->extra); + uiout->field_string ("extra-data", marker.extra.c_str ()); uiout->text ("\"\n"); if (!VEC_empty (breakpoint_p, tracepoints)) @@ -3861,11 +3830,9 @@ print_one_static_tracepoint_marker (int count, static void info_static_tracepoint_markers_command (const char *arg, int from_tty) { - VEC(static_tracepoint_marker_p) *markers; - struct cleanup *old_chain; - struct static_tracepoint_marker *marker; struct ui_out *uiout = current_uiout; - int i; + std::vector<static_tracepoint_marker> markers + = target_static_tracepoint_markers_by_strid (NULL); /* We don't have to check target_can_use_agent and agent's capability on static tracepoint here, in order to be compatible with older GDBserver. @@ -3889,19 +3856,8 @@ info_static_tracepoint_markers_command (const char *arg, int from_tty) uiout->table_body (); - markers = target_static_tracepoint_markers_by_strid (NULL); - old_chain = make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers); - - for (i = 0; - VEC_iterate (static_tracepoint_marker_p, - markers, i, marker); - i++) - { - print_one_static_tracepoint_marker (i + 1, marker); - release_static_tracepoint_marker (marker); - } - - do_cleanups (old_chain); + for (int i = 0; i < markers.size (); i++) + print_one_static_tracepoint_marker (i + 1, markers[i]); } /* The $_sdata convenience variable is a bit special. We don't know |