diff options
Diffstat (limited to 'gdb/testsuite')
| -rw-r--r-- | gdb/testsuite/gdb.base/list-multi-source.c | 60 | ||||
| -rw-r--r-- | gdb/testsuite/gdb.base/list-multi-source.exp | 129 | ||||
| -rw-r--r-- | gdb/testsuite/gdb.base/long_long.exp | 32 | ||||
| -rw-r--r-- | gdb/testsuite/gdb.multi/remote-with-running-inferior.exp | 26 | ||||
| -rw-r--r-- | gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.exp | 2 |
5 files changed, 211 insertions, 38 deletions
diff --git a/gdb/testsuite/gdb.base/list-multi-source.c b/gdb/testsuite/gdb.base/list-multi-source.c new file mode 100644 index 0000000..ab2b6a0 --- /dev/null +++ b/gdb/testsuite/gdb.base/list-multi-source.c @@ -0,0 +1,60 @@ +/* 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/>. */ + +extern int function_a (void); +extern int function_b (void); + +#ifdef MAIN +int +main (void) +{ + int res; + + res = function_a (); + + res += function_b (); + + return res; +} +#endif + +#if defined FILE_A || defined FILE_B +static int +get_value_common (void) +{ + /* NOTE: When reading this file in the source tree, the variable used in + the return statement below will be replaced by a constant value when + the file is copied into the source tree. */ + return value_to_return; /* List this line. */ +} +#endif + +#ifdef FILE_A +int +function_a (void) +{ + return get_value_common (); +} +#endif + +#ifdef FILE_B +int +function_b (void) +{ + return get_value_common (); +} +#endif diff --git a/gdb/testsuite/gdb.base/list-multi-source.exp b/gdb/testsuite/gdb.base/list-multi-source.exp new file mode 100644 index 0000000..887ff96 --- /dev/null +++ b/gdb/testsuite/gdb.base/list-multi-source.exp @@ -0,0 +1,129 @@ +# 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/>. + +# Test that 'list FILE:LINE' can print multiple results if FILE +# matches multiple files from the source tree. +# +# Then test that we can use 'list DIR/FILE:LINE' to restrict the +# results to a single source file. + +# With a remote host, source files are automatically copied to the +# host by dejagnu, and this drops the directory structure that is +# needed for this test to work, i.e. we need a/foo.c and b/foo.c, but +# dejagnu's automatic copying just gives us a single foo.c. Instead +# of trying to fix this, for now at least, just skip remote host +# testing. +require {!is_remote host} + +# This test uses a single source file that is copied into the build +# tree 3 times. The three copies are then copied with different +# defines set so that we see different functions in each copy. +standard_testfile .c + +# Create the source tree within the build directory. +set src_root [standard_output_file "src"] +set src_a "$src_root/a" +set src_b "$src_root/b" +set file_a "$src_a/foo.c" +set file_b "$src_b/foo.c" +set file_main "$src_root/main.c" +file mkdir "$src_root" +file mkdir "$src_a" +file mkdir "$src_b" + +# Helper proc. Copy global SRCFILE to DEST, replacing +# 'value_to_return' with VALUE during the copy. +proc copy_and_update_source_file { dest value } { + # Open the source file for reading. + set in [open "$::srcdir/$::subdir/$::srcfile" r] + + # Read in the entire contents of the file. This should be fine as + # the input file is not large. + set file_content [read $in] + + # Close the input file. + close $in + + # Perform the replacement over the entire file contents. + set updated_content [string map \ + [list "value_to_return" $value] \ + $file_content] + + # Open the destination file for writing. + set out [open $dest w] + + # Write the modified content to the destination file. + puts -nonewline $out $updated_content + + # Close the output file. + close $out +} + +# Make three copies of the single source file in the build directory +# based source tree. Two of the source files are modified slighly to +# make the output of 'list' unique for each copy. +file copy "$srcdir/$subdir/$srcfile" "$file_main" +copy_and_update_source_file $file_a "3" +copy_and_update_source_file $file_b "-3" + +# Build the executable. Use defines to make the source files +# different. +if { [prepare_for_testing_full "failed to prepare" \ + [list $testfile debug \ + $file_main [list debug additional_flags=-DMAIN] \ + $file_a [list debug additional_flags=-DFILE_A] \ + $file_b [list debug additional_flags=-DFILE_B]]]} { + return +} + +# The LINENUM we should list, and the first and last lines that should +# appear in the list output. +set linenum [gdb_get_line_number "List this line"] +set first_linenum [expr {$linenum - 5}] +set last_linenum [expr {$linenum + 4}] + +# List using FILE:LINE for a filename that is ambiguous. +gdb_test "list foo.c:$linenum" \ + [multi_line \ + "file: \"\[^\r\n\]+/a/foo.c\", line number: $linenum, symbol: \"get_value_common\"" \ + "$first_linenum\\s+\[^\r\n\]+" \ + ".*" \ + "$linenum\\s+[string_to_regexp {return 3; /* List this line. */}]" \ + ".*" \ + "$last_linenum\\s+\[^\r\n\]+" \ + "file: \"\[^\r\n\]+/b/foo.c\", line number: $linenum, symbol: \"get_value_common\"" \ + "$first_linenum\\s+\[^\r\n\]+" \ + ".*" \ + "$linenum\\s+[string_to_regexp {return -3; /* List this line. */}]" \ + ".*" \ + "$last_linenum\\s+\[^\r\n\]+"] + +# Now list using a more acurate filename, we should only get a single +# result. +gdb_test "list a/foo.c:$linenum" \ + [multi_line \ + "^$first_linenum\\s+\[^\r\n\]+" \ + ".*" \ + "$linenum\\s+[string_to_regexp {return 3; /* List this line. */}]" \ + ".*" \ + "$last_linenum\\s+\[^\r\n\]+"] + +gdb_test "list b/foo.c:$linenum" \ + [multi_line \ + "^$first_linenum\\s+\[^\r\n\]+" \ + ".*" \ + "$linenum\\s+[string_to_regexp {return -3; /* List this line. */}]" \ + ".*" \ + "$last_linenum\\s+\[^\r\n\]+"] diff --git a/gdb/testsuite/gdb.base/long_long.exp b/gdb/testsuite/gdb.base/long_long.exp index a28e07a..38d1934 100644 --- a/gdb/testsuite/gdb.base/long_long.exp +++ b/gdb/testsuite/gdb.base/long_long.exp @@ -133,25 +133,11 @@ gdb_test_ptr "p/a val.oct" "" "" "0x77053977" "0xa72ee53977053977" gdb_test "p/c val.oct" "'w'" if { $sizeof_double == 8 || $sizeof_long_double == 8 } { - # ARM FPA floating point numbers are not strictly little endian or big - # endian, but a hybrid. They are in little endian format with the two - # words swapped in big endian format. - # EABI targets default to natural-endian VFP format. - - if { ([istarget "arm*-*-*"]) \ - && !([istarget "*-*-*eabi*"] || \ - [istarget "*-*-mingw32ce*"] || \ - [istarget "*-*-openbsd*"]) } then { - # assume the long long represents a floating point double in ARM format - gdb_test "p/f val.oct" "2.1386676354387559e\\+265" - } else { - # assume the long long represents a floating point double in little - # endian format - gdb_test "p/f val.oct" "-5.9822653797615723e-120" - } + set re_val_oct_f [string_to_regexp "-5.9822653797615723e-120"] } else { - gdb_test "p/f val.oct" "-2.42716126e-15" + set re_val_oct_f [string_to_regexp "-2.42716126e-15"] } +gdb_test "p/f val.oct" $re_val_oct_f gdb_test_char "p/x *(char *)c" "0x1" gdb_test_char "p/d *(char *)c" "1" @@ -208,11 +194,7 @@ gdb_test "x/o w" "0110642547" gdb_test "x/t w" "00000001001000110100010101100111" gdb_test_xptr "x/a" { b "" } { h "" } { w "0x1234567" } { g "0x123456789abcdef" } gdb_test "x/c b" "1 '.001'" -if { $sizeof_double == 8 || $sizeof_long_double == 8 } { - gdb_test "x/f &val.oct" "-5.9822653797615723e-120" -} else { - gdb_test "x/f &val.oct" "-2.42716126e-15" -} +gdb_test "x/f &val.oct" $re_val_oct_f # Implicit Giant size (except for a, c, and f) @@ -225,9 +207,9 @@ gdb_test "x/2t g" "0000000100100011010001010110011110001001101010111100110111101 gdb_test_xptr "x/2a" { b "" } { h "" } { w "0x1234567.*0xa72ee539" } { g "0x123456789abcdef.*0xa72ee53977053977" } gdb_test "x/2c b" "1 '.001'.*-89 '.\[0-9\]*'" if { $sizeof_double == 8 || $sizeof_long_double == 8 } { - gdb_test "x/2f &val.oct" "-5.9822653797615723e-120.*-5.9041889495880968e-100" + gdb_test "x/2f &val.oct" "$re_val_oct_f.*-5.9041889495880968e-100" } else { - gdb_test "x/2f &val.oct" "-2.42716126e-15" + gdb_test "x/2f &val.oct" "$re_val_oct_f" } # Explicit sizes, and two memory locations ... @@ -266,7 +248,7 @@ gdb_test "x/2go g" "04432126361152746757.*01234567123456701234567" gdb_test "x/2gt g" "0000000100100011010001010110011110001001101010111100110111101111.*1010011100101110111001010011100101110111000001010011100101110111" gdb_test_ptr "x/2ga g" "" "" "0x89abcdef.*0x77053977" "0x123456789abcdef.*0xa72ee53977053977" gdb_test "x/2gc g" "-17 '.\[0-9\]*'.*119 'w'" -gdb_test "x/2gf g" "3.5127005640885037e-303.*-5.9822653797615723e-120" +gdb_test "x/2gf g" "3.5127005640885037e-303.*$re_val_oct_f" # Repeat behavior. gdb_test "x/2bx b" "0x01.*0xa7" "set up for repeat" diff --git a/gdb/testsuite/gdb.multi/remote-with-running-inferior.exp b/gdb/testsuite/gdb.multi/remote-with-running-inferior.exp index 43842ba..6f8a77c 100644 --- a/gdb/testsuite/gdb.multi/remote-with-running-inferior.exp +++ b/gdb/testsuite/gdb.multi/remote-with-running-inferior.exp @@ -57,7 +57,8 @@ proc run_test { target_non_stop non_stop } { gdb_test_no_output "set non-stop $non_stop" # Start the first inferior running in the background. - gdb_test -no-prompt-anchor "run&" "Starting program: .*" "start background inferior" + gdb_test -no-prompt-anchor "run&" "Starting program: .*" \ + "start background inferior" # Add a second inferior. gdb_test "add-inferior" "Added inferior 2.*" @@ -87,26 +88,26 @@ proc run_test { target_non_stop non_stop } { exp_continue } - -re "^\\s+Id\\s+Target Id\\s+Frame\\s*\r\n" { + -re {^\s+Id\s+Target Id\s+Frame\s*\r\n} { exp_continue } - -re "^\\s+1\\.1\\s+\[^\r\n\]+\\(running\\)\r\n" { + -re {^\s+1\.1\s+[^\r\n]+\(running\)\r\n} { set state_inferior_1 "running" exp_continue } - -re "^\\*\\s+2\\.1\\s+\[^\r\n\]+\\(running\\)\r\n" { + -re {^\*\s+2\.1\s+[^\r\n]+\(running\)\r\n} { set state_inferior_2 "running" exp_continue } - -re "^\\s+1\\.1\\s+\[^\r\n\]+\r\n" { + -re {^\s+1\.1\s+[^\r\n]+\r\n} { set state_inferior_1 "stopped" exp_continue } - -re "^\\*\\s+2\\.1\\s+\[^\r\n\]+\r\n" { + -re {^\*\s+2\.1\s+[^\r\n]+\r\n} { set state_inferior_2 "stopped" exp_continue } @@ -124,18 +125,19 @@ proc run_test { target_non_stop non_stop } { } } - # Allow inferior 2 to reach main. The confirms that inferior 2 can be + # Allow inferior 2 to reach main. This confirms that inferior 2 can be # set running again. - gdb_breakpoint main + gdb_test "break main inferior 2" \ + "Breakpoint $::decimal at .*" gdb_continue_to_breakpoint "breakpoint in main" gdb_test "bt 1" \ - "#0\\s+main \\(\\) at\[^\r\n\]+" \ + {#0\s+main \(\) at [^\r\n]+} \ "check inferior 2 is in main" # Switch to inferior 1 and allow it to continue. This is a # critical part of the test. When the test was added a bug (in # all-stop mode) would leave inferior 1 stopped, but GDB code - # would think the thread was running. As such. the thread + # would think the thread was running. As such, the thread # couldn't be resumed again. gdb_test "inferior 1" "Switching to inferior 1.*" @@ -151,8 +153,8 @@ proc run_test { target_non_stop non_stop } { gdb_continue_to_breakpoint "continue to breakpoint in breakpt" gdb_test "bt 1" \ [multi_line \ - "#0\\s+breakpt \\(\\) at\[^\r\n\]+" \ - "\\(More stack frames follow\\.\\.\\.\\)"] \ + {#0\s+breakpt \(\) at [^\r\n]+} \ + [string_to_regexp "(More stack frames follow...)"]] \ "check inferior 1 is in breakpt" # Switch back to inferior 2. The testing infrastructure will try to diff --git a/gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.exp b/gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.exp index 7773ff3..71c67ad 100644 --- a/gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.exp +++ b/gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.exp @@ -35,7 +35,7 @@ if {[build_executable "failed to prepare" $testfile $srcfile {hip nodebug}]} { clean_restart with_rocm_gpu_lock { - gdb_test "file $::binfile" ".*No debugging symbols.*" "load file" + gdb_load $::binfile if {![runto_main]} { return |
