+2013-11-14 Joel Brobecker <brobecker@adacore.com>
+
+ * mi/mi-parse.h (struct mi_parse) <language>: New field.
+ * mi/mi-main.c (mi_cmd_execute): Temporarily set language to
+ PARSE->LANGUAGE during command execution, if set.
+ * mi/mi-parse.c: Add "language.h" #include.
+ (mi_parse): Add parsing of "--language" command option.
+
+ * NEWS: Add entry mentioning the new "--language" command option.
+
2013-11-14 Pedro Alves <palves@redhat.com>
Joel Brobecker <brobecker@adacore.com>
* MI changes
+ ** All MI commands now accept an optional "--language" option.
+
** The -trace-save MI command can optionally save trace buffer in Common
Trace Format now.
+2013-11-14 Joel Brobecker <brobecker@adacore.com>
+
+ * gdb.texinfo (Show): Add xref anchor for "show language" command.
+ (Context management): Place current subsection text into its own
+ subsubsection. Add new subsubsection describing the "--language"
+ command option.
+
2013-11-13 Joel Brobecker <brobecker@adacore.com>
* gdb.texinfo (GDB/MI Miscellaneous Commands): Delete
@table @code
@item show language
+@anchor{show language}
@kindex show language
Display the current working language. This is the
language you can use with commands such as @code{print} to
@node Context management
@subsection Context management
+@subsubsection Threads and Frames
+
In most cases when @value{GDBN} accesses the target, this access is
done in context of a specific thread and frame (@pxref{Frames}).
Often, even when accessing global data, the target requires that a thread
right, so it is suggested to just always pass the @samp{--thread} and
@samp{--frame} options.
+@subsubsection Language
+
+The execution of several commands depends on which language is selected.
+By default, the current language (@pxref{show language}) is used.
+But for commands known to be language-sensitive, it is recommended
+to use the @samp{--language} option. This option takes one argument,
+which is the name of the language to use while executing the command.
+For instance:
+
+@smallexample
+-data-evaluate-expression --language c "sizeof (void*)"
+^done,value="4"
+(gdb)
+@end smallexample
+
+The valid language names are the same names accepted by the
+@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
+@samp{local} or @samp{unknown}.
+
@node Asynchronous and non-stop modes
@subsection Asynchronous command execution and non-stop mode
mi_cmd_execute (struct mi_parse *parse)
{
struct cleanup *cleanup;
+ enum language saved_language;
cleanup = prepare_execute_command ();
error (_("Invalid frame id: %d"), frame);
}
+ if (parse->language != language_unknown)
+ {
+ make_cleanup_restore_current_language ();
+ set_language (parse->language);
+ }
+
current_context = parse;
if (parse->cmd->suppress_notification != NULL)
#include <ctype.h>
#include "gdb_string.h"
#include "cli/cli-utils.h"
+#include "language.h"
static const char mi_no_values[] = "--no-values";
static const char mi_simple_values[] = "--simple-values";
parse->thread_group = -1;
parse->thread = -1;
parse->frame = -1;
+ parse->language = language_unknown;
cleanup = make_cleanup (mi_parse_cleanup, parse);
some important commands, like '-break-*' are implemented by
forwarding to the CLI layer directly. We want to parse --thread
and --frame here, so as not to leave those option in the string
- that will be passed to CLI. */
+ that will be passed to CLI.
+
+ Same for the --language option. */
+
for (;;)
{
const char *option;
size_t tgs = sizeof ("--thread-group ") - 1;
size_t ts = sizeof ("--thread ") - 1;
size_t fs = sizeof ("--frame ") - 1;
+ size_t ls = sizeof ("--language ") - 1;
if (strncmp (chp, "--all ", as) == 0)
{
parse->frame = strtol (chp, &endp, 10);
chp = endp;
}
+ else if (strncmp (chp, "--language ", ls) == 0)
+ {
+ char *lang_name;
+ struct cleanup *old_chain;
+
+ option = "--language";
+ chp += ls;
+ lang_name = extract_arg_const (&chp);
+ old_chain = make_cleanup (xfree, lang_name);
+
+ parse->language = language_enum (lang_name);
+ if (parse->language == language_unknown
+ || parse->language == language_auto)
+ error (_("Invalid --language argument: %s"), lang_name);
+
+ do_cleanups (old_chain);
+ }
else
break;
int thread_group; /* At present, the same as inferior number. */
int thread;
int frame;
+
+ /* The language that should be used to evaluate the MI command.
+ Ignored if set to language_unknown. */
+ enum language language;
};
/* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is
+2013-11-14 Joel Brobecker <brobecker@adacore.com>
+
+ * gdb.mi/mi-language.exp: New file.
+
2013-09-17 Keith Seitz <keiths@redhat.com>
PR c++/7935
--- /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
+}
+
+mi_gdb_test "set lang ada" \
+ ".*=cmd-param-changed,param=\"language\",value=\"ada\".*" \
+ "set lang ada"
+
+# Evaluate an expression that the Ada language is unable to parse.
+mi_gdb_test "-data-evaluate-expression \"sizeof (void*)\"" \
+ "\\^error,.*" \
+ "sizeof expression using current language"
+
+# Now, ask for the same expression to be parsed, but using the C
+# language.
+mi_gdb_test "-data-evaluate-expression --language c \"sizeof (void*)\"" \
+ "\\^done,value=\"$decimal\"" \
+ "sizeof expression using C language"
+
+# Double-check that the current language has not changed.
+mi_gdb_test "show lang ada" \
+ ".*The current source language is \\\\\"ada\\\\\".*" \
+ "set lang ada"
+
+# Test what happens when specifying an invalid language name...
+mi_gdb_test "-data-evaluate-expression --language invlang \"sizeof (void*)\"" \
+ "\\^error,msg=\"Invalid --language argument: invlang\"" \
+ "data-evaluate-expression with invalid language name"
+
+# Make sure that "--language auto" is also rejected.
+mi_gdb_test "-data-evaluate-expression --language auto \"sizeof (void*)\"" \
+ "\\^error,msg=\"Invalid --language argument: auto\"" \
+ "data-evaluate-expression with language auto"
+
+# Make sure that "--language local" is also rejected.
+mi_gdb_test "-data-evaluate-expression --language local \"sizeof (void*)\"" \
+ "\\^error,msg=\"Invalid --language argument: local\"" \
+ "data-evaluate-expression with language local"
+
+# Make sure that "--language unknown" is also rejected.
+mi_gdb_test "-data-evaluate-expression --language unknown \"sizeof (void*)\"" \
+ "\\^error,msg=\"Invalid --language argument: unknown\"" \
+ "data-evaluate-expression with language unknown"