aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
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/common
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/common')
-rw-r--r--gdb/common/btrace-common.c34
-rw-r--r--gdb/common/btrace-common.h45
2 files changed, 45 insertions, 34 deletions
diff --git a/gdb/common/btrace-common.c b/gdb/common/btrace-common.c
index 6cbbdc1..ec0ba6a 100644
--- a/gdb/common/btrace-common.c
+++ b/gdb/common/btrace-common.c
@@ -64,28 +64,20 @@ btrace_format_short_string (enum btrace_format format)
/* 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;
}
@@ -94,19 +86,19 @@ btrace_data_fini (struct btrace_data *data)
/* 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."));
@@ -115,10 +107,10 @@ btrace_data_empty (struct btrace_data *data)
/* 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. */
diff --git a/gdb/common/btrace-common.h b/gdb/common/btrace-common.h
index 80e9fc6..debf833 100644
--- a/gdb/common/btrace-common.h
+++ b/gdb/common/btrace-common.h
@@ -164,7 +164,32 @@ struct btrace_data_pt
/* 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
{
@@ -174,6 +199,12 @@ struct btrace_data
/* Format == BTRACE_FORMAT_PT. */
struct btrace_data_pt pt;
} variant;
+
+private:
+
+ DISABLE_COPY_AND_ASSIGN (btrace_data);
+
+ void fini ();
};
/* Target specific branch trace information. */
@@ -217,18 +248,6 @@ extern const char *btrace_format_string (enum btrace_format format);
/* 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. */