]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-bp-locations.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-bp-locations.exp
1 # Copyright (C) 2022-2024 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
16 load_lib gdb-python.exp
17
18 require allow_python_tests
19
20 standard_testfile
21
22 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
23 return -1
24 }
25
26 save_vars { GDBFLAGS } {
27 clean_restart $testfile
28 }
29
30 if ![runto_main] {
31 return -1
32 }
33
34 # Build a regexp string that represents the __repr__ of a
35 # gdb.BreakpointLocation object. Accepts arguments -enabled, -address,
36 # -source, -line, and -func.
37 proc build_bpl_regexp { args } {
38 parse_args [list {enabled True} [list address "$::hex"] {source ".*"} \
39 [list line "$::decimal"] {func ""}]
40
41 set pattern "<gdb.BreakpointLocation"
42
43 if {$enabled} {
44 set pattern "$pattern enabled"
45 } else {
46 set pattern "$pattern disabled"
47 }
48
49 set pattern "$pattern address=${address}(?: requested_address=$::hex)?"
50 set pattern "$pattern source=${source}:${line}"
51 if {$func ne ""} {
52 set pattern "$pattern in ${func}"
53 }
54 set pattern "$pattern>"
55 return $pattern
56 }
57
58 # Set breakpoint with 2 locations.
59 gdb_breakpoint "add"
60
61 set expected_line_a [gdb_get_line_number "a + b"]
62 set expected_line_b [gdb_get_line_number "c + d"]
63
64 # Test that the locations return correct source locations.
65 gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].source)" \
66 ".*('.*py-bp-locations.c', $expected_line_a).*"
67 gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\].source)" \
68 ".*('.*py-bp-locations.c', $expected_line_b).*"
69 gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\])" \
70 [build_bpl_regexp -enabled True -source ".*py-bp-locations.c" \
71 -line "$expected_line_b" -func ".*"] \
72 "check repr of enabled breakpoint location"
73
74 # Disable first location and make sure we don't hit it.
75 gdb_test "python gdb.breakpoints()\[1\].locations\[0\].enabled = False" ""
76 gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\])" \
77 [build_bpl_regexp -enabled False -source ".*py-bp-locations.c" \
78 -line "$expected_line_a" -func ".*"] \
79 "check repr of disabled breakpoint location"
80 gdb_continue_to_breakpoint "" ".*25.*"
81
82 if ![runto_main] {
83 return -1
84 }
85
86 gdb_breakpoint "add"
87 # Disable "add" owner breakpoint and verify all locations still are enabled.
88 gdb_test "python gdb.breakpoints()\[1\].enabled = False" "" "Disable add owner breakpoint."
89
90 gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].enabled)" "True" "First location still enabled"
91
92 gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\].enabled)" "True" "Second location still enabled"
93
94 # Set breakpoint at end and make sure we run past the still enabled locations,
95 gdb_breakpoint 32
96 gdb_continue_to_breakpoint "end of main" ".*32.*"