diff options
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.ada/array_of_variant.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/gstack.exp | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp | 148 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/set-solib-absolute-prefix.c | 32 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp | 51 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/shlib-unload.exp | 69 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-dprintf-modified-lib.c | 22 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-dprintf-modified.c | 55 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-dprintf-modified.exp | 119 | ||||
-rw-r--r-- | gdb/testsuite/gdb.testsuite/version-compare.exp | 74 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/access-mem-running-thread-exit.c | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp | 10 | ||||
-rw-r--r-- | gdb/testsuite/lib/ada.exp | 10 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb-utils.exp | 5 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 15 |
15 files changed, 539 insertions, 86 deletions
diff --git a/gdb/testsuite/gdb.ada/array_of_variant.exp b/gdb/testsuite/gdb.ada/array_of_variant.exp index 8b83f4e..83b626c 100644 --- a/gdb/testsuite/gdb.ada/array_of_variant.exp +++ b/gdb/testsuite/gdb.ada/array_of_variant.exp @@ -20,7 +20,7 @@ require allow_ada_tests standard_ada_testfile p -set old_gcc [gnat_version_compare <= 7] +set old_gcc [gnat_version_compare < 8] proc gdb_test_with_xfail { cmd re re_xfail msg } { global scenario old_gcc diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp index 8df36b1..89be676 100644 --- a/gdb/testsuite/gdb.base/gstack.exp +++ b/gdb/testsuite/gdb.base/gstack.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2024 Free Software Foundation, Inc. +# Copyright (C) 2024-2025 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 @@ -62,8 +62,10 @@ if { ![gdb_assert { ![expr {$res < 0 || $res == ""}] } $test] } { set test "got backtrace" set saw_backtrace false set no_awk false +set location_re ${srcfile}:${decimal} + gdb_expect { - -i "$res" -re "#0 +(0x\[0-9a-f\]+ in )?main \(\).*\r\nGSTACK-END\r\n\$" { + -i "$res" -re "#0 +(0x\[0-9a-f\]+ in )?main \(\).*$location_re.*\r\nGSTACK-END\r\n\$" { set saw_backtrace true pass $test exp_continue diff --git a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp index 45086f6..46561a9 100644 --- a/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp +++ b/gdb/testsuite/gdb.base/inline-frame-cycle-unwind.exp @@ -72,77 +72,89 @@ gdb_continue_to_breakpoint "stop at test breakpoint" gdb_test_no_output "source ${pyfile}"\ "import python scripts" -# Check the unbroken stack. -gdb_test_sequence "bt" "backtrace when the unwind is left unbroken" { - "\\r\\n#0 \[^\r\n\]* inline_func \\(\\) at " - "\\r\\n#1 \[^\r\n\]* normal_func \\(\\) at " - "\\r\\n#2 \[^\r\n\]* inline_func \\(\\) at " - "\\r\\n#3 \[^\r\n\]* normal_func \\(\\) at " - "\\r\\n#4 \[^\r\n\]* inline_func \\(\\) at " - "\\r\\n#5 \[^\r\n\]* normal_func \\(\\) at " - "\\r\\n#6 \[^\r\n\]* main \\(\\) at " -} +# Test with and without filters. +foreach bt_cmd { "bt" "bt -no-filters" } { + with_test_prefix "$bt_cmd" { -with_test_prefix "cycle at level 5" { - # Arrange to introduce a stack cycle at frame 5. - gdb_test_no_output "python stop_at_level=5" - gdb_test "maint flush register-cache" \ - "Register cache flushed\\." - gdb_test_lines "bt" "backtrace when the unwind is broken at frame 5" \ - [multi_line \ - "#0 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ - "#1 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ - "#2 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ - "#3 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ - "#4 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ - "#5 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ - "Backtrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)"] -} + # Check the unbroken stack. + gdb_test_sequence "$bt_cmd" "backtrace when the unwind is left unbroken" { + "\\r\\n#0 \[^\r\n\]* inline_func \\(\\) at " + "\\r\\n#1 \[^\r\n\]* normal_func \\(\\) at " + "\\r\\n#2 \[^\r\n\]* inline_func \\(\\) at " + "\\r\\n#3 \[^\r\n\]* normal_func \\(\\) at " + "\\r\\n#4 \[^\r\n\]* inline_func \\(\\) at " + "\\r\\n#5 \[^\r\n\]* normal_func \\(\\) at " + "\\r\\n#6 \[^\r\n\]* main \\(\\) at " + } -with_test_prefix "cycle at level 3" { - # Arrange to introduce a stack cycle at frame 3. - gdb_test_no_output "python stop_at_level=3" - gdb_test "maint flush register-cache" \ - "Register cache flushed\\." - gdb_test_lines "bt" "backtrace when the unwind is broken at frame 3" \ - [multi_line \ - "#0 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ - "#1 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ - "#2 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ - "#3 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ - "Backtrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)"] -} + with_test_prefix "cycle at level 5" { + # Arrange to introduce a stack cycle at frame 5. + gdb_test_no_output "python stop_at_level=5" + gdb_test "maint flush register-cache" \ + "Register cache flushed\\." + gdb_test_lines "$bt_cmd" "backtrace when the unwind is broken at frame 5" \ + [multi_line \ + "#0 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ + "#1 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ + "#2 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ + "#3 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ + "#4 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ + "#5 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ + "Backtrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)"] + } -with_test_prefix "cycle at level 1" { - # Arrange to introduce a stack cycle at frame 1. - gdb_test_no_output "python stop_at_level=1" - gdb_test "maint flush register-cache" \ - "Register cache flushed\\." - gdb_test_lines "bt" "backtrace when the unwind is broken at frame 1" \ - [multi_line \ - "#0 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ - "#1 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ - "Backtrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)"] -} + with_test_prefix "cycle at level 3" { + # Arrange to introduce a stack cycle at frame 3. + gdb_test_no_output "python stop_at_level=3" + gdb_test "maint flush register-cache" \ + "Register cache flushed\\." + gdb_test_lines "$bt_cmd" "backtrace when the unwind is broken at frame 3" \ + [multi_line \ + "#0 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ + "#1 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ + "#2 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ + "#3 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ + "Backtrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)"] + } -# Flush the register cache (which also flushes the frame cache) so we -# get a full backtrace again, then switch on frame debugging and try -# to back trace. At one point this triggered an assertion. -gdb_test "maint flush register-cache" \ - "Register cache flushed\\." "" -gdb_test_no_output "set debug frame 1" -set ok 1 -gdb_test_multiple "bt" "backtrace with debugging on" { - -re "^$gdb_prompt $" { - gdb_assert { $ok } $gdb_test_name - } - -re "Python Exception <class 'gdb.error'>: \[^\r\n\]*\r\n" { - set ok 0 - exp_continue - } - -re "\[^\r\n\]+\r\n" { - exp_continue + with_test_prefix "cycle at level 1" { + # Arrange to introduce a stack cycle at frame 1. + gdb_test_no_output "python stop_at_level=1" + gdb_test "maint flush register-cache" \ + "Register cache flushed\\." + gdb_test_lines "$bt_cmd" "backtrace when the unwind is broken at frame 1" \ + [multi_line \ + "#0 \[^\r\n\]* inline_func \\(\\) at \[^\r\n\]+" \ + "#1 \[^\r\n\]* normal_func \\(\\) at \[^\r\n\]+" \ + "Backtrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)"] + } + + # Flush the register cache (which also flushes the frame cache) so we + # get a full backtrace again, then switch on frame debugging and try + # to back trace. At one point this triggered an assertion. + gdb_test "maint flush register-cache" \ + "Register cache flushed\\." "" + gdb_test_no_output "set debug frame 1" + set ok 1 + gdb_test_multiple "$bt_cmd" "backtrace with debugging on" { + -re "^$gdb_prompt $" { + gdb_assert { $ok } $gdb_test_name + } + -re "Python Exception <class 'gdb.error'>: \[^\r\n\]*\r\n" { + set ok 0 + exp_continue + } + -re "\[^\r\n\]+\r\n" { + exp_continue + } + } + gdb_test "p 1 + 2 + 3" " = 6" \ + "ensure GDB is still alive" + + # Prepare for the next iteration of the test loop + gdb_test_no_output "set debug frame 0" + gdb_test_no_output "python stop_at_level=None" + gdb_test "maint flush register-cache" \ + "Register cache flushed\\." "maint flush register-cache at (loop end)" } } -gdb_test "p 1 + 2 + 3" " = 6" \ - "ensure GDB is still alive" diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c new file mode 100644 index 0000000..685a22e --- /dev/null +++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2012-2025 Free Software Foundation, Inc. + + This file is part of GDB. + + 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/>. */ + +#include <stdlib.h> + +/* Global var used to generate filler code. */ +volatile int global_var = 0; + +int +main () +{ + global_var++; + global_var++; + + abort (); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp new file mode 100644 index 0000000..cf74789 --- /dev/null +++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp @@ -0,0 +1,51 @@ +# Copyright 2012-2025 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/>. +# +# Compile a 32-bit x86 executable and then stop within a system call. +# Change the sysroot to a non-existent directory, GDB should try (and +# fail) to reload the currently loaded shared libraries. However, GDB +# should retain the symbols for the vDSO library as that is not loaded +# from the file system. +# +# Check the backtrace to ensure that the __kernel_vsyscall symbol is +# still in the backtrace, this indicates GDB still has the vDSO +# symbols available. + +require {is_any_target "i?86-*-linux*" "x86_64-*-linux*"} +standard_testfile + +# The binary must be compiled as 32-bit so that the system call +# `__kernel_vsyscall' originates from vDSO. +set flags { debug } +if { ![is_ilp32_target] } { + lappend flags "additional_flags=-m32" +} + +if { [prepare_for_testing $testfile.exp $testfile $srcfile $flags] } { + return +} + +if { ![runto_main] } { + return +} + +set non_existing_directory [standard_output_file "BOGUS"] + +gdb_test "continue" "Program received signal SIGABRT, Aborted.*" \ + "continue until abort" +gdb_test "set sysroot $non_existing_directory" \ + ".*warning: Unable to find dynamic linker breakpoint function.*" \ + "set sysroot" +gdb_test "bt" "__kernel_vsyscall.*" "backtrace with __kernel_vsyscall" diff --git a/gdb/testsuite/gdb.base/shlib-unload.exp b/gdb/testsuite/gdb.base/shlib-unload.exp index f3e8cce..9d47416 100644 --- a/gdb/testsuite/gdb.base/shlib-unload.exp +++ b/gdb/testsuite/gdb.base/shlib-unload.exp @@ -225,6 +225,75 @@ proc_with_prefix test_dprintf_with_rerun {} { "dprintf is non-pending after restart" } +# Check that we see breakpoint modified events (where appropriate) +# when the 'nosharedlibrary' command is used to unload all shared +# libraries. +# +# Also check that the 'nosharedlibrary' doesn't trigger a warning +# about shared library breakpoints being disabled. +proc_with_prefix test_silent_nosharedlib {} { + if { ![allow_python_tests] } { + unsupported "python support needed" + return + } + + foreach_with_prefix type { breakpoint dprintf } { + clean_restart $::binfile + + if {![runto_main]} { + return + } + + gdb_breakpoint $::srcfile:$::bp_line + gdb_continue_to_breakpoint "stop before dlclose" + + # Setup a dprintf or breakpoint in the shared library. + if { $type eq "breakpoint" } { + gdb_test "break foo" + } else { + gdb_test "dprintf foo,\"In foo\"" + } + + # Record the number of the b/p (or dprintf) we just inserted. + set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \ + "get b/p number"] + + # Load Python library to track b/p modifications. + gdb_test_no_output "source $::pyfile" "import python scripts" + + # Initialise the b/p modified hash. Currently dprintf style + # breakpoints are not visible from Python, so the modification + # count will remain unchanged in that case. + gdb_test_no_output "python bp_modified_counts\[$bp_num\] = 0" + + # Discard symbols from all loaded shared libraries. + gdb_test_no_output "nosharedlibrary" + + # Check that our b/p is now showing as disabled. + if { $type eq "breakpoint" } { + set re \ + [list "$bp_num\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo"] + set count 1 + } else { + set re \ + [list \ + "$bp_num\\s+dprintf\\s+keep\\s+y\\s+<PENDING>\\s+foo" \ + "\\s+printf \"In foo\""] + set count 0 + } + + gdb_test "info breakpoints $bp_num" \ + [multi_line "^Num\\s+Type\\s+Disp\\s+Enb\\s+Address\\s+What" \ + {*}$re] + + # Check we've seen the expected number of breakpoint modified + # events. Currently dprintf breakpoints are not visible from + # Python, so we will not see an event in that case. + gdb_test "python print(bp_modified_counts\[$bp_num\])" "^$count" + } +} + test_bp_modified_events test_dprintf_after_unload test_dprintf_with_rerun +test_silent_nosharedlib diff --git a/gdb/testsuite/gdb.mi/mi-dprintf-modified-lib.c b/gdb/testsuite/gdb.mi/mi-dprintf-modified-lib.c new file mode 100644 index 0000000..70fc328 --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-dprintf-modified-lib.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025 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/>. */ + +int +foo (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.mi/mi-dprintf-modified.c b/gdb/testsuite/gdb.mi/mi-dprintf-modified.c new file mode 100644 index 0000000..7a41adbac --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-dprintf-modified.c @@ -0,0 +1,55 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025 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/>. */ + +#include <stdlib.h> + +#ifdef __WIN32__ +#include <windows.h> +#define dlopen(name, mode) LoadLibrary (TEXT (name)) +#ifdef _WIN32_WCE +# define dlsym(handle, func) GetProcAddress (handle, TEXT (func)) +#else +# define dlsym(handle, func) GetProcAddress (handle, func) +#endif +#define dlclose(handle) FreeLibrary (handle) +#else +#include <dlfcn.h> +#endif + +#include <assert.h> + +int +main (void) +{ + int res; + void *handle; + int (*func) (void); + int val = 0; + + handle = dlopen (SHLIB_NAME, RTLD_LAZY); /* Break here. */ + assert (handle != NULL); + + func = (int (*)(void)) dlsym (handle, "foo"); + assert (func != NULL); + + val += func (); + + res = dlclose (handle); + assert (res == 0); + + return val; +} diff --git a/gdb/testsuite/gdb.mi/mi-dprintf-modified.exp b/gdb/testsuite/gdb.mi/mi-dprintf-modified.exp new file mode 100644 index 0000000..c3e1bdf --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-dprintf-modified.exp @@ -0,0 +1,119 @@ +# Copyright 2025 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/>. + +# Check that GDB doesn't emit a 'breakpoint-modified' notification for +# dprintf breakpoints when the dprintf commands haven't changed. +# +# GDB use to emit a 'breakpoint-modified' dprintf breakpoints each +# time the dprintf_breakpoint::re_set function was called as this +# would re-cacluate the dprintf command string, even though in most +# cases the calculated string was no different from the previous +# value. +# +# Then GDB got smarter and could recognise that the string had not +# changed, and so would skip the 'breakpoint-modified' notification. +# +# This test stops at a dlopen() call in the inferior and creates a +# dprintf breakpoint. Then we 'next' over the dlopen() which triggers +# a call to the ::re_set() functions. We check that there is no +# 'breakpoint-modified' event emitted for the dprintf breakpoint. + +load_lib mi-support.exp +set MIFLAGS "-i=mi" + +standard_testfile .c -lib.c + +# Build the library. +set libname ${testfile}-lib +set libfile [standard_output_file $libname] +if { [build_executable "build shlib" $libfile $srcfile2 {debug shlib}] == -1} { + return +} + +# Build the executable. +set opts [list debug shlib_load additional_flags=-DSHLIB_NAME=\"${libname}\"] +if { [build_executable "build exec" $binfile $srcfile $opts] == -1} { + return +} + +# The line number of the dlopen() call. +set bp_line [gdb_get_line_number "Break here" $srcfile] + +# Start the inferior. +mi_clean_restart $binfile +mi_runto_main + +# Place a breakpoint at the dlopen() line. +mi_create_breakpoint $srcfile:$bp_line "set breakpoint at dlopen call" \ + -disp keep -func main -file "\[^\r\n\]+/$srcfile" -line $bp_line + +# And run to the breakpoint. +mi_execute_to "exec-continue" "breakpoint-hit" main "" ".*/$srcfile" \ + $bp_line { "" "disp=\"keep\"" } "run to breakpoint" + +# Cleanup breakpoints. +mi_delete_breakpoints + +# Setup a dprintf breakpoint. +mi_gdb_test "-dprintf-insert --function main \"in main\"" \ + "\\^done,bkpt={.*}" "dprintf at main" + +set bpnum [mi_get_valueof "/d" "\$bpnum" "INVALID" \ + "get number for dprintf breakpoint"] + +# Use 'next' to step over loading the shared library. +mi_gdb_test "220-exec-next" ".*" "next over dlopen" + +# Now wait for the 'stopped' notification. While we wait we should +# see a 'library-loaded' notification for the loading of the shared +# library. +# +# In older versions of GDB we would also see a 'breakpoint-modified' +# notification for the dprintf breakpoint, but newer versions of GDB +# are smart enough to not emit this unnecessary notification. +set bp_re [mi_make_breakpoint -number $bpnum \ + -type dprintf -disp keep -enabled y -func main] +set saw_bp_modified false +set saw_lib_load false +set saw_stopped false +gdb_test_multiple "" "wait for 'next' to complete" { + -re "^=library-loaded,id=\[^\r\n\]+\r\n" { + set saw_lib_load true + exp_continue + } + + -re "^=breakpoint-modified,$bp_re\r\n" { + set saw_bp_modified true + exp_continue + } + + -re "^\\*stopped,reason=\"end-stepping-range\",\[^\r\n\]+\r\n" { + set saw_stopped true + exp_continue + } + + -re "^$mi_gdb_prompt$" { + gdb_assert { $saw_lib_load } \ + "$gdb_test_name, library was loaded" + gdb_assert { $saw_stopped } \ + "$gdb_test_name, saw stopped message" + gdb_assert { !$saw_bp_modified } \ + "$gdb_test_name, no breakpoint-modified" + } + + -re "^\[^\r\n\]+\r\n" { + exp_continue + } +} diff --git a/gdb/testsuite/gdb.testsuite/version-compare.exp b/gdb/testsuite/gdb.testsuite/version-compare.exp new file mode 100644 index 0000000..8f2573e --- /dev/null +++ b/gdb/testsuite/gdb.testsuite/version-compare.exp @@ -0,0 +1,74 @@ +# Copyright 2025 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/>. + +# Check version_compare proc. + +proc eq { a b } { + with_test_prefix "$a == $b" { + gdb_assert { [version_compare $a == $b] } + gdb_assert { [version_compare $a <= $b] } + gdb_assert { [version_compare $a >= $b] } + gdb_assert { ![version_compare $a < $b] } + gdb_assert { ![version_compare $a > $b] } + } +} + +proc lt { a b } { + with_test_prefix "$a < $b" { + gdb_assert { [version_compare $a < $b] } + gdb_assert { [version_compare $a <= $b] } + gdb_assert { [version_compare $b > $a] } + gdb_assert { [version_compare $b >= $a] } + gdb_assert { ![version_compare $a == $b] } + gdb_assert { ![version_compare $b == $a] } + gdb_assert { ![version_compare $a > $b] } + gdb_assert { ![version_compare $a >= $b] } + gdb_assert { ![version_compare $b < $a] } + gdb_assert { ![version_compare $b <= $a] } + } +} + +# Equal, same length. +eq {1 0} {1 0} + +# Smaller than, same length. +lt {1 0} {1 1} +lt {1 1} {2 0} + +# Smaller than, different length. +lt {1 3} {2} +lt {1} {2 0} + +# The question how v1 and v1.0 relate to each other is not a trivial one. +# +# For instance, Python considers v1 == v1.0: +# $ test.py +# #!/usr/bin/python3 +# from packaging.version import parse +# v1_0 = parse("1.0") +# v1 = parse("1") +# print (v1 == v1_0) +# $ ./test.py +# True +# +# OTOH, version sort from coreutils considers v1 < v1.0: +# $ cat bla.txt +# 1.0 +# 1 +# $ sort -V bla.txt +# 1 +# 1.0 +# +# Proc version_compare seems to have taken the latter approach. +lt {1} {1 0} diff --git a/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.c b/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.c index af05b13..e22bf12 100644 --- a/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.c +++ b/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.c @@ -97,6 +97,11 @@ thread_fn (void *arg) return NULL; } +static void +setup_done (void) +{ +} + int main (void) { @@ -104,6 +109,8 @@ main (void) global_var++; + setup_done (); + for (i = 0; i < 4; i++) { struct thread_arg *p; diff --git a/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp b/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp index 784f17f..42222c0 100644 --- a/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp +++ b/gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp @@ -54,7 +54,7 @@ proc test { non_stop } { clean_restart ${binfile} } - if ![runto_main] { + if ![runto setup_done] { return -1 } @@ -76,7 +76,7 @@ proc test { non_stop } { # Start the second inferior. with_test_prefix "second inferior" { # With stub targets that do reload on run, if we let the new - # inferior share inferior 1's connection, runto_main would + # inferior share inferior 1's connection, runto would # fail because GDB is already connected to something, like # e.g. with --target_board=native-gdbserver: # @@ -86,10 +86,10 @@ proc test { non_stop } { # Already connected to a remote target. Disconnect? (y or n) # # Instead, start the inferior with no connection, and let - # gdb_load/runto_main spawn a new remote connection/gdbserver. + # gdb_load/runto spawn a new remote connection/gdbserver. # # OTOH, with extended-remote, we must let the new inferior - # reuse the current connection, so that runto_main below can + # reuse the current connection, so that runto below can # issue the "run" command, and have the inferior run on the # remote target. If we forced no connection, then "run" would # either fail if "set auto-connect-native-target" is on, like @@ -108,7 +108,7 @@ proc test { non_stop } { gdb_load $binfile - if ![runto_main] { + if ![runto setup_done] { return -1 } } diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 0a1231b..e1a3a23 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -181,12 +181,16 @@ proc find_ada_tool {tool} { # compiler does not appear to be GCC, this will always return false. proc gnat_version_compare {op l2} { - set gccvers [gcc_major_version] - if {$gccvers == -1} { + set gnatmake [find_gnatmake] + set gnatmake [lindex [split $gnatmake] 0] + if {[catch {exec $gnatmake --version} output]} { + return 0 + } + if {![regexp {GNATMAKE ([0-9]+(\.[0-9]+)*)} $output match version]} { return 0 } - return [version_compare [split $gccvers .] $op $l2] + return [version_compare [split $version .] $op $l2] } # Return 1 if the GNAT runtime appears to have debug info. diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp index b8ab30a..f32f533 100644 --- a/gdb/testsuite/lib/gdb-utils.exp +++ b/gdb/testsuite/lib/gdb-utils.exp @@ -117,7 +117,10 @@ proc gdb_get_bp_addr { num } { # Compare the version numbers in L1 to those in L2 using OP, and # return 1 if the comparison is true. OP can be "<", "<=", ">", ">=", -# or "==". It is ok if the lengths of the lists differ. +# or "==". +# It is ok if the lengths of the lists differ, but note that we have +# "{1} < {1 0}" instead of "{1} == {1 0}". See also +# gdb.testsuite/version-compare.exp. proc version_compare { l1 op l2 } { switch -exact $op { diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 761a4f1..59967c7 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -3937,13 +3937,16 @@ gdb_caching_proc is_aarch32_target {} { return 0 } - set list {} - foreach reg \ - {r0 r1 r2 r3} { - lappend list "\tmov $reg, $reg" - } + return [gdb_can_simple_compile aarch32 { + int main (void) { + asm ("\tmov r0, r0"); + asm ("\tmov r1, r1"); + asm ("\tmov r2, r2"); + asm ("\tmov r3, r3"); - return [gdb_can_simple_compile aarch32 [join $list \n]] + return 0; + } + }] } # Return 1 if this target is an aarch64, either lp64 or ilp32. |