[gnome-builder] valgrind: add basic support for running with valgrind



commit c87cddae287914175ef7a8ca8b64fc11732c02d0
Author: Christian Hergert <chergert redhat com>
Date:   Tue Feb 21 00:13:00 2017 -0800

    valgrind: add basic support for running with valgrind
    
    This is a very minimal valgrind plugin that hooks into the IdeRunner to
    run the program with valgrind. The valgrind item should only be available
    if valgrind is in your runtime (org.gnome.Sdk ships with valgrind, so it
    will be available even when you use org.gnome.Platform).
    
    After running with valgrind, the output will be opened as a document in
    the editor containing the results of valgrind.

 configure.ac                                 |    2 +
 plugins/Makefile.am                          |    1 +
 plugins/valgrind/Makefile.am                 |   14 +++++
 plugins/valgrind/configure.ac                |   12 ++++
 plugins/valgrind/valgrind.plugin             |    8 +++
 plugins/valgrind/valgrind_plugin/__init__.py |   80 ++++++++++++++++++++++++++
 6 files changed, 117 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f014ed8..b9a2c1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -317,6 +317,7 @@ m4_include([plugins/sysprof/configure.ac])
 m4_include([plugins/todo/configure.ac])
 m4_include([plugins/terminal/configure.ac])
 m4_include([plugins/vala-pack/configure.ac])
+m4_include([plugins/valgrind/configure.ac])
 m4_include([plugins/xml-pack/configure.ac])
 
 
@@ -619,6 +620,7 @@ echo "  Symbol Tree .......................... : ${enable_symbol_tree_plugin}"
 echo "  Todo ................................. : ${enable_todo_plugin}"
 echo "  Terminal ............................. : ${enable_terminal_plugin}"
 echo "  Vala Language Pack ................... : ${enable_vala_pack_plugin}"
+echo "  Valgrind ............................. : ${enable_valgrind_plugin}"
 echo "  XML Language Pack .................... : ${enable_xml_pack_plugin}"
 echo ""
 echo " Templates"
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index eba51b9..b92bae2 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -39,6 +39,7 @@ SUBDIRS = \
        terminal \
        todo \
        vala-pack \
+       valgrind \
        xml-pack \
        $(NULL)
 
diff --git a/plugins/valgrind/Makefile.am b/plugins/valgrind/Makefile.am
new file mode 100644
index 0000000..93883d6
--- /dev/null
+++ b/plugins/valgrind/Makefile.am
@@ -0,0 +1,14 @@
+if ENABLE_VALGRIND_PLUGIN
+
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-builder/plugins
+dist_plugin_DATA = valgrind.plugin
+
+moduledir = $(libdir)/gnome-builder/plugins/valgrind_plugin
+dist_module_DATA = valgrind_plugin/__init__.py
+
+endif
+
+-include $(top_srcdir)/git.mk
+
diff --git a/plugins/valgrind/configure.ac b/plugins/valgrind/configure.ac
new file mode 100644
index 0000000..f5e9f08
--- /dev/null
+++ b/plugins/valgrind/configure.ac
@@ -0,0 +1,12 @@
+# --enable-valgrind-plugin=yes/no
+AC_ARG_ENABLE([valgrind-plugin],
+              [AS_HELP_STRING([--enable-valgrind-plugin=@<:@yes/no@:>@],
+                              [Include support for running with valgrind])],
+              [enable_valgrind_plugin=$enableval],
+              [enable_valgrind_plugin=yes])
+
+# for if ENABLE_VALGRIND_PLUGIN in Makefile.am
+AM_CONDITIONAL(ENABLE_VALGRIND_PLUGIN, test x$enable_python_scripting = xyes && test 
x$enable_valgrind_plugin = xyes)
+
+# Ensure our makefile is generated by autoconf
+AC_CONFIG_FILES([plugins/valgrind/Makefile])
diff --git a/plugins/valgrind/valgrind.plugin b/plugins/valgrind/valgrind.plugin
new file mode 100644
index 0000000..0cf8c8c
--- /dev/null
+++ b/plugins/valgrind/valgrind.plugin
@@ -0,0 +1,8 @@
+[Plugin]
+Module=valgrind_plugin
+Loader=python3
+Name=Valgrind
+Description=Provides integration with valgrind
+Authors=Christian Hergert <christian hergert me>
+Copyright=Copyright © 2017 Christian Hergert
+Builtin=true
diff --git a/plugins/valgrind/valgrind_plugin/__init__.py b/plugins/valgrind/valgrind_plugin/__init__.py
new file mode 100644
index 0000000..fae3676
--- /dev/null
+++ b/plugins/valgrind/valgrind_plugin/__init__.py
@@ -0,0 +1,80 @@
+#
+# __init__.py
+#
+# 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/>.
+#
+
+import gi
+import os
+
+gi.require_version('Ide', '1.0')
+
+from gi.repository import Ide
+from gi.repository import GLib
+from gi.repository import GObject
+
+_ = Ide.gettext
+
+class ValgrindWorkbenchAddin(GObject.Object, Ide.WorkbenchAddin):
+    workbench = None
+    has_handler = False
+
+    def do_load(self, workbench):
+        self.workbench = workbench
+
+        build_manager = self.workbench.get_context().get_build_manager()
+        build_manager.connect('notify::pipeline', self.notify_pipeline)
+        self.notify_pipeline(build_manager, None)
+
+    def notify_pipeline(self, build_manager, pspec):
+        run_manager = self.workbench.get_context().get_run_manager()
+
+        # When the pipeline changes, we need to check to see if we can find
+        # valgrind inside the runtime environment.
+        pipeline = build_manager.get_pipeline()
+        if pipeline:
+            runtime = pipeline.get_configuration().get_runtime()
+            if runtime and runtime.contains_program_in_path('valgrind'):
+                if not self.has_handler:
+                    run_manager.add_handler('valgrind', _('Run with Valgrind'), 'system-run-symbolic', 
'<control>F9', self.valgrind_handler)
+                    self.has_handler = True
+                return
+
+        if self.has_handler:
+            run_manager.remove_handler('valgrind')
+
+    def do_unload(self, workbench):
+        if self.has_handler:
+            run_manager = self.workbench.get_context().get_run_manager()
+            run_manager.remove_handler('valgrind')
+        self.workbench = None
+
+    def valgrind_handler(self, run_manager, runner):
+        # We want to run with valgrind --log-fd=N so that we get the valgrind
+        # output redirected to our temp file. Then when the process exits, we
+        # we will open the temp file in the builder editor.
+        source_fd, name = GLib.file_open_tmp('gnome-builder-valgrind-XXXXXX.txt')
+        map_fd = runner.take_fd(source_fd, -1)
+        runner.prepend_argv('--log-fd='+str(map_fd))
+        runner.prepend_argv('valgrind')
+        runner.connect('exited', self.runner_exited, name)
+
+    def runner_exited(self, runner, name):
+        # If we weren't unloaded in the meantime, we can open the file using
+        # the "editor" hint to ensure the editor opens the file.
+        if self.workbench:
+            uri = Ide.Uri.new('file://'+name, 0)
+            self.workbench.open_uri_async(uri, 'editor', 0, None, None, None)


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