diff options
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-entry-points.c | 43 | ||||
-rw-r--r-- | gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp | 213 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/entry-point.exp | 84 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/entry-point.f90 | 67 |
4 files changed, 407 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c new file mode 100644 index 0000000..87b4691 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.c @@ -0,0 +1,43 @@ +/* Copyright 2023 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/>. */ + +/* In the generated DWARF, we'll use the locations of foo_entry_label and + foobar_entry_label as the low_pc's of our entry point TAGs. */ + +int I = 0; +int J = 0; +int K = 0; + +__attribute__ ((noinline)) +void +bar_helper (void) +{ + asm ("bar_helper_label: .globl bar_helper_label"); + I++; + J++; + asm ("foo_entry_label: .globl foo_entry_label"); + J++; + K++; + asm ("foobar_entry_label: .globl foobar_entry_label"); +} + +int +main (void) +{ + asm ("main_label: .globl main_label"); + bar_helper (); + + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp new file mode 100644 index 0000000..f361820 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp @@ -0,0 +1,213 @@ +# Copyright 2023 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 the DW_TAG_entry_point is handled properly by GDB and that we can +# set breakpoints on function entry points. + +load_lib dwarf.exp + +# This test can only be run on targets that support DWARF-2 and use +# gas. +require dwarf2_support + +standard_testfile .c -dw.S + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcfile + declare_labels int_label int2_label + + get_func_info main + get_func_info bar_helper + + set int_size [get_sizeof "int" 4] + + set prog_line 1 + set bar_line 2 + set foo_line 3 + set foobar_line 4 + + set global_I [gdb_target_symbol I] + set global_J [gdb_target_symbol J] + set global_K [gdb_target_symbol K] + + cu {} { + compile_unit { + {language @DW_LANG_Fortran90} + {name dw2-entry-points.f90} + {comp_dir /tmp} + } { + int_label: base_type { + {name "int"} + {byte_size $int_size sdata} + {encoding @DW_ATE_signed} + } + subprogram { + {name prog} + {decl_file 1 data1} + {decl_line $prog_line data1} + {low_pc $main_start addr} + {high_pc "$main_start + $main_len" addr} + {external 1 flag} + {main_subprogram 1 flag} + } + subprogram { + {name bar} + {decl_file 1 data1} + {decl_line $bar_line data1} + {external 1 flag} + {low_pc $bar_helper_start addr} + {high_pc "$bar_helper_start + $bar_helper_len" addr} + } { + formal_parameter { + {name I} + {type :$int_label} + {location {addr $global_I} SPECIAL_expr} + } + formal_parameter { + {name J} + {type :$int_label} + {location {addr $global_J} SPECIAL_expr} + } + entry_point { + {name foo} + {decl_file 1 data1} + {decl_line $foo_line data1} + {low_pc foo_entry_label addr} + } { + formal_parameter { + {name J} + {type :$int_label} + {location {addr $global_J} SPECIAL_expr} + } + formal_parameter { + {name K} + {type :$int_label} + {location {addr $global_K} SPECIAL_expr} + } + } + entry_point { + {name foobar} + {decl_file 1 data1} + {decl_line $foobar_line data1} + {low_pc foobar_entry_label addr} + } { + formal_parameter { + {name J} + {type :$int_label} + {location {addr $global_J} SPECIAL_expr} + } + } + } + } + } + + cu {} { + compile_unit { + {language @DW_LANG_Fortran90} + {name dw2-entry-points-2.f90} + {comp_dir /tmp} + } { + int2_label: base_type { + {name "int"} + {byte_size $int_size sdata} + {encoding @DW_ATE_signed} + } + subprogram { + {name barso} + {decl_file 1 data1} + {decl_line $bar_line data1} + {external 1 flag} + {low_pc $bar_helper_start addr} + {high_pc "$bar_helper_start + $bar_helper_len" addr} + } { + formal_parameter { + {name I} + {type :$int2_label} + {location {addr $global_I} SPECIAL_expr} + } + formal_parameter { + {name J} + {type :$int2_label} + {location {addr $global_J} SPECIAL_expr} + } + entry_point { + {name fooso} + {decl_file 1 data1} + {decl_line $foo_line data1} + {low_pc foo_entry_label addr} + } { + formal_parameter { + {name J} + {type :$int2_label} + {location {addr $global_J} SPECIAL_expr} + } + formal_parameter { + {name K} + {type :$int2_label} + {location {addr $global_K} SPECIAL_expr} + } + } + } + } + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}]} { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Try whether we can set and hit breakpoints at the entry_points. +gdb_breakpoint "foo" +gdb_breakpoint "foobar" + +# Now hit the entry_point break point and check their call-stack. +gdb_continue_to_breakpoint "foo" +gdb_test "bt" [multi_line \ + "#0.*${hex} in foo \\(J=1, K=0\\).*" \ + "#1.*${hex} in prog \\(\\).*" \ + ] "bt foo" + +gdb_continue_to_breakpoint "foobar" +gdb_test "bt" [multi_line \ + "#0.*${hex} in foobar \\(J=2\\).*" \ + "#1.*${hex} in prog \\(\\).*" \ + ] "bt foobar" + +# Now try whether we can also set breakpoints on entry_points from other CUs. + +clean_restart ${testfile} + +if ![runto_main] { + return -1 +} + +gdb_breakpoint "fooso" +gdb_continue_to_breakpoint "foo_so" + +gdb_test "bt" [multi_line \ + "#0.*${hex} in foo \\(J=1, K=0\\).*" \ + "#1.*${hex} in prog \\(\\).*" \ +] "bt fooso" diff --git a/gdb/testsuite/gdb.fortran/entry-point.exp b/gdb/testsuite/gdb.fortran/entry-point.exp new file mode 100644 index 0000000..02d7b18 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/entry-point.exp @@ -0,0 +1,84 @@ +# Copyright 2023 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 Fortran entry points for subroutines. + +require allow_fortran_tests + +standard_testfile .f90 +load_lib "fortran.exp" + +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}] } { + return -1 +} + +if { ![fortran_runto_main] } { + untested "could not run to main" + return -1 +} + +# Test if we can set a breakpoint via the entry-point name. +set entry_point_name "foo" +gdb_breakpoint $entry_point_name +gdb_continue_to_breakpoint "continue to breakpoint: $entry_point_name" \ + ".*entry foo\\(J,K,L,I1\\).*" + +gdb_test "print j" "= 11" "print j, entered via $entry_point_name" +gdb_test "print k" "= 22" "print k, entered via $entry_point_name" +gdb_test "print l" "= 33" "print l, entered via $entry_point_name" +gdb_test "print i1" "= 44" "print i1, entered via $entry_point_name" +gdb_test "info args" \ + [multi_line "j = 11" \ + "k = 22" \ + "l = 33" \ + "i1 = 44"] \ + "info args, entered via $entry_point_name" + +# Test if we can set a breakpoint via the function name. +set entry_point_name "bar" +gdb_breakpoint $entry_point_name +gdb_continue_to_breakpoint "continue to breakpoint: $entry_point_name" \ + ".*subroutine bar\\(I,J,K,I1\\).*" + +gdb_test "print i" "= 444" "print i, entered via $entry_point_name" +gdb_test "print j" "= 555" "print j, entered via $entry_point_name" +gdb_test "print k" "= 666" "print k, entered via $entry_point_name" +gdb_test "print i1" "= 777" "print i1, entered via $entry_point_name" + +# Test a second entry point. +set entry_point_name "foobar" +gdb_breakpoint $entry_point_name +gdb_continue_to_breakpoint "continue to breakpoint: $entry_point_name" \ + ".* entry foobar\\(J\\).*" + +gdb_test "print j" "= 1" "print j, entered via $entry_point_name" +gdb_test "info args" "j = 1" "info args, entered via $entry_point_name" + +# Test breaking at the entrypoint defined inside the module mod via its +# scoped name. +set entry_point_name "mod::mod_foo" + +# GCC moves subroutines with entry points out of the module scope into the +# compile unit scope. +if {[test_compiler_info {gcc-*}]} { + setup_xfail "gcc/105272" "*-*-*" +} +gdb_breakpoint $entry_point_name + +if {[test_compiler_info {gcc-*}]} { + setup_xfail "gcc/105272" "*-*-*" +} +gdb_continue_to_breakpoint "continue to breakpoint: $entry_point_name" \ + ".* entry mod_foo\\(\\).*" diff --git a/gdb/testsuite/gdb.fortran/entry-point.f90 b/gdb/testsuite/gdb.fortran/entry-point.f90 new file mode 100644 index 0000000..7b1c7f9 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/entry-point.f90 @@ -0,0 +1,67 @@ +! Copyright 2023 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/>. + +module mod +implicit none + +contains + subroutine mod_bar + integer :: I = 3 + + goto 100 + + entry mod_foo + I = 33 + +100 print *, I + end subroutine mod_bar +end module mod + + +subroutine bar(I,J,K,I1) + integer :: I,J,K,L,I1 + integer :: A + real :: C + + A = 0 + C = 0.0 + + A = I + K + I1 + goto 300 + + entry foo(J,K,L,I1) + A = J + K + L + I1 + +200 C = J + goto 300 + + entry foobar(J) + goto 200 + +300 A = C + 1 + C = J * 1.5 + + return +end subroutine + +program TestEntryPoint + use mod + + call foo(11,22,33,44) + call bar(444,555,666,777) + call foobar(1) + + call mod_foo() +end program TestEntryPoint |