This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Make -exec-run and -exec-until into 'real' MI commands


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

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)
 {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]