diff options
author | Joel Brobecker <brobecker@adacore.com> | 2013-11-11 09:21:44 +0400 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2013-11-14 14:36:18 +0400 |
commit | 403cb6b138c38faf72f7abc034db3505b9bdb82f (patch) | |
tree | 9ece00d8fc7c36bff6838939d9f7f18063cbf14b /gdb/mi | |
parent | b5be8ce022f894831b133b3b424238d8058eb29e (diff) | |
download | gdb-403cb6b138c38faf72f7abc034db3505b9bdb82f.zip gdb-403cb6b138c38faf72f7abc034db3505b9bdb82f.tar.gz gdb-403cb6b138c38faf72f7abc034db3505b9bdb82f.tar.bz2 |
GDB/MI: Add new "--language LANG" command option.
Frontend sometimes need to evaluate expressions that are
language-specific. For instance, Eclipse uses the following
expression to determine the size of an address on the target:
-data-evaluate-expression "sizeof (void*)"
Unfortunately, if the main of the program being debugged is not C,
this may not work. For instance, if the main is in Ada, you get...
-data-evaluate-expression "sizeof (void*)"
^error,msg="No definition of \"sizeof\" in current context."
... and apparently decides to stop the debugging session as a result.
The recommendation sent was to specifically set the language to C
before trying to evaluate the expression. Something such as:
1. save current language
2. set language c
3. -data-evaluate-expression "sizeof (void*)"
4. Restore language
This has the same disadvantages as the ones outlined in the "Context
Management" section of the GDB/MI documentation regarding setting
the current thread or the current frame, thus recommending the use of
general command-line switches such as --frame, or --thread instead.
This patch follows the same steps for the language, adding a similar
new command option: --language LANG. Example of use:
-data-evaluate-expression --language c "sizeof (void*)"
^done,value="4"
gdb/ChangeLog:
* 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.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-language.exp: New file.
gdb/doc/ChangeLog:
* 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.
Diffstat (limited to 'gdb/mi')
-rw-r--r-- | gdb/mi/mi-main.c | 7 | ||||
-rw-r--r-- | gdb/mi/mi-parse.c | 25 | ||||
-rw-r--r-- | gdb/mi/mi-parse.h | 4 |
3 files changed, 35 insertions, 1 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index c3f7221..bbf944a 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2122,6 +2122,7 @@ static void mi_cmd_execute (struct mi_parse *parse) { struct cleanup *cleanup; + enum language saved_language; cleanup = prepare_execute_command (); @@ -2183,6 +2184,12 @@ mi_cmd_execute (struct mi_parse *parse) 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) diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c index a3c1849..9994307 100644 --- a/gdb/mi/mi-parse.c +++ b/gdb/mi/mi-parse.c @@ -27,6 +27,7 @@ #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"; @@ -244,6 +245,7 @@ mi_parse (const char *cmd, char **token) parse->thread_group = -1; parse->thread = -1; parse->frame = -1; + parse->language = language_unknown; cleanup = make_cleanup (mi_parse_cleanup, parse); @@ -292,7 +294,10 @@ mi_parse (const char *cmd, char **token) 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; @@ -300,6 +305,7 @@ mi_parse (const char *cmd, char **token) 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) { @@ -348,6 +354,23 @@ mi_parse (const char *cmd, char **token) 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; diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h index b20a389..325c1e1 100644 --- a/gdb/mi/mi-parse.h +++ b/gdb/mi/mi-parse.h @@ -50,6 +50,10 @@ struct mi_parse 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 |