X-Git-Url: http://git.jankratochvil.net/?p=gdbmicli.git;a=blobdiff_plain;f=main.c;fp=main.c;h=880c1feda6317df93e54088914078f87c97e1cf7;hp=0000000000000000000000000000000000000000;hb=905b144cd7b85ae999212837aa8d3ba929b158e5;hpb=cee8a4ca0b3e0c5fefb58a07524c249ffa902197 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); + } +}