run copyright.sh for 2011.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / printcmds.exp
index 8f3ba89eb99e3c9322dc317f951a3a146f48bffc..d3ea9a5d6302223fb4cfcea7e2080ffd667d33d4 100644 (file)
@@ -1,22 +1,23 @@
-# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003 Free
-# Software Foundation, Inc.
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2007,
+# 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 # 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 2 of the License, or
+# 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, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
+# bug-gdb@gnu.org
 
 # This file was written by Fred Fish. (fnf@cygnus.com)
 
@@ -24,31 +25,15 @@ if $tracelevel then {
        strace $tracelevel
 }
 
-set prms_id 0
-set bug_id 0
-
 set testfile "printcmds"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+     untested printcmds.exp
+     return -1
 }
 
-# Set the current language to C.  This counts as a test.  If it
-# fails, then we skip the other tests.
-
-proc set_lang_c {} {
-    global gdb_prompt
-
-    if [gdb_test "set language c" "" "set language c"] {
-       return 0
-    }
-
-    if [gdb_test "show language" ".* source language is \"c\".*"] {
-       return 0
-    }
-    return 1;
-}
+get_compiler_info ${binfile}
 
 proc test_integer_literals_accepted {} {
     global gdb_prompt
@@ -76,6 +61,13 @@ proc test_integer_literals_accepted {} {
     gdb_test "p 0xabcdef" " = 11259375"
     gdb_test "p 0xAbCdEf" " = 11259375"
     gdb_test "p/x 0x123" " = 0x123"
+
+    # Test various binary values.
+
+    gdb_test "p 0b0" " = 0"
+    gdb_test "p 0b1111" " = 15"
+    gdb_test "p 0B1111" " = 15"
+    gdb_test "p -0b1111" " = -15"
 }
 
 proc test_character_literals_accepted {} {
@@ -97,7 +89,8 @@ proc test_character_literals_accepted {} {
 proc test_integer_literals_rejected {} {
     global gdb_prompt
 
-    test_print_reject "p 0x" 
+    test_print_reject "p 0x"
+    test_print_reject "p 0b"
     gdb_test "p ''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
     gdb_test "p '''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
     test_print_reject "p '\\'"
@@ -109,17 +102,6 @@ proc test_integer_literals_rejected {} {
 
     test_print_reject "p DEADBEEF"
 
-    # Gdb currently fails this test for all configurations.  The C
-    # lexer thinks that 123DEADBEEF is a floating point number, but
-    # then fails to notice that atof() only eats the 123 part.
-    # FIXME:  This should be put into PRMS.
-    # Fixed, 4/25/97, by Bob Manson.
-
-    test_print_reject "p 123DEADBEEF"
-    test_print_reject "p 123foobar.bazfoo3"
-    test_print_reject "p 123EEEEEEEEEEEEEEEEE33333k333"
-    gdb_test "p 123.4+56.7" "180.(099\[0-9]*|100\[0-9\]*)" "check for floating addition"
-
     # Test various octal values.
 
     test_print_reject "p 09" 
@@ -129,12 +111,60 @@ proc test_integer_literals_rejected {} {
 
     test_print_reject "p 0xG" 
     test_print_reject "p 0xAG" 
+
+    # Test various binary values.
+
+    test_print_reject "p 0b2" 
+    test_print_reject "p 0b12" 
+}
+
+proc test_float_accepted {} {
+    global gdb_prompt
+
+    # This test is useful to catch successful parsing of the first fp value.
+    gdb_test "p 123.4+56.7" " = 180.(099\[0-9]*|100\[0-9\]*)" "check for floating addition"
+
+    # Test all the suffixes (including no suffix).
+    gdb_test "p 1." " = 1"
+    gdb_test "p 1.5" " = 1.5"
+    gdb_test "p 1.f" " = 1"
+    gdb_test "p 1.5f" " = 1.5"
+    gdb_test "p 1.l" " = 1"
+    gdb_test "p 1.5l" " = 1.5"
+
+    # Test hexadecimal floating point.
+    set test "p 0x1.1"
+    gdb_test_multiple $test $test {
+       -re " = 1\\.0625\r\n$gdb_prompt $" {
+           pass $test
+       }
+       -re "Invalid number \"0x1\\.1\"\\.\r\n$gdb_prompt $" {
+           # Older glibc does not support hex float, newer does.
+           xfail $test
+       }
+    }
+}
+
+proc test_float_rejected {} {
+    # Gdb use to fail this test for all configurations.  The C
+    # lexer thought that 123DEADBEEF was a floating point number, but
+    # then failed to notice that atof() only eats the 123 part.
+    # Fixed, 4/25/97, by Bob Manson.
+    test_print_reject "p 123DEADBEEF"
+
+    test_print_reject "p 123foobar.bazfoo3"
+    test_print_reject "p 123EEEEEEEEEEEEEEEEE33333k333"
+
+    # Test bad suffixes.
+    test_print_reject "p 1.1x"
+    test_print_reject "p 1.1ff"
+    test_print_reject "p 1.1ll"
 }
 
 proc test_print_all_chars {} {
     global gdb_prompt
 
-    gdb_test "p ctable1\[0\]"   " = 0 '\\\\0'"
+    gdb_test "p ctable1\[0\]"   " = 0 '\\\\000'"
     gdb_test "p ctable1\[1\]"   " = 1 '\\\\001'"
     gdb_test "p ctable1\[2\]"   " = 2 '\\\\002'"
     gdb_test "p ctable1\[3\]"   " = 3 '\\\\003'"
@@ -161,7 +191,7 @@ proc test_print_all_chars {} {
     gdb_test "p ctable1\[24\]"  " = 24 '\\\\030'"
     gdb_test "p ctable1\[25\]"  " = 25 '\\\\031'"
     gdb_test "p ctable1\[26\]"  " = 26 '\\\\032'"
-    gdb_test "p ctable1\[27\]"  " = 27 '\\\\e'"
+    gdb_test "p ctable1\[27\]"  " = 27 '\\\\033'"
     gdb_test "p ctable1\[28\]"  " = 28 '\\\\034'"
     gdb_test "p ctable1\[29\]"  " = 29 '\\\\035'"
     gdb_test "p ctable1\[30\]"  " = 30 '\\\\036'"
@@ -399,7 +429,7 @@ proc test_print_repeats_10 {} {
     global gdb_prompt
 
     for { set x 1; } { $x <= 16 } { incr x; } {
-       gdb_test "set print elements $x" ""
+       gdb_test_no_output "set print elements $x"
        for { set e 1; } { $e <= 16 } {incr e; } {
            set v [expr $e - 1];
            set command "p &ctable2\[${v}*16\]"
@@ -452,23 +482,23 @@ proc test_print_strings {} {
 
     # Test that setting print elements unlimited doesn't completely suppress
     # printing; this was a bug in older gdb's.
-    gdb_test "set print elements 0" ""
+    gdb_test_no_output "set print elements 0"
     gdb_test "p teststring" \
        " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 0"
-    gdb_test "set print elements 1" ""
+    gdb_test_no_output "set print elements 1"
     gdb_test "p teststring" \
        " = (.unsigned char .. )?\"t\"\\.\\.\\." "p teststring with elements set to 1"
-    gdb_test "set print elements 5" ""
+    gdb_test_no_output "set print elements 5"
     gdb_test "p teststring" \
        " = (.unsigned char .. )?\"tests\"\\.\\.\\." "p teststring with elements set to 5"
-    gdb_test "set print elements 19" ""
+    gdb_test_no_output "set print elements 19"
     gdb_test "p teststring" \
        " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 19"
-    gdb_test "set print elements 20" ""
+    gdb_test_no_output "set print elements 20"
     gdb_test "p teststring" \
        " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20"
 
-    gdb_test "set print elements 8" ""
+    gdb_test_no_output "set print elements 8"
 
     gdb_test "p &ctable1\[0\]" \
        " = \\(unsigned char \\*\\) \"\""
@@ -479,7 +509,7 @@ proc test_print_strings {} {
     gdb_test "p &ctable1\[2*8\]" \
        " = \\(unsigned char \\*\\) \"\\\\020\\\\021\\\\022\\\\023\\\\024\\\\025\\\\026\\\\027\"..."
     gdb_test "p &ctable1\[3*8\]" \
-       " = \\(unsigned char \\*\\) \"\\\\030\\\\031\\\\032\\\\e\\\\034\\\\035\\\\036\\\\037\"..."
+       " = \\(unsigned char \\*\\) \"\\\\030\\\\031\\\\032\\\\033\\\\034\\\\035\\\\036\\\\037\"..."
     gdb_test "p &ctable1\[4*8\]" \
        " = \\(unsigned char \\*\\) \" !\\\\\"#\\\$%&'\"..."
     gdb_test "p &ctable1\[5*8\]" \
@@ -541,7 +571,7 @@ proc test_print_strings {} {
 proc test_print_int_arrays {} {
     global gdb_prompt
 
-    gdb_test "set print elements 24" ""
+    gdb_test_no_output "set print elements 24"
 
     gdb_test_escape_braces "p int1dim" \
        " = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"
@@ -556,7 +586,7 @@ proc test_print_int_arrays {} {
 proc test_print_typedef_arrays {} {
     global gdb_prompt
 
-    gdb_test "set print elements 24" ""
+    gdb_test_no_output "set print elements 24"
 
     gdb_test_escape_braces "p a1" \
        " = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}"
@@ -567,6 +597,11 @@ proc test_print_typedef_arrays {} {
        " = \"abcd\""
     gdb_test "p a2\[0\]" " = 97 'a'"
     gdb_test "p a2\[3\]" " = 100 'd'"
+
+    # Regression test of null-stop; PR 11049.
+    gdb_test_no_output "set print null-stop on"
+    gdb_test "p a2" " = \"abcd\"" "print a2 with null-stop on"
+    gdb_test_no_output "set print null-stop off"
 }
 
 proc test_artificial_arrays {} {
@@ -583,8 +618,8 @@ proc test_print_char_arrays {} {
     global gdb_prompt
     global hex
 
-    gdb_test "set print elements 24" ""
-    gdb_test "set print address on" ""
+    gdb_test_no_output "set print elements 24"
+    gdb_test_no_output "set print address on"
 
     gdb_test "p arrays" \
        " = {array1 = \"abc\", array2 = \"d\", array3 = \"e\", array4 = \"fg\", array5 = \"hij\"}"
@@ -601,13 +636,13 @@ proc test_print_char_arrays {} {
     gdb_test "p parrays->array5"       " = \"hij\""
     gdb_test "p &parrays->array5"      " = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex"
 
-    gdb_test "set print address off" ""
+    gdb_test_no_output "set print address off"
 }
 
 proc test_print_string_constants {} {
     global gdb_prompt
 
-    gdb_test "set print elements 50" ""
+    gdb_test_no_output "set print elements 50"
 
     if [target_info exists gdb,cannot_call_functions] {
        setup_xfail "*-*-*" 2416
@@ -627,7 +662,6 @@ proc test_print_string_constants {} {
     gdb_test "p *\"foo\""              " = 102 'f'"
     gdb_test "ptype *\"foo\""          " = char"
     gdb_test "p &*\"foo\""             " = \"foo\""
-    setup_kfail "gdb/538" *-*-*
     gdb_test "ptype &*\"foo\"" "type = char \\*"
     gdb_test "p (char *)\"foo\""       " = \"foo\""
 }
@@ -649,7 +683,12 @@ proc test_print_array_constants {} {
     gdb_test_escape_braces "print {(long)0,(long)1,(long)2}"  " = {0, 1, 2}"
     gdb_test_escape_braces "print {{0,1,2},{3,4,5}}"  " = {{0, 1, 2}, {3, 4, 5}}"
     gdb_test "print {4,5,6}\[2\]"      " = 6"
-    gdb_test "print *&{4,5,6}\[1\]"    " = 5"
+    gdb_test "print *&{4,5,6}\[1\]"    "Attempt to take address of value not located in memory."
+}
+
+proc test_print_enums {} {
+    # Regression test for PR11827.
+    gdb_test "print some_volatile_enum" "enumvolval1"
 }
 
 proc test_printf {} {
@@ -664,6 +703,64 @@ proc test_printf {} {
     gdb_test "printf \"x=%d,y=%f,z=%d\\n\", 5, 6.0, 7" "x=5,y=6\.0+,z=7"
     gdb_test "printf \"%x %f, %c %x, %x, %f\\n\", 0xbad, -99.541, 'z',\
 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
+
+    # Regression test for C lexer bug.
+    gdb_test "printf \"%c\\n\", \"x\"\[1,0\]" "x"
+
+    # Regression test for "%% at end of format string.
+    # See http://sourceware.org/bugzilla/show_bug.cgi?id=11345
+    gdb_test "printf \"%%%d%%\\n\", 5" "%5%"
+}
+
+#Test printing DFP values with printf
+proc test_printf_with_dfp {} {
+
+    # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
+
+    # _Decimal32 constants, which can support up to 7 digits
+    gdb_test "printf \"%Hf\\n\",1.2df" "1.2"
+    gdb_test "printf \"%Hf\\n\",-1.2df" "-1.2"
+    gdb_test "printf \"%Hf\\n\",1.234567df" "1.234567"
+    gdb_test "printf \"%Hf\\n\",-1.234567df" "-1.234567"
+    gdb_test "printf \"%Hf\\n\",1234567.df" "1234567"
+    gdb_test "printf \"%Hf\\n\",-1234567.df" "-1234567"
+
+    gdb_test "printf \"%Hf\\n\",1.2E1df" "12"
+    gdb_test "printf \"%Hf\\n\",1.2E10df" "1.2E\\+10"
+    gdb_test "printf \"%Hf\\n\",1.2E-10df" "1.2E-10"
+
+    # The largest exponent for 32-bit dfp value is 96.
+    gdb_test "printf \"%Hf\\n\",1.2E96df" "1.200000E\\+96"
+
+    # _Decimal64 constants, which can support up to 16 digits
+    gdb_test "printf \"%Df\\n\",1.2dd" "1.2"
+    gdb_test "printf \"%Df\\n\",-1.2dd" "-1.2"
+    gdb_test "printf \"%Df\\n\",1.234567890123456dd" "1.234567890123456"
+    gdb_test "printf \"%Df\\n\",-1.234567890123456dd" "-1.234567890123456"
+    gdb_test "printf \"%Df\\n\",1234567890123456.dd" "1234567890123456"
+    gdb_test "printf \"%Df\\n\",-1234567890123456.dd" "-1234567890123456"
+
+    gdb_test "printf \"%Df\\n\",1.2E1dd" "12"
+    gdb_test "printf \"%Df\\n\",1.2E10dd" "1.2E\\+10"
+    gdb_test "printf \"%Df\\n\",1.2E-10dd" "1.2E-10"
+
+    # The largest exponent for 64-bit dfp value is 384.
+    gdb_test "printf \"%Df\\n\",1.2E384dd" "1.200000000000000E\\+384"
+
+    # _Decimal128 constants, which can support up to 34 digits
+    gdb_test "printf \"%DDf\\n\",1.2dl" "1.2"
+    gdb_test "printf \"%DDf\\n\",-1.2dl" "-1.2"
+    gdb_test "printf \"%DDf\\n\",1.234567890123456789012345678901234dl" "1.234567890123456789012345678901234"
+    gdb_test "printf \"%DDf\\n\",-1.234567890123456789012345678901234dl" "-1.234567890123456789012345678901234"
+    gdb_test "printf \"%DDf\\n\",1234567890123456789012345678901234.dl" "1234567890123456789012345678901234"
+    gdb_test "printf \"%DDf\\n\",-1234567890123456789012345678901234.dl" "-1234567890123456789012345678901234"
+
+    gdb_test "printf \"%DDf\\n\",1.2E1dl" "12"
+    gdb_test "printf \"%DDf\\n\",1.2E10dl" "1.2E\\+10"
+    gdb_test "printf \"%DDf\\n\",1.2E-10dl" "1.2E-10"
+
+    # The largest exponent for 128-bit dfp value is 6144.
+    gdb_test "printf \"%DDf\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
 }
 
 # Escape a left curly brace to prevent it from being interpreted as 
@@ -682,34 +779,53 @@ gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
 gdb_test "print \$pc" "No registers\\."
-# FIXME: should also test "print $pc" when there is an execfile but no
-# remote debugging target, process or corefile.
+
+# Some simple operations on strings should work even without a target
+# (and therefore without calling malloc).
+gdb_test "print \"abc\"" " = \"abc\""
+gdb_test "print sizeof (\"abc\")" " = 4"
+gdb_test "ptype \"abc\"" " = char \\\[4\\\]"
+gdb_test "print \$cvar = \"abc\"" " = \"abc\""
+gdb_test "print sizeof (\$cvar)" " = 4"
+
+gdb_file_cmd ${binfile}
+
+gdb_test "print \$pc" "No registers\\." "print \$pc (with file)"
+
+gdb_test_no_output "set print sevenbit-strings"
+gdb_test_no_output "set print address off"
+gdb_test_no_output "set width 0"
+
+if { [test_compiler_info "armcc-*"] } {
+    # ARM RealView compresses large arrays in the data segment.
+    # Before the program starts, we can not read them.  There is
+    # nothing in the file to indicate that data is compressed.
+    setup_xfail "arm*-*-eabi"
+}
+gdb_test "p ctable1\[120\]" "120 'x'" "p ctable1\[120\] #1"
 
 gdb_load ${binfile}
 
-gdb_test "set print sevenbit-strings" ""
-gdb_test "set print address off" ""
-gdb_test "set width 0" ""
-
-if [set_lang_c] then {
-    gdb_test "p ctable1\[120\]" "120 'x'" "p ctable1\[120\] #1"
-
-    if [runto_main] then {
-       test_integer_literals_accepted
-       test_integer_literals_rejected
-       test_character_literals_accepted
-       test_print_all_chars
-       test_print_repeats_10
-       test_print_strings
-       test_print_int_arrays
-       test_print_typedef_arrays
-       test_artificial_arrays
-       test_print_char_arrays
-# We used to do the runto main here.
-       test_print_string_constants
-       test_print_array_constants
-       test_printf
-    }
-} else {
-    fail "C print command tests suppressed"
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
 }
+
+test_integer_literals_accepted
+test_integer_literals_rejected
+test_float_accepted
+test_float_rejected
+test_character_literals_accepted
+test_print_all_chars
+test_print_repeats_10
+test_print_strings
+test_print_int_arrays
+test_print_typedef_arrays
+test_artificial_arrays
+test_print_char_arrays
+# We used to do the runto main here.
+test_print_string_constants
+test_print_array_constants
+test_print_enums
+test_printf
+test_printf_with_dfp
This page took 0.029867 seconds and 4 git commands to generate.