]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - 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
CommitLineData
1d506c26 1# Copyright (C) 2022-2024 Free Software Foundation, Inc.
e5213e2c
SF
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 gdb-python.exp
17
d82e5429 18require allow_python_tests
79749205 19
e5213e2c
SF
20standard_testfile
21
22if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
23 return -1
24}
25
26save_vars { GDBFLAGS } {
27 clean_restart $testfile
28}
29
e5213e2c
SF
30if ![runto_main] {
31 return -1
32}
33
bb2bd584
MBB
34# Build a regexp string that represents the __repr__ of a
35# gdb.BreakpointLocation object. Accepts arguments -enabled, -address,
36# -source, -line, and -func.
37proc 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
e5213e2c
SF
58# Set breakpoint with 2 locations.
59gdb_breakpoint "add"
60
61set expected_line_a [gdb_get_line_number "a + b"]
62set expected_line_b [gdb_get_line_number "c + d"]
63
64# Test that the locations return correct source locations.
65gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].source)" \
66 ".*('.*py-bp-locations.c', $expected_line_a).*"
67gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\].source)" \
68 ".*('.*py-bp-locations.c', $expected_line_b).*"
bb2bd584
MBB
69gdb_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"
e5213e2c
SF
73
74# Disable first location and make sure we don't hit it.
75gdb_test "python gdb.breakpoints()\[1\].locations\[0\].enabled = False" ""
bb2bd584
MBB
76gdb_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"
e5213e2c
SF
80gdb_continue_to_breakpoint "" ".*25.*"
81
82if ![runto_main] {
83 return -1
84}
85
86gdb_breakpoint "add"
87# Disable "add" owner breakpoint and verify all locations still are enabled.
88gdb_test "python gdb.breakpoints()\[1\].enabled = False" "" "Disable add owner breakpoint."
89
90gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].enabled)" "True" "First location still enabled"
91
92gdb_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,
95gdb_breakpoint 32
96gdb_continue_to_breakpoint "end of main" ".*32.*"