[gnome-builder/wip/chergert/bug1: 57/69] gdb: translate paths using builddir



commit ac3a39d08e2d8804fb1a289f2c737b607e35a21f
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 31 12:30:02 2017 -0700

    gdb: translate paths using builddir
    
    This fixes relative paths coming from gdb inside the flatpak runtime.

 plugins/gdb/gbp-gdb-debugger.c |   63 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/plugins/gdb/gbp-gdb-debugger.c b/plugins/gdb/gbp-gdb-debugger.c
index 3860f9b..e0e37c8 100644
--- a/plugins/gdb/gbp-gdb-debugger.c
+++ b/plugins/gdb/gbp-gdb-debugger.c
@@ -34,6 +34,7 @@ struct _GbpGdbDebugger
   gchar                    *read_buffer;
   GCancellable             *read_cancellable;
   GHashTable               *register_names;
+  GFile                    *builddir;
 
   DzlSignalGroup           *runner_signals;
 
@@ -63,6 +64,57 @@ typedef struct
 G_DEFINE_TYPE (GbpGdbDebugger, gbp_gdb_debugger, IDE_TYPE_DEBUGGER)
 
 static void
+gbp_gdb_debugger_set_context (IdeObject  *object,
+                              IdeContext *context)
+{
+  GbpGdbDebugger *self = (GbpGdbDebugger *)object;
+
+  g_assert (GBP_IS_GDB_DEBUGGER (self));
+  g_assert (!context || IDE_IS_CONTEXT (context));
+
+  IDE_OBJECT_CLASS (gbp_gdb_debugger_parent_class)->set_context (object, context);
+
+  if (context != NULL)
+    {
+      IdeBuildManager *build_manager;
+      IdeBuildPipeline *pipeline;
+      const gchar *builddir;
+
+      /*
+       * We need to save the build directory so that we can translate
+       * relative paths coming from gdb into the path within the project
+       * source tree.
+       */
+
+      build_manager = ide_context_get_build_manager (context);
+      pipeline = ide_build_manager_get_pipeline (build_manager);
+      builddir = ide_build_pipeline_get_builddir (pipeline);
+
+      g_clear_object (&self->builddir);
+      self->builddir = g_file_new_for_path (builddir);
+    }
+}
+
+static gchar *
+gbp_gdb_debugger_translate_path (GbpGdbDebugger *self,
+                                 const gchar    *path)
+{
+  g_autoptr(GFile) relative = NULL;
+
+  g_assert (GBP_IS_GDB_DEBUGGER (self));
+
+  if (path == NULL)
+    return NULL;
+
+  if (self->builddir == NULL || g_path_is_absolute (path))
+    return g_strdup (path);
+
+  relative = g_file_resolve_relative_path (self->builddir, path);
+
+  return g_file_get_path (relative);
+}
+
+static void
 gbp_gdb_debugger_panic (GbpGdbDebugger *self)
 {
   GList *list;
@@ -348,6 +400,7 @@ gbp_gdb_debugger_handle_breakpoint (GbpGdbDebugger              *self,
                                     enum gdbwire_mi_async_class  klass)
 {
   g_autoptr(IdeDebuggerBreakpoint) breakpoint = NULL;
+  g_autofree gchar *file = NULL;
   const struct gdbwire_mi_result *iter;
   G_GNUC_UNUSED const gchar *fullname = NULL;
   G_GNUC_UNUSED const gchar *original_location = NULL;
@@ -358,7 +411,6 @@ gbp_gdb_debugger_handle_breakpoint (GbpGdbDebugger              *self,
   const gchar *addr = NULL;
   const gchar *times = NULL;
   const gchar *func = NULL;
-  const gchar *file = NULL;
   const gchar *line = NULL;
 
   g_assert (GBP_IS_GDB_DEBUGGER (self));
@@ -386,7 +438,7 @@ gbp_gdb_debugger_handle_breakpoint (GbpGdbDebugger              *self,
           else if (g_strcmp0 (iter->variable, "func") == 0)
             func = iter->variant.cstring;
           else if (g_strcmp0 (iter->variable, "file") == 0)
-            file = iter->variant.cstring;
+            file = gbp_gdb_debugger_translate_path (self, iter->variant.cstring);
           else if (g_strcmp0 (iter->variable, "fullname") == 0)
             fullname = iter->variant.cstring;
           else if (g_strcmp0 (iter->variable, "line") == 0)
@@ -1417,11 +1469,11 @@ gbp_gdb_debugger_list_frames_cb (GObject      *object,
               if (liter->kind == GDBWIRE_MI_TUPLE)
                 {
                   g_autoptr(IdeDebuggerFrame) frame = NULL;
+                  g_autofree gchar *file = NULL;
                   G_GNUC_UNUSED const gchar *fullname = NULL;
                   G_GNUC_UNUSED const gchar *from = NULL;
                   const struct gdbwire_mi_result *iter;
                   const gchar *func = NULL;
-                  const gchar *file = NULL;
                   IdeDebuggerAddress addr = 0;
                   guint level = 0;
                   guint line = 0;
@@ -1437,7 +1489,7 @@ gbp_gdb_debugger_list_frames_cb (GObject      *object,
                           else if (g_strcmp0 (iter->variable, "func") == 0)
                             func = iter->variant.cstring;
                           else if (g_strcmp0 (iter->variable, "file") == 0)
-                            file = iter->variant.cstring;
+                            file = gbp_gdb_debugger_translate_path (self, iter->variant.cstring);
                           else if (g_strcmp0 (iter->variable, "fullname") == 0)
                             fullname = iter->variant.cstring;
                           else if (g_strcmp0 (iter->variable, "line") == 0)
@@ -2353,11 +2405,14 @@ static void
 gbp_gdb_debugger_class_init (GbpGdbDebuggerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeObjectClass *ide_object_class = IDE_OBJECT_CLASS (klass);
   IdeDebuggerClass *debugger_class = IDE_DEBUGGER_CLASS (klass);
 
   object_class->dispose = gbp_gdb_debugger_dispose;
   object_class->finalize = gbp_gdb_debugger_finalize;
 
+  ide_object_class->set_context = gbp_gdb_debugger_set_context;
+
   debugger_class->supports_runner = gbp_gdb_debugger_supports_runner;
   debugger_class->prepare = gbp_gdb_debugger_prepare;
   debugger_class->disassemble_async = gbp_gdb_debugger_disassemble_async;


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