From patchwork Mon Jul 17 19:15:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 21650 Received: (qmail 17069 invoked by alias); 17 Jul 2017 19:16:06 -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 17007 invoked by uid 89); 17 Jul 2017 19:16:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=NORMAL 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; Mon, 17 Jul 2017 19:16:00 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F2884A6E6; Mon, 17 Jul 2017 19:15:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4F2884A6E6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4F2884A6E6 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C6335E243; Mon, 17 Jul 2017 19:15:58 +0000 (UTC) Subject: Re: [PATCH 13/40] Introduce strncmp_iw To: Yao Qi References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-14-git-send-email-palves@redhat.com> <86d19ndw31.fsf@gmail.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Mon, 17 Jul 2017 20:15:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <86d19ndw31.fsf@gmail.com> On 06/29/2017 09:41 AM, Yao Qi wrote: > Pedro Alves writes: > >> +/* Do a strncmp() type operation on STRING1 and STRING2, ignoring any >> + differences in whitespace. STRING2_LEN is STRING2's length. >> + Returns 0 if STRING1 matches STRING2_LEN characters of STRING2, >> + non-zero otherwise (slightly different than strncmp()'s range of >> + return values). */ >> +extern int strncmp_iw (const char *, const char *, size_t); > > Use parameter name in the declaration, otherwise, STRING1, STRING2 and > STRING2_LEN in comments are pointless. Indeed, fixed. > Otherwise, patch is good to me. > Pushed as below. Thanks much, Pedro Alves From 1d550c828c00978860de9ba35b9ab5b182b968bc Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 17 Jul 2017 20:08:48 +0100 Subject: [PATCH] Introduce strncmp_iw The explicit locations completer patch will need a strncmp_iw function, that to strcmp_iw like strncmp is to strcmp. This patch implements it. (Unit tests added a bit further down in this series will exercise this.) gdb/ChangeLog: 2017-07-17 Pedro Alves * utils.c (enum class strncmp_iw_mode): New. (strcmp_iw): Rename to ... (strncmp_iw_with_mode): ... this. Add string2_len and mode parameters. Handle them. (strncmp_iw): New. (strcmp_iw): Reimplement as wrapper around strncmp_iw_with_mode. * utils.h (strncmp_iw): Declare. (strcmp_iw): Move describing comments here. --- gdb/ChangeLog | 11 +++++++++ gdb/utils.c | 77 +++++++++++++++++++++++++++++++++++++++++------------------ gdb/utils.h | 19 ++++++++++++++- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8778cae..f1e21f1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ 2017-07-17 Pedro Alves + * utils.c (enum class strncmp_iw_mode): New. + (strcmp_iw): Rename to ... + (strncmp_iw_with_mode): ... this. Add string2_len and mode + parameters. Handle them. + (strncmp_iw): New. + (strcmp_iw): Reimplement as wrapper around strncmp_iw_with_mode. + * utils.h (strncmp_iw): Declare. + (strcmp_iw): Move describing comments here. + +2017-07-17 Pedro Alves + * c-exp.y (operator_stoken): Use CP_OPERATOR_LEN and CP_OPERATOR_STR. * c-typeprint.c (is_type_conversion_operator): Use diff --git a/gdb/utils.c b/gdb/utils.c index b66132a..43e1827 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2363,41 +2363,72 @@ fprintf_symbol_filtered (struct ui_file *stream, const char *name, } } -/* Do a strcmp() type operation on STRING1 and STRING2, ignoring any - differences in whitespace. Returns 0 if they match, non-zero if they - don't (slightly different than strcmp()'s range of return values). +/* Modes of operation for strncmp_iw_with_mode. */ - As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO". - This "feature" is useful when searching for matching C++ function names - (such as if the user types 'break FOO', where FOO is a mangled C++ - function). */ +enum class strncmp_iw_mode +{ + /* Work like strncmp, while ignoring whitespace. */ + NORMAL, -int -strcmp_iw (const char *string1, const char *string2) + /* Like NORMAL, but also apply the strcmp_iw hack. I.e., + string1=="FOO(PARAMS)" matches string2=="FOO". */ + MATCH_PARAMS, +}; + +/* Helper for strncmp_iw and strcmp_iw. */ + +static int +strncmp_iw_with_mode (const char *string1, const char *string2, + size_t string2_len, strncmp_iw_mode mode) { - while ((*string1 != '\0') && (*string2 != '\0')) + const char *end_str2 = string2 + string2_len; + + while (1) { while (isspace (*string1)) - { - string1++; - } - while (isspace (*string2)) - { - string2++; - } + string1++; + while (string2 < end_str2 && isspace (*string2)) + string2++; + if (*string1 == '\0' || string2 == end_str2) + break; if (case_sensitivity == case_sensitive_on && *string1 != *string2) break; if (case_sensitivity == case_sensitive_off && (tolower ((unsigned char) *string1) != tolower ((unsigned char) *string2))) break; - if (*string1 != '\0') - { - string1++; - string2++; - } + + string1++; + string2++; } - return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0'); + + if (string2 == end_str2) + { + if (mode == strncmp_iw_mode::NORMAL) + return 0; + else + return (*string1 != '\0' && *string1 != '('); + } + else + return 1; +} + +/* See utils.h. */ + +int +strncmp_iw (const char *string1, const char *string2, size_t string2_len) +{ + return strncmp_iw_with_mode (string1, string2, string2_len, + strncmp_iw_mode::NORMAL); +} + +/* See utils.h. */ + +int +strcmp_iw (const char *string1, const char *string2) +{ + return strncmp_iw_with_mode (string1, string2, strlen (string2), + strncmp_iw_mode::MATCH_PARAMS); } /* This is like strcmp except that it ignores whitespace and treats diff --git a/gdb/utils.h b/gdb/utils.h index 3347c23..6df752f 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -31,7 +31,24 @@ extern void initialize_utils (void); extern int sevenbit_strings; -extern int strcmp_iw (const char *, const char *); +/* Do a strncmp() type operation on STRING1 and STRING2, ignoring any + differences in whitespace. STRING2_LEN is STRING2's length. + Returns 0 if STRING1 matches STRING2_LEN characters of STRING2, + non-zero otherwise (slightly different than strncmp()'s range of + return values). */ +extern int strncmp_iw (const char *string1, const char *string2, + size_t string2_len); + +/* Do a strcmp() type operation on STRING1 and STRING2, ignoring any + differences in whitespace. Returns 0 if they match, non-zero if + they don't (slightly different than strcmp()'s range of return + values). + + As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO". + This "feature" is useful when searching for matching C++ function + names (such as if the user types 'break FOO', where FOO is a + mangled C++ function). */ +extern int strcmp_iw (const char *string1, const char *string2); extern int strcmp_iw_ordered (const char *, const char *);