1 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 load_lib gdb-python.exp
18 require allow_python_tests
22 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
26 save_vars { GDBFLAGS } {
27 clean_restart $testfile
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 ""}]
41 set pattern "<gdb.BreakpointLocation"
44 set pattern "$pattern enabled"
46 set pattern "$pattern disabled"
49 set pattern "$pattern address=${address}(?: requested_address=$::hex)?"
50 set pattern "$pattern source=${source}:${line}"
52 set pattern "$pattern in ${func}"
54 set pattern "$pattern>"
58 # Set breakpoint with 2 locations.
61 set expected_line_a [gdb_get_line_number "a + b"]
62 set expected_line_b [gdb_get_line_number "c + d"]
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"
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.*"
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."
90 gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].enabled)" "True" "First location still enabled"
92 gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\].enabled)" "True" "Second location still enabled"
94 # Set breakpoint at end and make sure we run past the still enabled locations,
96 gdb_continue_to_breakpoint "end of main" ".*32.*"