1# Copyright 1998, 1999, 2001, 2002, 2003, 2004 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 2 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, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 17# tests for misc. C++ method stuff 18# Written by Satish Pai <pai@apollo.hp.com> 1997-07-08 19 20# This file is part of the gdb testsuite 21 22# This tests: 23# 0. method arguments are correct 24# 1. access to class data members inside method scopes 25# 2. correct param types for methods in ptype. 26# 3. const and volatile methods 27 28# (#0 and #1 above relate to an HP specific problem -- GDB must correctly 29# integrate FPARAM symbols in HP debug info into the local var list 30# for the function or method's block.) 31 32if $tracelevel then { 33 strace $tracelevel 34 } 35 36# 37# test running programs 38# 39set prms_id 0 40set bug_id 0 41 42if { [skip_cplus_tests] } { continue } 43 44set testfile "method" 45set srcfile ${testfile}.cc 46set binfile ${objdir}/${subdir}/${testfile} 47 48if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { 49 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 50} 51 52if [get_compiler_info $binfile "c++"] { 53 return -1 54} 55 56gdb_exit 57gdb_start 58gdb_reinitialize_dir $srcdir/$subdir 59gdb_load ${binfile} 60 61 62# 63# set it up at a breakpoint so we can play with the variable values 64# 65if ![runto_main] then { 66 perror "couldn't run to breakpoint" 67 continue 68} 69 70gdb_test "break A::foo" \ 71 "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38\\." 72 73gdb_test "continue" \ 74 "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo(\\(int\\)|) \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;" \ 75 "continue to A::foo" 76 77# Check ability to access this-relative stuff. 78 79gdb_test "print x" \ 80 "\\$\[0-9\]* = 20" \ 81 "print x in A::foo" 82 83# Check access to this pointer 84 85gdb_test "print this" \ 86 "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex" \ 87 "print this in A::foo" 88 89# Now do everything over again for A::bar, because sometimes processing one method 90# (the first one) is fine, but the second one's debug info gets munged beyond recognition. 91 92gdb_test "break A::bar" \ 93 "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\." 94 95gdb_test "continue" \ 96 "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::bar(|\\(int\\) const| const) \\(this=$hex, arg=15\\) at .*method\\.cc:44\r\n44\[\t \]*return arg \\+ 2 \\* x;" \ 97 "continue to A::bar" 98 99# Check ability to access this-relative stuff. 100 101gdb_test "print x" \ 102 "\\$\[0-9\]* = 33" \ 103 "print x in A::bar" 104 105# Check access to this pointer 106 107get_debug_format 108 109send_gdb "print this\n" 110gdb_expect { 111 -re "\\$\[0-9\]* = \\(const (class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { 112 pass "print this in A::bar" 113 } 114 -re "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { 115 # gcc versions up to 3.0.4 with -gstabs+ do not emit "const" indicators, 116 # so the output is "A *". It should be "const A *" or "const A * const". 117 setup_xfail_format "stabs" 118 fail "print this in A::bar (missing const)" 119 } 120 -re "\\$\[0-9\]* = \\(const (class |)\{\\.\\.\\.\} *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { 121 # gcc versions gcc-3_1-branch%20020404 and HEAD%20020404 with -gstabs+ 122 # produce good stabs, but gdb prints "const class {...} *" const. 123 # This is PR gdb/277. 124 # setup_kfail "gdb/277" 125 fail "print this in A::bar (gdb/277)" 126 } 127 -re ".*$gdb_prompt $" { fail "print this in A::bar" } 128 timeout { fail "(timeout) print this in A::bar" } 129} 130 131# Check again with funk::getFunky (this is the original test case 132# for CHFts23426); sometimes having a constructor with no arguments 133# will nuke the debug info read in for other methods in the class. 134 135gdb_test "break 21" \ 136 "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 21\\." 137 138gdb_test "continue" \ 139 "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, funk::getFunky(\\(int, int\\)|) \\(this=$hex, a=1, b=2\\) at .*method\\.cc:21\r\n21\[\t \]*data_ = res;" \ 140 "continue to 21" 141 142# Check ability to access this-relative stuff. 143 144gdb_test "print data_" \ 145 "\\$\[0-9\]* = 33" \ 146 "print data_ in funk::getFunky" 147 148# Check access to this pointer 149 150gdb_test "print this" \ 151 "\\$\[0-9\]* = \\((class |)funk *\\* *(const|)\\) $hex" \ 152 "print this in funk::getFunky" 153 154# Check access to local variable 155 156gdb_test "print res" \ 157 "\\$\[0-9\]* = -30" \ 158 "print res in funk::getFunky" 159 160# Check ptype of class -- should show const/volatile methods 161 162send_gdb "ptype A\n" 163gdb_expect { 164 -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) (const volatile|volatile const);\r\n\}\r\n$gdb_prompt $" { 165 pass "ptype A" 166 } 167 -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*A & operator=\\(A const ?&\\);\r\n\[ \]*A\\(A const ?&\\);\r\n\[ \]*A\\((void|)\\);\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) (const volatile|volatile const);\r\n\}\r\n$gdb_prompt $" { 168 pass "ptype A" 169 } 170 -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) (const volatile|volatile const);\r\n\[ \]*A & operator=\\(A const ?&\\);\r\n\[ \]*A\\(A const ?&\\);\r\n\[ \]*A\\((void|)\\);\r\n\}\r\n$gdb_prompt $" { 171 pass "ptype A" 172 } 173 -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\);\r\n\[ \]*int qux\\(int, float\\) const;\r\n\}\r\n$gdb_prompt $" { 174 pass "ptype A (HP aCC bug -- volatile not indicated)" 175 } 176 -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) const volatile;\r\n\}\r\n$gdb_prompt $" { 177 pass "ptype A" 178 } 179 -re ".*$gdb_prompt $" { fail "ptype A" } 180 timeout { fail "(timeout) ptype A" } 181} 182 183send_gdb "cont\n" 184gdb_expect { 185 -re "Continuing.\r\n\r\nProgram exited normally.*$gdb_prompt $" { 186 pass "finish program" 187 } 188 -re "Continuing.* EXIT code 0.*Program exited normally.*$gdb_prompt $" { 189 pass "finish program (exit wrapper)" 190 } 191 -re ".*$gdb_prompt $" { fail "finish program" } 192 default:{ fail "finish program (timeout)" } 193} 194 195