aboutsummaryrefslogtreecommitdiff
path: root/gdb/btrace.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-06-07 15:34:36 -0600
committerTom Tromey <tom@tromey.com>2018-06-08 07:05:49 -0600
commit8dcc53b37f4fe4797825c2a43bb1fb3df56b30d1 (patch)
treeaf3cd396cb7b198f651eb45986be87911a01c35b /gdb/btrace.c
parentcb36699271e2f3308b6f1aa40086950111308020 (diff)
downloadgdb-8dcc53b37f4fe4797825c2a43bb1fb3df56b30d1.zip
gdb-8dcc53b37f4fe4797825c2a43bb1fb3df56b30d1.tar.gz
gdb-8dcc53b37f4fe4797825c2a43bb1fb3df56b30d1.tar.bz2
Remove cleanups from btrace code
This removes some cleanups from the btrace code by minorly C++-ifying struct btrace_data. gdb/ChangeLog 2018-06-08 Tom Tromey <tom@tromey.com> * common/btrace-common.h (struct btrace_data): Add constructor, destructor, move assignment operator. <empty, clear, fini>: New methods. <format>: Initialize. (btrace_data_init, btrace_data_fini, btrace_data_clear) (btrace_data_empty): Don't declare. * common/btrace-common.c (btrace_data_init): Remove. (btrace_data::fini): Rename from btrace_data_fini. (btrace_data::empty): Rename from btrace_data_empty. (btrace_data::clear): Rename from btrace_data_clear. Return bool. * btrace.h (make_cleanup_btrace_data): Don't declare. * btrace.c (btrace_add_pc, btrace_stitch_trace, btrace_clear) (parse_xml_btrace): Update. (do_btrace_data_cleanup, make_cleanup_btrace_data): Remove. (maint_btrace_clear_packet_history_cmd): Update. gdb/gdbserver/ChangeLog 2018-06-08 Tom Tromey <tom@tromey.com> * linux-low.c (linux_low_read_btrace): Update.
Diffstat (limited to 'gdb/btrace.c')
-rw-r--r--gdb/btrace.c47
1 files changed, 9 insertions, 38 deletions
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 269ee51..6907705 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1565,25 +1565,19 @@ btrace_add_pc (struct thread_info *tp)
struct btrace_data btrace;
struct btrace_block *block;
struct regcache *regcache;
- struct cleanup *cleanup;
CORE_ADDR pc;
regcache = get_thread_regcache (tp->ptid);
pc = regcache_read_pc (regcache);
- btrace_data_init (&btrace);
btrace.format = BTRACE_FORMAT_BTS;
btrace.variant.bts.blocks = NULL;
- cleanup = make_cleanup_btrace_data (&btrace);
-
block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
block->begin = pc;
block->end = pc;
btrace_compute_ftrace (tp, &btrace, NULL);
-
- do_cleanups (cleanup);
}
/* See btrace.h. */
@@ -1777,7 +1771,7 @@ static int
btrace_stitch_trace (struct btrace_data *btrace, struct thread_info *tp)
{
/* If we don't have trace, there's nothing to do. */
- if (btrace_data_empty (btrace))
+ if (btrace->empty ())
return 0;
switch (btrace->format)
@@ -1894,7 +1888,6 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu)
struct btrace_thread_info *btinfo;
struct btrace_target_info *tinfo;
struct btrace_data btrace;
- struct cleanup *cleanup;
int errcode;
DEBUG ("fetch thread %s (%s)", print_thread_id (tp),
@@ -1920,9 +1913,6 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu)
/* We should not be called on running or exited threads. */
gdb_assert (can_access_registers_ptid (tp->ptid));
- btrace_data_init (&btrace);
- cleanup = make_cleanup_btrace_data (&btrace);
-
/* Let's first try to extend the trace we already have. */
if (!btinfo->functions.empty ())
{
@@ -1938,7 +1928,7 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu)
errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_NEW);
/* If we got any new trace, discard what we have. */
- if (errcode == 0 && !btrace_data_empty (&btrace))
+ if (errcode == 0 && !btrace.empty ())
btrace_clear (tp);
}
@@ -1957,7 +1947,7 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu)
error (_("Failed to read branch trace."));
/* Compute the trace, provided we have any. */
- if (!btrace_data_empty (&btrace))
+ if (!btrace.empty ())
{
/* Store the raw trace data. The stored data will be cleared in
btrace_clear, so we always append the new trace. */
@@ -1967,8 +1957,6 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu)
btrace_clear_history (btinfo);
btrace_compute_ftrace (tp, &btrace, cpu);
}
-
- do_cleanups (cleanup);
}
/* See btrace.h. */
@@ -1992,7 +1980,7 @@ btrace_clear (struct thread_info *tp)
/* Must clear the maint data before - it depends on BTINFO->DATA. */
btrace_maint_clear (btinfo);
- btrace_data_clear (&btinfo->data);
+ btinfo->data.clear ();
btrace_clear_history (btinfo);
}
@@ -2217,21 +2205,20 @@ static const struct gdb_xml_element btrace_elements[] = {
void
parse_xml_btrace (struct btrace_data *btrace, const char *buffer)
{
- struct cleanup *cleanup;
int errcode;
#if defined (HAVE_LIBEXPAT)
- btrace->format = BTRACE_FORMAT_NONE;
+ btrace_data result;
+ result.format = BTRACE_FORMAT_NONE;
- cleanup = make_cleanup_btrace_data (btrace);
errcode = gdb_xml_parse_quick (_("btrace"), "btrace.dtd", btrace_elements,
- buffer, btrace);
+ buffer, &result);
if (errcode != 0)
error (_("Error parsing branch trace."));
/* Keep parse results. */
- discard_cleanups (cleanup);
+ *btrace = std::move (result);
#else /* !defined (HAVE_LIBEXPAT) */
@@ -2844,22 +2831,6 @@ btrace_is_empty (struct thread_info *tp)
return btrace_insn_cmp (&begin, &end) == 0;
}
-/* Forward the cleanup request. */
-
-static void
-do_btrace_data_cleanup (void *arg)
-{
- btrace_data_fini ((struct btrace_data *) arg);
-}
-
-/* See btrace.h. */
-
-struct cleanup *
-make_cleanup_btrace_data (struct btrace_data *data)
-{
- return make_cleanup (do_btrace_data_cleanup, data);
-}
-
#if defined (HAVE_LIBIPT)
/* Print a single packet. */
@@ -3381,7 +3352,7 @@ maint_btrace_clear_packet_history_cmd (const char *args, int from_tty)
/* Must clear the maint data before - it depends on BTINFO->DATA. */
btrace_maint_clear (btinfo);
- btrace_data_clear (&btinfo->data);
+ btinfo->data.clear ();
}
/* The "maintenance btrace clear" command. */