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.t21 / cplusfuncs.exp < prev    next >
Encoding:
Text File  |  1993-05-12  |  12.5 KB  |  382 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. # Variables to keep track of number of passes, number of failures, and
  25. # a limit on the number of failures.  We periodically test to see how
  26. # many failures have occurred, and abandon a particular test if the
  27. # maximum has been exceeded.  Note that exactly how many failures are
  28. # allowed depends on the setting of max_dem_failcount, how often we
  29. # test it, and exactly where the errors occur with respect to the tests.
  30.  
  31. set dem_passcount 0
  32. set dem_failcount 0
  33. set max_dem_failcount 20
  34.  
  35. #
  36. #  Cause gdb to lookup a specific C++ function and print the demangled
  37. #  form.
  38. #
  39.  
  40. proc info_func { regex demangled } {
  41.     global prompt
  42.     global dem_passcount
  43.     global dem_failcount
  44.     global xfail_flag
  45.  
  46.     send "info function $regex\n"
  47.     expect {
  48.     -re "File .*:\r\n$demangled\r\n$prompt $" {
  49.         incr dem_passcount
  50.         if $xfail_flag then { pass "info function for \"$regex\"" }
  51.     }
  52.     -re ".*$prompt $" {
  53.         incr dem_failcount
  54.         fail "info function for \"$regex\""
  55.     }
  56.     timeout {
  57.         incr dem_failcount
  58.         fail "info function for \"$regex\" (timeout)"
  59.     }
  60.     }
  61. }
  62.  
  63. #
  64. #  Run print &'$arg' on the input arg and verify that we can correctly
  65. #  lookup the fully qualified C++ function.
  66. #  We ignore the return type of the function since we are only interested
  67. #  in the rootname and arguments part.
  68. #
  69.  
  70. proc print_addr_of { arg } {
  71.     global prompt
  72.     global dem_passcount
  73.     global dem_failcount
  74.     global hex
  75.     global xfail_flag
  76.  
  77.     send "print &'$arg'\n"
  78.     expect {
  79.     -re ".* = .* $hex <" {}
  80.     -re ".*$prompt $" {
  81.         incr dem_failcount ; fail "print &'$arg'" ; return
  82.     }
  83.     timeout {
  84.         incr dem_failcount ; fail "print &'$arg' (timeout)" ; return
  85.     }
  86.     }
  87.     expect {
  88.     "$arg" {}
  89.     -re ".*$prompt $" {
  90.         incr dem_failcount ; fail "print &'$arg'" ; return
  91.     }
  92.     timeout {
  93.         incr dem_failcount ; fail "print &'$arg' (timeout)" ; return
  94.     }
  95.     }
  96.     expect {
  97.     -re ">\r\n$prompt $" {}
  98.     -re ".*$prompt $" {
  99.         incr dem_failcount ; fail "print &'$arg'" ; return
  100.     }
  101.     timeout {
  102.         incr dem_failcount ; fail "print &'$arg' (timeout)" ; return
  103.     }
  104.     }
  105.     incr dem_passcount
  106.     if $xfail_flag then { pass "print &'$arg'" }
  107. }
  108.  
  109. #
  110. # Test name demangling for operators.
  111. #
  112. # The '(' at the end of each regex input pattern is so that we match only
  113. # the one we are looking for.  I.E. "operator&" would match both
  114. # "operator&(foo &)" and "operator&&(foo &)".
  115. #
  116.  
  117. proc test_lookup_operator_functions {} {
  118.     global dem_passcount
  119.     global dem_failcount
  120.     global max_dem_failcount
  121.  
  122.     set dem_passcount 0
  123.     set dem_failcount 0
  124.  
  125.     # These tests don't work for COFF targets; don't even try them
  126.     if [istarget "a29k-*-udi"] then {
  127.     setup_xfail "a29k-*-udi"
  128.     fail "skipping operator tests"
  129.     return
  130.     }
  131.  
  132.     info_func "operator&&("  "void foo::operator&&\(foo &\);"
  133.     info_func "operator&=("  "void foo::operator&=\(foo &\);"
  134.     info_func "operator&("  "void foo::operator&\(foo &\);"
  135.     info_func "operator/=("  "void foo::operator/=\(foo &\);"
  136.     info_func "operator^=("  "void foo::operator\^=\(foo &\);"
  137.     info_func "operator<<=("  "void foo::operator<<=\(foo &\);"
  138.     info_func "operator%=("  "void foo::operator%=\(foo &\);"
  139.     info_func "operator-=("  "void foo::operator-=\(foo &\);"
  140.  
  141.     # There doesn't appear to be anyway to get '*' treated as a character
  142.     # to match, rather than as a regex special character.
  143.     setup_xfail "*-*-*"
  144.     info_func "operator\*=("  "void foo::operator\*=\(foo &\);"
  145.  
  146.     info_func "operator|=("  "void foo::operator\|=\(foo &\);"
  147.     info_func "operator+=("  "void foo::operator\+=\(foo &\);"
  148.     info_func "operator>>=("  "void foo::operator>>=\(foo &\);"
  149.     info_func "operator=("  "void foo::operator=\(foo &\);"
  150.     info_func "operator()("  "void foo::operator\(\)\(foo &\);"
  151.  
  152.     # The function should be "operator," not "operator, ".  (note space)
  153.     # This test will work; I've commented it out because it should not
  154.     # count as a pass, since it is incorrect.  Ian Taylor.
  155.     # info_func "operator, ("  "void foo::operator, \(foo &\);"
  156.     setup_xfail "*-*-*"
  157.     info_func "operator,("  "void foo::operator,\(foo &\);"
  158.  
  159.     info_func "operator~("  "void foo::operator~\(void\);"
  160.     info_func "operator delete("  "void foo::operator delete\(void \*\);"
  161.     info_func "operator/("  "void foo::operator/\(foo &\);"
  162.     info_func "operator==("  "void foo::operator==\(foo &\);"
  163.     info_func "operator^("  "void foo::operator\^\(foo &\);"
  164.  
  165.     if $dem_failcount>$max_dem_failcount then {
  166.     fail "remaining tests suppressed after $dem_failcount failures..."
  167.     return
  168.     }
  169.  
  170.     info_func "operator>=("  "void foo::operator>=\(foo &\);"
  171.     info_func "operator>("  "void foo::operator>\(foo &\);"
  172.     info_func "operator<=("  "void foo::operator<=\(foo &\);"
  173.     info_func "operator<<("  "void foo::operator<<\(foo &\);"
  174.     info_func "operator<("  "void foo::operator<\(foo &\);"
  175.     info_func "operator%("  "void foo::operator%\(foo &\);"
  176.     info_func "operator-("  "void foo::operator-\(foo &\);"
  177.  
  178.     # There doesn't appear to be anyway to get '*' treated as a character
  179.     # to match, rather than as a regex special character.
  180.     setup_xfail "*-*-*"
  181.     info_func "operator\*("  "void foo::operator\*\(foo &\);"
  182.  
  183.     info_func "operator--("  "void foo::operator--\(int\);"
  184.     info_func "operator!=("  "void foo::operator!=\(foo &\);"
  185.     info_func "operator!("  "void foo::operator!\(void\);"
  186.     info_func "operator new("  "void \*foo::operator new\(int\);"
  187.     info_func "operator||("  "void foo::operator\|\|\(foo &\);"
  188.     info_func "operator char \*("  "char \*foo::operator char \*\(void\);"
  189.     info_func "operator int("  "int foo::operator int\(void\);"
  190.     info_func "operator|("  "void foo::operator\|\(foo &\);"
  191.     info_func "operator+("  "void foo::operator\+\(foo &\);"
  192.     info_func "operator++("  "void foo::operator\+\+\(int\);"
  193.     info_func "operator->("  "void foo::operator->\(void\);"
  194.     info_func "operator->\*("  "void foo::operator->\*\(foo &\);"
  195.     info_func "operator>>("  "void foo::operator>>\(foo &\);"
  196.  
  197.     # There doesn't appear to be anyway to get '[' and ']' treated as
  198.     # characters to match, rather than as regex special characters.
  199.     setup_xfail "*-*-*"
  200.     info_func "operator\\\[\\\]("  "void foo::operator\\\[\\\]\(foo &\);"
  201.  
  202.     if $dem_passcount then {
  203.     pass "$dem_passcount correct rootname operator function lookups"
  204.     }
  205. }
  206.  
  207.  
  208. proc test_paddr_operator_functions {} {
  209.     global dem_passcount
  210.     global dem_failcount
  211.     global max_dem_failcount
  212.  
  213.     set dem_passcount 0
  214.     set dem_failcount 0
  215.  
  216.     print_addr_of "foo::operator&&(foo &)"
  217.     print_addr_of "foo::operator&=(foo &)"
  218.     print_addr_of "foo::operator&(foo &)"
  219.     print_addr_of "foo::operator/=(foo &)"
  220.     print_addr_of "foo::operator^=(foo &)"
  221.     print_addr_of "foo::operator<<=(foo &)"
  222.     print_addr_of "foo::operator%=(foo &)"
  223.     print_addr_of "foo::operator-=(foo &)"
  224.     print_addr_of "foo::operator*=(foo &)"
  225.     print_addr_of "foo::operator|=(foo &)"
  226.     print_addr_of "foo::operator+=(foo &)"
  227.     print_addr_of "foo::operator>>=(foo &)"
  228.     print_addr_of "foo::operator=(foo &)"
  229.     print_addr_of "foo::operator()(foo &)"
  230.     print_addr_of "foo::operator, (foo &)"
  231.     print_addr_of "foo::operator~(void)"
  232.     print_addr_of "foo::operator delete(void *)"
  233.     print_addr_of "foo::operator/(foo &)"
  234.     print_addr_of "foo::operator==(foo &)"
  235.  
  236.     if $dem_failcount>$max_dem_failcount then {
  237.     fail "remaining tests suppressed after $dem_failcount failures..."
  238.     return
  239.     }
  240.  
  241.     print_addr_of "foo::operator^(foo &)"
  242.     print_addr_of "foo::operator>=(foo &)"
  243.     print_addr_of "foo::operator>(foo &)"
  244.     print_addr_of "foo::operator<=(foo &)"
  245.     print_addr_of "foo::operator<<(foo &)"
  246.     print_addr_of "foo::operator<(foo &)"
  247.     print_addr_of "foo::operator%(foo &)"
  248.     print_addr_of "foo::operator-(foo &)"
  249.     print_addr_of "foo::operator*(foo &)"
  250.     print_addr_of "foo::operator--(int)"
  251.     print_addr_of "foo::operator!=(foo &)"
  252.     print_addr_of "foo::operator!(void)"
  253.     print_addr_of "foo::operator new(int)"
  254.     print_addr_of "foo::operator||(foo &)"
  255.     print_addr_of "foo::operator char *(void)"
  256.     print_addr_of "foo::operator int(void)"
  257.     print_addr_of "foo::operator|(foo &)"
  258.     print_addr_of "foo::operator+(foo &)"
  259.     print_addr_of "foo::operator++(int)"
  260.     print_addr_of "foo::operator->(void)"
  261.     print_addr_of "foo::operator->*(foo &)"
  262.     print_addr_of "foo::operator>>(foo &)"
  263.     print_addr_of "foo::operator\[\](foo &)"
  264.  
  265.     if $dem_passcount then {
  266.     pass "$dem_passcount correct fully qualified operator function lookups"
  267.     }
  268. }
  269.  
  270. #
  271. # Test overloaded functions (1 arg).
  272. #
  273.  
  274. proc test_paddr_overloaded_functions {} {
  275.     global dem_passcount
  276.     global dem_failcount
  277.     global max_dem_failcount
  278.  
  279.     set dem_passcount 0
  280.     set dem_failcount 0
  281.  
  282.     print_addr_of "overload1arg(signed char)"
  283.     print_addr_of "overload1arg(unsigned char)"
  284.     print_addr_of "overload1arg(unsigned int)"
  285.     print_addr_of "overload1arg(unsigned long)"
  286.     print_addr_of "overload1arg(unsigned short)"
  287.     print_addr_of "overload1arg(char)"
  288.     print_addr_of "overload1arg(double)"
  289.     print_addr_of "overload1arg(float)"
  290.     print_addr_of "overload1arg(int)"
  291.     print_addr_of "overload1arg(long)"
  292.     print_addr_of "overload1arg(short)"
  293.     print_addr_of "overload1arg(void)"
  294.  
  295.     if $dem_failcount>$max_dem_failcount then {
  296.     fail "remaining tests suppressed after $dem_failcount failures..."
  297.     return
  298.     }
  299.  
  300.     print_addr_of "overloadargs(int)"
  301.     print_addr_of "overloadargs(int, int)"
  302.     print_addr_of "overloadargs(int, int, int)"
  303.     print_addr_of "overloadargs(int, int, int, int)"
  304.     print_addr_of "overloadargs(int, int, int, int, int)"
  305.     print_addr_of "overloadargs(int, int, int, int, int, int)"
  306.     print_addr_of "overloadargs(int, int, int, int, int, int, int)"
  307.     print_addr_of "overloadargs(int, int, int, int, int, int, int, int)"
  308.     print_addr_of "overloadargs(int, int, int, int, int, int, int, int, int)"
  309.     print_addr_of "overloadargs(int, int, int, int, int, int, int, int, int, int)"
  310.     print_addr_of "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
  311.  
  312.     if $dem_passcount then {
  313.     pass "$dem_passcount correct fully qualified overloaded function lookups"
  314.     }
  315. }
  316.  
  317. proc test_paddr_hairy_functions {} {
  318.     global dem_passcount
  319.     global dem_failcount
  320.     global max_dem_failcount
  321.  
  322.     set dem_passcount 0
  323.     set dem_failcount 0
  324.  
  325.     print_addr_of "hairyfunc1(int)"
  326.     print_addr_of "hairyfunc2(int (*)(char *))"
  327.     print_addr_of "hairyfunc3(int (*)(short (*)(long *)))"
  328.     print_addr_of "hairyfunc4(int (*)(short (*)(char *)))"
  329.     print_addr_of "hairyfunc5(int (*(*)(char *))(long))"
  330.     print_addr_of "hairyfunc6(int (*(*)(int *))(long))"
  331.     print_addr_of "hairyfunc7(int (*(*)(int (*)(char *)))(long))"
  332.  
  333.     if $dem_passcount then {
  334.     pass "$dem_passcount correct fully qualified hairy function lookups"
  335.     }
  336. }
  337.  
  338. proc do_tests {} {
  339.     global prms_id
  340.     global bug_id
  341.     global subdir
  342.     global objdir
  343.     global srcdir
  344.     global binfile
  345.     global prompt
  346.  
  347.     set prms_id 0
  348.     set bug_id 0
  349.  
  350.     # Start with a fresh gdb.
  351.  
  352.     gdb_exit
  353.     gdb_start
  354.     gdb_reinitialize_dir $srcdir/$subdir
  355.     gdb_load $objdir/$subdir/$binfile
  356.  
  357.     send "set language c++\n"
  358.     expect -re "$prompt $"
  359.     send "set width 0\n"
  360.     expect -re "$prompt $"
  361.  
  362.     test_paddr_overloaded_functions
  363.     test_paddr_operator_functions
  364.     test_paddr_hairy_functions
  365.     test_lookup_operator_functions
  366. }
  367.  
  368. # Check to see if we have an executable to test.  If not, then either we
  369. # haven't tried to compile one, or the compilation failed for some reason.
  370. # In either case, just notify the user and skip the tests in this file.
  371.  
  372. set binfile "gdbme"
  373. set srcfile $binfile.cc
  374.  
  375. if ![file exists $objdir/$subdir/$binfile] then {
  376.     warning "$binfile does not exist; tests suppressed."
  377. } else {
  378.     do_tests
  379. }
  380.