From: Jan Kratochvil Date: Fri, 10 Aug 2012 13:23:25 +0000 (+0200) Subject: Support file/core/pid arguments. X-Git-Url: https://git.jankratochvil.net/?p=gdbmicli.git;a=commitdiff_plain;h=3b800401c63ffb97e3eb183d5a3a2f04645db256 Support file/core/pid arguments. --- diff --git a/main.c b/main.c index 54360b3..040c6f1 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ #define fatal(fmt...) fatal_func (__FILE__, __LINE__, __PRETTY_FUNCTION__, fmt) #define gdb_assert assert #define gdb_assert_not_reached(msg) fatal ("%s", (msg)) +#define _(x) x static ATTRIBUTE_NORETURN void fatal_func (const char *file, int line, const char *func, const char *fmt, ...) @@ -353,7 +354,7 @@ main (int argc, char **argv) { mi_h *h; char *cmd; - const char *ex[argc]; + const char *ex[argc], *arg_file = NULL, *arg_core = NULL, *arg_pid = NULL; unsigned ex_count = 0, ex_used = 0; setbuf (stdout, NULL); @@ -362,9 +363,32 @@ main (int argc, char **argv) { if (strcmp (*argv, "-ex") == 0 && argv[1] != NULL) ex[ex_count++] = *++argv; + else if (strcmp (*argv, "-c") == 0 && argv[1] != NULL) + arg_core = *++argv; + else if (strncmp (*argv, "--core=", strlen ("--core=")) == 0) + arg_core = xstrdup (&(*argv)[strlen ("--core=")]); + else if (strcmp (*argv, "-p") == 0 && argv[1] != NULL) + arg_pid = *++argv; + else if (strncmp (*argv, "--pid=", strlen ("--pid=")) == 0) + arg_pid = xstrdup (&(*argv)[strlen ("--pid=")]); + else if (arg_file == NULL) + arg_file = *argv; + else if (arg_core == NULL && arg_pid == NULL) + { + char *end = NULL; + + strtol (*argv, &end, 0); + if (isdigit ((*argv)[0]) && (end == NULL || *end == '\0')) + arg_pid = *argv; + else + arg_core = *argv; + } else - fatal ("Unknown parameter: %s", *argv); + fatal (_("Excess command line argument: %s"), *argv); } + if (arg_core != NULL && arg_pid != NULL) + fatal (_("Can't attach to process and specify a core file " + "at the same time.")); mi_set_workaround (MI_PSYM_SEARCH, 0); @@ -397,9 +421,21 @@ main (int argc, char **argv) for (;;) { if (ex_used < ex_count) + cmd = xstrdup (ex[ex_used++]); + else if (arg_file != NULL) + { + cmd = xstrprintf ("file %s", arg_file); + arg_file = NULL; + } + else if (arg_core != NULL) + { + cmd = xstrprintf ("core-file %s", arg_core); + arg_core = NULL; + } + else if (arg_pid != NULL) { - cmd = xstrdup (ex[ex_used++]); - printf ("(gdb) %s\n", cmd); + cmd = xstrprintf ("attach %s", arg_pid); + arg_pid = NULL; } else {