1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * gdbmi-test.c
4 * Copyright (C) Naba Kumar 2005 <naba@gnome.org>
5 *
6 * gdbmi-test.c is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2, or (at your option) any later version.
11 *
12 * main.c is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with main.c. See the file "COPYING". If not,
19 * write to: The Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 /* MI parser */
25 #include <stdio.h>
26 #include <glib.h>
27 #include <gtk/gtk.h>
28
29 #include "gdbmi.h"
30 #include "debugger.h"
31
32 static gchar *gdb_test_line =
33 "^done,BreakpointTable={nr_rows=\"2\",nr_cols=\"6\",hdr=[{width=\"3\",alignment=\"-1\",col_name=\"number\",colhdr=\"Num\"},{width=\"14\",alignment=\"-1\",col_name=\"type\",colhdr=\"Type\"},{width=\"4\",alignment=\"-1\",col_name=\"disp\",colhdr=\"Disp\"},{width=\"3\",alignment=\"-1\",col_name=\"enabled\",colhdr=\"Enb\"},{width=\"10\",alignment=\"-1\",col_name=\"addr\",colhdr=\"Address\"},{width=\"40\",alignment=\"2\",col_name=\"what\",colhdr=\"What\"}],body=[bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0x08050f5d\",func=\"main\",file=\"main.c\",line=\"122\",times=\"1\"},bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0x0096fbae\",func=\"anjuta_plugin_activate\",file=\"anjuta-plugin.c\",line=\"395\",times=\"1\"}]}";
34
35 #if 0
36 static void
37 output_callback (Debugger *debugger, DebuggerOutputType type,
38 const gchar *data, gpointer user_data)
39 {
40 printf ("%s", data);
41 }
42
43 static void
44 output_parser (Debugger* debugger, const GDBMIValue *mi_result,
45 const GList* cli_result, gpointer data, gpointer extra_data)
46 {
47 gdbmi_value_dump (mi_result, 0);
48 }
49
50 static void
51 on_location_changed (Debugger* debugger, const gchar *file, gint line,
52 gchar *addr, gpointer data)
53 {
54 printf ("Location changed %s:%d\n", file, line);
55 }
56
57 static void
58 on_program_running (Debugger* debugger, gpointer data)
59 {
60 }
61
62 static void
63 on_program_exited (Debugger* debugger, const GDBMIValue *value,
64 gpointer data)
65 {
66 }
67
68 static void
69 on_program_stopped (Debugger* debugger, const GDBMIValue *value,
70 gpointer data)
71 {
72 }
73
74 static void
75 on_entry_activate (GtkEntry *entry, Debugger *debugger)
76 {
77 debugger_command (debugger, gtk_entry_get_text (entry),
78 FALSE, output_parser, NULL);
79 }
80 #endif
81
82 int
main(int argc,char ** argv)83 main(int argc, char **argv)
84 {
85 GDBMIValue *val;
86 gchar *ptr;
87 /* Debugger *debugger; */
88 /* GtkWidget *win, *entry; */
89
90 printf("Test GDB MI interface.\n");
91 ptr = gdb_test_line;
92 val = gdbmi_value_parse (ptr);
93 if (val)
94 {
95 printf ("GDB MI parse test successful:\n");
96 printf ("Data ==>\n");
97 gdbmi_value_dump (val, 0);
98 }
99 else
100 {
101 printf ("GDB MI parse test failed\n");
102 }
103 printf ("Testing debugger\n");
104 gtk_init (&argc, &argv);
105
106 #if 0
107 debugger = debugger_new_with_program (NULL, NULL, output_callback, NULL,
108 "./gdbmi-test", TRUE);
109
110 g_signal_connect (debugger, "location-changed",
111 G_CALLBACK (on_location_changed), NULL);
112 g_signal_connect (debugger, "program-running",
113 G_CALLBACK (on_program_running), NULL);
114 g_signal_connect (debugger, "program-exited",
115 G_CALLBACK (on_program_exited), NULL);
116 g_signal_connect (debugger, "program-stopped",
117 G_CALLBACK (on_program_stopped), NULL);
118
119 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
120 entry = gtk_entry_new ();
121 gtk_container_add (GTK_CONTAINER (win), entry);
122 g_signal_connect (entry, "activate",
123 G_CALLBACK (on_entry_activate),
124 debugger);
125 gtk_widget_show_all (win);
126 gtk_main();
127 #endif
128 return (0);
129 }
130