+2013-12-03 Pedro Alves <palves@redhat.com>
+ Joel Brobecker <brobecker@adacore.com>
+
+ * exceptions.h (enum_errors) <UNDEFINED_COMMAND_ERROR>: New enum.
+ * mi/mi-parse.c (mi_parse): Throw UNDEFINED_COMMAND_ERROR instead
+ of a regular error when the GDB/MI command does not exist.
+ * mi/mi-main.c (mi_cmd_list_features): Add
+ "undefined-command-error-code".
+ (mi_print_exception): Print an "undefined-command"
+ error code if EXCEPTION.ERROR is UNDEFINED_COMMAND_ERROR.
+ * NEWS: Add entry documenting the new "code" variable in
+ "^error" result records.
+
2013-12-03 Joel Brobecker <brobecker@adacore.com>
* mi/mi-cmds.h (mi_cmd_info_gdb_mi_command): Declare.
** The new command -info-gdb-mi-command allows the user to determine
whether a GDB/MI command is supported or not.
+ ** The "^error" result record returned when trying to execute an undefined
+ GDB/MI command now provides a variable named "code" whose content is the
+ "undefined-command" error code. Support for this feature can be verified
+ by using the "-list-features" command, which should contain
+ "undefined-command-error-code".
+
** The -trace-save MI command can optionally save trace buffer in Common
Trace Format now.
+2013-12-03 Joel Brobecker <brobecker@adacore.com>
+
+ * gdb.texinfo (GDB/MI Result Records): Fix the syntax of the
+ "^error" result record concerning the error message. Document
+ the error code that may also be part of that result record.
+ (GDB/MI Miscellaneous Commands): Document the
+ "undefined-command-error-code" element in the output of
+ the "-list-features" GDB/MI command.
+
2013-12-03 Joel Brobecker <brobecker@adacore.com>
* gdb.texinfo (GDB/MI Miscellaneous Commands): Document
@findex ^connected
@value{GDBN} has connected to a remote target.
-@item "^error" "," @var{c-string}
+@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
@findex ^error
-The operation failed. The @code{@var{c-string}} contains the corresponding
-error message.
+The operation failed. The @code{msg=@var{c-string}} variable contains
+the corresponding error message.
+
+If present, the @code{code=@var{c-string}} variable provides an error
+code on which consumers can rely on to detect the corresponding
+error condition. At present, only one error code is defined:
+
+@table @samp
+@item "undefined-command"
+Indicates that the command causing the error does not exist.
+@end table
@item "^exit"
@findex ^exit
option (@pxref{Context management}).
@item info-gdb-mi-command
Indicates support for the @code{-info-gdb-mi-command} command.
+@item undefined-command-error-code
+Indicates support for the "undefined-command" error code in error result
+records, produced when trying to execute an undefined @sc{gdb/mi} command
+(@pxref{GDB/MI Result Records}).
@end table
@subheading The @code{-list-target-features} Command
aborted as the inferior state is no longer valid. */
TARGET_CLOSE_ERROR,
+ /* An undefined command was executed. */
+ UNDEFINED_COMMAND_ERROR,
+
/* Add more errors here. */
NR_ERRORS
};
ui_out_field_string (uiout, NULL, "ada-exceptions");
ui_out_field_string (uiout, NULL, "language-option");
ui_out_field_string (uiout, NULL, "info-gdb-mi-command");
+ ui_out_field_string (uiout, NULL, "undefined-command-error-code");
#if HAVE_PYTHON
if (gdb_python_initialized)
fputs_unfiltered ("unknown error", raw_stdout);
else
fputstr_unfiltered (exception.message, '"', raw_stdout);
- fputs_unfiltered ("\"\n", raw_stdout);
+ fputs_unfiltered ("\"", raw_stdout);
+
+ switch (exception.error)
+ {
+ case UNDEFINED_COMMAND_ERROR:
+ fputs_unfiltered (",code=\"undefined-command\"", raw_stdout);
+ break;
+ }
+
+ fputs_unfiltered ("\n", raw_stdout);
}
void
/* Find the command in the MI table. */
parse->cmd = mi_lookup (parse->command);
if (parse->cmd == NULL)
- error (_("Undefined MI command: %s"), parse->command);
+ throw_error (UNDEFINED_COMMAND_ERROR,
+ _("Undefined MI command: %s"), parse->command);
/* Skip white space following the command. */
chp = skip_spaces_const (chp);
+2013-12-03 Joel Brobecker <brobecker@adacore.com>
+
+ * gdb.mi/mi-undefined-cmd.exp: New testcase.
+
2013-12-03 Joel Brobecker <brobecker@adacore.com>
* gdb.mi/mi-i-cmd.exp: New file.
--- /dev/null
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+ continue
+}
+
+
+# First, verify that the debugger correctly advertises support
+# for the "undefined-command" error code...
+mi_gdb_test "-list-features" \
+ "\\^done,features=\\\[.*\"undefined-command-error-code\".*\\\]" \
+ "-list-features should include \"undefined-command-error-code\""
+
+mi_gdb_test "-undefined-command" \
+ "\\^error,.*,code=\"undefined-command\"" \
+ "error code when executing undefined command"