Make "frame apply" support -OPT options
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / options.exp
index 1891176dc1dbca9a5ba7706c0a33eb6e24927114..195bbb168ae5fd25b707f6d4e5f93eac04a0dc16 100644 (file)
 
 # 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
+#  - compile print
+#  - backtrace
+#  - frame apply
+#  - faas
+#  - tfaas
 
 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 +132,245 @@ 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\\."
+}
+
+# Basic option-machinery + "backtrace" command integration tests.
+proc_with_prefix test-backtrace {} {
+    clean_restart
+
+    test_gdb_complete_unique "backtrace" "backtrace"
+    test_gdb_complete_none "backtrace "
+
+    gdb_test "backtrace -" "Ambiguous option at: -"
+    gdb_test "backtrace --" "No stack\\."
+    gdb_test "backtrace -- -" "No stack\\."
+
+    test_gdb_complete_multiple "backtrace " "-" "" {
+       "-entry-values"
+       "-frame-arguments"
+       "-full"
+       "-hide"
+       "-no-filters"
+       "-past-entry"
+       "-past-main"
+       "-raw-frame-arguments"
+    }
+
+    # Test that we complete the qualifiers, if there's any.
+    test_gdb_complete_unique \
+       "backtrace ful" \
+       "backtrace full"
+    test_gdb_complete_unique \
+       "backtrace hid" \
+       "backtrace hide"
+    test_gdb_complete_unique \
+       "backtrace no-fil" \
+       "backtrace no-filters"
+
+    global binfile
+    clean_restart $binfile
+
+    if ![runto_main] {
+       fail "cannot run to main"
+       return
+    }
+
+    # COUNT in "backtrace COUNT" is parsed as an expression.  Check
+    # that we complete expressions.
+
+    test_gdb_complete_unique \
+       "backtrace xxx" \
+       "backtrace xxx1"
+
+    test_gdb_complete_unique \
+       "backtrace -xxx" \
+       "backtrace -xxx1"
+
+    test_gdb_complete_unique \
+       "backtrace 1 + xxx" \
+       "backtrace 1 + xxx1"
+
+    test_gdb_complete_unique \
+       "backtrace (1 + xxx" \
+       "backtrace (1 + xxx1"
+}
+
+# Basic option-machinery + "frame apply" command integration tests.
+proc_with_prefix test-frame-apply {} {
+    test_gdb_complete_unique "frame apply all" "frame apply all"
+
+    gdb_test "frame apply level 0-" \
+       "Please specify a command to apply on the selected frames"
+    test_gdb_complete_none "frame apply level 0-"
+
+    foreach cmd {
+       "frame apply all"
+       "frame apply 1"
+       "frame apply level 0"
+       "faas"
+       "tfaas"
+    } {
+       test_gdb_completion_offers_commands "$cmd "
+
+       # tfaas is silent on command error by design.  This procedure
+       # hides that aspect.  EXPECTED_RE is only considered when not
+       # testing with "faas"/"tfaas".
+       proc test_error_cmd {cmd arg expected_re} {
+           if {$cmd == "tfaas"} {
+               gdb_test_no_output "$cmd$arg"
+           } else {
+               gdb_test "$cmd$arg" $expected_re
+           }
+       }
+       # Same, but for tests where both "faas" and "tfaas" are
+       # expected to be silent.
+       proc test_error_cmd2 {cmd arg expected_re} {
+           if {$cmd == "tfaas" || $cmd == "faas"} {
+               gdb_test_no_output "$cmd$arg"
+           } else {
+               gdb_test "$cmd$arg" $expected_re
+           }
+       }
+
+       test_error_cmd $cmd " -" "Ambiguous option at: -"
+       test_gdb_complete_multiple "$cmd " "-" "" {
+           "-c"
+           "-past-entry"
+           "-past-main"
+           "-q"
+           "-s"
+       }
+
+       with_test_prefix "no-trailing-space" {
+           test_error_cmd $cmd " --" \
+               "Please specify a command to apply on the selected frames"
+           test_gdb_complete_unique "$cmd --" "$cmd --"
+       }
+
+       with_test_prefix "trailing-space" {
+           test_error_cmd $cmd " -- " \
+               "Please specify a command to apply on the selected frames"
+           test_gdb_completion_offers_commands "$cmd -- "
+       }
+
+       # '-' is a valid TUI command.
+       test_error_cmd2 $cmd " -- -" \
+           "Cannot enable the TUI when output is not a terminal"
+       test_gdb_complete_unique \
+           "$cmd -- -" \
+           "$cmd -- -"
+
+       test_error_cmd2 $cmd " -foo" \
+           "Undefined command: \"-foo\".  Try \"help\"\\."
+       test_gdb_complete_none "$cmd -foo"
+
+       test_gdb_completion_offers_commands "$cmd -s "
+    }
+}
+
 # Miscellaneous tests.
 proc_with_prefix test-misc {variant} {
     global all_options
@@ -552,3 +806,29 @@ foreach_with_prefix cmd {
     }
     test-enum $cmd
 }
+
+# Run the print integration tests, both as "standalone", and under
+# "frame apply".  The latter checks that the "frame apply ... COMMAND"
+# commands recurse the completion machinery for COMMAND completion
+# correctly.
+foreach prefix {
+    ""
+    "frame apply all "
+    "frame apply 1 "
+    "frame apply level 0 "
+} {
+    test-print $prefix
+}
+
+# Same for "compile print".  Not really a wrapper prefix command like
+# "frame apply", but similar enough that we test pretty much the same
+# things.
+if ![skip_compile_feature_tests] {
+    test-print "compile "
+}
+
+# Basic "backtrace" integration tests.
+test-backtrace
+
+# Basic "frame apply" integration tests.
+test-frame-apply
This page took 0.028182 seconds and 4 git commands to generate.