draft
authorJan Kratochvil <jan.kratochvil@redhat.com>
Thu, 26 Jul 2012 15:27:49 +0000 (17:27 +0200)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Thu, 26 Jul 2012 15:27:49 +0000 (17:27 +0200)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
ansidecl.h [new file with mode: 0644]
libmigdb/examples/Makefile
libmigdb/src/Makefile
libmigdb/src/connect.c
main.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..768b2de
--- /dev/null
@@ -0,0 +1,32 @@
+main.o
+gdbmicli
+tags
+
+libmigdb/examples/linux_test
+libmigdb/examples/pty_test
+libmigdb/examples/remote_test
+libmigdb/examples/target_frames
+libmigdb/examples/test_target
+libmigdb/examples/x11_cpp_test
+libmigdb/examples/x11_fr_test
+libmigdb/examples/x11_test
+libmigdb/examples/x11_wp_test
+libmigdb/src/.parse.c.swp
+libmigdb/src/alloc.o
+libmigdb/src/breakpoint.o
+libmigdb/src/connect.o
+libmigdb/src/cpp_int.o
+libmigdb/src/data_man.o
+libmigdb/src/error.o
+libmigdb/src/get_free_pty.o
+libmigdb/src/get_free_vt.o
+libmigdb/src/libmigdb.a
+libmigdb/src/misc.o
+libmigdb/src/parse.o
+libmigdb/src/prg_control.o
+libmigdb/src/stack_man.o
+libmigdb/src/symbol_query.o
+libmigdb/src/target_man.o
+libmigdb/src/thread.o
+libmigdb/src/var_obj.o
+libmigdb/tags
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..555e196
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+OBJS=main.o
+
+all: gdbmicli
+
+gdbmicli: $(OBJS) libmigdb/src/libmigdb.a
+       gcc -o $@ $^ -Wall -Werror -lreadline
+
+libmigdb/src/libmigdb.a:
+       $(MAKE) -C libmigdb/src libmigdb.a
+
+%.o: %.c
+       gcc -c -o $@ $^ -Wall -Werror -g -Ilibmigdb/src
+
+clean:
+       $(RM) $(OBJS) gdbmicli
+
diff --git a/ansidecl.h b/ansidecl.h
new file mode 100644 (file)
index 0000000..7628064
--- /dev/null
@@ -0,0 +1,4 @@
+#if (GCC_VERSION < 2007)
+# define __attribute__(x)
+#endif
+#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
index 0e6060c..0d9817b 100644 (file)
@@ -3,8 +3,8 @@
 all: test_target x11_test remote_test linux_test target_frames x11_fr_test \
        x11_wp_test x11_cpp_test pty_test
 
-CFLAGS=-O0 -Wall -gstabs+3 -I../src
-CXXFLAGS=-O0 -Wall -gstabs+3 -I../src
+CFLAGS=-Wall -g3 -I../src
+CXXFLAGS=-Wall -g3 -I../src
 LDLIBS=
 
 ticepic: ticepic.c ../src/libmigdb.a
index b94d7de..7149acb 100644 (file)
@@ -3,8 +3,8 @@ PREFIX=/usr
 
 all: libmigdb.a
 
-CFLAGS=-O2 -Wall -gstabs+3 -I.
-CXXFLAGS=-O2 -Wall -gstabs+3
+CFLAGS=-Wall -g3 -I.
+CXXFLAGS=-Wall -g3
 LDLIBS=
 
 connect.o: mi_gdb.h
index 319be6f..9d61e57 100644 (file)
@@ -124,7 +124,7 @@ void mi_set_nonblk(int h)
  int flf;
  flf=fcntl(h,F_GETFL,0);
  flf=flf | O_NONBLOCK;
- fcntl(h,F_SETFL,flf);
+// fcntl(h,F_SETFL,flf);
 }
 
 int mi_getline(mi_h *h)
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..880c1fe
--- /dev/null
+++ b/main.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <readline/readline.h>
+#include "ansidecl.h"
+#include "mi_gdb.h"
+
+static ATTRIBUTE_NORETURN void
+fatal (const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start (ap, fmt);
+  vfprintf (stderr, fmt, ap);
+  va_end (ap);
+  exit (EXIT_FAILURE);
+}
+
+static void
+console_cb (const char *str, void *data)
+{
+  fputs (str, stdout);
+}
+
+int
+main (int argc, char **argv)
+{
+  mi_h *h;
+  char *cmd;
+  const char *ex[argc];
+  unsigned ex_count = 0, ex_used = 0;
+
+  setbuf (stdout, NULL);
+
+  while (*++argv != NULL)
+    {
+      if (strcmp (*argv, "-ex") == 0 && argv[1] != NULL)
+       ex[ex_count++] = *++argv;
+      else
+       fatal ("Unknown parameter: %s", *argv);
+    }
+
+  mi_set_workaround (MI_PSYM_SEARCH, 0);
+
+  h = mi_connect_local ();
+  if (h == NULL)
+    fatal ("Cannot connect to GDB");
+
+  mi_set_console_cb (h, console_cb, NULL);
+
+  for (;;)
+    {
+      mi_output *rec, *res;
+
+      if (ex_used < ex_count)
+       {
+         cmd = strdup (ex[ex_used++]);
+         printf ("(gdb) %s\n", cmd);
+       }
+      else
+       {
+         cmd = readline ("(gdb) ");
+         if (cmd == NULL)
+           cmd = strdup ("quit");
+       }
+
+      mi_send (h, "-interpreter-exec console \"%s\"\n", cmd);
+      free (cmd);
+
+      res = mi_get_response_blk (h);
+      if (res == NULL)
+       fatal ("mi_get_response_blk == NULL");
+
+      rec = mi_get_rrecord (res);
+      if (rec == NULL)
+       fatal ("mi_get_rrecord == NULL");
+      if (rec->tclass != MI_CL_DONE)
+       fatal ("mi_get_rrecord != MI_CL_DONE");
+
+      mi_free_output (res);
+    }
+}