From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA 2/2] Add "undefined-command" error code at end of ^error result...
Date: Mon, 18 Nov 2013 17:21:00 -0000 [thread overview]
Message-ID: <1384794719-20594-3-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1384794719-20594-1-git-send-email-brobecker@adacore.com>
... when trying to execute an undefined GDB/MI command. When trying
to execute a GDB/MI command which does not exist, the current error
result record looks like this:
-unsupported
^error,msg="Undefined MI command: unsupported"
The only indication that the command does not exist is the error
message. It would be a little fragile for a consumer to rely solely
on the contents of the error message in order to determine whether
a command exists or not.
This patch improves the situation by adding concept of error
code, starting with one well-defined error code ("undefined-command")
identifying errors due to a non-existant command. Here is the new
output:
-unsupported
^error,msg="Undefined MI command: unsupported",code="undefined-command"
This error code is only displayed when the corresponding error
condition is met. Otherwise, the error record remains unchanged.
For instance:
-symbol-list-lines foo.adb
^error,msg="-symbol-list-lines: Unknown source file name."
For frontends to be able to know whether they can rely on this
variable, a new entry "undefined-command-error-code" has been
added to the "-list-features" command. Another option would be
to always generate an error="..." variable (for the default case,
we could decide for instance that the error code is the empty string).
But it seems more efficient to provide that info in "-list-features"
and then only add the error code when meaningful.
gdb/ChangeLog:
(from Pedro Alves <palves@redhat.com>)
(from Joel Brobecker <brobecker@adacore.com>)
* exceptions.h (enum_errors) <UNKNOWN_COMMAND_ERROR>: New enum.
* mi/mi-parse.c (mi_parse): Thow UNKNOWN_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 in UNKNOWN_COMMAND_ERROR.
* NEWS: Add entry documenting the new "code" variable in
"^error" result records.
gdb/doc/ChangeLog:
* 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.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-undefined-cmd.exp: New testcase.
Tested on x86_64-linux. OK to commit?
(hmmm, now that I have spent all that time typing everything up,
I am wondering if I should rename UNKNOWN_COMMAND_ERROR into
UNDEFINED_COMMAND_ERROR - no real biggie either way...)
Thanks!
--
Joel
---
gdb/NEWS | 4 ++++
gdb/doc/gdb.texinfo | 17 ++++++++++++++--
gdb/exceptions.h | 3 +++
gdb/mi/mi-main.c | 12 ++++++++++-
gdb/mi/mi-parse.c | 3 ++-
gdb/testsuite/gdb.mi/mi-undefined-cmd.exp | 33 +++++++++++++++++++++++++++++++
6 files changed, 68 insertions(+), 4 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/mi-undefined-cmd.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index e61c79f..d22c56a 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -156,6 +156,10 @@ show startup-with-shell
** 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.
+
** The -trace-save MI command can optionally save trace buffer in Common
Trace Format now.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index e85b5b6..f0662ff 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -29315,11 +29315,20 @@ which threads are resumed.
@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
+The operation failed. The @var{msg} variable contains the corresponding
error message.
+If present, the @var{code} variable provides an error code on which
+consumers can rely in order 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
@value{GDBN} has terminated.
@@ -35169,6 +35178,10 @@ Indicates that all @sc{gdb/mi} commands accept the @option{--language}
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
diff --git a/gdb/exceptions.h b/gdb/exceptions.h
index 129d29a..d9be897 100644
--- a/gdb/exceptions.h
+++ b/gdb/exceptions.h
@@ -93,6 +93,9 @@ enum errors {
aborted as the inferior state is no longer valid. */
TARGET_CLOSE_ERROR,
+ /* An unknown command was executed. */
+ UNKNOWN_COMMAND_ERROR,
+
/* Add more errors here. */
NR_ERRORS
};
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index e4251c9..53075af 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1818,6 +1818,7 @@ mi_cmd_list_features (char *command, char **argv, int argc)
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)
@@ -2023,7 +2024,16 @@ mi_print_exception (const char *token, struct gdb_exception exception)
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 UNKNOWN_COMMAND_ERROR:
+ fputs_unfiltered (",code=\"undefined-command\"", raw_stdout);
+ break;
+ }
+
+ fputs_unfiltered ("\n", raw_stdout);
}
void
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index 9994307..3bd7400 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -285,7 +285,8 @@ mi_parse (const char *cmd, char **token)
/* 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 (UNKNOWN_COMMAND_ERROR,
+ _("Undefined MI command: %s"), parse->command);
/* Skip white space following the command. */
chp = skip_spaces_const (chp);
diff --git a/gdb/testsuite/gdb.mi/mi-undefined-cmd.exp b/gdb/testsuite/gdb.mi/mi-undefined-cmd.exp
new file mode 100644
index 0000000..8df0a76
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-undefined-cmd.exp
@@ -0,0 +1,33 @@
+# 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"
--
1.8.1.2
next prev parent reply other threads:[~2013-11-18 17:13 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-10 17:16 [RFC] Add ada-exception-catchpoints to -list-features command output Joel Brobecker
2013-11-10 22:16 ` Eli Zaretskii
2013-11-12 11:25 ` Joel Brobecker
2013-11-12 16:39 ` Eli Zaretskii
2013-11-13 3:02 ` Joel Brobecker
2013-11-11 15:22 ` Tom Tromey
2013-11-12 9:18 ` Joel Brobecker
2013-11-12 12:11 ` [RFC] New GDB/MI command "-info-gdb-mi-command" Joel Brobecker
2013-11-12 17:04 ` Eli Zaretskii
2013-11-12 17:48 ` Joel Brobecker
2013-11-12 18:34 ` Eli Zaretskii
2013-11-13 3:19 ` Joel Brobecker
2013-11-12 21:17 ` André Pönitz
2013-11-13 2:47 ` Joel Brobecker
2013-11-14 0:36 ` André Pönitz
2013-11-14 9:48 ` Joel Brobecker
2013-11-14 18:31 ` André Pönitz
2013-11-14 19:03 ` Pedro Alves
2013-11-14 19:37 ` Pedro Alves
2013-11-14 20:30 ` Tom Tromey
2013-11-15 5:35 ` Joel Brobecker
2013-11-15 12:39 ` Pedro Alves
2013-11-15 14:38 ` Joel Brobecker
2013-11-15 14:40 ` Pedro Alves
2013-11-18 17:12 ` [RFA GDB/MI] Help determine if GDB/MI command exists or not Joel Brobecker
2013-11-18 17:13 ` [RFA 1/2] New GDB/MI command "-info-gdb-mi-command" Joel Brobecker
2013-11-18 17:29 ` Eli Zaretskii
2013-11-19 4:35 ` Joel Brobecker
2013-11-19 16:11 ` Eli Zaretskii
2013-12-02 3:26 ` Joel Brobecker
2013-12-02 3:51 ` Eli Zaretskii
2013-12-02 4:41 ` Joel Brobecker
2013-12-02 14:53 ` Pedro Alves
2013-12-03 4:06 ` pushed: " Joel Brobecker
2013-11-18 17:21 ` Joel Brobecker [this message]
2013-11-18 17:29 ` [RFA 2/2] Add "undefined-command" error code at end of ^error result Eli Zaretskii
2013-11-19 6:02 ` Joel Brobecker
2013-11-19 16:16 ` Eli Zaretskii
2013-11-19 11:19 ` Pedro Alves
2013-11-20 3:46 ` Joel Brobecker
2013-12-03 4:08 ` pushed: " Joel Brobecker
2013-11-19 15:05 ` [RFA GDB/MI] Help determine if GDB/MI command exists or not Pedro Alves
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=1384794719-20594-3-git-send-email-brobecker@adacore.com \
--to=brobecker@adacore.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).