1# Copyright 2008-2020 Free Software Foundation, Inc.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16load_lib "ada.exp"
17
18if { [skip_ada_tests] } { return -1 }
19
20standard_ada_testfile homonym_main
21
22if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
23  return -1
24}
25
26clean_restart ${testfile}
27
28
29# Do these tests before running, so we are operating in a known
30# environment.
31
32gdb_test "break Get_Value" \
33    "Breakpoint \[0-9\]+ at $hex: Get_Value. .2 locations." \
34    "set breakpoint at Get_Value"
35
36gdb_test "break homonym.adb:Get_Value" \
37    "Breakpoint \[0-9\]+ at $hex: homonym.adb:Get_Value. .2 locations." \
38    "set breakpoint at homonym.adb:Get_Value"
39
40gdb_test "break <homonym__get_value>" \
41    "Breakpoint \[0-9\]+ at $hex: file .*homonym\\.adb, line $decimal\\." \
42    "set breakpoint at <homonym__get_value>"
43
44delete_breakpoints
45
46set bp_location [gdb_get_line_number "BREAK_1" ${testdir}/homonym.adb]
47runto "homonym.adb:$bp_location"
48
49# Check the variables and types defined inside the current scope.
50# There are some homonyms in a different scope, so we want to make
51# sure that the debugger doesn't get mixed up.
52
53gdb_test "ptype local_type" \
54         "type = range -100 \\.\\. 100" \
55         "ptype local_type at BREAK_1"
56
57gdb_test "ptype local_type_subtype" \
58         "type = range -100 \\.\\. 100" \
59         "ptype local_type_subtype at BREAK_1"
60
61gdb_test "ptype int_type" \
62         "type = range -100 \\.\\. 100" \
63         "ptype int_type at BREAK_1"
64
65gdb_test "ptype lcl" \
66         "type = range -100 \\.\\. 100" \
67         "ptype lcl at BREAK_1"
68
69gdb_test "print lcl" \
70         "= 29" \
71         "print lcl at BREAK_1"
72
73# Now, continue until reaching BREAK_2, and do the same commands
74# as above.  The result should be different since the definitions
75# in the new scope are different.
76
77set bp_location [gdb_get_line_number "BREAK_2" ${testdir}/homonym.adb]
78gdb_test "break homonym.adb:$bp_location" \
79         "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: file .*homonym\.adb, line \[0-9\]+\." \
80         "break at BREAK_2"
81
82gdb_test "continue" \
83         ".*Breakpoint \[0-9\]+, homonym\\.get_value \\(\\) at .*homonym\\.adb:.*" \
84         "continue until BREAK_2"
85
86gdb_test "ptype local_type" \
87         "type = range 1 \\.\\. 19740804" \
88         "ptype local_type at BREAK_2"
89
90gdb_test "ptype local_type_subtype" \
91         "type = range 1 \\.\\. 19740804" \
92         "ptype local_type_subtype at BREAK_2"
93
94gdb_test "ptype lcl" \
95         "type = range 1 \\.\\. 19740804" \
96         "ptype lcl at BREAK_2"
97
98gdb_test "print lcl" \
99         "= 17" \
100         "print lcl at BREAK_2"
101