old-cross-binutils/gdb/testsuite/gdb.mi/mi-language.exp

69 lines
2.8 KiB
Text
Raw Normal View History

# Copyright 2013-2014 Free Software Foundation, Inc.
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.
2013-11-11 05:21:44 +00:00
# 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 --language option.
mi_gdb_test "-list-features" \
"\\^done,features=\\\[.*\"language-option\".*\\\]" \
"-list-features should include \"language-option\""
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.
2013-11-11 05:21:44 +00:00
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"