[gnome-builder/wip/chergert/bug1] debugger: start on disassembly view
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/bug1] debugger: start on disassembly view
- Date: Mon, 28 Aug 2017 23:19:04 +0000 (UTC)
commit 2a5b111f4c0474716827fbab69e69d56fc4056b5
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 28 16:18:49 2017 -0700
debugger: start on disassembly view
libide/debugger/ide-debugger-disassembly-view.c | 132 ++++++++++++++++++++++
libide/debugger/ide-debugger-disassembly-view.h | 37 ++++++
libide/debugger/ide-debugger-disassembly-view.ui | 24 ++++
libide/debugger/ide-debugger-perspective.c | 28 +++++-
libide/libide.gresource.xml | 1 +
libide/meson.build | 2 +
6 files changed, 222 insertions(+), 2 deletions(-)
---
diff --git a/libide/debugger/ide-debugger-disassembly-view.c b/libide/debugger/ide-debugger-disassembly-view.c
new file mode 100644
index 0000000..0efd3e4
--- /dev/null
+++ b/libide/debugger/ide-debugger-disassembly-view.c
@@ -0,0 +1,132 @@
+/* ide-debugger-disassembly-view.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 "ide-debugger-disassembly-view"
+
+#include <gtksourceview/gtksource.h>
+
+#include "debugger/ide-debugger-disassembly-view.h"
+#include "debugger/ide-debugger-instruction.h"
+
+struct _IdeDebuggerDisassemblyView
+{
+ IdeLayoutView parent_instance;
+
+ /* Owned references */
+ GPtrArray *instructions;
+
+ /* Template references */
+ GtkSourceView *source_view;
+ GtkSourceBuffer *source_buffer;
+
+ IdeDebuggerAddress current_address;
+};
+
+G_DEFINE_TYPE (IdeDebuggerDisassemblyView, ide_debugger_disassembly_view, IDE_TYPE_LAYOUT_VIEW)
+
+static void
+ide_debugger_disassembly_view_destroy (GtkWidget *widget)
+{
+ IdeDebuggerDisassemblyView *self = (IdeDebuggerDisassemblyView *)widget;
+
+ g_clear_pointer (&self->instructions, g_ptr_array_unref);
+
+ GTK_WIDGET_CLASS (ide_debugger_disassembly_view_parent_class)->destroy (widget);
+}
+
+static void
+ide_debugger_disassembly_view_class_init (IdeDebuggerDisassemblyViewClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ widget_class->destroy = ide_debugger_disassembly_view_destroy;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/builder/ui/ide-debugger-disassembly-view.ui");
+ gtk_widget_class_bind_template_child (widget_class, IdeDebuggerDisassemblyView, source_buffer);
+ gtk_widget_class_bind_template_child (widget_class, IdeDebuggerDisassemblyView, source_view);
+}
+
+static void
+ide_debugger_disassembly_view_init (IdeDebuggerDisassemblyView *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+void
+ide_debugger_disassembly_view_set_current_address (IdeDebuggerDisassemblyView *self,
+ IdeDebuggerAddress current_address)
+{
+ g_return_if_fail (IDE_IS_DEBUGGER_DISASSEMBLY_VIEW (self));
+
+ self->current_address = current_address;
+
+ /* Update gutter/etc */
+}
+
+/**
+ * ide_debugger_disassembly_view_set_instructions:
+ * @self: a #IdeDebuggerDisassemblyView
+ * @instructions: (nullable) (element-type Ide.DebuggerInstruction): An array of
+ * instructions or %NULL.
+ *
+ * Sets the instructions to display in the disassembly view.
+ *
+ * This will take a reference to @instructions if non-%NULL so it is
+ * important that you do not modify @instructions after calling this.
+ */
+void
+ide_debugger_disassembly_view_set_instructions (IdeDebuggerDisassemblyView *self,
+ GPtrArray *instructions)
+{
+ g_return_if_fail (IDE_IS_DEBUGGER_DISASSEMBLY_VIEW (self));
+
+ if (self->instructions == instructions)
+ return;
+
+ g_clear_pointer (&self->instructions, g_ptr_array_unref);
+ if (instructions != NULL)
+ self->instructions = g_ptr_array_ref (instructions);
+
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (self->source_buffer), "", 0);
+
+ if (self->instructions != NULL && self->instructions->len > 0)
+ {
+ IdeDebuggerAddress first;
+ GtkTextIter iter;
+ GtkTextIter trim;
+
+ first = ide_debugger_instruction_get_address (g_ptr_array_index (self->instructions, 0));
+
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (self->source_buffer), &iter);
+
+ for (guint i = 0; i < self->instructions->len; i++)
+ {
+ IdeDebuggerInstruction *inst = g_ptr_array_index (self->instructions, i);
+ g_autofree gchar *str = g_strdup_printf ("0x%"G_GINT64_MODIFIER"x <+%03"G_GINT64_MODIFIER"u>:
%s\n",
+ ide_debugger_instruction_get_address (inst),
+ ide_debugger_instruction_get_address (inst) - first,
+ ide_debugger_instruction_get_display (inst));
+ gtk_text_buffer_insert (GTK_TEXT_BUFFER (self->source_buffer), &iter, str, -1);
+ }
+
+ /* Trim the trailing \n */
+ trim = iter;
+ gtk_text_iter_backward_char (&iter);
+ gtk_text_buffer_delete (GTK_TEXT_BUFFER (self->source_buffer), &iter, &trim);
+ }
+}
diff --git a/libide/debugger/ide-debugger-disassembly-view.h b/libide/debugger/ide-debugger-disassembly-view.h
new file mode 100644
index 0000000..09d1488
--- /dev/null
+++ b/libide/debugger/ide-debugger-disassembly-view.h
@@ -0,0 +1,37 @@
+/* ide-debugger-disassembly-view.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/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "debugger/ide-debugger-types.h"
+#include "layout/ide-layout-view.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_DEBUGGER_DISASSEMBLY_VIEW (ide_debugger_disassembly_view_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeDebuggerDisassemblyView, ide_debugger_disassembly_view, IDE,
DEBUGGER_DISASSEMBLY_VIEW, IdeLayoutView)
+
+void ide_debugger_disassembly_view_set_current_address (IdeDebuggerDisassemblyView *self,
+ IdeDebuggerAddress address);
+void ide_debugger_disassembly_view_set_instructions (IdeDebuggerDisassemblyView *self,
+ GPtrArray *instructions);
+
+G_END_DECLS
diff --git a/libide/debugger/ide-debugger-disassembly-view.ui
b/libide/debugger/ide-debugger-disassembly-view.ui
new file mode 100644
index 0000000..f84cee0
--- /dev/null
+++ b/libide/debugger/ide-debugger-disassembly-view.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="IdeDebuggerDisassemblyView" parent="IdeLayoutView">
+ <property name="icon-name">application-x-executable-symbolic</property>
+ <property name="title" translatable="yes">Disassembly</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="expand">true</property>
+ <property name="visible">true</property>
+ <child>
+ <object class="GtkSourceView" id="source_view">
+ <property name="show-line-numbers">true</property>
+ <property name="editable">false</property>
+ <property name="monospace">true</property>
+ <property name="buffer">source_buffer</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkSourceBuffer" id="source_buffer">
+ </object>
+</interface>
diff --git a/libide/debugger/ide-debugger-perspective.c b/libide/debugger/ide-debugger-perspective.c
index b57ba17..4114da2 100644
--- a/libide/debugger/ide-debugger-perspective.c
+++ b/libide/debugger/ide-debugger-perspective.c
@@ -26,6 +26,7 @@
#include "buffers/ide-buffer.h"
#include "debugger/ide-debugger.h"
#include "debugger/ide-debugger-breakpoints-view.h"
+#include "debugger/ide-debugger-disassembly-view.h"
#include "debugger/ide-debugger-locals-view.h"
#include "debugger/ide-debugger-libraries-view.h"
#include "debugger/ide-debugger-perspective.h"
@@ -434,6 +435,14 @@ ide_debugger_perspective_init (IdeDebuggerPerspective *self)
}
static void
+locate_disassembly_view (GtkWidget *widget,
+ IdeDebuggerDisassemblyView **view)
+{
+ if (IDE_IS_DEBUGGER_DISASSEMBLY_VIEW (widget))
+ *view = IDE_DEBUGGER_DISASSEMBLY_VIEW (widget);
+}
+
+static void
ide_debugger_perspective_disassemble_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -442,6 +451,7 @@ ide_debugger_perspective_disassemble_cb (GObject *object,
g_autoptr(IdeDebuggerPerspective) self = user_data;
g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) instructions = NULL;
+ IdeDebuggerDisassemblyView *view = NULL;
IDE_ENTRY;
@@ -457,7 +467,21 @@ ide_debugger_perspective_disassemble_cb (GObject *object,
IDE_EXIT;
}
+ ide_layout_grid_foreach_view (self->layout_grid,
+ (GtkCallback) locate_disassembly_view,
+ &view);
+
+ if (view == NULL)
+ {
+ view = g_object_new (IDE_TYPE_DEBUGGER_DISASSEMBLY_VIEW,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (self->layout_grid), GTK_WIDGET (view));
+ }
+
+ ide_debugger_disassembly_view_set_instructions (view, instructions);
+ /* TODO: Set current instruction */
}
void
@@ -479,9 +503,9 @@ ide_debugger_perspective_navigate_to_address (IdeDebuggerPerspective *self,
range.from = address - 0x10;
if (G_MAXUINT64 - 0x20 < address)
- range.from = G_MAXUINT64;
+ range.to = G_MAXUINT64;
else
- range.from = address + 0x20;
+ range.to = address + 0x20;
ide_debugger_disassemble_async (self->debugger,
&range,
diff --git a/libide/libide.gresource.xml b/libide/libide.gresource.xml
index ce3d817..9e602bc 100644
--- a/libide/libide.gresource.xml
+++ b/libide/libide.gresource.xml
@@ -57,6 +57,7 @@
<gresource prefix="/org/gnome/builder/ui">
<file compressed="true" preprocess="xml-stripblanks"
alias="ide-debugger-breakpoints-view.ui">debugger/ide-debugger-breakpoints-view.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="ide-debugger-controls.ui">debugger/ide-debugger-controls.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks"
alias="ide-debugger-disassembly-view.ui">debugger/ide-debugger-disassembly-view.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="ide-debugger-libraries-view.ui">debugger/ide-debugger-libraries-view.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="ide-debugger-locals-view.ui">debugger/ide-debugger-locals-view.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="ide-debugger-perspective.ui">debugger/ide-debugger-perspective.ui</file>
diff --git a/libide/meson.build b/libide/meson.build
index 2af727e..84c2a56 100644
--- a/libide/meson.build
+++ b/libide/meson.build
@@ -511,6 +511,8 @@ libide_sources = libide_generated_headers + libide_public_sources + [
'debugger/ide-debugger-breakpoints-view.h',
'debugger/ide-debugger-controls.c',
'debugger/ide-debugger-controls.h',
+ 'debugger/ide-debugger-disassembly-view.c',
+ 'debugger/ide-debugger-disassembly-view.h',
'debugger/ide-debugger-fallbacks.c',
'debugger/ide-debugger-breakpoints.c',
'debugger/ide-debugger-breakpoints.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]