📄 member-ptr.exp
字号:
# Copyright 1998, 1999, 2003, 2004, 2006, 2007, 2008# Free Software Foundation, Inc.# This file is part of the gdb testsuite# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 3 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>.# Tests for pointer-to-member support# Written by Satish Pai <pai@apollo.hp.com> 1997-08-19# Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-11set vhn "\\$\[0-9\]+"if $tracelevel then { strace $tracelevel}if { [skip_cplus_tests] } { continue }set prms_id 0set bug_id 0set testfile "member-ptr"set srcfile ${testfile}.ccset binfile ${objdir}/${subdir}/${testfile}if [get_compiler_info ${binfile} "c++"] { return -1}if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { untested member-ptr.exp return -1}gdb_exitgdb_startgdb_reinitialize_dir $srcdir/$subdirgdb_load ${binfile}if ![runto_main] then { perror "couldn't run to breakpoint" continue}gdb_breakpoint [gdb_get_line_number "Breakpoint 1 here"]gdb_continue_to_breakpoint "continue to pmi = NULL"# ======================# pointer to member data# ======================# ptype on pointer to data memberset name "ptype pmi (A::j)"gdb_test_multiple "ptype pmi" $name { -re "type = int A::\\*\r\n$gdb_prompt $" { pass $name }}# print pointer to data memberset name "print pmi (A::j) "gdb_test_multiple "print pmi" $name { -re "$vhn = &A::j\r\n$gdb_prompt $" { pass $name } -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::j\r\n$gdb_prompt $" { pass $name } -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) ?&A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" { # gcc 2.95.3 -gdwarf-2 kfail "gdb/NNNN" $name } -re "$vhn = &A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" { # gcc 2.95.3 -gstabs+ kfail "gdb/NNNN" $name } -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" { # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2 # gcc HEAD 2004-01-11 05:33:21 -gstabs+ kfail "gdb/NNNN" $name } -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870920\r\n$gdb_prompt $" { # the value is 0x20000008 hex. 0x20000000 is an internal flag. # Use '|' to add in more values as needed. # hpacc A.03.45 kfail "gdb/NNNN" $name }}# print dereferenced pointer to data memberset name "print a.*pmi (A::j)"gdb_test_multiple "print a.*pmi" $name { -re "$vhn = 121\r\n$gdb_prompt $" { pass $name } -re "$vhn = 855638016\r\n$gdb_prompt $" { # gcc 2.95.3 -gdwarf-2 # gcc 2.95.3 -gstabs+ kfail "gdb/NNNN" $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# print dereferenced pointer to data member# this time, dereferenced through a pointerset name "print a_p->*pmi (A::j)"gdb_test_multiple "print a_p->*pmi" $name { -re "$vhn = 121\r\n$gdb_prompt $" { pass $name } -re "$vhn = 855638016\r\n$gdb_prompt $" { # gcc 2.95.3 -gdwarf-2 # gcc 2.95.3 -gstabs+ kfail "gdb/NNNN" $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# set the pointer to a different data memberset name "set var pmi = &A::jj"gdb_test_multiple "set var pmi = &A::jj" $name { -re "Invalid cast.\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name } -re "set var pmi = &A::jj\r\n$gdb_prompt $" { # I have to match the echo'ed input explicitly here. # If I leave it out, the pattern becomes too general # and matches anything that ends in "$gdb_prompt $". pass $name }}# print the pointer againset name "print pmi (A::jj)"gdb_test_multiple "print pmi" $name { -re "$vhn = &A::jj\r\n$gdb_prompt $" { pass $name } -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" { pass $name } -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" { # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2 # gcc HEAD 2004-01-11 05:33:21 -gstabs+ kfail "gdb/NNNN" $name } -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870924\r\n$gdb_prompt $" { # the value is 0x20000008 hex. 0x20000000 is an internal flag. # Use '|' to add in more values as needed. # hpacc A.03.45 kfail "gdb/NNNN" $name }}# print dereferenced pointer to data member againset name "print a.*pmi (A::jj)"gdb_test_multiple "print a.*pmi" $name { -re "$vhn = 1331\r\n$gdb_prompt $" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# set the pointer to data member back to A::jset name "set var pmi = &A::j"gdb_test_multiple "set var pmi = &A::j" $name { -re "Invalid cast.\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name } -re "set var pmi = &A::j\r\n$gdb_prompt $" { # I have to match the echo'ed input explicitly here. # If I leave it out, the pattern becomes too general # and matches anything that ends in "$gdb_prompt $". pass $name }}# print dereferenced pointer to data member yet again (extra check, why not)set name "print a.*pmi (A::j) (again)"gdb_test_multiple "print a.*pmi" $name { -re "$vhn = 121\r\n$gdb_prompt $" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# Set the data member pointed to.set name "print a.*pmi = 33"gdb_test_multiple "print a.*pmi = 33" $name { -re "$vhn = 33\r\n$gdb_prompt $" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# Now check that the data really was changedset name "print a.*pmi (A::j) (33)"gdb_test_multiple "print a.*pmi" $name { -re "$vhn = 33\r\n$gdb_prompt $" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# Double-check by printing a.set name "print a (j = 33)"gdb_test_multiple "print a" $name { -re "$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, (_vptr.A|_vptr\\$) = ($hex|$hex <A virtual table>)\}\r\n$gdb_prompt $" { pass $name } -re "$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" { pass $name } -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" { pass $name } -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# Set the data member pointed to, using ->*set name "print a_p->*pmi = 44"gdb_test_multiple "print a_p->*pmi = 44" $name { -re "$vhn = 44\r\n$gdb_prompt $" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# Check that the data really was changedset name "print a_p->*pmi (44)"gdb_test_multiple "print a_p->*pmi" $name { -re "$vhn = 44\r\n$gdb_prompt $" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# Double-check by printing a.set name "print a (j = 44)"gdb_test_multiple "print a" $name { -re "$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, (_vptr.A|_vptr\\$) = ($hex|$hex <A virtual table>)\}\r\n$gdb_prompt $" { pass $name } -re "$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" { pass $name } -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" { pass $name } -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2 # gcc HEAD 2004-01-10 -gstabs+ kfail "gdb/NNNN" $name }}# ptype the dereferenced pointer to member.set name "ptype a.*pmi"gdb_test_multiple "ptype a.*pmi" $name { -re "type = int\r\n$gdb_prompt" { pass $name } -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" { # gcc HEAD 2004-01-10 -gdwarf-2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -