[gnome-builder/wip/chergert/debugger: 25/58] mi2: setup tty for inferior in test
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/debugger: 25/58] mi2: setup tty for inferior in test
- Date: Sun, 26 Mar 2017 07:23:27 +0000 (UTC)
commit 9945ae848487401aea5656371e793e29b692544b
Author: Christian Hergert <chergert redhat com>
Date: Fri Mar 24 00:36:37 2017 -0700
mi2: setup tty for inferior in test
contrib/mi2/test-client.c | 81 ++++++++++++++++++++++++++++++++++++++++----
1 files changed, 73 insertions(+), 8 deletions(-)
---
diff --git a/contrib/mi2/test-client.c b/contrib/mi2/test-client.c
index 8411c2f..5247a03 100644
--- a/contrib/mi2/test-client.c
+++ b/contrib/mi2/test-client.c
@@ -16,17 +16,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
+#include <fcntl.h>
+#include <gio/gunixinputstream.h>
+#include <gio/gunixoutputstream.h>
+#include <stdlib.h>
+#include <unistd.h>
+
#include "mi2-client.h"
#include "mi2-error.h"
static GMainLoop *main_loop;
static gint g_breakpoint_id;
+static gchar *
+open_pty (gint *out_master_fd,
+ gint *out_slave_fd)
+{
+ gint master_fd;
+ gint slave_fd;
+ char name[PATH_MAX + 1];
+
+ master_fd = posix_openpt (O_NOCTTY | O_RDWR);
+ grantpt (master_fd);
+ unlockpt (master_fd);
+
+#ifdef HAVE_PTSNAME_R
+ ptsname_r (master_fd, name, sizeof name - 1);
+ name[sizeof name - 1] = '\0';
+#else
+ name = ptsname (master_fd);
+#endif
+
+ slave_fd = open (name, O_RDWR | O_CLOEXEC);
+
+ *out_slave_fd = slave_fd;
+ *out_master_fd = master_fd;
+
+ return g_strdup (name);
+}
+
static GIOStream *
create_io_stream_to_gdb (void)
{
g_autoptr(GSubprocess) subprocess = NULL;
g_autoptr(GIOStream) io_stream = NULL;
+ g_autoptr(GInputStream) input = NULL;
+ g_autoptr(GOutputStream) output = NULL;
g_autoptr(GError) error = NULL;
subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE,
@@ -36,8 +73,9 @@ create_io_stream_to_gdb (void)
g_assert_no_error (error);
g_assert (subprocess);
- io_stream = g_simple_io_stream_new (g_subprocess_get_stdout_pipe (subprocess),
- g_subprocess_get_stdin_pipe (subprocess));
+ input = g_subprocess_get_stdout_pipe (subprocess);
+ output = g_subprocess_get_stdin_pipe (subprocess);
+ io_stream = g_simple_io_stream_new (input, output);
g_subprocess_wait_async (subprocess, NULL, NULL, NULL);
@@ -137,6 +175,8 @@ on_stopped (Mi2Client *client,
g_assert (MI2_IS_CLIENT (client));
g_assert (MI2_IS_MESSAGE (message));
+ g_print ("stopped %d %s\n", reason, mi2_message_get_param_string (message, "reason"));
+ g_print ("%s\n", g_strjoinv (" ", mi2_message_get_params (message)));
if (reason == MI2_STOP_BREAKPOINT_HIT)
mi2_client_continue_async (client, FALSE, NULL, NULL, NULL);
@@ -183,17 +223,46 @@ on_breakpoint_removed (Mi2Client *client,
g_main_loop_quit (main_loop);
}
+static void
+tty_done (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Mi2Client *client = (Mi2Client *)object;
+ g_autoptr(GError) error = NULL;
+ gboolean r;
+
+ g_assert (MI2_IS_CLIENT (client));
+
+ r = mi2_client_exec_finish (client, result, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (r);
+
+ mi2_client_exec_async (client,
+ /* converted to -stack-info-frame */
+ "stack-info-frame",
+ NULL,
+ stack_info_frame_cb,
+ NULL);
+}
+
gint
main (gint argc,
gchar *argv[])
{
g_autoptr(Mi2Client) client = NULL;
g_autoptr(GIOStream) io_stream = NULL;
+ g_autofree gchar *path = NULL;
+ g_autofree gchar *cmd = NULL;
+ gint master_fd;
+ gint slave_fd;
main_loop = g_main_loop_new (NULL, FALSE);
io_stream = create_io_stream_to_gdb ();
client = mi2_client_new (io_stream);
+ path = open_pty (&master_fd, &slave_fd);
+
g_signal_connect (client, "log", G_CALLBACK (log_handler), NULL);
g_signal_connect (client, "event::thread-group-added", G_CALLBACK (thread_group_added), NULL);
g_signal_connect (client, "event", G_CALLBACK (event), NULL);
@@ -203,12 +272,8 @@ main (gint argc,
mi2_client_start_listening (client);
- mi2_client_exec_async (client,
- /* converted to -stack-info-frame */
- "stack-info-frame",
- NULL,
- stack_info_frame_cb,
- NULL);
+ cmd = g_strdup_printf ("-gdb-set inferior-tty %s", path);
+ mi2_client_exec_async (client, cmd, NULL, tty_done, NULL);
g_main_loop_run (main_loop);
g_main_loop_unref (main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]