diff options
Diffstat (limited to 'gdb/testsuite')
32 files changed, 572 insertions, 129 deletions
diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 03ead59..a1dd974 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -381,11 +381,15 @@ proc run_mid_line_completion_tests { root cmd } { proc run_quoting_and_escaping_tests { root } { # Test all the commands which allow quoting of filenames, and # which require whitespace to be escaped in unquoted filenames. - foreach_with_prefix cmd { file exec-file symbol-file add-symbol-file \ - remove-symbol-file \ - "target core" "target exec" "target tfile" \ - "maint print c-tdesc" "compile file" \ - "save gdb-index" "save gdb-index -dwarf-5" } { + set all_cmds { file exec-file symbol-file add-symbol-file \ + remove-symbol-file \ + "target core" "target exec" "target tfile" \ + "maint print c-tdesc" "save gdb-index" + "save gdb-index -dwarf-5" } + if { [allow_compile_tests] } { + lappend all_cmds "compile file" + } + foreach_with_prefix cmd $all_cmds { # Try each test placing the filename as the first argument # then again with a quoted string immediately after the # command. This works because the filename completer will 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/options.exp b/gdb/testsuite/gdb.base/options.exp index a1ca39e..8760a91 100644 --- a/gdb/testsuite/gdb.base/options.exp +++ b/gdb/testsuite/gdb.base/options.exp @@ -99,21 +99,21 @@ proc make_cmd {variant} { # operand. proc expect_none {operand} { return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\ - -string '' -filename '' -- $operand" + -string '' -filename '' -color magenta -- $operand" } # Return a string for the expected result of running "maint # test-options xxx", with -flag set. OPERAND is the expected operand. proc expect_flag {operand} { return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\ - -string '' -filename '' -- $operand" + -string '' -filename '' -color magenta -- $operand" } # Return a string for the expected result of running "maint # test-options xxx", with -bool set. OPERAND is the expected operand. proc expect_bool {operand} { return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint-unl 0 -pint-unl 0\ - -string '' -filename '' -- $operand" + -string '' -filename '' -color magenta -- $operand" } # Return a string for the expected result of running "maint @@ -123,10 +123,10 @@ proc expect_bool {operand} { proc expect_integer {option val operand} { if {$option == "uinteger-unlimited"} { return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl $val\ - -pint-unl 0 -string '' -filename '' -- $operand" + -pint-unl 0 -string '' -filename '' -color magenta -- $operand" } elseif {$option == "pinteger-unlimited"} { return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0\ - -pint-unl $val -string '' -filename '' -- $operand" + -pint-unl $val -string '' -filename '' -color magenta -- $operand" } else { error "unsupported option: $option" } @@ -144,7 +144,7 @@ proc expect_string {str operand} { set str [string range $str 1 end-1] } return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\ - -string '$str' -filename '' -- $operand" + -string '$str' -filename '' -color magenta -- $operand" } # Return a string for the expected result of running "maint @@ -159,11 +159,12 @@ proc expect_filename {str operand} { set str [string range $str 1 end-1] } return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\ - -string '' -filename '$str' -- $operand" + -string '' -filename '$str' -color magenta -- $operand" } set all_options { "-bool" + "-color" "-enum" "-filename" "-flag" @@ -628,7 +629,7 @@ proc_with_prefix test-flag {variant} { # Extract twice the same flag, separated by one space. gdb_test "$cmd -xx1 -xx2 -xx1 -xx2 -xx1 -- non flags args" \ "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\ - -string '' -filename '' -- non flags args" + -string '' -filename '' -color magenta -- non flags args" # Extract 2 known flags in front of unknown flags. gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \ 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.compile/compile-cplus-anonymous.exp b/gdb/testsuite/gdb.compile/compile-cplus-anonymous.exp index 3e76d38..ddad628 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-anonymous.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-anonymous.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-array-decay.exp b/gdb/testsuite/gdb.compile/compile-cplus-array-decay.exp index 505a4e1..c7d15ce 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-array-decay.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-array-decay.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++ additional_flags=-std=c++11}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-inherit.exp b/gdb/testsuite/gdb.compile/compile-cplus-inherit.exp index 1a5f60a..9ef1e83 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-inherit.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-inherit.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-member.exp b/gdb/testsuite/gdb.compile/compile-cplus-member.exp index 5ffbb30..ac9111c 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-member.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-member.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-method.exp b/gdb/testsuite/gdb.compile/compile-cplus-method.exp index 0a0e0fa..bcbfbb0 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-method.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-method.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-namespace.exp b/gdb/testsuite/gdb.compile/compile-cplus-namespace.exp index 3ab8ece..2abc366 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-namespace.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-namespace.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-nested.exp b/gdb/testsuite/gdb.compile/compile-cplus-nested.exp index 19efd4f..247d270 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-nested.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-nested.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-print.exp b/gdb/testsuite/gdb.compile/compile-cplus-print.exp index 594f94a..e4413f0 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-print.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-print.exp @@ -19,6 +19,8 @@ standard_testfile require is_c_compiler_gcc +require allow_compile_tests + set options {} if [test_compiler_info gcc*] { lappend options additional_flags=-g3 diff --git a/gdb/testsuite/gdb.compile/compile-cplus-virtual.exp b/gdb/testsuite/gdb.compile/compile-cplus-virtual.exp index 8761df5..a770208 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus-virtual.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus-virtual.exp @@ -23,6 +23,8 @@ require allow_cplus_tests require is_c_compiler_gcc +require allow_compile_tests + if {[prepare_for_testing $testfile $testfile $srcfile \ {debug nowarnings c++}]} { return -1 diff --git a/gdb/testsuite/gdb.compile/compile-cplus.exp b/gdb/testsuite/gdb.compile/compile-cplus.exp index 711f299..35ae692 100644 --- a/gdb/testsuite/gdb.compile/compile-cplus.exp +++ b/gdb/testsuite/gdb.compile/compile-cplus.exp @@ -19,6 +19,8 @@ standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c require is_c_compiler_gcc +require allow_compile_tests + set options {} if { [test_compiler_info gcc*] || [test_compiler_info clang*] } { lappend options additional_flags=-g3 diff --git a/gdb/testsuite/gdb.compile/compile-ifunc.exp b/gdb/testsuite/gdb.compile/compile-ifunc.exp index b004bd7..e490890 100644 --- a/gdb/testsuite/gdb.compile/compile-ifunc.exp +++ b/gdb/testsuite/gdb.compile/compile-ifunc.exp @@ -17,6 +17,8 @@ load_lib compile-support.exp require allow_ifunc_tests +require allow_compile_tests + standard_testfile require is_c_compiler_gcc diff --git a/gdb/testsuite/gdb.compile/compile-ops.exp b/gdb/testsuite/gdb.compile/compile-ops.exp index f75e02c..cfbe2b0 100644 --- a/gdb/testsuite/gdb.compile/compile-ops.exp +++ b/gdb/testsuite/gdb.compile/compile-ops.exp @@ -22,6 +22,8 @@ load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. require dwarf2_support +require allow_compile_tests + require is_c_compiler_gcc standard_testfile .c -dbg.S diff --git a/gdb/testsuite/gdb.compile/compile-print.exp b/gdb/testsuite/gdb.compile/compile-print.exp index f8f2297..61ce750 100644 --- a/gdb/testsuite/gdb.compile/compile-print.exp +++ b/gdb/testsuite/gdb.compile/compile-print.exp @@ -19,6 +19,8 @@ standard_testfile require is_c_compiler_gcc +require allow_compile_tests + if { [prepare_for_testing "failed to prepare" "$testfile"] } { return -1 } diff --git a/gdb/testsuite/gdb.compile/compile-setjmp.exp b/gdb/testsuite/gdb.compile/compile-setjmp.exp index f387a05..ad8732b 100644 --- a/gdb/testsuite/gdb.compile/compile-setjmp.exp +++ b/gdb/testsuite/gdb.compile/compile-setjmp.exp @@ -19,6 +19,8 @@ standard_testfile .c compile-setjmp-mod.c require is_c_compiler_gcc +require allow_compile_tests + if { [prepare_for_testing "failed to prepare" $testfile] } { return -1 } diff --git a/gdb/testsuite/gdb.compile/compile-tls.exp b/gdb/testsuite/gdb.compile/compile-tls.exp index 2f8dc5a..45e290e 100644 --- a/gdb/testsuite/gdb.compile/compile-tls.exp +++ b/gdb/testsuite/gdb.compile/compile-tls.exp @@ -19,6 +19,8 @@ standard_testfile .c require is_c_compiler_gcc +require allow_compile_tests + if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ executable {debug}] != "" } { return -1 diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp index 2c2e321..5128dc62 100644 --- a/gdb/testsuite/gdb.compile/compile.exp +++ b/gdb/testsuite/gdb.compile/compile.exp @@ -15,6 +15,8 @@ load_lib compile-support.exp +require allow_compile_tests + standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c require is_c_compiler_gcc 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.python/py-source-styling.exp b/gdb/testsuite/gdb.python/py-source-styling.exp index ba7e795..8eed56b 100644 --- a/gdb/testsuite/gdb.python/py-source-styling.exp +++ b/gdb/testsuite/gdb.python/py-source-styling.exp @@ -33,12 +33,43 @@ if { [build_executable "failed to build" ${testfile} ${srcfile}] == -1 } { set line_number [gdb_get_line_number "List this line."] +# Helper proc. Run CMD, which should produce a source listing, and +# check if the source code is styled or not. EXPECT_STYLED indicates +# if we expect the source listing to be styled or not. +proc check_source_listing_styling { cmd expect_styled { testname "" } } { + if { $testname eq "" } { + set testname $cmd + } + + set seen_style_escape false + gdb_test_multiple $cmd $testname { + -re -wrap "Python Exception.*" { + fail $gdb_test_name + return + } + -re "\033" { + set seen_style_escape true + exp_continue + } + -re "$::gdb_prompt $" { + gdb_assert { $seen_style_escape == $expect_styled } \ + $gdb_test_name + } + } +} + # Check that the Python pygments module can be used for source # highlighting when GNU source highlight is not available (or is # disabled, as is done in this test). proc test_pygments_styling {} { clean_restart $::binfile + # Remote host boards disable styling via GDB's command line. Turn + # it back on now. + if {[is_remote host]} { + gdb_test "set style enabled on" + } + if { ![gdb_py_module_available "pygments"] } { unsupported "pygments module not available" return @@ -52,19 +83,7 @@ proc test_pygments_styling {} { gdb_test "maint flush source-cache" "Source cache flushed\\." - set seen_style_escape false - gdb_test_multiple "list $::line_number" "" { - -re "Python Exception.*" { - fail $gdb_test_name - } - -re "\033" { - set seen_style_escape true - exp_continue - } - -re "$::gdb_prompt $" { - gdb_assert { $seen_style_escape } $gdb_test_name - } - } + check_source_listing_styling "list $::line_number" true } # Use gdb.execute to list source code containing non-utf-8 character. @@ -93,6 +112,67 @@ proc test_gdb_execute_non_utf8_source {} { gdb_test "python print(source)" ".*List this line.*" } +# Use gdb.execute() to list source code. Alternate between asking for +# styled, and unstyled source code. In some cases we ask for the +# output to be returned via a string, and in other cases we ask for +# the output to be sent straight to stdout. +proc_with_prefix test_source_cache_style_tracking {} { + clean_restart $::binfile + + # Remote host boards disable styling via GDB's command line. Turn + # it back on now. + if {[is_remote host]} { + gdb_test "set style enabled on" + } + + gdb_test_no_output "set host-charset ISO-8859-1" + + # Commands which return styled, and non-styled source code mixed + # together. This ensures that the source cache will need to keep + # discarding the entry with the wrong styling mode. All of these + # gdb.execute calls send their output via a string. + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', to_string=True), end='')" \ + false + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', to_string=True, styling=True), end='')" \ + true + foreach from_tty { True False } { + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', $from_tty, True), end='')" \ + false + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', $from_tty, True, True), end='')" \ + true + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', $from_tty, True, False), end='')" \ + false + } + + # The same again, but this time the output is sent directly to + # stdout. + check_source_listing_styling \ + "python gdb.execute('list $::line_number')" \ + true + check_source_listing_styling \ + "python gdb.execute('list $::line_number', to_string=False, styling=False)" \ + false + check_source_listing_styling \ + "python gdb.execute('list $::line_number', to_string=False, styling=True)" \ + true + foreach from_tty { True False } { + check_source_listing_styling \ + "python gdb.execute('list $::line_number', $from_tty, False, False)" \ + false + check_source_listing_styling \ + "python gdb.execute('list $::line_number', $from_tty, False, True)" \ + true + check_source_listing_styling \ + "python gdb.execute('list $::line_number', $from_tty, False)" \ + true + } +} + # We need an ANSI-capable terminal to get the output, additionally we # need to set LC_ALL so GDB knows the terminal is UTF-8 capable, # otherwise we'll get a UnicodeEncodeError trying to encode the @@ -100,4 +180,5 @@ proc test_gdb_execute_non_utf8_source {} { with_ansi_styling_terminal { test_pygments_styling test_gdb_execute_non_utf8_source + test_source_cache_style_tracking } diff --git a/gdb/testsuite/gdb.rocm/precise-memory.cpp b/gdb/testsuite/gdb.rocm/precise-memory.cpp index 769b58a..7a8c37e 100644 --- a/gdb/testsuite/gdb.rocm/precise-memory.cpp +++ b/gdb/testsuite/gdb.rocm/precise-memory.cpp @@ -31,7 +31,17 @@ __global__ void kernel () { - __builtin_amdgcn_s_sleep (1); + + /* Simple kernel which loads from address 0 to trigger a pagefault. + When precise memory is not enabled, it is expected that the memory fault + is reported after the s_nop instruction. With precise-memory, the + exception should be reported on the s_nop. */ + asm volatile ("s_mov_b64 [s10, s11], 0\n" + "s_load_dword s12, [s10, s11]\n" + "s_nop 0" + : + : + : "s10", "s11", "s12"); } int diff --git a/gdb/testsuite/gdb.rocm/precise-memory.exp b/gdb/testsuite/gdb.rocm/precise-memory.exp index f423a11..8c39f80 100644 --- a/gdb/testsuite/gdb.rocm/precise-memory.exp +++ b/gdb/testsuite/gdb.rocm/precise-memory.exp @@ -39,18 +39,40 @@ proc do_test { } { "AMDGPU precise memory access reporting is off \\(currently disabled\\)." \ "show precise-memory setting in CLI before" - if {[hip_devices_support_precise_memory]} { - gdb_test_no_output "set amdgpu precise-memory on" - set cli_effective_value "enabled" - } else { - gdb_test "set amdgpu precise-memory on" \ - "warning: AMDGPU precise memory access reporting could not be enabled." - set cli_effective_value "disabled" + # Assume precise-memory is available, unless GDB reports otherwise. + gdb_test_multiple "set amdgpu precise-memory on" "" { + -re -wrap "warning: AMDGPU precise memory access reporting could not be enabled\\." { + set cli_effective_value "disabled" + pass $gdb_test_name + } + -re -wrap "^" { + set cli_effective_value "enabled" + pass $gdb_test_name + } } gdb_test "show amdgpu precise-memory" \ - "AMDGPU precise memory access reporting is on \\(currently ${cli_effective_value}\\)." \ + "AMDGPU precise memory access reporting is on \\(currently ${cli_effective_value}\\)\\." \ "show precise-memory setting in CLI after" + + if { $cli_effective_value eq "disabled" } { + return + } + + # Get to the begining of the GPU kernel without precise memory enabled. + with_test_prefix "goto gpu code" { + gdb_test_no_output "set amdgpu precise-memory off" + gdb_breakpoint "kernel" allow-pending + gdb_test "continue" "Thread ${::decimal}.* hit Breakpoint .*" + gdb_test_no_output "set amdgpu precise-memory on" + } + + # If precise-memory is available, run until a SIGSEGV is reported. At + # that point, the PC should point to the s_nop instruction (the one + # following the one which caused the memory violation). + gdb_test "continue" "Thread ${::decimal}\[^\r\n\]* received signal SIGSEGV, Segmentation fault.*" + + gdb_test "x/i \$pc" "=> ${::hex} <_Z6kernelv\\+${::decimal}>:\[ \t\]+s_nop\[ \t\]+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/compile-support.exp b/gdb/testsuite/lib/compile-support.exp index aa8aaf3..6d7a4ce 100644 --- a/gdb/testsuite/lib/compile-support.exp +++ b/gdb/testsuite/lib/compile-support.exp @@ -45,6 +45,9 @@ proc _do_check_compile {expr} { # This appears to be a bug in the compiler plugin. set result "apparent compiler plugin bug" } + -re "This command is not supported." { + set result "compiler disabled at configure time" + } -re "\r\n$gdb_prompt $" { } } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 3349da7..761a4f1 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2799,6 +2799,12 @@ gdb_caching_proc allow_python_tests {} { return [expr {[string first "--with-python" $output] != -1}] } +# Return a 1 if GDB was configured to support compile commands. +gdb_caching_proc allow_compile_tests {} { + set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS -ex \"compile int x = 1\" -batch"] + return [expr {[string first "The program must be running" $output] != -1}] +} + # Return a 1 for configurations that use system readline rather than the # in-repo copy. @@ -5940,6 +5946,23 @@ proc gdb_compile {source dest type options} { } } + # On AIX systems, until GCC 12 (maybe later), stabs was the default + # debug option, but we'd like to have dwarf instead. + # If we're running on one of those systems and debug was requested, + # but no explicit -g<format> option was given, use -gdwarf to force + # that as the debug info for the inferior. + # This list should be exhaustive: + set debug_format "btf|ctf|stabs|vms|coff|xcoff" + # Since additional_flags is a comma separated list, identify if there + # are other (optional) flags in the list. + set other_options "-\[a-zA-Z0-9\]*," + set full_regexp "^additional_flags=\($other_options\)*-g\($debug_format\)" + if { [istarget *-*-aix*] + && [lsearch -exact $options debug] != -1 + && [lsearch -regexp $options $full_regexp] == -1} { + lappend new_options "additional_flags=-gdwarf" + } + set shlib_found 0 set shlib_load 0 foreach opt $options { diff --git a/gdb/testsuite/lib/rocm.exp b/gdb/testsuite/lib/rocm.exp index 3eb51db..5164f1e 100644 --- a/gdb/testsuite/lib/rocm.exp +++ b/gdb/testsuite/lib/rocm.exp @@ -176,22 +176,3 @@ proc hip_devices_support_debug_multi_process {} { } return 1 } - -# Return true if all the devices on the host support precise memory. - -proc hip_devices_support_precise_memory {} { - set unsupported_targets \ - {gfx900 gfx906 gfx908 gfx1010 gfx1011 gfx1012 gfx1030 gfx1031 gfx1032} - - set targets [find_amdgpu_devices] - if { [llength $targets] == 0 } { - return 0 - } - - foreach target $targets { - if { [lsearch -exact $unsupported_targets $target] != -1 } { - return 0 - } - } - return 1 -} |