From patchwork Tue Jun 4 22:34:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 33000 Received: (qmail 48016 invoked by alias); 4 Jun 2019 22:35:27 -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 47914 invoked by uid 89); 4 Jun 2019 22:35:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 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=*STR 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:35:24 +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 7ADAB7FDFF for ; Tue, 4 Jun 2019 22:35:23 +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 0114B19C69 for ; Tue, 4 Jun 2019 22:35:22 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v3 23/24] Delete parse_flags/parse_flags_qcs Date: Tue, 4 Jun 2019 23:34:43 +0100 Message-Id: <20190604223444.26472-24-palves@redhat.com> In-Reply-To: <20190604223444.26472-1-palves@redhat.com> References: <20190604223444.26472-1-palves@redhat.com> Now that "thread/frame apply" have been converted to the gdb::option framework, these functions are no longer used. For a while, I thought about keeping the unit tests, by making a local version of parse_flags_qcs in the unit tests file. But all that would really test that is used by GDB itself, is the validate_flags_qcs function. So in the end, I went through all the unit tests, and converted any that wasn't already covered to gdb.base/options.exp tests. And those have all already been added in previous patches. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * cli/cli-utils.c (parse_flags, parse_flags_qcs): Delete. * cli/cli-utils.h (parse_flags, parse_flags_qcs): Delete. * unittests/cli-utils-selftests.c (test_parse_flags) (test_parse_flags_qcs): Delete. (test_cli_utils): Don't call deleted functions. --- gdb/cli/cli-utils.c | 56 --------------- gdb/cli/cli-utils.h | 30 -------- gdb/unittests/cli-utils-selftests.c | 133 ------------------------------------ 3 files changed, 219 deletions(-) diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index 30d4091a0d1..f5d47aeffbc 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -524,62 +524,6 @@ check_for_argument (const char **str, const char *arg, int arg_len) /* See documentation in cli-utils.h. */ -int -parse_flags (const char **str, const char *flags) -{ - const char *p = skip_spaces (*str); - - if (p[0] == '-' - && isalpha (p[1]) - && (p[2] == '\0' || isspace (p[2]))) - { - const char pf = p[1]; - const char *f = flags; - - while (*f != '\0') - { - if (*f == pf) - { - *str = skip_spaces (p + 2); - return f - flags + 1; - } - f++; - } - } - - return 0; -} - -/* See documentation in cli-utils.h. */ - -bool -parse_flags_qcs (const char *which_command, const char **str, - qcs_flags *flags) -{ - switch (parse_flags (str, "qcs")) - { - case 0: - return false; - case 1: - flags->quiet = true; - break; - case 2: - flags->cont = true; - break; - case 3: - flags->silent = true; - break; - default: - gdb_assert_not_reached ("int qcs flag out of bound"); - } - - validate_flags_qcs (which_command, flags); - - return true; -} - -/* See documentation in cli-utils.h. */ - void validate_flags_qcs (const char *which_command, qcs_flags *flags) { diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index e6b877d5ab7..c2a0f374a6e 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -220,15 +220,6 @@ check_for_argument (char **str, const char *arg) return check_for_argument (str, arg, strlen (arg)); } -/* A helper function that looks for a set of flags at the start of a - string. The possible flags are given as a null terminated string. - A flag in STR must either be at the end of the string, - or be followed by whitespace. - Returns 0 if no valid flag is found at the start of STR. - Otherwise updates *STR, and returns N (which is > 0), - such that FLAGS [N - 1] is the valid found flag. */ -extern int parse_flags (const char **str, const char *flags); - /* qcs_flags struct groups the -q, -c, and -s flags parsed by "thread apply" and "frame apply" commands */ @@ -239,27 +230,6 @@ struct qcs_flags int silent = false; }; -/* A helper function that uses parse_flags to handle the flags qcs : - A flag -q sets FLAGS->QUIET to true. - A flag -c sets FLAGS->CONT to true. - A flag -s sets FLAGS->SILENT to true. - - The caller is responsible to initialize *FLAGS to false before the (first) - call to parse_flags_qcs. - parse_flags_qcs can then be called iteratively to search for more - valid flags, as part of a 'main parsing loop' searching for -q/-c/-s - flags together with other flags and options. - - Returns true and updates *STR and one of FLAGS->QUIET, FLAGS->CONT, - FLAGS->SILENT if it finds a valid flag. - Returns false if no valid flag is found at the beginning of STR. - - Throws an error if a flag is found such that both FLAGS->CONT and - FLAGS->SILENT are true. */ - -extern bool parse_flags_qcs (const char *which_command, const char **str, - qcs_flags *flags); - /* Validate FLAGS. Throws an error if both FLAGS->CONT and FLAGS->SILENT are true. WHICH_COMMAND is included in the error message. */ diff --git a/gdb/unittests/cli-utils-selftests.c b/gdb/unittests/cli-utils-selftests.c index 99b98bf8cd1..a251a8e58f8 100644 --- a/gdb/unittests/cli-utils-selftests.c +++ b/gdb/unittests/cli-utils-selftests.c @@ -101,143 +101,10 @@ test_number_or_range_parser () } } -static void -test_parse_flags () -{ - const char *flags = "abc"; - const char *non_flags_args = "non flags args"; - - /* Extract twice the same flag, separated by one space. */ - { - const char *t1 = "-a -a non flags args"; - - SELF_CHECK (parse_flags (&t1, flags) == 1); - SELF_CHECK (parse_flags (&t1, flags) == 1); - SELF_CHECK (strcmp (t1, non_flags_args) == 0); - } - - /* Extract some flags, separated by one or more spaces. */ - { - const char *t2 = "-c -b -c -b -c non flags args"; - - SELF_CHECK (parse_flags (&t2, flags) == 3); - SELF_CHECK (parse_flags (&t2, flags) == 2); - SELF_CHECK (parse_flags (&t2, flags) == 3); - SELF_CHECK (parse_flags (&t2, flags) == 2); - SELF_CHECK (parse_flags (&t2, flags) == 3); - SELF_CHECK (strcmp (t2, non_flags_args) == 0); - } - - /* Check behaviour where there is no flag to extract. */ - { - const char *t3 = non_flags_args; - - SELF_CHECK (parse_flags (&t3, flags) == 0); - SELF_CHECK (strcmp (t3, non_flags_args) == 0); - } - - /* Extract 2 known flags in front of unknown flags. */ - { - const char *t4 = "-c -b -x -y -z -c"; - - SELF_CHECK (parse_flags (&t4, flags) == 3); - SELF_CHECK (parse_flags (&t4, flags) == 2); - SELF_CHECK (strcmp (t4, "-x -y -z -c") == 0); - SELF_CHECK (parse_flags (&t4, flags) == 0); - SELF_CHECK (strcmp (t4, "-x -y -z -c") == 0); - } - - /* Check combined flags are not recognised. */ - { - const char *t5 = "-c -cb -c"; - - SELF_CHECK (parse_flags (&t5, flags) == 3); - SELF_CHECK (parse_flags (&t5, flags) == 0); - SELF_CHECK (strcmp (t5, "-cb -c") == 0); - } -} - -static void -test_parse_flags_qcs () -{ - const char *non_flags_args = "non flags args"; - - /* Test parsing of 2 flags out of the known 3. */ - { - const char *t1 = "-q -s non flags args"; - qcs_flags flags; - - SELF_CHECK (parse_flags_qcs ("test_parse_flags_qcs.t1.q", - &t1, - &flags) == 1); - SELF_CHECK (flags.quiet && !flags.cont && !flags.silent); - SELF_CHECK (parse_flags_qcs ("test_parse_flags_qcs.t1.s", - &t1, - &flags) == 1); - SELF_CHECK (flags.quiet && !flags.cont && flags.silent); - SELF_CHECK (strcmp (t1, non_flags_args) == 0); - } - - /* Test parsing when there is no flag. */ - { - const char *t2 = "non flags args"; - qcs_flags flags; - - SELF_CHECK (parse_flags_qcs ("test_parse_flags_qcs.t2", - &t2, - &flags) == 0); - SELF_CHECK (!flags.quiet && !flags.cont && !flags.silent); - SELF_CHECK (strcmp (t2, non_flags_args) == 0); - } - - /* Test parsing stops at a negative integer. */ - { - const char *t3 = "-123 non flags args"; - const char *orig_t3 = t3; - qcs_flags flags; - - SELF_CHECK (parse_flags_qcs ("test_parse_flags_qcs.t3", - &t3, - &flags) == 0); - SELF_CHECK (!flags.quiet && !flags.cont && !flags.silent); - SELF_CHECK (strcmp (t3, orig_t3) == 0); - } - - /* Test mutual exclusion between -c and -s. */ - { - const char *t4 = "-c -s non flags args"; - qcs_flags flags; - - try - { - SELF_CHECK (parse_flags_qcs ("test_parse_flags_qcs.t4.cs", - &t4, - &flags) == 1); - - (void) parse_flags_qcs ("test_parse_flags_qcs.t4.cs", - &t4, - &flags); - SELF_CHECK (false); - } - catch (const gdb_exception_error &ex) - { - SELF_CHECK (ex.reason == RETURN_ERROR); - SELF_CHECK (ex.error == GENERIC_ERROR); - SELF_CHECK - (strcmp (ex.what (), - "test_parse_flags_qcs.t4.cs: " - "-c and -s are mutually exclusive") == 0); - } - } - -} - static void test_cli_utils () { selftests::cli_utils::test_number_or_range_parser (); - selftests::cli_utils::test_parse_flags (); - selftests::cli_utils::test_parse_flags_qcs (); } }