From patchwork Tue Jun 4 22:34:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 33006 Received: (qmail 63464 invoked by alias); 4 Jun 2019 22:42:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 63408 invoked by uid 89); 4 Jun 2019 22:42:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=teaching, HX-Languages-Length:4395 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jun 2019 22:42:16 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69DC18F918 for ; Tue, 4 Jun 2019 22:35:18 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E652B19C69 for ; Tue, 4 Jun 2019 22:35:17 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v3 17/24] "backtrace full/no-filters/hide" completer Date: Tue, 4 Jun 2019 23:34:37 +0100 Message-Id: <20190604223444.26472-18-palves@redhat.com> In-Reply-To: <20190604223444.26472-1-palves@redhat.com> References: <20190604223444.26472-1-palves@redhat.com> "backtrace"'s completer now completes on command options: (gdb) bt -[TAB] -entry-values -full -no-filters -past-main -frame-arguments -hide -past-entry -raw-frame-arguments But it doesn't know how to complete on qualifiers: (gdb) bt fu[TAB] funlockfile futimens futimes.c funlockfile.c futimens.c futimesat futex-internal.h futimes futimesat.c This commit fixes that: (gdb) bt fu[TAB]ll (gdb) bt n[TAB]o-filters (gdb) bt h[TAB]ide I considered teaching the gdb::option framework to handle non-'-' options, but decided it wasn't worth it for this special case, and I'd rather not make it easy to add new qualifier-like options. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * stack.c (parse_backtrace_qualifiers): New. (backtrace_command): Use it. (backtrace_command_completer): Complete on qualifiers. gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.base/options.exp (test-backtrace): Test completing qualifiers. --- gdb/stack.c | 84 ++++++++++++++++++++++++++++---------- gdb/testsuite/gdb.base/options.exp | 11 +++++ 2 files changed, 73 insertions(+), 22 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index 5e878d3c887..1cb1fc9c38c 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2027,6 +2027,45 @@ make_backtrace_options_def_group (frame_print_options *fp_opts, }}; } +/* Parse the backtrace command's qualifiers. Returns ARG advanced + past the qualifiers, if any. BT_CMD_OPTS, if not null, is used to + store the parsed qualifiers. */ + +static const char * +parse_backtrace_qualifiers (const char *arg, + backtrace_cmd_options *bt_cmd_opts = nullptr) +{ + while (true) + { + const char *save_arg = arg; + std::string this_arg = extract_arg (&arg); + + if (this_arg.empty ()) + return arg; + + if (subset_compare (this_arg.c_str (), "no-filters")) + { + if (bt_cmd_opts != nullptr) + bt_cmd_opts->no_filters = true; + } + else if (subset_compare (this_arg.c_str (), "full")) + { + if (bt_cmd_opts != nullptr) + bt_cmd_opts->full = true; + } + else if (subset_compare (this_arg.c_str (), "hide")) + { + if (bt_cmd_opts != nullptr) + bt_cmd_opts->hide = true; + } + else + { + /* Not a recognized qualifier, so stop. */ + return save_arg; + } + } +} + static void backtrace_command (const char *arg, int from_tty) { @@ -2043,28 +2082,7 @@ backtrace_command (const char *arg, int from_tty) compatibility. */ if (arg != NULL) { - while (true) - { - const char *save_arg = arg; - std::string this_arg = extract_arg (&arg); - - if (this_arg.empty ()) - break; - - if (subset_compare (this_arg.c_str (), "no-filters")) - bt_cmd_opts.no_filters = true; - else if (subset_compare (this_arg.c_str (), "full")) - bt_cmd_opts.full = true; - else if (subset_compare (this_arg.c_str (), "hide")) - bt_cmd_opts.hide = true; - else - { - /* Not a recognized argument, so stop. */ - arg = save_arg; - break; - } - } - + arg = parse_backtrace_qualifiers (arg, &bt_cmd_opts); if (*arg == '\0') arg = NULL; } @@ -2090,6 +2108,28 @@ backtrace_command_completer (struct cmd_list_element *ignore, (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group)) return; + if (*text != '\0') + { + const char *p = skip_to_space (text); + if (*p == '\0') + { + static const char *const backtrace_cmd_qualifier_choices[] = { + "full", "no-filters", "hide", nullptr, + }; + complete_on_enum (tracker, backtrace_cmd_qualifier_choices, + text, text); + + if (tracker.have_completions ()) + return; + } + else + { + const char *cmd = parse_backtrace_qualifiers (text); + tracker.advance_custom_word_point_by (cmd - text); + text = cmd; + } + } + const char *word = advance_to_expression_complete_word_point (tracker, text); expression_completer (ignore, tracker, text, word); } diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp index 17573460b4d..5a35074054e 100644 --- a/gdb/testsuite/gdb.base/options.exp +++ b/gdb/testsuite/gdb.base/options.exp @@ -256,6 +256,17 @@ proc_with_prefix test-backtrace {} { "-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