[gnome-builder/wip/chergert/bug1: 31/42] debugger: stub out some navigation and disassembly



commit 46f75a47acc0fee31ae89c5c596c02d42d6af62c
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 28 14:43:24 2017 -0700

    debugger: stub out some navigation and disassembly

 libide/debugger/ide-debugger-perspective.c |  120 +++++++++++++++++++++++-----
 libide/debugger/ide-debugger-perspective.h |    5 +
 2 files changed, 106 insertions(+), 19 deletions(-)
---
diff --git a/libide/debugger/ide-debugger-perspective.c b/libide/debugger/ide-debugger-perspective.c
index e8ae7fe..b57ba17 100644
--- a/libide/debugger/ide-debugger-perspective.c
+++ b/libide/debugger/ide-debugger-perspective.c
@@ -34,6 +34,7 @@
 #include "debugger/ide-debugger-view.h"
 #include "layout/ide-layout-grid.h"
 #include "workbench/ide-perspective.h"
+#include "util/ide-gtk.h"
 
 struct _IdeDebuggerPerspective
 {
@@ -254,6 +255,10 @@ ide_debugger_perspective_frame_activated (IdeDebuggerPerspective *self,
                                           IdeDebuggerFrame       *frame,
                                           IdeDebuggerThreadsView *threads_view)
 {
+  IdeDebuggerAddress addr;
+  const gchar *path;
+  guint line;
+
   IDE_ENTRY;
 
   g_assert (IDE_IS_DEBUGGER_PERSPECTIVE (self));
@@ -263,6 +268,30 @@ ide_debugger_perspective_frame_activated (IdeDebuggerPerspective *self,
 
   ide_debugger_locals_view_load_async (self->locals_view, thread, frame, NULL, NULL, NULL);
 
+  path = ide_debugger_frame_get_file (frame);
+  line = ide_debugger_frame_get_line (frame);
+
+  if (path != NULL)
+    {
+      g_autoptr(IdeSourceLocation) location = NULL;
+      IdeContext *context = ide_widget_get_context (GTK_WIDGET (self));
+
+      location = ide_source_location_new_for_path (context, path, line, 0);
+      ide_debugger_perspective_navigate_to_location (self, location);
+
+      IDE_EXIT;
+    }
+
+  addr = ide_debugger_frame_get_address (frame);
+
+  if (addr != IDE_DEBUGGER_ADDRESS_INVALID)
+    {
+      ide_debugger_perspective_navigate_to_address (self, addr);
+      IDE_EXIT;
+    }
+
+  g_warning ("Failed to locate source or memory address for frame");
+
   IDE_EXIT;
 }
 
@@ -405,6 +434,65 @@ ide_debugger_perspective_init (IdeDebuggerPerspective *self)
 }
 
 static void
+ide_debugger_perspective_disassemble_cb (GObject      *object,
+                                         GAsyncResult *result,
+                                         gpointer      user_data)
+{
+  IdeDebugger *debugger = (IdeDebugger *)object;
+  g_autoptr(IdeDebuggerPerspective) self = user_data;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GPtrArray) instructions = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_DEBUGGER (debugger));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_DEBUGGER_PERSPECTIVE (self));
+
+  instructions = ide_debugger_disassemble_finish (debugger, result, &error);
+
+  if (instructions == NULL)
+    {
+      g_warning ("%s", error->message);
+      IDE_EXIT;
+    }
+
+
+}
+
+void
+ide_debugger_perspective_navigate_to_address (IdeDebuggerPerspective *self,
+                                              IdeDebuggerAddress      address)
+{
+  IdeDebuggerAddressRange range;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_DEBUGGER_PERSPECTIVE (self));
+
+  if (address == IDE_DEBUGGER_ADDRESS_INVALID || self->debugger == NULL)
+    IDE_EXIT;
+
+  if (address < 0x10)
+    range.from = 0;
+  else
+    range.from = address - 0x10;
+
+  if (G_MAXUINT64 - 0x20 < address)
+    range.from = G_MAXUINT64;
+  else
+    range.from = address + 0x20;
+
+  ide_debugger_disassemble_async (self->debugger,
+                                  &range,
+                                  NULL,
+                                  ide_debugger_perspective_disassemble_cb,
+                                  g_object_ref (self));
+
+  IDE_EXIT;
+}
+
+static void
 ide_debugger_perspective_locate_by_file (GtkWidget *widget,
                                          gpointer   user_data)
 {
@@ -422,9 +510,18 @@ ide_debugger_perspective_locate_by_file (GtkWidget *widget,
 }
 
 void
+ide_debugger_perspective_navigate_to_location (IdeDebuggerPerspective *self,
+                                               IdeSourceLocation      *location)
+{
+  g_assert (IDE_IS_DEBUGGER_PERSPECTIVE (self));
+  g_assert (location != NULL);
+}
+
+void
 ide_debugger_perspective_navigate_to_breakpoint (IdeDebuggerPerspective *self,
                                                  IdeDebuggerBreakpoint  *breakpoint)
 {
+  IdeDebuggerAddress addr;
   struct {
     const gchar     *file;
     IdeDebuggerView *view;
@@ -436,29 +533,14 @@ ide_debugger_perspective_navigate_to_breakpoint (IdeDebuggerPerspective *self,
   g_return_if_fail (IDE_IS_DEBUGGER_BREAKPOINT (breakpoint));
   g_return_if_fail (IDE_IS_DEBUGGER (self->debugger));
 
-  /*
-   * To display the source for the breakpoint, first we need to discover what
-   * file contains the source. If there is no file, then we need to ask the
-   * IdeDebugger to retrieve the disassembly for us so that we can show
-   * something "useful" to the developer.
-   *
-   * If we also fail to get the disassembly for the current breakpoint, we
-   * need to load some dummy text into a buffer to denote to the developer
-   * that technically they can click forward, but the behavior is rather
-   * undefined.
-   *
-   * If the file on disk is out of date (due to changes behind the scenes) we
-   * will likely catch that with a CRC check. We will show the file, but the
-   * user will have an infobar displayed that denotes that the file is not
-   * longer in sync with the debugged executable.
-   */
-
   lookup.file = ide_debugger_breakpoint_get_file (breakpoint);
+  addr = ide_debugger_breakpoint_get_address (breakpoint);
 
-  /* Some breakpoints require disassembly */
+  /* Some breakpoints require disassembling */
   if (lookup.file == NULL)
     {
-      /* TODO: disassemble frame and load source */
+      if (addr != IDE_DEBUGGER_ADDRESS_INVALID)
+        ide_debugger_perspective_navigate_to_address (self, addr);
       IDE_EXIT;
     }
 
diff --git a/libide/debugger/ide-debugger-perspective.h b/libide/debugger/ide-debugger-perspective.h
index d83075e..0143cba 100644
--- a/libide/debugger/ide-debugger-perspective.h
+++ b/libide/debugger/ide-debugger-perspective.h
@@ -18,6 +18,7 @@
 
 #pragma once
 
+#include "diagnostics/ide-source-location.h"
 #include "debugger/ide-debugger-breakpoint.h"
 #include "layout/ide-layout.h"
 
@@ -31,5 +32,9 @@ void ide_debugger_perspective_set_debugger           (IdeDebuggerPerspective *se
                                                       IdeDebugger            *debugger);
 void ide_debugger_perspective_navigate_to_breakpoint (IdeDebuggerPerspective *self,
                                                       IdeDebuggerBreakpoint  *breakpoint);
+void ide_debugger_perspective_navigate_to_location   (IdeDebuggerPerspective *self,
+                                                      IdeSourceLocation      *location);
+void ide_debugger_perspective_navigate_to_address    (IdeDebuggerPerspective *self,
+                                                      IdeDebuggerAddress      address);
 
 G_END_DECLS


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