From: Vladimir Prus <vladimir@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: Make -exec-run and -exec-until into 'real' MI commands
Date: Wed, 13 Jan 2010 13:29:00 -0000 [thread overview]
Message-ID: <201001131629.25873.vladimir@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 346 bytes --]
At present, '-exec-run' and '-exec-until' are directly routed
to CLI, with very little MI intervention. I have tried to fix
that before, but there were backward compatibility concerns.
While working on multiexec MI patches, I really needed to have
-exec-run handled in MI, so I've made another attempt, which
is attached. Comments?
- Volodya
[-- Attachment #2: run-until.diff --]
[-- Type: text/x-patch, Size: 5573 bytes --]
commit 21beee1a1c8602552cabf74aa84ae20df8653b04
Author: Vladimir Prus <vladimir@codesourcery.com>
Date: Fri Dec 25 16:04:03 2009 +0300
Make -exec-run and -exec-until proper MI commands.
* mi/mi-cmds.h (mi_cmd_exec_run, mi_cmd_exec_until): Declare.
* mi/mi-cmds.c (mi_cmds): Adjust.
* mi/mi-main.c (recompose_args, mi_cmd_exec_run)
(mi_cmd_exec_until): New.
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 201d66b..729cc5f 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -65,10 +65,10 @@ struct mi_cmd mi_cmds[] =
{ "exec-next", { NULL, 0 }, mi_cmd_exec_next},
{ "exec-next-instruction", { NULL, 0 }, mi_cmd_exec_next_instruction},
{ "exec-return", { NULL, 0 }, mi_cmd_exec_return},
- { "exec-run", { "run", 1 }, NULL},
+ { "exec-run", { NULL, 0}, mi_cmd_exec_run},
{ "exec-step", { NULL, 0 }, mi_cmd_exec_step},
{ "exec-step-instruction", { NULL, 0 }, mi_cmd_exec_step_instruction},
- { "exec-until", { "until", 1 }, NULL},
+ { "exec-until", { NULL, 1 }, mi_cmd_exec_until},
{ "file-exec-and-symbols", { "file", 1 }, NULL },
{ "file-exec-file", { "exec-file", 1 }, NULL },
{ "file-list-exec-source-file", { NULL, 0 }, mi_cmd_file_list_exec_source_file},
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index f76e217..7e1c819 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -54,13 +54,15 @@ extern mi_cmd_argv_ftype mi_cmd_env_path;
extern mi_cmd_argv_ftype mi_cmd_env_pwd;
extern mi_cmd_argv_ftype mi_cmd_exec_continue;
extern mi_cmd_argv_ftype mi_cmd_exec_finish;
+extern mi_cmd_argv_ftype mi_cmd_exec_interrupt;
extern mi_cmd_argv_ftype mi_cmd_exec_jump;
extern mi_cmd_argv_ftype mi_cmd_exec_next;
extern mi_cmd_argv_ftype mi_cmd_exec_next_instruction;
extern mi_cmd_argv_ftype mi_cmd_exec_return;
+extern mi_cmd_argv_ftype mi_cmd_exec_run;
extern mi_cmd_argv_ftype mi_cmd_exec_step;
extern mi_cmd_argv_ftype mi_cmd_exec_step_instruction;
-extern mi_cmd_argv_ftype mi_cmd_exec_interrupt;
+extern mi_cmd_argv_ftype mi_cmd_exec_until;
extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_file;
extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_files;
extern mi_cmd_argv_ftype mi_cmd_gdb_exit;
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index dde0062..c2c8ec6 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -275,6 +275,117 @@ mi_cmd_exec_interrupt (char *command, char **argv, int argc)
error ("Usage: -exec-interrupt [--all|--thread-group id]");
}
+/* Given MI command arguments, recompose then back into a single string
+ suitable for passing to a CLI command.
+ The return value should be freed by the caller. */
+
+static char *
+recompose_args (char **argv, int argc, int add_ampersand)
+{
+ int size = 0;
+ char *recomposed;
+ char *out;
+ int i;
+ char *p;
+
+ for (i = 0; i < argc; ++i)
+ size += strlen (argv[i]) + 2 /* quotes, maybe */ + 1 /* space */;
+ out = recomposed = xmalloc (size + 1 /* & */ + 1 /* \0 */);
+
+ for (i = 0; i < argc; ++i)
+ {
+ int has_whitespace = 0;
+ for (p = argv[i]; *p; ++p)
+ if (isspace (*p))
+ {
+ has_whitespace = 1;
+ break;
+ }
+
+ if (i != 0)
+ out += sprintf (out, " ");
+ if (has_whitespace)
+ out += sprintf (out, "\"%s\"", argv[i]);
+ else
+ out += sprintf (out, "%s", argv[i]);
+ }
+ if (add_ampersand)
+ sprintf (out, "&");
+
+ return recomposed;
+}
+
+void
+mi_cmd_exec_until (char *command, char **argv, int argc)
+{
+ struct cleanup *back_to;
+ char *r = 0;
+
+ /* Previously, -exec-until was routed via CLI directly,
+ and quoting was processed by CLI. Now, it's a full
+ blown MI command, and accepts a single argument.
+
+ This means that if a frontend sends something like:
+
+ -exec-until C:/My Documents/a.c:10
+
+ we'll immediately error out and the frontend has to
+ quote it. However, such usage would not have worked
+ before either -- maybe with more cryptic error. So,
+ not backward compatibilty concerns here. */
+
+ if (argc > 1)
+ error ("-exec-until must be invoked with a signle argument");
+
+ back_to = make_cleanup (null_cleanup, NULL);
+ if (argc == 1)
+ {
+ r = recompose_args (argv, argc, target_can_async_p ());
+ make_cleanup (xfree, r);
+ }
+
+ mi_execute_cli_command ("until", argc == 1, r);
+
+ do_cleanups (back_to);
+}
+
+void
+mi_cmd_exec_run (char *command, char **argv, int argc)
+{
+ /* In GDB 7.0, '-exec-run' routed to CLI, and therefore any arguments were
+ passed to 'run' without processing. Strictly speaking, -exec-run was
+ never documented to accept any argument, and no frontend that actually
+ passes an argument is known. But in the case such frontend exist,
+ we reconstruct back the argument.
+
+ If either the input was overly quoted:
+
+ "foo bar" "biz"
+
+ then the reconstructed string will not have quoting on second string. Also,
+ if the input had two spaces between tokens, e.g.
+
+ "foo bar" "biz"
+
+ then the reconstructed string will have one. It should not matter. */
+
+ if (argc == 0)
+ {
+ mi_execute_cli_command ("run", target_can_async_p (),
+ target_can_async_p () ? "&" : NULL);
+ }
+ else
+ {
+ struct cleanup *back_to;
+ char *r = recompose_args (argv, argc, target_can_async_p ());
+ back_to = make_cleanup (xfree, r);
+
+ mi_execute_cli_command ("run", 1, r);
+
+ do_cleanups (back_to);
+ }
+}
+
static int
find_thread_of_process (struct thread_info *ti, void *p)
{
next reply other threads:[~2010-01-13 13:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-13 13:29 Vladimir Prus [this message]
2010-01-13 13:44 ` Marc Khouzam
2010-01-13 15:00 ` Vladimir Prus
2010-01-13 20:10 ` Daniel Jacobowitz
2010-01-13 20:13 ` Vladimir Prus
2010-01-13 20:26 ` Daniel Jacobowitz
2010-01-14 4:46 ` Joel Brobecker
2010-02-22 14:24 ` Vladimir Prus
2010-02-25 17:25 ` Joel Brobecker
2010-02-22 14:23 ` Vladimir Prus
2010-02-24 7:34 ` Vladimir Prus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201001131629.25873.vladimir@codesourcery.com \
--to=vladimir@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox