gdb/testsuite: make gdb_supported_languages a caching proc
Commit Message
Rewrite gdb_supported_languages as a caching proc that actually
queries GDB for the list of supported languages, rather than just
containing a hard-coded list of languages.
There's only one test that uses this proc right now,
gdb.python/py-function.exp, and that still passes after this change,
with no changes in the test names.
---
gdb/testsuite/lib/gdb.exp | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
base-commit: a02fcd08ddc5080696248ed7fb4bf50a24763431
Comments
On 5/12/23 06:00, Andrew Burgess via Gdb-patches wrote:
> Rewrite gdb_supported_languages as a caching proc that actually
> queries GDB for the list of supported languages, rather than just
> containing a hard-coded list of languages.
>
> There's only one test that uses this proc right now,
> gdb.python/py-function.exp, and that still passes after this change,
> with no changes in the test names.
> ---
> gdb/testsuite/lib/gdb.exp | 27 ++++++++++++++++++++++-----
> 1 file changed, 22 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 010da097766..52af0c7358f 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -8591,11 +8591,28 @@ proc cd { dir } {
> }
>
> # Return a list of all languages supported by GDB, suitable for use in
> -# 'set language NAME'. This doesn't include either the 'local' or
> -# 'auto' keywords.
> -proc gdb_supported_languages {} {
> - return [list c objective-c c++ d go fortran modula-2 asm pascal \
> - opencl rust minimal ada]
> +# 'set language NAME'. This doesn't include the languages auto,
> +# local, or unknown.
> +gdb_caching_proc gdb_supported_languages {} {
> + # The extra space after 'complete set language ' in the command below is
> + # critical. Only with that space will GDB complete the next level of
> + # the command, i.e. fill in the actual language names.
> + set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS -batch -ex \"complete set language \""]
> +
> + set langs {}
> + if {[lindex $output 0] == 0} {
Maybe error out if the exit status is not 0?
Otherwise:
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
Simon Marchi <simark@simark.ca> writes:
> On 5/12/23 06:00, Andrew Burgess via Gdb-patches wrote:
>> Rewrite gdb_supported_languages as a caching proc that actually
>> queries GDB for the list of supported languages, rather than just
>> containing a hard-coded list of languages.
>>
>> There's only one test that uses this proc right now,
>> gdb.python/py-function.exp, and that still passes after this change,
>> with no changes in the test names.
>> ---
>> gdb/testsuite/lib/gdb.exp | 27 ++++++++++++++++++++++-----
>> 1 file changed, 22 insertions(+), 5 deletions(-)
>>
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 010da097766..52af0c7358f 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -8591,11 +8591,28 @@ proc cd { dir } {
>> }
>>
>> # Return a list of all languages supported by GDB, suitable for use in
>> -# 'set language NAME'. This doesn't include either the 'local' or
>> -# 'auto' keywords.
>> -proc gdb_supported_languages {} {
>> - return [list c objective-c c++ d go fortran modula-2 asm pascal \
>> - opencl rust minimal ada]
>> +# 'set language NAME'. This doesn't include the languages auto,
>> +# local, or unknown.
>> +gdb_caching_proc gdb_supported_languages {} {
>> + # The extra space after 'complete set language ' in the command below is
>> + # critical. Only with that space will GDB complete the next level of
>> + # the command, i.e. fill in the actual language names.
>> + set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS -batch -ex \"complete set language \""]
>> +
>> + set langs {}
>> + if {[lindex $output 0] == 0} {
>
> Maybe error out if the exit status is not 0?
Done.
>
> Otherwise:
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Pushed.
Thanks,
Andrew
>
> Simon
@@ -8591,11 +8591,28 @@ proc cd { dir } {
}
# Return a list of all languages supported by GDB, suitable for use in
-# 'set language NAME'. This doesn't include either the 'local' or
-# 'auto' keywords.
-proc gdb_supported_languages {} {
- return [list c objective-c c++ d go fortran modula-2 asm pascal \
- opencl rust minimal ada]
+# 'set language NAME'. This doesn't include the languages auto,
+# local, or unknown.
+gdb_caching_proc gdb_supported_languages {} {
+ # The extra space after 'complete set language ' in the command below is
+ # critical. Only with that space will GDB complete the next level of
+ # the command, i.e. fill in the actual language names.
+ set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS -batch -ex \"complete set language \""]
+
+ set langs {}
+ if {[lindex $output 0] == 0} {
+ foreach line [split [lindex $output 1] \n] {
+ if {[regexp "set language (\[^\r\]+)" $line full_match lang]} {
+ # If LANG is not one of the languages that we ignore, then
+ # add it to our list of languages.
+ if {[lsearch -exact {auto local unknown} $lang] == -1} {
+ lappend langs $lang
+ }
+ }
+ }
+ }
+
+ return $langs
}
# Check if debugging is enabled for gdb.