home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / testsuite / gdb.t20 / classes.exp next >
Encoding:
Text File  |  1993-05-12  |  23.8 KB  |  777 lines

  1. # Copyright (C) 1992 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. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-gdb@prep.ai.mit.edu
  17.  
  18. # This file was written by Fred Fish. (fnf@cygnus.com)
  19.  
  20. if $tracelevel then {
  21.     strace $tracelevel
  22. }
  23.  
  24. #
  25. # Test ptype of class objects.
  26. #
  27.  
  28. proc test_ptype_class_objects {} {
  29.     global prompt
  30.  
  31.     set passcount 0
  32.  
  33.     # Note that struct members are public by default, so we don't print
  34.     # "public:" for the public members of structs.
  35.  
  36.     send "ptype struct default_public_struct\n"
  37.     expect {
  38.     -re "type = struct default_public_struct \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  39.         incr passcount
  40.     }
  41.     -re ".*$prompt $" { fail "ptype struct default_public_struct" }
  42.     timeout { fail "ptype struct default_public_struct (timeout)" ; return }
  43.     }
  44.  
  45.     # Note that struct members are public by default, so we don't print
  46.     # "public:" for the public members of structs.
  47.  
  48.     send "ptype struct explicit_public_struct\n"
  49.     expect {
  50.     -re "type = struct explicit_public_struct \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  51.         incr passcount
  52.     }
  53.     -re ".*$prompt $" { fail "ptype struct explicit_public_struct" }
  54.     timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
  55.     }
  56.  
  57.     # Accept it as an expected failure if gdb just fails to distinguish between
  58.     # class and struct, and everything else is OK.
  59.  
  60.     setup_xfail "*-*-*"
  61.     send "ptype struct protected_struct\n"
  62.     expect {
  63.     -re "type = struct protected_struct \{\r\n\[ \]*protected:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  64.         incr passcount
  65.     }
  66.     -re "type = class protected_struct \{\r\n\[ \]*protected:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  67.         fail "ptype struct protected_struct (FIXME)"
  68.     }
  69.     -re ".*$prompt $" { fail "ptype struct protected_struct" }
  70.     timeout { fail "ptype struct protected_struct (timeout)" ; return }
  71.     }
  72.  
  73.     # Accept it as an expected failure if gdb just fails to distinguish between
  74.     # class and struct, and everything else is OK.
  75.  
  76.     setup_xfail "*-*-*"
  77.     send "ptype struct private_struct\n"
  78.     expect {
  79.     -re "type = struct private_struct \{\r\n\[ \]*private:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  80.         incr passcount
  81.     }
  82.     -re "type = class private_struct \{\r\n\[ \]*private:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" { 
  83.         fail "ptype struct private_struct (FIXME)"
  84.     }
  85.     -re ".*$prompt $" { fail "ptype struct private_struct" }
  86.     timeout { fail "ptype struct private_struct (timeout)" ; return }
  87.     }
  88.  
  89.     # Accept it as an expected failure if gdb just fails to distinguish between
  90.     # class and struct, and everything else is OK.
  91.  
  92.     setup_xfail "*-*-*"
  93.     send "ptype struct mixed_protection_struct\n"
  94.     expect {
  95.     -re "type = struct mixed_protection_struct \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\[ \]*private:\r\n\[ \]*int c;\r\n\[ \]*int d;\r\n\[ \]*protected:\r\n\[ \]*int e;\r\n\[ \]*int f;\r\n\[ \]*public:\r\n\[ \]*int g;\r\n\[ \]*private:\r\n\[ \]*int h;\r\n\[ \]*protected:\r\n\[ \]*int i;\r\n\}\r\n$prompt $" {
  96.         incr passcount
  97.     }
  98.     -re "type = class mixed_protection_struct \{\r\n\[ \]*public:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\[ \]*private:\r\n\[ \]*int c;\r\n\[ \]*int d;\r\n\[ \]*protected:\r\n\[ \]*int e;\r\n\[ \]*int f;\r\n\[ \]*public:\r\n\[ \]*int g;\r\n\[ \]*private:\r\n\[ \]*int h;\r\n\[ \]*protected:\r\n\[ \]*int i;\r\n\}\r\n$prompt $" {
  99.         fail "ptype struct mixed_protection_struct (FIXME)"
  100.     }
  101.     -re ".*$prompt $" { fail "ptype struct mixed_protection_struct" }
  102.     timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
  103.     }
  104.  
  105.     # Accept it as an expected failure if gdb just fails to distinguish between
  106.     # class and struct, and everything else is OK.
  107.  
  108.     setup_xfail "*-*-*"
  109.     send "ptype class public_class\n"
  110.     expect {
  111.     -re "type = class public_class \{\[ \]*public:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  112.         incr passcount
  113.     }
  114.     -re "type = struct public_class \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  115.         fail "ptype class public_class (FIXME)"
  116.     }
  117.     -re ".*$prompt $" { fail "ptype class public_class" }
  118.     timeout { fail "ptype class public_class (timeout)" ; return }
  119.     }
  120.  
  121.     send "ptype class protected_class\n"
  122.     expect {
  123.     -re "type = class protected_class \{\r\n\[ \]*protected:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  124.         incr passcount
  125.     }
  126.     -re "type = struct protected_class \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  127.         setup_xfail "*-*-*"
  128.         fail "ptype class protected_class"
  129.     }
  130.     -re ".*$prompt $" { fail "ptype class protected_class" }
  131.     timeout { fail "ptype class protected_class (timeout)" ; return }
  132.     }
  133.  
  134.     # Accept it as an expected failure if gdb just emits a superflous "private:"
  135.     # attribute, since classes default to private and for consistency with
  136.     # structs (where we don't print the "public:" attribute) we don't print
  137.     # the "private:" attribute.
  138.  
  139.     setup_xfail "*-*-*"
  140.     send "ptype class default_private_class\n"
  141.     expect {
  142.     -re "type = class default_private_class \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  143.         incr passcount
  144.     }
  145.     -re "type = class default_private_class \{\r\n\[ \]*private:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  146.         fail "ptype class default_private_class (FIXME)"
  147.     }
  148.     -re ".*$prompt $" { fail "ptype class default_private_class" }
  149.     timeout { fail "ptype class default_private_class (timeout)" ; return }
  150.     }
  151.  
  152.     send "ptype class explicit_private_class\n"
  153.     expect {
  154.     -re "type = class explicit_private_class \{\r\n\[ \]*private:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  155.         incr passcount
  156.     }
  157.     -re "type = struct explicit_private_class \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\}\r\n$prompt $" {
  158.         setup_xfail "*-*-*"
  159.         fail "ptype class explicit_private_class"
  160.     }
  161.     -re ".*$prompt $" { fail "ptype class explicit_private_class" }
  162.     timeout { fail "ptype class explicit_private_class (timeout)" ; return }
  163.     }
  164.  
  165.     send "ptype class mixed_protection_class\n"
  166.     expect {
  167.     -re "type = class mixed_protection_class \{\r\n\[ \]*public:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\[ \]*private:\r\n\[ \]*int c;\r\n\[ \]*int d;\r\n\[ \]*protected:\r\n\[ \]*int e;\r\n\[ \]*int f;\r\n\[ \]*public:\r\n\[ \]*int g;\r\n\[ \]*private:\r\n\[ \]*int h;\r\n\[ \]*protected:\r\n\[ \]*int i;\r\n\}\r\n$prompt $" {
  168.         incr passcount
  169.     }
  170.     -re "type = struct mixed_protection_class \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\[ \]*int c;\r\n\[ \]*int d;\r\n\[ \]*int e;\r\n\[ \]*int f;\r\n\[ \]*int g;\r\n\[ \]*int h;\r\n\[ \]*int i;\r\n\}\r\n$prompt $" {
  171.         setup_xfail "*-*-*"
  172.         fail "ptype class mixed_protection_class"
  173.     }
  174.     -re ".*$prompt $" { fail "ptype class mixed_protection_class" }
  175.     timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
  176.     }
  177.  
  178.     # Accept it as an expected failure if gdb just fails to distinguish between
  179.     # class and struct, and everything else is OK.
  180.  
  181.     setup_xfail "*-*-*"
  182.     send "ptype class A\n"
  183.     expect {
  184.     -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int a;\r\n\[ \]*int x;\r\n\[ \]*\}\r\n$prompt $" {
  185.         incr passcount
  186.     }
  187.     -re "type = struct A \{\r\n\[ \]*int a;\r\n\[ \]*int x;\r\n\[ \]*\}\r\n$prompt $" {
  188.         fail "ptype class A (FIXME)"
  189.     }
  190.     -re ".*$prompt $" { fail "ptype class A" }
  191.     timeout { fail "ptype class A (timeout)" ; return }
  192.     }
  193.  
  194.     # Accept it as an expected failure if gdb just fails to distinguish between
  195.     # class and struct, and everything else is OK.
  196.  
  197.     send "ptype class B\n"
  198.     expect {
  199.     -re "type = class B : public A \{\r\n\[ \]*public:\r\n\[ \]*int b;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  200.         incr passcount
  201.     }
  202.     -re "type = struct B \{\r\n\[ \]*struct A A;\r\n\[ \]*int b;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  203.         setup_xfail "*-*-*"
  204.         fail "ptype class B"
  205.     }
  206.     -re ".*$prompt $" { fail "ptype class B" }
  207.     timeout { fail "ptype class B (timeout)" ; return }
  208.     }
  209.  
  210.     send "ptype class C\n"
  211.     expect {
  212.     -re "type = class C : public A \{\r\n\[ \]*public:\r\n\[ \]*int c;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  213.         incr passcount
  214.     }
  215.     -re "type = struct C \{\r\n\[ \]*struct A A;\r\n\[ \]*int c;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  216.         setup_xfail "*-*-*"
  217.         fail "ptype class C"
  218.     }
  219.     -re ".*$prompt $" { fail "ptype class C" }
  220.     timeout { fail "ptype class C (timeout)" ; return }
  221.     }
  222.  
  223.     send "ptype class D\n"
  224.     expect {
  225.     -re "type = class D : public B, public C \{\r\n\[ \]*public:\r\n\[ \]*int d;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  226.         incr passcount
  227.     }
  228.     -re "type = struct D \{\r\n\[ \]*struct B B;\r\n\[ \]*struct C C;\r\n\[ \]*int d;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  229.         setup_xfail "*-*-*"
  230.         fail "ptype class D"
  231.     }
  232.     -re ".*$prompt $" { fail "ptype class D" }
  233.     timeout { fail "ptype class D (timeout)" ; return }
  234.     }
  235.  
  236.     send "ptype class E\n"
  237.     expect {
  238.     -re "type = class E : public D \{\r\n\[ \]*public:\r\n\[ \]*int e;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  239.         incr passcount
  240.     }
  241.     -re "type = struct E \{\r\n\[ \]*struct D D;\r\n\[ \]*int e;\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  242.         setup_xfail "*-*-*"
  243.         fail "ptype class D"
  244.     }
  245.     -re ".*$prompt $" { fail "ptype class E" }
  246.     timeout { fail "ptype class E (timeout)" ; return }
  247.     }
  248.  
  249.     # Accept it as an expected failure if gdb just fails to distinguish between
  250.     # class and struct, and everything else is OK.
  251.  
  252.     setup_xfail "*-*-*"
  253.     send "ptype class vA\n"
  254.     expect {
  255.     -re "type = class vA \{\r\n\[ \]*public:\r\n\[ \]*int va;\r\n\[ \]*int vx;\r\n\}\r\n$prompt $" {
  256.         incr passcount
  257.     }
  258.     -re "type = struct vA \{\r\n\[ \]*int va;\r\n\[ \]*int vx;\r\n\}\r\n$prompt $" {
  259.         fail "ptype class vA (FIXME)"
  260.     }
  261.     -re ".*$prompt $" { fail "ptype class vA" }
  262.     timeout { fail "ptype class vA (timeout)" ; return }
  263.     }
  264.  
  265.     # Accept the form with embedded GNU style mangled virtual table constructs
  266.     # for now, but with a FIXME.  At some future point, gdb should use a
  267.     # portable representation for the virtual table constructs.
  268.  
  269.     setup_xfail "*-*-*"
  270.     send "ptype class vB\n"
  271.     expect {
  272.     -re "type = class vB : public virtual vA \{\r\n\[ \]*private:\r\n\[ \]*vA \*_vb\\\$vA;\r\n\[ \]*public:\r\n\[ \]*int vb;\r\n\[ \]*int vx;\r\n\}\r\n$prompt $" {
  273.         fail "ptype class vB (FIXME)"
  274.     }
  275.     -re ".*$prompt $" { fail "ptype class vB" }
  276.     timeout { fail "ptype class vB (timeout)" ; return }
  277.     }
  278.  
  279.     # Accept the form with embedded GNU style mangled virtual table constructs
  280.     # for now, but with a FIXME.  At some future point, gdb should use a
  281.     # portable representation for the virtual table constructs.
  282.  
  283.     setup_xfail "*-*-*"
  284.     send "ptype class vC\n"
  285.     expect {
  286.     -re "type = class vC : public virtual vA \{\r\n\[ \]*private:\r\n\[ \]*vA \*_vb\\\$vA;\r\n\[ \]*public:\r\n\[ \]*int vc;\r\n\[ \]*int vx;\r\n\}\r\n$prompt $" {
  287.         fail "ptype class vC (FIXME)"
  288.     }
  289.     -re ".*$prompt $" { fail "ptype class vC" }
  290.     timeout { fail "ptype class vC (timeout)" ; return }
  291.     }
  292.  
  293.     # Accept the form with embedded GNU style mangled virtual table constructs
  294.     # for now, but with a FIXME.  At some future point, gdb should use a
  295.     # portable representation for the virtual table constructs.
  296.  
  297.     setup_xfail "*-*-*"
  298.     send "ptype class vD\n"
  299.     expect {
  300.     -re "type = class vD : public virtual vB, public virtual vC \{\r\n\[ \]*private:\r\n\[ \]*vC \*_vb\\\$vC;\r\n\[ \]*vB \*_vb\\\$vB;\r\n\[ \]*public:\r\n\[ \]*int vd;\r\n\[ \]*int vx;\r\n\}\r\n$prompt $" {
  301.         fail "ptype class vD (FIXME)"
  302.     }
  303.     -re ".*$prompt $" { fail "ptype class vD" }
  304.     timeout { fail "ptype class vD (timeout)" ; return }
  305.     }
  306.  
  307.     # Accept the form with embedded GNU style mangled virtual table constructs
  308.     # for now, but with a FIXME.  At some future point, gdb should use a
  309.     # portable representation for the virtual table constructs.
  310.  
  311.     setup_xfail "*-*-*"
  312.     send "ptype class vE\n"
  313.     expect {
  314.     -re "type = class vE : public virtual vD \{\r\n\[ \]*private:\r\n\[ \]*vD \*_vb\\\$vD;\r\n\[ \]*public:\r\n\[ \]*int ve;\r\n\[ \]*int vx;\r\n\}\r\n$prompt $" {
  315.         fail "ptype class vE (FIXME)"
  316.     }
  317.     -re ".*$prompt $" { fail "ptype class vE" }
  318.     timeout { fail "ptype class vE (timeout)" ; return }
  319.     }
  320.  
  321.     send "ptype class Base1\n"
  322.     expect {
  323.     -re "type = class Base1 \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\r\n\[ \]*Base1\(int\);\r\n\}\r\n$prompt $" {
  324.         incr passcount
  325.     }
  326.     -re "type = struct Base1 \{\r\n\[ \]*int x;\r\n\}\r\n$prompt $" {
  327.         setup_xfail "*-*-*"
  328.         fail "ptype class Base1"
  329.     }
  330.     -re ".*$prompt $" { fail "ptype class Base1" }
  331.     timeout { fail "ptype class Base1 (timeout)" ; return }
  332.     }
  333.  
  334.     send "ptype class Foo\n"
  335.     expect {
  336.     -re "type = class Foo \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\[ \]*static int st;\r\n\r\n\[ \]*Foo\(int, int\);\r\n\[ \]*int operator\!\(void\);\r\n\[ \]*int operator int\(void\);\r\n\[ \]*int times\(int\);\r\n\}\r\n$prompt $" {
  337.         incr passcount
  338.     }
  339.     -re "type = struct Foo \{\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\}\r\n$prompt $" {
  340.         setup_xfail "*-*-*"
  341.         fail "ptype class Foo"
  342.     }
  343.     -re ".*$prompt $" { fail "ptype class Foo" }
  344.     timeout { fail "ptype class Foo (timeout)" ; return }
  345.     }
  346.  
  347.     send "ptype class Bar\n"
  348.     expect {
  349.     -re "type = class Bar : public Base1, public Foo \{\r\n\[ \]*public:\r\n\[ \]*int z;\r\n\r\n\[ \]*Bar\(int, int, int\);\r\n\}\r\n$prompt $" {
  350.         incr passcount
  351.     }
  352.     -re "type = struct Bar \{\r\n\[ \]*struct Base1 Base1;\r\n\[ \]*struct Foo Foo;\r\n\[ \]*int z;\r\n\}\r\n$prompt $" {
  353.         setup_xfail "*-*-*"
  354.         fail "ptype class Bar"
  355.     }
  356.     -re ".*$prompt $" { fail "ptype class Bar" }
  357.     timeout { fail "ptype class Bar (timeout)" ; return }
  358.     }
  359.  
  360.     if $passcount then {
  361.     pass "$passcount correct ptype results for class objects"
  362.     }
  363. }
  364.  
  365. #
  366. # Test simple access to class members.
  367. #
  368.  
  369. proc test_non_inherited_member_access {} {
  370.     global prompt
  371.     
  372.     set passcount 0
  373.  
  374.     # Print non-inherited members of g_A.
  375.  
  376.     send "print g_A.a\n"
  377.     expect {
  378.     -re ".* = 1\r\n$prompt $" { incr passcount }
  379.     -re ".*$prompt $" { fail "g_A.a incorrect" }
  380.     timeout { fail "print g_A.a (timeout)" ; return }
  381.     }
  382.  
  383.     send "print g_A.x\n"
  384.     expect {
  385.     -re ".* = 2\r\n$prompt $" { incr passcount }
  386.     -re ".*$prompt $" { fail "g_A.x incorrect" }
  387.     timeout { fail "print g_A.x (timeout)" ; return }
  388.     }
  389.  
  390.     # Print non-inherited members of g_B.
  391.  
  392.     send "print g_B.b\n"
  393.     expect {
  394.     -re ".* = 5\r\n$prompt $" { incr passcount }
  395.     -re ".*$prompt $" { fail "g_B.b incorrect" }
  396.     timeout { fail "print g_B.b (timeout)" ; return }
  397.     }
  398.  
  399.     send "print g_B.x\n"
  400.     expect {
  401.     -re ".* = 6\r\n$prompt $" { incr passcount }
  402.     -re ".*$prompt $" { fail "g_B.x incorrect" }
  403.     timeout { fail "print g_B.x (timeout)" ; return }
  404.     }
  405.  
  406.     # Print non-inherited members of g_C.
  407.  
  408.     send "print g_C.c\n"
  409.     expect {
  410.     -re ".* = 9\r\n$prompt $" { incr passcount }
  411.     -re ".*$prompt $" { fail "g_C.c incorrect" }
  412.     timeout { fail "print g_C.c (timeout)" ; return }
  413.     }
  414.  
  415.     send "print g_C.x\n"
  416.     expect {
  417.     -re ".* = 10\r\n$prompt $" { incr passcount }
  418.     -re ".*$prompt $" { fail "g_C.x incorrect" }
  419.     timeout { fail "print g_C.x (timeout)" ; return }
  420.     }
  421.  
  422.     # Print non-inherited members of g_D.
  423.  
  424.     send "print g_D.d\n"
  425.     expect {
  426.     -re ".* = 19\r\n$prompt $" { incr passcount }
  427.     -re ".*$prompt $" { fail "g_D.d incorrect" }
  428.     timeout { fail "print g_D.d (timeout)" ; return }
  429.     }
  430.  
  431.     send "print g_D.x\n"
  432.     expect {
  433.     -re ".* = 20\r\n$prompt $" { incr passcount }
  434.     -re ".*$prompt $" { fail "g_D.x incorrect" }
  435.     timeout { fail "print g_D.x (timeout)" ; return }
  436.     }
  437.  
  438.     # Print non-inherited members of g_E.
  439.  
  440.     send "print g_E.e\n"
  441.     expect {
  442.     -re ".* = 31\r\n$prompt $" { incr passcount }
  443.     -re ".*$prompt $" { fail "g_E.e incorrect" }
  444.     timeout { fail "print g_E.e (timeout)" ; return }
  445.     }
  446.  
  447.     send "print g_E.x\n"
  448.     expect {
  449.     -re ".* = 32\r\n$prompt $" { incr passcount }
  450.     -re ".*$prompt $" { fail "g_E.x incorrect" }
  451.     timeout { fail "print g_E.x (timeout)" ; return }
  452.     }
  453.  
  454.     if $passcount then {
  455.     pass "$passcount correct reads of non-inherited class members"
  456.     }
  457. }
  458.  
  459. #
  460. # Try access to non-members that are members of another class.
  461. # Should give errors.
  462. #
  463.  
  464. proc test_wrong_class_members {} {
  465.     global prompt
  466.  
  467.     set passcount 0
  468.  
  469.     send "print g_A.b\n"
  470.     expect {
  471.     -re "There is no member named b.\r\n$prompt $" { incr passcount }
  472.     -re ".*$prompt $" { fail "print g_A.b should be error" }
  473.     timeout { fail "print g_A.b (timeout)" ; return }
  474.     }
  475.  
  476.     send "print g_B.c\n"
  477.     expect {
  478.     -re "There is no member named c.\r\n$prompt $" { incr passcount }
  479.     -re ".*$prompt $" { fail "print g_B.c should be error" }
  480.     timeout { fail "print g_B.c (timeout)" ; return }
  481.     }
  482.  
  483.     send "print g_B.d\n"
  484.     expect {
  485.     -re "There is no member named d.\r\n$prompt $" { incr passcount }
  486.     -re ".*$prompt $" { fail "print g_B.d should be error" }
  487.     timeout { fail "print g_B.d (timeout)" ; return }
  488.     }
  489.  
  490.     send "print g_C.b\n"
  491.     expect {
  492.     -re "There is no member named b.\r\n$prompt $" { incr passcount }
  493.     -re ".*$prompt $" { fail "print g_C.b should be error" }
  494.     timeout { fail "print g_C.b (timeout)" ; return }
  495.     }
  496.  
  497.     send "print g_C.d\n"
  498.     expect {
  499.     -re "There is no member named d.\r\n$prompt $" { incr passcount }
  500.     -re ".*$prompt $" { fail "print g_C.d should be error" }
  501.     timeout { fail "print g_C.d (timeout)" ; return }
  502.     }
  503.  
  504.     send "print g_D.e\n"
  505.     expect {
  506.     -re "There is no member named e.\r\n$prompt $" { incr passcount }
  507.     -re ".*$prompt $" { fail "print g_D.e should be error" }
  508.     timeout { fail "print g_D.e (timeout)" ; return }
  509.     }
  510.  
  511.     if $passcount then {
  512.     pass "$passcount correct errors for incorrect members"
  513.     }
  514. }
  515.  
  516. #
  517. # Try access to non-members that are not members of any class.
  518. # Should give errors.
  519. #
  520.  
  521. proc test_nonexistant_members {} {
  522.     global prompt
  523.  
  524.     set passcount 0
  525.  
  526.     send "print g_A.y\n"
  527.     expect {
  528.     -re "There is no member named y.\r\n$prompt $" { incr passcount }
  529.     -re ".*$prompt $" { fail "print g_A.y should be error" }
  530.     timeout { fail "print g_A.y (timeout)" ; return }
  531.     }
  532.  
  533.     send "print g_B.z\n"
  534.     expect {
  535.     -re "There is no member named z.\r\n$prompt $" { incr passcount }
  536.     -re ".*$prompt $" { fail "print g_B.z should be error" }
  537.     timeout { fail "print g_B.z (timeout)" ; return }
  538.     }
  539.  
  540.     send "print g_C.q\n"
  541.     expect {
  542.     -re "There is no member named q.\r\n$prompt $" { incr passcount }
  543.     -re ".*$prompt $" { fail "print g_C.q should be error" }
  544.     timeout { fail "print g_C.q (timeout)" ; return }
  545.     }
  546.  
  547.     send "print g_D.p\n"
  548.     expect {
  549.     -re "There is no member named p.\r\n$prompt $" { incr passcount }
  550.     -re ".*$prompt $" { fail "print g_D.p should be error" }
  551.     timeout { fail "print g_D.p (timeout)" ; return }
  552.     }
  553.  
  554.     if $passcount then {
  555.     pass "$passcount correct errors for nonexistant members"
  556.     }
  557. }
  558.  
  559. #
  560. # Pointers to class members
  561. #
  562.  
  563. proc test_pointers_to_class_members {} {
  564.     global prompt
  565.     global decimal
  566.  
  567.     set passcount 0
  568.  
  569.     send "print Bar::z\n"
  570.     expect {
  571.     -re ".* = \(int\[ \]*\(\[ \]*Bar::&\)\)\[ \]*Bar::z\r\n$prompt $" {
  572.         incr passcount
  573.     }
  574.     -re ".*$prompt $" { fail "print Bar::z" }
  575.     timeout { fail "print Bar::z (timeout)" ; return }
  576.     }
  577.  
  578.     send "print &Foo::x\n"
  579.     expect {
  580.     -re ".* = \(int\[ \]*\(\[ \]*Foo::\*\)\)\[ \]*&Foo::x\r\n$prompt $" {
  581.         incr passcount
  582.     }
  583.     -re ".*$prompt $" { fail "print &Foo::x" }
  584.     timeout { fail "print &Foo::x (timeout)" ; return }
  585.     }
  586.  
  587.     send "print (int)&Foo::x\n"
  588.     expect {
  589.     -re ".* = 0\r\n$prompt $" {
  590.         incr passcount
  591.     }
  592.     -re ".*$prompt $" { fail "print (int)&Foo::x" }
  593.     timeout { fail "print (int)&Foo::x (timeout)" ; return}
  594.     }
  595.  
  596.     send "print (int)&Bar::y == 2*sizeof(int)\n"
  597.     expect {
  598.     -re ".* = 1\r\n$prompt $" {
  599.         incr passcount
  600.     }
  601.     -re "There is no field named y.*$prompt $" {
  602.         setup_xfail "*-*-*"
  603.         fail "print (int)&Bar::y == 2*sizeof(int)"
  604.     }
  605.     -re ".*$prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
  606.     timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
  607.     }
  608.  
  609.     send "next\n"
  610.     expect {
  611.     -re "$decimal\[ \t\]+inheritance3 \(\);\r\n$prompt $" {}
  612.     -re ".*$prompt $" { fail "next to inheritance3" ; return }
  613.     }
  614.  
  615.     send "print (int)pmi == sizeof(int)\n"
  616.     expect {
  617.     -re ".* = 0\r\n$prompt $" {
  618.         incr passcount
  619.     }
  620.     -re ".*$prompt $" { fail "print (int)pmi == sizeof(int)" }
  621.     timeout { fail "print (int)pmi == sizeof(int) (timeout)" ; return }
  622.     }
  623.  
  624.     if $passcount then {
  625.     pass "$passcount correct results using pointers to class members"
  626.     }
  627. }
  628.  
  629. #
  630. # Test static members.
  631. #
  632.  
  633. proc test_static_members {} {
  634.     global prompt
  635.     global hex
  636.  
  637.     set passcount 0
  638.  
  639.     send "print Foo::st\n"
  640.     expect {
  641.     -re ".* = 100\r\n$prompt $" {
  642.         incr passcount
  643.     }
  644.     -re "There is no field named st.*$prompt $" {
  645.         setup_xfail "*-*-*"
  646.         fail "print Foo::st"
  647.     }
  648.     -re ".*$prompt $" { fail "print Foo::st" }
  649.        timeout { fail "print Foo::st (timeout)" ; return }
  650.     }
  651.  
  652.     send "set foo.st = 200\n"
  653.     expect {
  654.     -re ".*$prompt $" {}
  655.     }
  656.  
  657.     send "print bar.st\n"
  658.     expect {
  659.     -re ".* = 200\r\n$prompt $" {
  660.         incr passcount
  661.     }
  662.     -re "There is no member named st.*$prompt $" {
  663.         setup_xfail "*-*-*"
  664.         fail "print bar.st"
  665.     }
  666.     -re ".*$prompt $" { fail "print bar.st" }
  667.        timeout { fail "print bar.st (timeout)" ; return }
  668.     }
  669.  
  670.     send "print &foo.st\n"
  671.     expect {
  672.     -re ".* = \(int \*\) $hex\r\n$prompt $" {
  673.         incr passcount
  674.     }
  675.     -re "There is no member named st.*$prompt $" {
  676.         setup_xfail "*-*-*"
  677.         fail "print &foo.st"
  678.     }
  679.     -re ".*$prompt $" { fail "print &foo.st" }
  680.        timeout { fail "print &foo.st (timeout)" ; return }
  681.     }
  682.  
  683.     set got_bar_st 0
  684.     send "print &Bar::st\n"
  685.     expect {
  686.     -re ".* = \(int \*\) $hex\r\n$prompt $" {
  687.         incr passcount
  688.         set got_bar_st 1
  689.     }
  690.     -re "There is no field named st.*$prompt $" {
  691.         setup_xfail "*-*-*"
  692.         fail "print &Bar::st"
  693.     }
  694.     -re ".*$prompt $" { fail "print &Bar::st" }
  695.        timeout { fail "print &Bar::st (timeout)" ; return }
  696.     }
  697.  
  698.     if $got_bar_st then {
  699.     send "print *\$\n"
  700.     expect {
  701.         -re ".* = 200\r\n$prompt $" {
  702.         incr passcount
  703.         }
  704.         -re ".*$prompt $" { fail "print *\$" }
  705.            timeout { fail "print *\$ (timeout)" ; return }
  706.     }
  707.     }
  708.  
  709.     if $passcount then {
  710.     pass "$passcount correct tests of static class members"
  711.     }
  712. }
  713.  
  714. proc do_tests {} {
  715.     global prms_id
  716.     global bug_id
  717.     global subdir
  718.     global objdir
  719.     global srcdir
  720.     global binfile
  721.     global prompt
  722.  
  723.     set prms_id 0
  724.     set bug_id 0
  725.  
  726.     # Start with a fresh gdb.
  727.  
  728.     gdb_exit
  729.     gdb_start
  730.     gdb_reinitialize_dir $srcdir/$subdir
  731.     gdb_load $objdir/$subdir/$binfile
  732.  
  733.     send "set language c++\n"
  734.     expect -re "$prompt $"
  735.     send "set width 0\n"
  736.     expect -re "$prompt $"
  737.  
  738.     test_ptype_class_objects
  739.  
  740.     if [ runto 'inheritance2(void)' ] then {
  741.     test_non_inherited_member_access
  742.     test_wrong_class_members
  743.     test_nonexistant_members
  744.     }
  745.  
  746.     if [istarget "a29k-*-udi"] then {
  747.     # FIXME: If PR 2415 is fixed, this is not needed.
  748.     gdb_target_udi
  749.     gdb_load $objdir/$subdir/$binfile
  750.     }
  751.  
  752.     if [ runto main ] then {
  753.     test_pointers_to_class_members
  754.     test_static_members
  755.     }
  756.  
  757.     if [istarget "a29k-*-udi"] then {
  758.     # FIXME: If PR 2415 is fixed, this is not needed.
  759.     gdb_target_udi
  760.     }
  761. }
  762.  
  763. # Check to see if we have an executable to test.  If not, then either we
  764. # haven't tried to compile one, or the compilation failed for some reason.
  765. # In either case, just notify the user and skip the tests in this file.
  766.  
  767. set binfile "gdbme"
  768. set srcfile $binfile.cc
  769.  
  770. if ![file exists $objdir/$subdir/$binfile] then {
  771.     warning "$binfile does not exist; tests suppressed."
  772. } else {
  773.     do_tests
  774. }
  775.