[gnome-builder/wip/gtk4-port: 981/1774] plugins/debuggerui: add simple highlighting for disassembly
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 981/1774] plugins/debuggerui: add simple highlighting for disassembly
- Date: Mon, 11 Jul 2022 22:31:30 +0000 (UTC)
commit 2358a42e9bcbf7583247789b01d8bd7059a26d7f
Author: Christian Hergert <chergert redhat com>
Date: Wed May 11 14:00:25 2022 -0700
plugins/debuggerui: add simple highlighting for disassembly
src/libide/gui/ide-application.c | 5 ++
src/plugins/debuggerui/builder-disassembly.lang | 81 ++++++++++++++++++++++
src/plugins/debuggerui/debuggerui.gresource.xml | 3 +
.../debuggerui/ide-debugger-disassembly-view.c | 13 +++-
4 files changed, 101 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/gui/ide-application.c b/src/libide/gui/ide-application.c
index 9feb93894..5e71bb239 100644
--- a/src/libide/gui/ide-application.c
+++ b/src/libide/gui/ide-application.c
@@ -157,6 +157,7 @@ ide_application_startup (GApplication *app)
IdeApplication *self = (IdeApplication *)app;
g_autofree gchar *style_path = NULL;
GtkSourceStyleSchemeManager *styles;
+ GtkSourceLanguageManager *langs;
GtkIconTheme *icon_theme;
g_assert (IDE_IS_MAIN_THREAD ());
@@ -174,6 +175,10 @@ ide_application_startup (GApplication *app)
gtk_source_style_scheme_manager_append_search_path (styles, style_path);
gtk_source_style_scheme_manager_append_search_path (styles, PACKAGE_DATADIR"/gtksourceview-5/styles/");
+ /* Add custom locations for language specs */
+ langs = gtk_source_language_manager_get_default ();
+ gtk_source_language_manager_append_search_path (langs,
"resource:///org/gnome/builder/gtksourceview/language-specs");
+
/* Setup access to portal settings */
_ide_application_init_settings (self);
diff --git a/src/plugins/debuggerui/builder-disassembly.lang b/src/plugins/debuggerui/builder-disassembly.lang
new file mode 100644
index 000000000..24d557e64
--- /dev/null
+++ b/src/plugins/debuggerui/builder-disassembly.lang
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ide-debugger.lang
+
+Copyright 2022 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/>.
+
+SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<language id="builder-disassembly" name="builder-disassembly" hidden="true" version="2.0">
+
+ <styles>
+ <style id="offset" name="Address Offset" map-to="def:floating-point"/>
+ <style id="address" name="Address" map-to="def:base-n-integer"/>
+ <style id="instruction" name="Instruction" map-to="def:keyword"/>
+ <style id="function" name="Function" map-to="def:function"/>
+ <style id="location" name="Location" map-to="def:preprocessor"/>
+ <style id="register" name="Register" map-to="def:special-char"/>
+ </styles>
+
+ <definitions>
+ <context id="instructions">
+ <match extended="true">:\t([a-zA-Z0-9]+)</match>
+ <include>
+ <context id="instruction" sub-pattern="1" style-ref="instruction"/>
+ </include>
+ </context>
+
+ <context id="function" style-ref="function">
+ <match>[a-zA-Z][a-zA-Z0-9_:]?</match>
+ </context>
+
+ <context id="offset" style-ref="offset">
+ <match extended="true">\+[0-9]+</match>
+ </context>
+
+ <context id="location" style-ref="location">
+ <start><</start>
+ <end>></end>
+ <include>
+ <context ref="function"/>
+ <context ref="offset"/>
+ </include>
+ </context>
+
+ <context id="register" style-ref="register">
+ <match>%[a-z0-9]+</match>
+ </context>
+
+ <context id="address" style-ref="address">
+ <match extended="true">
+ (?<![\w\.])
+ \$?0[xX][a-fA-F0-9]+
+ (?![\w\.])
+ </match>
+ </context>
+
+ <!-- Main Context -->
+ <context id="builder-disassembly">
+ <include>
+ <context ref="address"/>
+ <context ref="instructions"/>
+ <context ref="register"/>
+ <context ref="location"/>
+ </include>
+ </context>
+ </definitions>
+
+</language>
diff --git a/src/plugins/debuggerui/debuggerui.gresource.xml b/src/plugins/debuggerui/debuggerui.gresource.xml
index d4dcfa07c..dc3e411ac 100644
--- a/src/plugins/debuggerui/debuggerui.gresource.xml
+++ b/src/plugins/debuggerui/debuggerui.gresource.xml
@@ -15,4 +15,7 @@
<file preprocess="xml-stripblanks">ide-debugger-threads-view.ui</file>
<file preprocess="xml-stripblanks">ide-debugger-log-view.ui</file>
</gresource>
+ <gresource prefix="/org/gnome/builder/gtksourceview/language-specs">
+ <file>builder-disassembly.lang</file>
+ </gresource>
</gresources>
diff --git a/src/plugins/debuggerui/ide-debugger-disassembly-view.c
b/src/plugins/debuggerui/ide-debugger-disassembly-view.c
index 9711a52da..88f7bb386 100644
--- a/src/plugins/debuggerui/ide-debugger-disassembly-view.c
+++ b/src/plugins/debuggerui/ide-debugger-disassembly-view.c
@@ -24,6 +24,7 @@
#include <libide-sourceview.h>
+#include "gbp-debuggerui-resources.h"
#include "ide-debugger-disassembly-view.h"
#include "ide-debugger-instruction.h"
@@ -78,13 +79,23 @@ ide_debugger_disassembly_view_class_init (IdeDebuggerDisassemblyViewClass *klass
gtk_widget_class_set_template_from_resource (widget_class,
"/plugins/debuggerui/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);
+
+ g_resources_register (gbp_debuggerui_get_resource ());
}
static void
ide_debugger_disassembly_view_init (IdeDebuggerDisassemblyView *self)
{
+ GtkSourceLanguageManager *langs;
+ GtkSourceLanguage *lang;
+
gtk_widget_init_template (GTK_WIDGET (self));
+ langs = gtk_source_language_manager_get_default ();
+ lang = gtk_source_language_manager_get_language (langs, "builder-disassembly");
+ g_assert (lang != NULL);
+ gtk_source_buffer_set_language (self->source_buffer, lang);
+
g_object_bind_property_full (IDE_APPLICATION_DEFAULT, "style-scheme",
self->source_buffer, "style-scheme",
G_BINDING_SYNC_CREATE,
@@ -144,7 +155,7 @@ ide_debugger_disassembly_view_set_instructions (IdeDebuggerDisassemblyView *self
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",
+ g_autofree gchar *str = g_strdup_printf ("0x%"G_GINT64_MODIFIER"x
<+%03"G_GINT64_MODIFIER"u>:\t%s\n",
ide_debugger_instruction_get_address (inst),
ide_debugger_instruction_get_address (inst) - first,
ide_debugger_instruction_get_display (inst));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]