[PATCH v4 3/9] tests/functional: Provide GDB to the functional tests

Gustavo Romero posted 9 patches 2 days, 10 hours ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Thomas Huth <thuth@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Zhao Liu <zhao1.liu@intel.com>
[PATCH v4 3/9] tests/functional: Provide GDB to the functional tests
Posted by Gustavo Romero 2 days, 10 hours ago
The probe of GDB is done in 'configure' and the full path is passed to
meson.build via the -Dgdb=option.

Because a single functional test can cover different arches, such as
aarch64, ppc64, and x86_64, only a GDB that supports all the arches in
the target list is passed to Meson for use in the functional tests. To
handle this check, a new shell function, is_target_arch_in_arch_list, is
introduced in 'configure'.

Meson then can pass the location of GDB to the test via an environment
variable: QEMU_TEST_GDB.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 configure                     | 21 +++++++++++++++++++++
 meson_options.txt             |  2 ++
 scripts/meson-buildoptions.sh |  2 ++
 tests/functional/meson.build  |  6 ++++++
 4 files changed, 31 insertions(+)

diff --git a/configure b/configure
index 0f7eb95586..20e05d233f 100755
--- a/configure
+++ b/configure
@@ -1142,12 +1142,31 @@ fi
 #########################################
 # gdb test
 
+# Check if all target arches are in a provided list of arches.
+is_target_arch_in_arch_list() {
+    arch_list=$1
+    for target in $target_list; do
+        arch=${target%%-*}
+        if test "${arch_list#*$arch}" = "$arch_list"; then
+            # Target arch not in arch list
+            return 1
+        fi
+    done
+    return 0
+}
+
 if test -n "$gdb_bin"; then
     gdb_version_string=$($gdb_bin --version | head -n 1)
     # Extract last field in the version string
     gdb_version=${gdb_version_string##* }
     if version_ge $gdb_version 9.1; then
         gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
+
+	if is_target_arch_in_arch_list "$gdb_arches"; then
+            gdb_multiarch="yes"
+        else
+            gdb_multiarch=""
+	fi
     else
         gdb_bin=""
     fi
@@ -1984,6 +2003,8 @@ if test "$skip_meson" = no; then
   test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
   test "$plugins" = yes && meson_option_add "-Dplugins=true"
   test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
+  test "$gdb_multiarch" = yes && meson_option_add "-Dgdb=$gdb_bin"
+
   run_meson() {
     NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
   }
diff --git a/meson_options.txt b/meson_options.txt
index fff1521e58..5bb41bcbc4 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -36,6 +36,8 @@ option('trace_file', type: 'string', value: 'trace',
 option('coroutine_backend', type: 'combo',
        choices: ['ucontext', 'sigaltstack', 'windows', 'wasm', 'auto'],
        value: 'auto', description: 'coroutine backend to use')
+option('gdb', type: 'string', value: '',
+       description: 'Path to GDB')
 
 # Everything else can be set via --enable/--disable-* option
 # on the configure script command line.  After adding an option
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 0ebe6bc52a..f4bd21220e 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -58,6 +58,7 @@ meson_options_help() {
   printf "%s\n" '  --enable-ubsan           enable undefined behaviour sanitizer'
   printf "%s\n" '  --firmwarepath=VALUES    search PATH for firmware files [share/qemu-'
   printf "%s\n" '                           firmware]'
+  printf "%s\n" '  --gdb=VALUE              Path to GDB'
   printf "%s\n" '  --iasl=VALUE             Path to ACPI disassembler'
   printf "%s\n" '  --includedir=VALUE       Header file directory [include]'
   printf "%s\n" '  --interp-prefix=VALUE    where to find shared libraries etc., use %M for'
@@ -323,6 +324,7 @@ _meson_option_parse() {
     --disable-fuzzing) printf "%s" -Dfuzzing=false ;;
     --enable-gcrypt) printf "%s" -Dgcrypt=enabled ;;
     --disable-gcrypt) printf "%s" -Dgcrypt=disabled ;;
+    --gdb=*) quote_sh "-Dgdb=$2" ;;
     --enable-gettext) printf "%s" -Dgettext=enabled ;;
     --disable-gettext) printf "%s" -Dgettext=disabled ;;
     --enable-gio) printf "%s" -Dgio=enabled ;;
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 2a0c5aa141..725630d308 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -77,6 +77,12 @@ foreach speed : ['quick', 'thorough']
     test_env.set('PYTHONPATH', meson.project_source_root() / 'python:' +
                                meson.current_source_dir())
 
+    # Define the GDB environment variable if gdb is available.
+    gdb = get_option('gdb')
+    if gdb != ''
+      test_env.set('QEMU_TEST_GDB', gdb)
+    endif
+
     foreach test : target_tests
       testname = '@0@-@1@'.format(target_base, test)
       if fs.exists('generic' / 'test_' + test + '.py')
-- 
2.34.1
Re: [PATCH v4 3/9] tests/functional: Provide GDB to the functional tests
Posted by Thomas Huth 2 days, 5 hours ago
On 26/09/2025 07.15, Gustavo Romero wrote:
> The probe of GDB is done in 'configure' and the full path is passed to
> meson.build via the -Dgdb=option.
> 
> Because a single functional test can cover different arches, such as
> aarch64, ppc64, and x86_64, only a GDB that supports all the arches in
> the target list is passed to Meson for use in the functional tests. To
> handle this check, a new shell function, is_target_arch_in_arch_list, is
> introduced in 'configure'.
> 
> Meson then can pass the location of GDB to the test via an environment
> variable: QEMU_TEST_GDB.
> 
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   configure                     | 21 +++++++++++++++++++++
>   meson_options.txt             |  2 ++
>   scripts/meson-buildoptions.sh |  2 ++
>   tests/functional/meson.build  |  6 ++++++
>   4 files changed, 31 insertions(+)
> 
> diff --git a/configure b/configure
> index 0f7eb95586..20e05d233f 100755
> --- a/configure
> +++ b/configure
> @@ -1142,12 +1142,31 @@ fi
>   #########################################
>   # gdb test
>   
> +# Check if all target arches are in a provided list of arches.
> +is_target_arch_in_arch_list() {
> +    arch_list=$1
> +    for target in $target_list; do
> +        arch=${target%%-*}
> +        if test "${arch_list#*$arch}" = "$arch_list"; then
> +            # Target arch not in arch list
> +            return 1
> +        fi
> +    done
> +    return 0
> +}
> +
>   if test -n "$gdb_bin"; then
>       gdb_version_string=$($gdb_bin --version | head -n 1)
>       # Extract last field in the version string
>       gdb_version=${gdb_version_string##* }
>       if version_ge $gdb_version 9.1; then
>           gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
> +
> +	if is_target_arch_in_arch_list "$gdb_arches"; then

No TABs, please!

> +            gdb_multiarch="yes"
> +        else
> +            gdb_multiarch=""
> +	fi

This unfortunately does not work with the GDB from Fedora - it only supports 
"arch64_be arm riscv64 riscv32 ppc i386 s390x ppc64 aarch64 ppc64le x86_64", 
but if you configured a target like "alpha-softmmu", this breaks.
(BTW, does the gdb-multiarch from Debian/Ubuntu really also support exotic 
QEMU targets like tricore?)

I think it would be better to drop this hunk, and rather check in the spot 
where we use GDB if the required target is really there (i.e. in the 
functional test that uses it).

  Thomas
Re: [PATCH v4 3/9] tests/functional: Provide GDB to the functional tests
Posted by Gustavo Romero 1 day, 21 hours ago
Hi Thomas,

On 9/26/25 07:03, Thomas Huth wrote:
> On 26/09/2025 07.15, Gustavo Romero wrote:
>> The probe of GDB is done in 'configure' and the full path is passed to
>> meson.build via the -Dgdb=option.
>>
>> Because a single functional test can cover different arches, such as
>> aarch64, ppc64, and x86_64, only a GDB that supports all the arches in
>> the target list is passed to Meson for use in the functional tests. To
>> handle this check, a new shell function, is_target_arch_in_arch_list, is
>> introduced in 'configure'.
>>
>> Meson then can pass the location of GDB to the test via an environment
>> variable: QEMU_TEST_GDB.
>>
>> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   configure                     | 21 +++++++++++++++++++++
>>   meson_options.txt             |  2 ++
>>   scripts/meson-buildoptions.sh |  2 ++
>>   tests/functional/meson.build  |  6 ++++++
>>   4 files changed, 31 insertions(+)
>>
>> diff --git a/configure b/configure
>> index 0f7eb95586..20e05d233f 100755
>> --- a/configure
>> +++ b/configure
>> @@ -1142,12 +1142,31 @@ fi
>>   #########################################
>>   # gdb test
>> +# Check if all target arches are in a provided list of arches.
>> +is_target_arch_in_arch_list() {
>> +    arch_list=$1
>> +    for target in $target_list; do
>> +        arch=${target%%-*}
>> +        if test "${arch_list#*$arch}" = "$arch_list"; then
>> +            # Target arch not in arch list
>> +            return 1
>> +        fi
>> +    done
>> +    return 0
>> +}
>> +
>>   if test -n "$gdb_bin"; then
>>       gdb_version_string=$($gdb_bin --version | head -n 1)
>>       # Extract last field in the version string
>>       gdb_version=${gdb_version_string##* }
>>       if version_ge $gdb_version 9.1; then
>>           gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
>> +
>> +    if is_target_arch_in_arch_list "$gdb_arches"; then
> 
> No TABs, please!
> 
>> +            gdb_multiarch="yes"
>> +        else
>> +            gdb_multiarch=""
>> +    fi
> 
> This unfortunately does not work with the GDB from Fedora - it only supports "arch64_be arm riscv64 riscv32 ppc i386 s390x ppc64 aarch64 ppc64le x86_64", but if you configured a target like "alpha-softmmu", this breaks.

argh! ok


> (BTW, does the gdb-multiarch from Debian/Ubuntu really also support exotic QEMU targets like tricore?)

No, I've checked GDB upstream and I can't see any trace of tricore.
And I just saw that Alex left a comment in scripts/probe-gdb-support.py
saying "# no tricore in upstream gdb", so nope, it seems that it still holds.


> I think it would be better to drop this hunk, and rather check in the spot where we use GDB if the required target is really there (i.e. in the functional test that uses it).

OK. I'm also not a big fan of doing it in bash. How do you suggest
to do it? Directly in the code, via a skipIf decorator, or something else?


Cheers,
Gustavo

Re: [PATCH v4 3/9] tests/functional: Provide GDB to the functional tests
Posted by Gustavo Romero 1 day, 21 hours ago
Hi Thomas,

On 9/26/25 15:08, Gustavo Romero wrote:
> Hi Thomas,
> 
> On 9/26/25 07:03, Thomas Huth wrote:
>> On 26/09/2025 07.15, Gustavo Romero wrote:
>>> The probe of GDB is done in 'configure' and the full path is passed to
>>> meson.build via the -Dgdb=option.
>>>
>>> Because a single functional test can cover different arches, such as
>>> aarch64, ppc64, and x86_64, only a GDB that supports all the arches in
>>> the target list is passed to Meson for use in the functional tests. To
>>> handle this check, a new shell function, is_target_arch_in_arch_list, is
>>> introduced in 'configure'.
>>>
>>> Meson then can pass the location of GDB to the test via an environment
>>> variable: QEMU_TEST_GDB.
>>>
>>> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> ---
>>>   configure                     | 21 +++++++++++++++++++++
>>>   meson_options.txt             |  2 ++
>>>   scripts/meson-buildoptions.sh |  2 ++
>>>   tests/functional/meson.build  |  6 ++++++
>>>   4 files changed, 31 insertions(+)
>>>
>>> diff --git a/configure b/configure
>>> index 0f7eb95586..20e05d233f 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -1142,12 +1142,31 @@ fi
>>>   #########################################
>>>   # gdb test
>>> +# Check if all target arches are in a provided list of arches.
>>> +is_target_arch_in_arch_list() {
>>> +    arch_list=$1
>>> +    for target in $target_list; do
>>> +        arch=${target%%-*}
>>> +        if test "${arch_list#*$arch}" = "$arch_list"; then
>>> +            # Target arch not in arch list
>>> +            return 1
>>> +        fi
>>> +    done
>>> +    return 0
>>> +}
>>> +
>>>   if test -n "$gdb_bin"; then
>>>       gdb_version_string=$($gdb_bin --version | head -n 1)
>>>       # Extract last field in the version string
>>>       gdb_version=${gdb_version_string##* }
>>>       if version_ge $gdb_version 9.1; then
>>>           gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
>>> +
>>> +    if is_target_arch_in_arch_list "$gdb_arches"; then
>>
>> No TABs, please!
>>
>>> +            gdb_multiarch="yes"
>>> +        else
>>> +            gdb_multiarch=""
>>> +    fi
>>
>> This unfortunately does not work with the GDB from Fedora - it only supports "arch64_be arm riscv64 riscv32 ppc i386 s390x ppc64 aarch64 ppc64le x86_64", but if you configured a target like "alpha-softmmu", this breaks.
> 
> argh! ok
> 
> 
>> (BTW, does the gdb-multiarch from Debian/Ubuntu really also support exotic QEMU targets like tricore?)
> 
> No, I've checked GDB upstream and I can't see any trace of tricore.
> And I just saw that Alex left a comment in scripts/probe-gdb-support.py
> saying "# no tricore in upstream gdb", so nope, it seems that it still holds.
> 
> 
>> I think it would be better to drop this hunk, and rather check in the spot where we use GDB if the required target is really there (i.e. in the functional test that uses it).
> 
> OK. I'm also not a big fan of doing it in bash. How do you suggest
> to do it? Directly in the code, via a skipIf decorator, or something else?

$gdb_arches, obtained using scripts/probe-gdb-support.py in configure,
could be passed to meson and meson sets it in the test env, as we're
doing for $gdb_bin and QEMU_TEST_GDB env var. wdyt?


Cheers,
Gustavo