📄 classes.exp
字号:
{ field public "int z;" } { method public "Bar(int, int, int);" } }}# Test simple access to class members.proc test_non_inherited_member_access {} { # Print non-inherited members of g_A. gdb_test "print g_A.a" ".* = 1" gdb_test "print g_A.x" ".* = 2" # Print non-inherited members of g_B. gdb_test "print g_B.b" ".* = 5" gdb_test "print g_B.x" ".* = 6" # Print non-inherited members of g_C. gdb_test "print g_C.c" ".* = 9" gdb_test "print g_C.x" ".* = 10" # Print non-inherited members of g_D. gdb_test "print g_D.d" ".* = 19" gdb_test "print g_D.x" ".* = 20" # Print non-inherited members of g_E. gdb_test "print g_E.e" ".* = 31" gdb_test "print g_E.x" ".* = 32"}# Test access to members of other classes.# gdb should refuse to print them.# (I feel old -- I remember when this was legal in C -- chastain).proc test_wrong_class_members {} { gdb_test "print g_A.b" "There is no member( or method|) named b." gdb_test "print g_B.c" "There is no member( or method|) named c." gdb_test "print g_B.d" "There is no member( or method|) named d." gdb_test "print g_C.b" "There is no member( or method|) named b." gdb_test "print g_C.d" "There is no member( or method|) named d." gdb_test "print g_D.e" "There is no member( or method|) named e."}# Test access to names that are not members of any class.proc test_nonexistent_members {} { gdb_test "print g_A.y" "There is no member( or method|) named y." gdb_test "print g_B.z" "There is no member( or method|) named z." gdb_test "print g_C.q" "There is no member( or method|) named q." gdb_test "print g_D.p" "There is no member( or method|) named p."}# Call a method that expects a base class parameter with base, inherited,# and unrelated class arguments.proc test_method_param_class {} { gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" gdb_test "call class_param.Aref_a (g_A)" ".* = 1" gdb_test "call class_param.Aref_x (g_A)" ".* = 2" gdb_test "call class_param.Aref_a (g_B)" ".* = 3" gdb_test "call class_param.Aref_x (g_B)" ".* = 4" gdb_test "call class_param.Aval_a (g_A)" ".* = 1" gdb_test "call class_param.Aval_x (g_A)" ".* = 2" gdb_test "call class_param.Aval_a (g_B)" ".* = 3" gdb_test "call class_param.Aval_x (g_B)" ".* = 4" gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param" gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m" gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"}# Examine a class with an enum field.proc test_enums {} { global gdb_prompt global nl # print the object gdb_test "print obj_with_enum" \ "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \ "print obj_with_enum (1)" # advance one line gdb_test "next" "" # print the object again gdb_test "print obj_with_enum" \ "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \ "print obj_with_enum (2)" # print the enum member gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green" # ptype on the enum member gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" { -re "type = enum ClassWithEnum::PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" } -re "type = enum PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { # gcc 2.95.3 -gdwarf-2 # gcc 3.3.2 -gdwarf-2 pass "ptype obj_with_enum.priv_enum" } -re "type = enum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { # This case case is a little dubious, but it's not clear what # ought to be required of a ptype on a private enum... # -sts 19990324 # # It bugs me that this happens with gcc 3. # -- chastain 2003-12-30 # # gcc 2.95.3 -gstabs+ # gcc 3.3.2 -gstabs+ # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ pass "ptype obj_with_enum.priv_enum" } } # ptype on the object # NOTE: carlton/2003-02-28: One could certainly argue that plain # "PrivEnum" # is acceptable: PrivEnum is a member of ClassWithEnum, so # there's no need to explicitly qualify its name with # "ClassWithEnum::". The truth, though, is that GDB is simply # forgetting that PrivEnum is a member of ClassWithEnum, so we do # that output for a bad reason instead of a good reason. Under # stabs, we probably can't get this right; under DWARF-2, we can. cp_test_ptype_class \ "ptype obj_with_enum" "" "class" "ClassWithEnum" \ { { field public "ClassWithEnum::PrivEnum priv_enum;" } { field public "int x;" } } \ "" \ { { "ClassWithEnum::PrivEnum priv_enum;" "PrivEnum priv_enum;" { setup_kfail "gdb/57" "*-*-*" } } } # I'll do this test two different ways, because of a parser bug. # See PR gdb/1588. gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" { -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" } -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" { # "parse error" is bison 1.35. # "syntax error" is bison 1.875. kfail "gdb/1588" "print (ClassWithEnum::PrivEnum) 42" } } gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" { -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" { # gcc 3.3.2 -gstabs+ # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ pass "print ('ClassWithEnum::PrivEnum') 42" } -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.$nl$gdb_prompt $" { # gcc 2.95.3 -gdwarf-2 # gcc 3.3.2 -gdwarf-2 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 # gcc 2.95.3 -gstabs+ kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42" } }}# Pointers to class membersproc test_pointers_to_class_members {} { gdb_test "print Bar::z" "\\$\[0-9\]+ = \\(int ?\\( ?Bar::& ?\\) ?\\) ?Bar::z" gdb_test "print &Foo::x" "\\$\[0-9\]+ = \\(int ?\\( ?Foo::\\* ?\\) ?\\) ?&Foo::x" gdb_test "print (int)&Foo::x" "\\$\[0-9\]+ = 0" gdb_test "print (int)&Bar::y == 2*sizeof(int)" "\\$\[0-9\]+ = true" # TODO: this is a bogus test. It's looking at a variable that # has not even been declared yet, so it's accessing random junk # on the stack and comparing that it's NOT equal to a specific # value. It's been like this since gdb 4.10 in 1993! # -- chastain 2004-01-01 gdb_test "print (int)pmi == sizeof(int)" ".* = false"}# Test static members.proc test_static_members {} { global hex gdb_test "print Foo::st" "\\$\[0-9\]+ = 100" gdb_test "set foo.st = 200" "" "" gdb_test "print bar.st" "\\$\[0-9\]+ = 200" gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex" gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex" gdb_test "print *\$" "\\$\[0-9\]+ = 200" gdb_test "set print static-members off" "" gdb_test "print csi" \ "{x = 10, y = 20}" \ "print csi without static members" gdb_test "print cnsi" \ "{x = 30, y = 40}" \ "print cnsi without static members" gdb_test "set print static-members on" "" gdb_test "print csi" \ "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \ "print csi with static members" gdb_test "print cnsi" \ "{x = 30, y = 40, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>, static yy = {z = 5, static xx = {x = 1, y = 2, static null = <same as static member of an already seen type>, static yy = <same as static member of an already seen type>}}}, static yy = <same as static member of an already seen type>}" \ "print cnsi with static members"}proc do_tests {} { global prms_id global bug_id global subdir global objdir global srcdir global binfile global gdb_prompt global nl set prms_id 0 set bug_id 0 # Start with a fresh gdb. gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $binfile gdb_test "set language c++" "" "" gdb_test "set width 0" "" "" if ![runto_main ] then { perror "couldn't run to breakpoint" return } gdb_breakpoint inheritance2 gdb_test "continue" ".*Breakpoint .* inheritance2.*" "" test_ptype_class_objects test_non_inherited_member_access test_wrong_class_members test_nonexistent_members test_method_param_class gdb_breakpoint enums2 gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)" gdb_test "finish" "" "" test_enums gdb_test "finish" "" "" test_pointers_to_class_members test_static_members # Now some random tests that were just thrown in here. gdb_breakpoint marker_reg1 gdb_test "continue" ".*Breakpoint .* marker_reg1.*" "" gdb_test "finish" "Run till exit from.*" "finish from marker_reg1" # This class is so small that an instance of it can fit in a register. # When gdb tries to call a method, it gets embarrassed about taking # the address of a register. # # TODO: I think that message should be a PASS, not an XFAIL. # gdb prints an informative message and declines to do something # impossible. # # The method call actually succeeds if the compiler allocates very # small classes in memory instead of registers. So this test does # not tell us anything interesting if the call succeeds. # # -- chastain 2003-12-31 gdb_test_multiple "print v.method ()" "calling method for small class" { -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" { # gcc 3.3.2 -gdwarf-2 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 # gcc 3.3.2 -gstabs+ # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ pass "calling method for small class" } -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" { # gcc 2.95.3 -gdwarf-2 # gcc 2.95.3 -gstabs+ setup_xfail "*-*-*" 2972 fail "calling method for small class" } }}do_tests
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -