From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6394 invoked by alias); 11 Apr 2007 23:51:07 -0000 Received: (qmail 6383 invoked by uid 22791); 11 Apr 2007 23:51:05 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.palmsource.com (HELO mx1.palmsource.com) (12.7.175.13) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 12 Apr 2007 00:50:59 +0100 Received: from localhost (localhost [127.0.0.1]) by localhost.domain.tld (Postfix) with ESMTP id 9B76F5F240 for ; Wed, 11 Apr 2007 16:50:56 -0700 (PDT) Received: from mx1.palmsource.com ([127.0.0.1]) by localhost (mx1.palmsource.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 31274-03-3 for ; Wed, 11 Apr 2007 16:50:55 -0700 (PDT) Received: from ussunex03.svl.access-company.com (ussunm001.palmsource.com [192.168.101.12]) by mx1.palmsource.com (Postfix) with ESMTP id 0CABB5EFCA for ; Wed, 11 Apr 2007 16:50:55 -0700 (PDT) Received: from 192.168.92.56 ([192.168.92.56]) by ussunex03.svl.access-company.com ([192.168.101.12]) via Exchange Front-End Server owa.access-company.com ([10.0.20.19]) with Microsoft Exchange Server HTTP-DAV ; Wed, 11 Apr 2007 23:52:23 +0000 Received: from svmsnyderlnx by owa.access-company.com; 11 Apr 2007 16:50:57 -0700 Subject: [RFA] set debug mi From: Michael Snyder To: gdb-patches@sources.redhat.com Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Wed, 11 Apr 2007 23:51:00 -0000 Message-Id: <1176335457.26620.48.camel@svmsnyderlnx.palmsource.com> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-04/txt/msg00151.txt.bz2 Anybody think this is useful? 2007-04-11 Michael Snyder * 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" : + ""); + + 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