From 905b144cd7b85ae999212837aa8d3ba929b158e5 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Thu, 26 Jul 2012 17:27:49 +0200 Subject: [PATCH] draft --- .gitignore | 32 ++++++++++++++++++ Makefile | 16 +++++++++ ansidecl.h | 4 +++ libmigdb/examples/Makefile | 4 +-- libmigdb/src/Makefile | 4 +-- libmigdb/src/connect.c | 2 +- main.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 ansidecl.h create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..768b2de --- /dev/null +++ b/.gitignore @@ -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 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 index 0000000..7628064 --- /dev/null +++ b/ansidecl.h @@ -0,0 +1,4 @@ +#if (GCC_VERSION < 2007) +# define __attribute__(x) +#endif +#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) diff --git a/libmigdb/examples/Makefile b/libmigdb/examples/Makefile index 0e6060c..0d9817b 100644 --- a/libmigdb/examples/Makefile +++ b/libmigdb/examples/Makefile @@ -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 diff --git a/libmigdb/src/Makefile b/libmigdb/src/Makefile index b94d7de..7149acb 100644 --- a/libmigdb/src/Makefile +++ b/libmigdb/src/Makefile @@ -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 diff --git a/libmigdb/src/connect.c b/libmigdb/src/connect.c index 319be6f..9d61e57 100644 --- a/libmigdb/src/connect.c +++ b/libmigdb/src/connect.c @@ -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 index 0000000..880c1fe --- /dev/null +++ b/main.c @@ -0,0 +1,81 @@ +#include +#include +#include +#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); + } +} -- 1.8.3.1