1# Copyright 2007-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# Test that breakpoints on C++ constructors work, despite the 17# fact that gcc generates several versions of constructor function. 18 19require allow_cplus_tests 20 21 22standard_testfile .cc 23 24if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { 25 return -1 26} 27 28if {[test_compiler_info {clang-*-*} c++]} { 29 set using_clang true 30} else { 31 set using_clang false 32} 33 34if {![runto_main]} { 35 return 36} 37 38# Set a breakpoint with multiple locations 39# and a condition. 40 41gdb_test "break 'Derived::Derived(int)'" \ 42 "Breakpoint.*at.*: Derived::Derived.int.. \\(2 locations\\).*" \ 43 "set-breakpoint at ctor" 44 45gdb_breakpoint [gdb_get_line_number "set breakpoint here"] 46 47gdb_test "break 'Derived::~Derived()'" \ 48 "Breakpoint.*at.*: Derived::~Derived... \\(2 locations\\).*" \ 49 "set-breakpoint at dtor" 50 51gdb_test "continue" \ 52 ".*Breakpoint.*Derived.*i=7.*" \ 53 "run to breakpoint 1 v1" 54 55gdb_continue_to_breakpoint "set breakpoint here, first time" ".* breakpoint here" 56 57gdb_test "continue" \ 58 ".*Breakpoint.*Derived.*i=15.*" \ 59 "run to breakpoint 1 v2" 60 61gdb_continue_to_breakpoint "set breakpoint here, second time" ".* breakpoint here" 62 63gdb_test "continue" \ 64 ".*Breakpoint.*Derived.*i=24.*" \ 65 "run to breakpoint 1 dynamic v1" 66 67gdb_continue_to_breakpoint "set breakpoint here, first dynamic time"\ 68 ".* breakpoint here" 69 70gdb_test "continue" \ 71 ".*Breakpoint.*Derived.*i=42.*" \ 72 "run to breakpoint 1 dynamic v2" 73 74gdb_continue_to_breakpoint "set breakpoint here, second dynamic time"\ 75 ".* breakpoint here" 76 77gdb_test "continue" ".*Breakpoint.*~Derived.*" "Run to dynamic destructor v1" 78 79# Clang makes Derived::~Derived(this) call Derived::~Derives(this, vtt) 80# whereas gcc puts all the logic necessary on both functions. 81if {$using_clang} { 82 gdb_test "continue" ".*Breakpoint.*~Derived.*"\ 83 "clang's nested dynamic destructor call" 84} 85 86gdb_test "continue" ".*Breakpoint.*~Derived.*" "Run to dynamic destructor v2" 87 88gdb_test "continue" \ 89 ".*Breakpoint.*~Derived.*" \ 90 "run to breakpoint 3 v1" 91 92gdb_test "continue" \ 93 ".*Breakpoint.*~Derived.*" \ 94 "run to breakpoint 3 v2" 95 96if {$using_clang} { 97 gdb_test "continue" ".*Breakpoint.*~Derived.*"\ 98 "clang's nested destructor call" 99} 100 101gdb_test "continue" \ 102 ".*exited normally.*" \ 103 "run to exit" 104 105 106 107