+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.
+
2018-06-07 Pedro Alves <palves@redhat.com>
* target.h (target_ops) <beneath>: Now a method. All references
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. */
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)
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),
/* 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 ())
{
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);
}
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. */
btrace_clear_history (btinfo);
btrace_compute_ftrace (tp, &btrace, cpu);
}
-
- do_cleanups (cleanup);
}
/* See btrace.h. */
/* 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);
}
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) */
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. */
/* 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. */
/* Return non-zero if the branch trace for TP is empty; zero otherwise. */
extern int btrace_is_empty (struct thread_info *tp);
-/* Create a cleanup for DATA. */
-extern struct cleanup *make_cleanup_btrace_data (struct btrace_data *data);
-
#endif /* BTRACE_H */
/* See btrace-common.h. */
void
-btrace_data_init (struct btrace_data *data)
+btrace_data::fini ()
{
- data->format = BTRACE_FORMAT_NONE;
-}
-
-/* See btrace-common.h. */
-
-void
-btrace_data_fini (struct btrace_data *data)
-{
- switch (data->format)
+ switch (format)
{
case BTRACE_FORMAT_NONE:
/* Nothing to do. */
return;
case BTRACE_FORMAT_BTS:
- VEC_free (btrace_block_s, data->variant.bts.blocks);
+ VEC_free (btrace_block_s, variant.bts.blocks);
return;
case BTRACE_FORMAT_PT:
- xfree (data->variant.pt.data);
+ xfree (variant.pt.data);
return;
}
/* See btrace-common.h. */
-int
-btrace_data_empty (struct btrace_data *data)
+bool
+btrace_data::empty () const
{
- switch (data->format)
+ switch (format)
{
case BTRACE_FORMAT_NONE:
- return 1;
+ return true;
case BTRACE_FORMAT_BTS:
- return VEC_empty (btrace_block_s, data->variant.bts.blocks);
+ return VEC_empty (btrace_block_s, variant.bts.blocks);
case BTRACE_FORMAT_PT:
- return (data->variant.pt.size == 0);
+ return (variant.pt.size == 0);
}
internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
/* See btrace-common.h. */
void
-btrace_data_clear (struct btrace_data *data)
+btrace_data::clear ()
{
- btrace_data_fini (data);
- btrace_data_init (data);
+ fini ();
+ format = BTRACE_FORMAT_NONE;
}
/* See btrace-common.h. */
/* The branch trace data. */
struct btrace_data
{
- enum btrace_format format;
+ btrace_data () = default;
+
+ ~btrace_data ()
+ {
+ fini ();
+ }
+
+ btrace_data &operator= (btrace_data &&other)
+ {
+ if (this != &other)
+ {
+ fini ();
+ format = other.format;
+ variant = other.variant;
+ other.format = BTRACE_FORMAT_NONE;
+ }
+ return *this;
+ }
+
+ /* Return true if this is empty; false otherwise. */
+ bool empty () const;
+
+ /* Clear this object. */
+ void clear ();
+
+ enum btrace_format format = BTRACE_FORMAT_NONE;
union
{
/* Format == BTRACE_FORMAT_PT. */
struct btrace_data_pt pt;
} variant;
+
+private:
+
+ DISABLE_COPY_AND_ASSIGN (btrace_data);
+
+ void fini ();
};
/* Target specific branch trace information. */
/* Return an abbreviation string representation of FORMAT. */
extern const char *btrace_format_short_string (enum btrace_format format);
-/* Initialize DATA. */
-extern void btrace_data_init (struct btrace_data *data);
-
-/* Cleanup DATA. */
-extern void btrace_data_fini (struct btrace_data *data);
-
-/* Clear DATA. */
-extern void btrace_data_clear (struct btrace_data *data);
-
-/* Return non-zero if DATA is empty; zero otherwise. */
-extern int btrace_data_empty (struct btrace_data *data);
-
/* Append the branch trace data from SRC to the end of DST.
Both SRC and DST must use the same format.
Returns zero on success; a negative number otherwise. */
+2018-06-08 Tom Tromey <tom@tromey.com>
+
+ * linux-low.c (linux_low_read_btrace): Update.
+
2018-06-04 Stan Cox <scox@redhat.com>
* server.h (struct client_state): New.
enum btrace_error err;
int i;
- btrace_data_init (&btrace);
-
err = linux_read_btrace (&btrace, tinfo, type);
if (err != BTRACE_ERR_NONE)
{
else
buffer_grow_str0 (buffer, "E.Generic Error.");
- goto err;
+ return -1;
}
switch (btrace.format)
{
case BTRACE_FORMAT_NONE:
buffer_grow_str0 (buffer, "E.No Trace.");
- goto err;
+ return -1;
case BTRACE_FORMAT_BTS:
buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
default:
buffer_grow_str0 (buffer, "E.Unsupported Trace Format.");
- goto err;
+ return -1;
}
- btrace_data_fini (&btrace);
return 0;
-
-err:
- btrace_data_fini (&btrace);
- return -1;
}
/* See to_btrace_conf target method. */