#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); } }