From patchwork Sat May 5 19:28:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 27124 Received: (qmail 14970 invoked by alias); 5 May 2018 19:28:26 -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 14839 invoked by uid 89); 5 May 2018 19:28:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=solo, one X-HELO: mailsec109.isp.belgacom.be Received: from mailsec109.isp.belgacom.be (HELO mailsec109.isp.belgacom.be) (195.238.20.105) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 05 May 2018 19:28:23 +0000 IronPort-PHdr: =?us-ascii?q?9a23=3AaGdHJhRaGR/li4i42bwYCSyLMdpsv+yvbD5Q0YIu?= =?us-ascii?q?jvd0So/mwa6yYByN2/xhgRfzUJnB7Loc0qyK6/umATRIyK3CmUhKSIZLWR4BhJ?= =?us-ascii?q?detC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+?= =?us-ascii?q?KPjrFY7OlcS30P2594HObwlSizexfb1/IA+qoQnNq8IbnZZsJqEtxxXTv3BGYf?= =?us-ascii?q?5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbD?= =?us-ascii?q?VwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4qF2QxHqlS?= =?us-ascii?q?gHLSY0/mHJhMJtgqxVoxWvqB5xw4PPfI2ZKOBzcr/HcN8GWWZMWNtaWSxbAoO7?= =?us-ascii?q?aosCF/APPeZZr4n5plsOtQO+ChexD+zv0DBInHj23bQn0+QgDw7GxhcgFM8JvX?= =?us-ascii?q?TMrNX1NaMSUeGtzKnQ0zrPdf1X1i3n6IjPaxAhvPCMUqxqccrK0kQvDADFj1WW?= =?us-ascii?q?qYP7IzOZzP8CvHaC4udmSOmhiHYnphlsrjSzwsogkJTFi4wJxlze6Cl13oc4Kc?= =?us-ascii?q?emREN1f9KpFoZbuTuAOItsWMwiRnlluCM9yrIbp5G2ZDMKyJE7xx7HbPyHbpSI?= =?us-ascii?q?7grjVOmPJTd4g2poeLeiiBqo8Uigzej8Wdes3FZLqCpKjMXMu2gQ2xDP7sWLUO?= =?us-ascii?q?Zx80m91TqVygzf9OBJLVoqmafVNZIt2rswmYASsUTHEC/2gkL2jKqOe0U8+uio?= =?us-ascii?q?6uDnYrT+pp+EKYB4kA//Pb40msy4GOQ4LwkOUHaB+eSnz7Dj5k75QbVMjvIojq?= =?us-ascii?q?nVqovVKtoDqq6jHwBVypoj6wq4Dzq+39QXgGIIIEtdeB2dk4jmJ1HOL+7jDfqk?= =?us-ascii?q?mFSslyprx+raMbL/DJTCNGLDn6n7cbZ68U5cxxI5zcpD6JJMFrEBPPXzV1fptN?= =?us-ascii?q?zYDx85Nw20w/7/CNpjzI8fV3iAArWeMKPLrF+I5/wgI/OXZIIOozb9KPgk5/jw?= =?us-ascii?q?gn8lg1MSZremjtMrbyW3Ev4jO0yFanrhmf8aFnoQtQchRfbnzlqYXm19fXG3Cp?= =?us-ascii?q?o85zU6EJqrRbjKXIe0nb2MxjzzSoVWZ2RHEkiBV2jhbYKdRvYBcjm6OcxwlDEY?= =?us-ascii?q?E7KsHdxynSqyvRP3nuI0ZtHf/TcV4Mru?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2AbBgAkBe5a/+h+gm1cHQEBBQELAYNEg?= =?us-ascii?q?VuMGF6MFQGCKQFDGo8IhByBeAsrAYMsgRQCgjciNBgBAgEBAQEBAQIBayiCNSK?= =?us-ascii?q?CUgYnLyMQPxI5HoU+qWgzhFiDaYI4iXk/gQ6CV4p8ApgkCIFljF0LgTWLLSuHF?= =?us-ascii?q?okIgSUcOIFSbYMXkE89gSgBGgGMXyuCGQEB?= X-IPAS-Result: =?us-ascii?q?A2AbBgAkBe5a/+h+gm1cHQEBBQELAYNEgVuMGF6MFQGCKQF?= =?us-ascii?q?DGo8IhByBeAsrAYMsgRQCgjciNBgBAgEBAQEBAQIBayiCNSKCUgYnLyMQPxI5H?= =?us-ascii?q?oU+qWgzhFiDaYI4iXk/gQ6CV4p8ApgkCIFljF0LgTWLLSuHFokIgSUcOIFSbYM?= =?us-ascii?q?XkE89gSgBGgGMXyuCGQEB?= Received: from 232.126-130-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.130.126.232]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 05 May 2018 21:28:17 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFC 1/5] Add helper functions check_for_flags and check_for_flags_vqcs Date: Sat, 5 May 2018 21:28:00 +0200 Message-Id: <20180505192804.12731-2-philippe.waroquiers@skynet.be> In-Reply-To: <20180505192804.12731-1-philippe.waroquiers@skynet.be> References: <20180505192804.12731-1-philippe.waroquiers@skynet.be> X-IsSubscribed: yes check_for_flags helper function allows to look for a set of flags at the start of a string. check_for_flags_vqcs is a specialised helper function to handle the flags vqcs, that are used in the new command 'frame apply' and in the command 'thread apply. Modify number_or_range_parser::get_number to differentiate a - followed by digits from a - followed by a flag (i.e. an alpha). That is needed for the addition of the optional -FLAGS... argument to thread apply ID... [-FLAGS...] COMMAND Modify gdb/testsuite/gdb.multi/tids.exp, as the gdb error message for 'thread apply -$unknownconvvar p 1' is now the more clear: Invalid thread ID: -$unknownconvvar p 1 instead of previously: negative value --- gdb/cli/cli-utils.c | 116 ++++++++++++++++++++++++++++++++++++++- gdb/cli/cli-utils.h | 30 ++++++++++ gdb/testsuite/gdb.multi/tids.exp | 4 +- 3 files changed, 145 insertions(+), 5 deletions(-) diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index c55b5035e4..4abd501d52 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -22,7 +22,6 @@ #include "value.h" #include - /* See documentation in cli-utils.h. */ int @@ -169,7 +168,10 @@ number_or_range_parser::get_number () /* Default case: state->m_cur_tok is pointing either to a solo number, or to the first number of a range. */ m_last_retval = get_number_trailer (&m_cur_tok, '-'); - if (*m_cur_tok == '-') + /* if get_number_trailer has found a -, it might be the start + of flags. So, do not parse a range if the - is followed by + an alpha. */ + if (*m_cur_tok == '-' && !isalpha(*(m_cur_tok+1))) { const char **temp; @@ -196,7 +198,10 @@ number_or_range_parser::get_number () } } else - error (_("negative value")); + { + if (*m_cur_tok >= '0' && *m_cur_tok <= '9') + error (_("negative value")); + } m_finished = *m_cur_tok == '\0'; return m_last_retval; } @@ -304,3 +309,108 @@ check_for_argument (const char **str, const char *arg, int arg_len) } return 0; } + +int +check_for_flags (const char **str, const char *flags, + int *flags_counts) +{ + const char *p = *str; + bool all_valid = true; + + /* First set the flags_counts to 0. */ + { + const char *f = flags; + while (*f) + { + flags_counts[f - flags] = 0; + f++; + } + } + + if (*p != '-') + return 0; + + p++; + /* If - is the last char, or is followed by a space or a $, then + we do not have flags. */ + if (*p == '\0' || (isspace (*p) || *p == '$')) + return 0; + + /* We might have a command that accepts optional flags followed by + a negative integer. So, do not handle a negative integer as invalid + flags : rather let the caller handle the negative integer. */ + { + const char *p1 = p; + while (*p1 >= '0' && *p1 <= '9') + ++p1; + if (p != p1 && (*p1 == '\0' || isspace (*p1))) + return 0; + } + + /* We have a set of flags : + Scan and validate the flags, and update flags_counts for valid flags. */ + while (*p != '\0' && !isspace (*p)) + { + const char *f = flags; + bool valid = false; + + while (*f && !valid) + { + valid = *f == *p; + if (valid) + { + flags_counts[f - flags]++; + break; + } + f++; + } + all_valid = all_valid && valid; + p++; + } + + /* Skip the space(s) */ + while (*p && isspace((int) *p)) + ++p; + + if (all_valid) + { + *str = p; + return 1; + } + else + return -1; +} + +int +check_for_flags_vqcs (const char *which_command, const char **str, + int *print_what_v, int max_v, + bool *cont, bool *silent) +{ + const char *flags = "vqcs"; + int flags_counts[4]; + int res; + + *cont = false; + *silent = false; + + res = check_for_flags (str, flags, flags_counts); + if (res == 0) + return 0; + if (res == -1) + error (_("%s only accepts flags %s"), which_command, flags); + gdb_assert (res == 1); + + *print_what_v = *print_what_v + flags_counts[0] - flags_counts[1]; + if (*print_what_v < 0) + *print_what_v = 0; + if (*print_what_v > max_v) + *print_what_v = max_v; + + *cont = flags_counts[2] > 0; + *silent = flags_counts[3] > 0; + if (*cont && *silent) + error (_("%s does not accept at the same time flags c and s"), + which_command); + + return res; +} diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index e34ee0df37..defbedf980 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -173,4 +173,34 @@ check_for_argument (char **str, const char *arg, int arg_len) arg, arg_len); } +/* 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. + The flags must also either be at the end of the string, + or be followed by whitespace. Returns 1 if it finds only valid flags, + 0 if no flags are found, -1 if invalid flags are found. + FLAGS_COUNTS must be an int array of length equal to strlen(flags). + Sets *FLAGS_COUNTS to the number of times the corresponding flag + was found in *STR. + If only valid flags are found, it updates *STR. Note that a negative + integer (e.g. -123) will not be considered as an invalid set of flags. */ +extern int check_for_flags (const char **str, const char *flags, + int *flags_counts); + +/* A helper function that uses check_for_flags to handle the flags vqcs : + A flag v increases *print_what_v. + A flag q decreases *print_what_v. + A flag c sets *cont to true, otherwise to false. + A flag s sets *silent to true, otherwise to false. + The caller must initialise *PRINT_WHAT_V to the default verbosity. + MAX_V gives the maximum verbosity : the value returned in *PRINT_WHAT_V + will always be >= 0 and <= MAX_V. + WHICH_COMMAND is used in the error message in case invalid flags are found. + + Returns 1 and updates *STR if it finds only valid flags. + Returns 0 if no flags are found. + Raises an error if invalid flags are found. +*/ +extern int check_for_flags_vqcs (const char *which_command, const char **str, + int *print_what_v, int max_v, + bool *cont, bool *silent); #endif /* CLI_UTILS_H */ diff --git a/gdb/testsuite/gdb.multi/tids.exp b/gdb/testsuite/gdb.multi/tids.exp index 67349b5759..ae8328d997 100644 --- a/gdb/testsuite/gdb.multi/tids.exp +++ b/gdb/testsuite/gdb.multi/tids.exp @@ -350,8 +350,8 @@ with_test_prefix "two inferiors" { thr_apply_info_thr_error "${prefix}1-" "inverted range" thr_apply_info_thr_error "${prefix}2-1" "inverted range" thr_apply_info_thr_error "${prefix}2-\$one" "inverted range" - thr_apply_info_thr_error "${prefix}-1" "negative value" - thr_apply_info_thr_error "${prefix}-\$one" "negative value" + thr_apply_info_thr_error "${prefix}-1" "Invalid thread ID: ${prefix_re}-1" + thr_apply_info_thr_error "${prefix}-\$one" "Invalid thread ID: ${prefix_re}-\\\$one" thr_apply_info_thr_error "${prefix}\$minus_one" \ "negative value: ${prefix_re}\\\$minus_one"