[gnome-builder/wip/chergert/gdb-interpret: 1/2] debugger: add API to interpret a command



commit 787b51cd56ccf776cb42894d5f8410ca83d51ed0
Author: Christian Hergert <chergert redhat com>
Date:   Fri Sep 28 23:44:43 2018 -0700

    debugger: add API to interpret a command
    
    This gives us the plumbing necessary to be able to send a command to
    execute to the debugger backend. In particular, this could be used to
    create an interactive console to gdb or other debuggers that the user
    can type into (and maybe even someday get autocompletion on).

 src/libide/debugger/ide-debugger-fallbacks.c | 29 +++++++++++++
 src/libide/debugger/ide-debugger-private.h   |  8 ++++
 src/libide/debugger/ide-debugger.c           | 61 ++++++++++++++++++++++++++++
 src/libide/debugger/ide-debugger.h           | 18 ++++++++
 4 files changed, 116 insertions(+)
---
diff --git a/src/libide/debugger/ide-debugger-fallbacks.c b/src/libide/debugger/ide-debugger-fallbacks.c
index 3d5444503..a926ff4ba 100644
--- a/src/libide/debugger/ide-debugger-fallbacks.c
+++ b/src/libide/debugger/ide-debugger-fallbacks.c
@@ -257,3 +257,32 @@ _ide_debugger_real_disassemble_finish (IdeDebugger   *self,
 
   return g_task_propagate_pointer (G_TASK (result), error);
 }
+
+void
+_ide_debugger_real_interpret_async (IdeDebugger         *self,
+                                    const gchar         *command,
+                                    GCancellable        *cancellable,
+                                    GAsyncReadyCallback  callback,
+                                    gpointer             user_data)
+{
+  g_assert (IDE_IS_DEBUGGER (self));
+  g_assert (command != NULL);
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  g_task_report_new_error (self, callback, user_data,
+                           _ide_debugger_real_interpret_async,
+                           G_IO_ERROR,
+                           G_IO_ERROR_NOT_SUPPORTED,
+                           "Interpret command is not supported");
+}
+
+gboolean
+_ide_debugger_real_interpret_finish (IdeDebugger   *self,
+                                     GAsyncResult  *result,
+                                     GError       **error)
+{
+  g_assert (IDE_IS_DEBUGGER (self));
+  g_assert (G_IS_TASK (result));
+
+  return g_task_propagate_boolean (G_TASK (result), error);
+}
diff --git a/src/libide/debugger/ide-debugger-private.h b/src/libide/debugger/ide-debugger-private.h
index b5d7c1f8f..dc880aa82 100644
--- a/src/libide/debugger/ide-debugger-private.h
+++ b/src/libide/debugger/ide-debugger-private.h
@@ -44,6 +44,14 @@ void                    _ide_debugger_real_list_frames_async        (IdeDebugger
 GPtrArray              *_ide_debugger_real_list_frames_finish       (IdeDebugger                    *self,
                                                                      GAsyncResult                   *result,
                                                                      GError                        **error);
+void                    _ide_debugger_real_interpret_async          (IdeDebugger                    *self,
+                                                                     const gchar                    *command,
+                                                                     GCancellable                   
*cancellable,
+                                                                     GAsyncReadyCallback             
callback,
+                                                                     gpointer                        
user_data);
+gboolean                _ide_debugger_real_interpret_finish         (IdeDebugger                    *self,
+                                                                     GAsyncResult                   *result,
+                                                                     GError                        **error);
 void                    _ide_debugger_real_interrupt_async          (IdeDebugger                    *self,
                                                                      IdeDebuggerThreadGroup         
*thread_group,
                                                                      GCancellable                   
*cancellable,
diff --git a/src/libide/debugger/ide-debugger.c b/src/libide/debugger/ide-debugger.c
index 3ad03bbd5..83066ff55 100644
--- a/src/libide/debugger/ide-debugger.c
+++ b/src/libide/debugger/ide-debugger.c
@@ -488,6 +488,8 @@ ide_debugger_class_init (IdeDebuggerClass *klass)
   klass->thread_group_removed = ide_debugger_real_thread_group_removed;
   klass->thread_removed = ide_debugger_real_thread_removed;
   klass->thread_selected = ide_debugger_real_thread_selected;
+  klass->interpret_async = _ide_debugger_real_interpret_async;
+  klass->interpret_finish = _ide_debugger_real_interpret_finish;
 
   /**
    * IdeDebugger:display-name:
@@ -1998,3 +2000,62 @@ ide_debugger_prepare (IdeDebugger *self,
   if (IDE_DEBUGGER_GET_CLASS (self)->prepare)
     IDE_DEBUGGER_GET_CLASS (self)->prepare (self, runner);
 }
+
+/**
+ * ide_debugger_interpret_async:
+ * @self: an #IdeDebugger
+ * @command: a command to execute
+ * @cancellable: (nullable): a #GCancellable or %NULL
+ * @callback: a callback to execute, or %NULL
+ * @user_data: user data for @callback
+ *
+ * Asynchronously requests that the debugger interpret the command.
+ *
+ * This is used by the interactive-console to submit commands to the debugger
+ * that are in the native syntax of that debugger.
+ *
+ * The debugger is expected to return any textual output via the
+ * IdeDebugger::log signal.
+ *
+ * Call ide_debugger_interpret_finish() from @callback to determine if the
+ * command was interpreted.
+ *
+ * Since: 3.32
+ */
+void
+ide_debugger_interpret_async (IdeDebugger         *self,
+                              const gchar         *command,
+                              GCancellable        *cancellable,
+                              GAsyncReadyCallback  callback,
+                              gpointer             user_data)
+{
+  g_return_if_fail (IDE_IS_DEBUGGER (self));
+  g_return_if_fail (command != NULL);
+
+  return IDE_DEBUGGER_GET_CLASS (self)->interpret_async (self, command, cancellable, callback, user_data);
+}
+
+/**
+ * ide_debugger_interpret_finish:
+ * @self: an #IdeDebugger
+ * @result: a #GAsyncResult provided to callback
+ * @error: a location for a #GError, or %NULL
+ *
+ * Retrieves the result of the asynchronous operation to interpret a debugger
+ * command.
+ *
+ * Returns: %TRUE if the command was interpreted, otherwise %FALSE and
+ *    @error is set.
+ *
+ * Since: 3.32
+ */
+gboolean
+ide_debugger_interpret_finish (IdeDebugger   *self,
+                               GAsyncResult  *result,
+                               GError       **error)
+{
+  g_return_val_if_fail (IDE_IS_DEBUGGER (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+  return IDE_DEBUGGER_GET_CLASS (self)->interpret_finish (self, result, error);
+}
diff --git a/src/libide/debugger/ide-debugger.h b/src/libide/debugger/ide-debugger.h
index a20f09c9a..dac00ecb6 100644
--- a/src/libide/debugger/ide-debugger.h
+++ b/src/libide/debugger/ide-debugger.h
@@ -186,6 +186,14 @@ struct _IdeDebuggerClass
   GPtrArray *(*disassemble_finish)       (IdeDebugger                    *self,
                                           GAsyncResult                   *result,
                                           GError                        **error);
+  void       (*interpret_async)          (IdeDebugger                    *self,
+                                          const gchar                    *command,
+                                          GCancellable                   *cancellable,
+                                          GAsyncReadyCallback             callback,
+                                          gpointer                        user_data);
+  gboolean   (*interpret_finish)         (IdeDebugger                    *self,
+                                          GAsyncResult                   *result,
+                                          GError                        **error);
 
   /*< private >*/
   gpointer _reserved[32];
@@ -386,5 +394,15 @@ void               ide_debugger_emit_library_loaded       (IdeDebugger
 IDE_AVAILABLE_IN_ALL
 void               ide_debugger_emit_library_unloaded     (IdeDebugger                    *self,
                                                            IdeDebuggerLibrary             *library);
+IDE_AVAILABLE_IN_3_32
+void               ide_debugger_interpret_async           (IdeDebugger                    *self,
+                                                           const gchar                    *command,
+                                                           GCancellable                   *cancellable,
+                                                           GAsyncReadyCallback             callback,
+                                                           gpointer                        user_data);
+IDE_AVAILABLE_IN_3_32
+gboolean           ide_debugger_interpret_finish          (IdeDebugger                    *self,
+                                                           GAsyncResult                   *result,
+                                                           GError                        **error);
 
 G_END_DECLS


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