[RFA] set debug mi

Michael Snyder Michael.Snyder@access-company.com
Wed Apr 11 23:51:00 GMT 2007


Anybody think this is useful?

2007-04-11  Michael Snyder  <michael.snyder@access-company.com>

	* mi/mi-main.c (print_mi_command, print_mi_status): New functions.
	(captured_mi_execute_command): Call those if mi_debug_p is true.
	(mi_execute_cli_command): Make debugging output more concise.
	(show_mi_debug): New function.
	(_initialize_mi_main): Add "set/show debug mi" command.

Index: mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.95
diff -p -r1.95 mi-main.c
*** mi-main.c	10 Apr 2007 14:53:46 -0000	1.95
--- mi-main.c	11 Apr 2007 23:28:04 -0000
***************
*** 25,30 ****
--- 25,31 ----
  /* Work in progress.  */
  
  #include "defs.h"
+ #include "gdbcmd.h"
  #include "target.h"
  #include "inferior.h"
  #include "gdb_string.h"
*************** struct captured_mi_execute_command_args
*** 86,94 ****
    struct mi_parse *command;
  };
  
- int mi_debug_p;
  struct ui_file *raw_stdout;
  
  /* This is used to pass the current command timestamp
     down to continuation routines.  */
  static struct mi_timestamp *current_command_ts;
--- 87,144 ----
    struct mi_parse *command;
  };
  
  struct ui_file *raw_stdout;
  
+ /* Non-zero tells MI to output debugging info.  */
+ int mi_debug_p;
+ 
+ /* MI debugging output routines.  */
+ static void
+ print_mi_command (struct mi_parse *cmd, struct ui_file *out)
+ {
+   int i;
+ 
+   fprintf_unfiltered (out, " token='%s' cmd='%s' (%s)",
+ 		      cmd->token, cmd->command,
+ 		      cmd->op == MI_COMMAND ? "MI_COMMAND" :
+ 		      cmd->op == CLI_COMMAND ? "CLI_COMMAND" :
+ 		      "<unknown op>");
+ 
+   if (cmd->args && cmd->args[0])
+     fprintf_unfiltered (out, " args='%s'", cmd->args);
+ 
+   for (i = 0; i < cmd->argc; i++)
+     fprintf_unfiltered (out, "\n\t argv[%d] = '%s'", i, cmd->argv[i]);
+ 
+   fprintf_unfiltered (out, "\n");
+   gdb_flush (out);
+ }
+ 
+ static void
+ print_mi_status (enum mi_cmd_result result,
+ 		 struct mi_parse *cmd, 
+ 		 struct ui_file *out)
+ {
+   switch (result) {
+   case MI_CMD_DONE:
+     fprintf_unfiltered (out, "-token '%s' returned '^done'\n",
cmd->token);
+     break;
+   case MI_CMD_FORGROUND:
+   case MI_CMD_ERROR:
+     fprintf_unfiltered (out, "-token '%s' returned '^error', %s\n",
+ 			cmd->token, mi_error_message);
+     break;
+   case MI_CMD_QUIET:
+     fprintf_unfiltered (out, "-token '%s' returned quietly.\n",
cmd->token);
+     break;
+   default:
+     fprintf_unfiltered (out, "-token '%s' returned unknown ret
code.\n",
+ 			cmd->token);
+     break;
+   }
+   gdb_flush (out);
+ }
+ 
  /* This is used to pass the current command timestamp
     down to continuation routines.  */
  static struct mi_timestamp *current_command_ts;
*************** captured_mi_execute_command (struct ui_o
*** 1068,1082 ****
  
    struct mi_timestamp cmd_finished;
  
    switch (context->op)
      {
  
      case MI_COMMAND:
        /* A MI command was read from the input stream.  */
-       if (mi_debug_p)
- 	/* FIXME: gdb_???? */
- 	fprintf_unfiltered (raw_stdout, " token=`%s' command=`%s' args=`%
s'\n",
- 			    context->token, context->command, context->args);
        /* FIXME: cagney/1999-09-25: Rather than this convoluted
           condition expression, each function should return an
           indication of what action is required and then switch on
--- 1118,1131 ----
  
    struct mi_timestamp cmd_finished;
  
+   if (mi_debug_p)
+     print_mi_command (context, gdb_stdlog);
+ 
    switch (context->op)
      {
  
      case MI_COMMAND:
        /* A MI command was read from the input stream.  */
        /* FIXME: cagney/1999-09-25: Rather than this convoluted
           condition expression, each function should return an
           indication of what action is required and then switch on
*************** captured_mi_execute_command (struct ui_o
*** 1091,1096 ****
--- 1140,1148 ----
        if (do_timings)
            timestamp (&cmd_finished);
  
+       if (mi_debug_p)
+ 	print_mi_status (args->rc, context, gdb_stdlog);
+ 
        if (!target_can_async_p () || !target_executing)
  	{
  	  /* Print the result if there were no errors.
*************** captured_mi_execute_command (struct ui_o
*** 1148,1153 ****
--- 1200,1208 ----
  	argv[1] = context->command;
  	args->rc = mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
  
+ 	if (mi_debug_p)
+ 	  print_mi_status (args->rc, context, gdb_stdlog);
+ 
  	/* If we changed interpreters, DON'T print out anything.  */
  	if (current_interp_named_p (INTERP_MI)
  	    || current_interp_named_p (INTERP_MI1)
*************** captured_mi_execute_command (struct ui_o
*** 1186,1192 ****
    return;
  }
  
- 
  void
  mi_execute_command (char *cmd, int from_tty)
  {
--- 1241,1246 ----
*************** mi_execute_cli_command (const char *cmd,
*** 1331,1339 ****
        else
  	run = xstrdup (cmd);
        if (mi_debug_p)
! 	/* FIXME: gdb_???? */
! 	fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
! 			    cmd, run);
        old_cleanups = make_cleanup (xfree, run);
        execute_command ( /*ui */ run, 0 /*from_tty */ );
        do_cleanups (old_cleanups);
--- 1385,1397 ----
        else
  	run = xstrdup (cmd);
        if (mi_debug_p)
! 	{
! 	  fprintf_unfiltered (gdb_stdlog, "  CLI=%s", cmd);
! 	  if (args_p)
! 	    fprintf_unfiltered (gdb_stdlog, ", args='%s'", args);
! 	  fprintf_unfiltered (gdb_stdlog, "\n");
! 	  gdb_flush (gdb_stdlog);
! 	}
        old_cleanups = make_cleanup (xfree, run);
        execute_command ( /*ui */ run, 0 /*from_tty */ );
        do_cleanups (old_cleanups);
*************** mi_setup_architecture_data (void)
*** 1513,1523 ****
--- 1571,1598 ----
    memset (old_regs, 0, (NUM_REGS + NUM_PSEUDO_REGS) *
MAX_REGISTER_SIZE + 1);
  }
  
+ static void
+ show_mi_debug (struct ui_file *file, int from_tty,
+ 	       struct cmd_list_element *c, const char *value)
+ {
+   fprintf_filtered (file, _("Debugging of mi protocol is %s.\n"),
+ 		    value);
+ }
+ 
  void
  _initialize_mi_main (void)
  {
    DEPRECATED_REGISTER_GDBARCH_SWAP (old_regs);
    deprecated_register_gdbarch_swap (NULL, 0,
mi_setup_architecture_data);
+ 
+   add_setshow_zinteger_cmd ("mi", no_class, &mi_debug_p, _("\
+ Set debugging of mi protocol."), _("\
+ Show debugging of mi protocol."), _("\
+ When enabled, each message sent or received via the mi protocol\n\
+ is displayed."),
+ 			    NULL, 
+ 			    show_mi_debug, 
+ 			    &setdebuglist, &showdebuglist);
  }
  
  static void 



More information about the Gdb-patches mailing list