diff options
Diffstat (limited to 'gdb/testsuite/gdb.base/options.exp')
-rw-r--r-- | gdb/testsuite/gdb.base/options.exp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp index 1891176..3b4e7ee 100644 --- a/gdb/testsuite/gdb.base/options.exp +++ b/gdb/testsuite/gdb.base/options.exp @@ -19,9 +19,18 @@ # The test uses the "maintenance test-options" subcommands to exercise # TAB-completion and option processing. +# +# It also tests option integration in various commands, including +# "print" and "compile print". load_lib completion-support.exp +standard_testfile .c + +if {[build_executable "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + clean_restart if { ![readline_is_used] } { @@ -117,6 +126,111 @@ set all_options { "-zuinteger-unlimited" } +# Basic option-machinery + "print" command integration tests. +proc_with_prefix test-print {{prefix ""}} { + clean_restart + + # Completing "print" with no argument completes on symbols only, + # no options are offered. Since we haven't loaded any symbols, + # the match list should be empty. + test_gdb_complete_none "${prefix}print " + + # OTOH, completing at "-" should list all options. + test_gdb_complete_multiple "${prefix}print " "-" "" { + "-address" + "-array" + "-array-indexes" + "-elements" + "-max-depth" + "-null-stop" + "-object" + "-pretty" + "-repeats" + "-static-members" + "-symbol" + "-union" + "-vtbl" + } + + global binfile + clean_restart $binfile + + if ![runto_main] { + fail "cannot run to main" + return + } + + # Mix options and format. + gdb_test "${prefix}print -pretty -- /x 1" " = 0x1" + + # Smoke test that options actually work. + gdb_test "${prefix}print -pretty -- g_s" \ + [multi_line \ + " = {" \ + " a = 1," \ + " b = 2," \ + " c = 3" \ + "}"] + + test_gdb_complete_unique \ + "${prefix}print xxx" \ + "${prefix}print xxx1" + test_gdb_complete_unique \ + "${prefix}print -- xxx" \ + "${prefix}print -- xxx1" + + # Error messages when testing with "compile" are different from + # the error messages gdb's internal parser throws. This procedure + # hides the difference. EXPECTED_RE is only considered when not + # testing with "compile". + proc test_invalid_expression {cmd expected_re} { + upvar prefix prefix + + if {$prefix != "compile "} { + gdb_test $cmd $expected_re + } else { + # Error messages depend on compiler version, so we just + # look for the last line indicating a failure. + gdb_test $cmd "Compilation failed\\." + } + } + + # Check that '-XXX' without a "--" is handled as an + # expression. + gdb_test "${prefix}print -1" " = -1" + test_invalid_expression \ + "${prefix}print --1" \ + "Left operand of assignment is not an lvalue\\." + test_invalid_expression \ + "${prefix}print -object" \ + "No symbol \"object\".*" + + # Test printing with options and no expression. + set test "${prefix}print -object --" + if {$prefix != "compile "} { + # Regular "print" repeats the last history value. + gdb_test $test " = -1" + } else { + # "compile print" starts a multiline expression. + gdb_test_multiple $test $test { + -re ">$" { + gdb_test "-1\nend" " = -1" \ + $test + } + } + } + + # Check that everything after "-- " is treated as an + # expression, not confused with an option. + test_invalid_expression \ + "${prefix}print -- -address" \ + "No symbol.*" + gdb_test "${prefix}print -- -1" " = -1" + test_invalid_expression \ + "${prefix}print -- --1" \ + "Left operand of assignment is not an lvalue\\." +} + # Miscellaneous tests. proc_with_prefix test-misc {variant} { global all_options @@ -552,3 +666,11 @@ foreach_with_prefix cmd { } test-enum $cmd } + +# Run the print integration tests. +test-print "" + +# Same for "compile print". +if ![skip_compile_feature_tests] { + test-print "compile " +} |