[gnome-builder/wip/chergert/debugger: 73/134] mi2: add breakpoint abstraction



commit b1057e693c2e3debf8019d7f67bba587b28eed14
Author: Christian Hergert <chergert redhat com>
Date:   Thu Mar 23 21:47:06 2017 -0700

    mi2: add breakpoint abstraction

 contrib/mi2/Makefile.am      |    2 +
 contrib/mi2/mi2-breakpoint.c |  329 ++++++++++++++++++++++++++++++++++++++++++
 contrib/mi2/mi2-breakpoint.h |   52 +++++++
 3 files changed, 383 insertions(+), 0 deletions(-)
---
diff --git a/contrib/mi2/Makefile.am b/contrib/mi2/Makefile.am
index c7e3b3b..ea739c5 100644
--- a/contrib/mi2/Makefile.am
+++ b/contrib/mi2/Makefile.am
@@ -9,6 +9,8 @@ pkglibdir = $(libdir)/gnome-builder
 pkglib_LTLIBRARIES = libmi2-glib.la
 
 libmi2_glib_la_public_sources =          \
+       mi2-breakpoint.c                 \
+       mi2-breakpoint.h                 \
        mi2-client.c                     \
        mi2-client.h                     \
        mi2-command-message.c            \
diff --git a/contrib/mi2/mi2-breakpoint.c b/contrib/mi2/mi2-breakpoint.c
new file mode 100644
index 0000000..8a5554e
--- /dev/null
+++ b/contrib/mi2/mi2-breakpoint.c
@@ -0,0 +1,329 @@
+/* mi2-breakpoint.c
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "mi2-breakpoint"
+
+#include "mi2-breakpoint.h"
+
+struct _Mi2Breakpoint
+{
+  GObject  parent_instance;
+  gchar   *address;
+  gchar   *linespec;
+  gchar   *filename;
+  gchar   *function;
+  gint     line_offset;
+  gint     id;
+};
+
+enum {
+  PROP_0,
+  PROP_ADDRESS,
+  PROP_FILENAME,
+  PROP_FUNCTION,
+  PROP_ID,
+  PROP_LINE_OFFSET,
+  PROP_LINESPEC,
+  N_PROPS
+};
+
+G_DEFINE_TYPE (Mi2Breakpoint, mi2_breakpoint, G_TYPE_OBJECT)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+mi2_breakpoint_finalize (GObject *object)
+{
+  Mi2Breakpoint *self = (Mi2Breakpoint *)object;
+
+  g_clear_pointer (&self->address, g_free);
+  g_clear_pointer (&self->filename, g_free);
+  g_clear_pointer (&self->function, g_free);
+  g_clear_pointer (&self->linespec, g_free);
+
+  G_OBJECT_CLASS (mi2_breakpoint_parent_class)->finalize (object);
+}
+
+static void
+mi2_breakpoint_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  Mi2Breakpoint *self = MI2_BREAKPOINT (object);
+
+  switch (prop_id)
+    {
+    case PROP_ADDRESS:
+      g_value_set_string (value, mi2_breakpoint_get_address (self));
+      break;
+
+    case PROP_ID:
+      g_value_set_int (value, mi2_breakpoint_get_id (self));
+      break;
+
+    case PROP_FILENAME:
+      g_value_set_string (value, mi2_breakpoint_get_filename (self));
+      break;
+
+    case PROP_FUNCTION:
+      g_value_set_string (value, mi2_breakpoint_get_function (self));
+      break;
+
+    case PROP_LINESPEC:
+      g_value_set_string (value, mi2_breakpoint_get_linespec (self));
+      break;
+
+    case PROP_LINE_OFFSET:
+      g_value_set_int (value, mi2_breakpoint_get_line_offset (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+mi2_breakpoint_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+  Mi2Breakpoint *self = MI2_BREAKPOINT (object);
+
+  switch (prop_id)
+    {
+    case PROP_ADDRESS:
+      mi2_breakpoint_set_address (self, g_value_get_string (value));
+      break;
+
+    case PROP_ID:
+      mi2_breakpoint_set_id (self, g_value_get_int (value));
+      break;
+
+    case PROP_FILENAME:
+      mi2_breakpoint_set_filename (self, g_value_get_string (value));
+      break;
+
+    case PROP_FUNCTION:
+      mi2_breakpoint_set_function (self, g_value_get_string (value));
+      break;
+
+    case PROP_LINESPEC:
+      mi2_breakpoint_set_linespec (self, g_value_get_string (value));
+      break;
+
+    case PROP_LINE_OFFSET:
+      mi2_breakpoint_set_line_offset (self, g_value_get_int (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+mi2_breakpoint_class_init (Mi2BreakpointClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = mi2_breakpoint_finalize;
+  object_class->get_property = mi2_breakpoint_get_property;
+  object_class->set_property = mi2_breakpoint_set_property;
+
+  properties [PROP_ID] =
+    g_param_spec_int ("id",
+                      "Id",
+                      "Id",
+                      0, G_MAXINT, 0,
+                      (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_ADDRESS] =
+    g_param_spec_string ("address",
+                         "Address",
+                         "Address",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_FILENAME] =
+    g_param_spec_string ("filename",
+                         "Filename",
+                         "Filename",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_FUNCTION] =
+    g_param_spec_string ("function",
+                         "Function",
+                         "Function",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_LINESPEC] =
+    g_param_spec_string ("linespec",
+                         "Linespec",
+                         "Linespec",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_LINE_OFFSET] =
+    g_param_spec_int ("line-offset",
+                      "Line Offset",
+                      "The relative offset from the function or from the file",
+                      G_MININT, G_MAXINT, 0,
+                      (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+mi2_breakpoint_init (Mi2Breakpoint *self)
+{
+}
+
+gint
+mi2_breakpoint_get_id (Mi2Breakpoint *self)
+{
+  g_return_val_if_fail (MI2_IS_BREAKPOINT (self), 0);
+
+  return self->id;
+}
+
+void
+mi2_breakpoint_set_id (Mi2Breakpoint *self,
+                       gint           id)
+{
+  g_return_if_fail (MI2_IS_BREAKPOINT (self));
+  g_return_if_fail (id >= 0);
+
+  if (id != self->id)
+    {
+      self->id = id;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ID]);
+    }
+}
+
+gint
+mi2_breakpoint_get_line_offset (Mi2Breakpoint *self)
+{
+  g_return_val_if_fail (MI2_IS_BREAKPOINT (self), 0);
+
+  return self->line_offset;
+}
+
+void
+mi2_breakpoint_set_line_offset (Mi2Breakpoint *self,
+                                gint           line_offset)
+{
+  g_return_if_fail (MI2_IS_BREAKPOINT (self));
+  g_return_if_fail (line_offset >= 0);
+
+  if (line_offset != self->line_offset)
+    {
+      self->line_offset = line_offset;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LINE_OFFSET]);
+    }
+}
+
+const gchar *
+mi2_breakpoint_get_filename (Mi2Breakpoint *self)
+{
+  g_return_val_if_fail (MI2_IS_BREAKPOINT (self), NULL);
+
+  return self->filename;
+}
+
+void
+mi2_breakpoint_set_filename (Mi2Breakpoint *self,
+                             const gchar   *filename)
+{
+  g_return_if_fail (MI2_IS_BREAKPOINT (self));
+
+  if (g_strcmp0 (self->filename, filename) != 0)
+    {
+      g_free (self->filename);
+      self->filename = g_strdup (filename);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FILENAME]);
+    }
+}
+
+const gchar *
+mi2_breakpoint_get_function (Mi2Breakpoint *self)
+{
+  g_return_val_if_fail (MI2_IS_BREAKPOINT (self), NULL);
+
+  return self->function;
+}
+
+void
+mi2_breakpoint_set_function (Mi2Breakpoint *self,
+                             const gchar   *function)
+{
+  if (g_strcmp0 (self->function, function) != 0)
+    {
+      g_free (self->function);
+      self->function = g_strdup (function);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FUNCTION]);
+    }
+}
+
+const gchar *
+mi2_breakpoint_get_linespec (Mi2Breakpoint *self)
+{
+  g_return_val_if_fail (MI2_IS_BREAKPOINT (self), NULL);
+
+  return self->linespec;
+}
+
+void
+mi2_breakpoint_set_linespec (Mi2Breakpoint *self,
+                             const gchar   *linespec)
+{
+  if (g_strcmp0 (self->linespec, linespec) != 0)
+    {
+      g_free (self->linespec);
+      self->linespec = g_strdup (linespec);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_LINESPEC]);
+    }
+}
+
+const gchar *
+mi2_breakpoint_get_address (Mi2Breakpoint *self)
+{
+  g_return_val_if_fail (MI2_IS_BREAKPOINT (self), NULL);
+
+  return self->address;
+}
+
+void
+mi2_breakpoint_set_address (Mi2Breakpoint *self,
+                            const gchar   *address)
+{
+  if (g_strcmp0 (self->address, address) != 0)
+    {
+      g_free (self->address);
+      self->address = g_strdup (address);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ADDRESS]);
+    }
+}
+
+Mi2Breakpoint *
+mi2_breakpoint_new (void)
+{
+  return g_object_new (MI2_TYPE_BREAKPOINT, NULL);
+}
diff --git a/contrib/mi2/mi2-breakpoint.h b/contrib/mi2/mi2-breakpoint.h
new file mode 100644
index 0000000..969b03f
--- /dev/null
+++ b/contrib/mi2/mi2-breakpoint.h
@@ -0,0 +1,52 @@
+/* mi2-breakpoint.h
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MI2_BREAKPOINT_H
+#define MI2_BREAKPOINT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MI2_TYPE_BREAKPOINT (mi2_breakpoint_get_type())
+
+G_DECLARE_FINAL_TYPE (Mi2Breakpoint, mi2_breakpoint, MI2, BREAKPOINT, GObject)
+
+Mi2Breakpoint *mi2_breakpoint_new             (void);
+gint           mi2_breakpoint_get_id          (Mi2Breakpoint *self);
+void           mi2_breakpoint_set_id          (Mi2Breakpoint *self,
+                                               gint           id);
+gint           mi2_breakpoint_get_line_offset (Mi2Breakpoint *self);
+void           mi2_breakpoint_set_line_offset (Mi2Breakpoint *self,
+                                               gint           line_offset);
+const gchar   *mi2_breakpoint_get_address     (Mi2Breakpoint *self);
+void           mi2_breakpoint_set_address     (Mi2Breakpoint *self,
+                                               const gchar   *address);
+const gchar   *mi2_breakpoint_get_linespec    (Mi2Breakpoint *self);
+void           mi2_breakpoint_set_linespec    (Mi2Breakpoint *self,
+                                               const gchar   *linespec);
+const gchar   *mi2_breakpoint_get_filename    (Mi2Breakpoint *self);
+void           mi2_breakpoint_set_filename    (Mi2Breakpoint *self,
+                                               const gchar   *filename);
+const gchar   *mi2_breakpoint_get_function    (Mi2Breakpoint *self);
+void           mi2_breakpoint_set_function    (Mi2Breakpoint *self,
+                                               const gchar   *function);
+
+G_END_DECLS
+
+#endif /* MI2_BREAKPOINT_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]