1 1.1.1.2 christos # Copyright (C) 2022-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos load_lib gdb-python.exp 17 1.1 christos 18 1.1.1.2 christos require allow_python_tests 19 1.1.1.2 christos 20 1.1 christos standard_testfile 21 1.1 christos 22 1.1 christos if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } { 23 1.1 christos return -1 24 1.1 christos } 25 1.1 christos 26 1.1 christos save_vars { GDBFLAGS } { 27 1.1 christos clean_restart $testfile 28 1.1 christos } 29 1.1 christos 30 1.1 christos if ![runto_main] { 31 1.1 christos return -1 32 1.1 christos } 33 1.1 christos 34 1.1.1.2 christos # Build a regexp string that represents the __repr__ of a 35 1.1.1.2 christos # gdb.BreakpointLocation object. Accepts arguments -enabled, -address, 36 1.1.1.2 christos # -source, -line, and -func. 37 1.1.1.2 christos proc build_bpl_regexp { args } { 38 1.1.1.2 christos parse_args [list {enabled True} [list address "$::hex"] {source ".*"} \ 39 1.1.1.2 christos [list line "$::decimal"] {func ""}] 40 1.1.1.2 christos 41 1.1.1.2 christos set pattern "<gdb.BreakpointLocation" 42 1.1.1.2 christos 43 1.1.1.2 christos if {$enabled} { 44 1.1.1.2 christos set pattern "$pattern enabled" 45 1.1.1.2 christos } else { 46 1.1.1.2 christos set pattern "$pattern disabled" 47 1.1.1.2 christos } 48 1.1.1.2 christos 49 1.1.1.2 christos set pattern "$pattern address=${address}(?: requested_address=$::hex)?" 50 1.1.1.2 christos set pattern "$pattern source=${source}:${line}" 51 1.1.1.2 christos if {$func ne ""} { 52 1.1.1.2 christos set pattern "$pattern in ${func}" 53 1.1.1.2 christos } 54 1.1.1.2 christos set pattern "$pattern>" 55 1.1.1.2 christos return $pattern 56 1.1.1.2 christos } 57 1.1.1.2 christos 58 1.1 christos # Set breakpoint with 2 locations. 59 1.1 christos gdb_breakpoint "add" 60 1.1 christos 61 1.1 christos set expected_line_a [gdb_get_line_number "a + b"] 62 1.1 christos set expected_line_b [gdb_get_line_number "c + d"] 63 1.1 christos 64 1.1 christos # Test that the locations return correct source locations. 65 1.1 christos gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].source)" \ 66 1.1 christos ".*('.*py-bp-locations.c', $expected_line_a).*" 67 1.1 christos gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\].source)" \ 68 1.1 christos ".*('.*py-bp-locations.c', $expected_line_b).*" 69 1.1.1.2 christos gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\])" \ 70 1.1.1.2 christos [build_bpl_regexp -enabled True -source ".*py-bp-locations.c" \ 71 1.1.1.2 christos -line "$expected_line_b" -func ".*"] \ 72 1.1.1.2 christos "check repr of enabled breakpoint location" 73 1.1 christos 74 1.1 christos # Disable first location and make sure we don't hit it. 75 1.1 christos gdb_test "python gdb.breakpoints()\[1\].locations\[0\].enabled = False" "" 76 1.1.1.2 christos gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\])" \ 77 1.1.1.2 christos [build_bpl_regexp -enabled False -source ".*py-bp-locations.c" \ 78 1.1.1.2 christos -line "$expected_line_a" -func ".*"] \ 79 1.1.1.2 christos "check repr of disabled breakpoint location" 80 1.1 christos gdb_continue_to_breakpoint "" ".*25.*" 81 1.1 christos 82 1.1 christos if ![runto_main] { 83 1.1 christos return -1 84 1.1 christos } 85 1.1 christos 86 1.1 christos gdb_breakpoint "add" 87 1.1 christos # Disable "add" owner breakpoint and verify all locations still are enabled. 88 1.1 christos gdb_test "python gdb.breakpoints()\[1\].enabled = False" "" "Disable add owner breakpoint." 89 1.1 christos 90 1.1 christos gdb_test "python print(gdb.breakpoints()\[1\].locations\[0\].enabled)" "True" "First location still enabled" 91 1.1 christos 92 1.1 christos gdb_test "python print(gdb.breakpoints()\[1\].locations\[1\].enabled)" "True" "Second location still enabled" 93 1.1 christos 94 1.1 christos # Set breakpoint at end and make sure we run past the still enabled locations, 95 1.1 christos gdb_breakpoint 32 96 1.1 christos gdb_continue_to_breakpoint "end of main" ".*32.*" 97