From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZibACxv0pmXu/j0AWB0awg (envelope-from ) for ; Tue, 16 Jan 2024 16:24:43 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GSc+F6/D; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1C5361E0C3; Tue, 16 Jan 2024 16:24:43 -0500 (EST) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 09CA51E0C2 for ; Tue, 16 Jan 2024 16:24:41 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7203F3858283 for ; Tue, 16 Jan 2024 21:24:40 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B61D03858D20 for ; Tue, 16 Jan 2024 21:24:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B61D03858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B61D03858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705440252; cv=none; b=I+F6+WCA8JYd7+/8L/212yj9B+F2ehrtSktu16jkFjsfxHaOTUmwmNvIW+1spHdKvD+Kx4SkWKSIqMKkX3tN/wGWVVgzqkmjWRYWOrT+b2mqM+kYURaNynUP1Q6RRkkId7C3ciM0/TlBoBPhh7TyKfC8PmUlbLqtJcvKQiRiZDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705440252; c=relaxed/simple; bh=ZXZvol8l+ArDYqEcUbB450VxQ150BpWhAj9kqIFXBfE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oj5L9nnT+sNCmvYJg2qGqaftHWl8Ua5rT3sk+oOKz9JvBK99oNriH+8bfHFuBVVVm2+V8wxheKq62qTDsS4h/FmHTIXBJOImGuu3Mz3xHcwc5DEhV1Pikktd5CvlUOVuXkC6eGuIpMgLfMLTQ+p94l+TTKySEKV18WH3Dl69Pew= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705440249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PJ9dSOLE+qa38L+9bQ4U6M6TKHH4zStvX7/9i2z1ggs=; b=GSc+F6/DikKqj72Jbns5A0EEAhhn/Q5gyafXY2XcgUZX1L929E9ycQU8UNuIT/PS8ISJmk nstLpU+dnb/YOVuRa9E6NHLPzBKhB4hEThLtIBNSGhQLU/+qEGdPbfu8zJJQCWvHjxUNXq EnNrEdAca/DFc0ALb9QitFivLZIVMT8= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-wKXCV5m4OHKSsoLMczixPg-1; Tue, 16 Jan 2024 16:24:08 -0500 X-MC-Unique: wKXCV5m4OHKSsoLMczixPg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-337a9795c5cso1683982f8f.2 for ; Tue, 16 Jan 2024 13:24:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705440246; x=1706045046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PJ9dSOLE+qa38L+9bQ4U6M6TKHH4zStvX7/9i2z1ggs=; b=l5IYZnZysB3roSIIN1Zl+sdRNxI64xV2AKzXp4HhRQarICI1EEtBIF53W+HTcG5FmY h/7/3f3+PSYCBtzCtGkQJ/z7+RVViYgg3eab4IHX/yG0nAvQYt+mzCRqRR1+RXzgF6pB KbpZvp2deMrKsBZFZ3g8g/mE0KHWf8DAHBfcDLfaB02dmPW1RQFaHG03bNQRbA4NLGw/ A3Cipq1lj4ku096DVvmbDdlRjBwq6KERYwaEEcVjrfohWZcqnLOKL4Q/l2dx7vy5a+Zh 3T639bIFT5N1XXYkIf1nXsXkJaT5NSrqUAfPbRaFEay/RX5HmpztBfBhXwnuQ3CtgbNk kutA== X-Gm-Message-State: AOJu0Yx8lKXPMNB5F5YhAyXx6yUjXY03hmpn36Z1gZB7iXwGJH8OvVay bEQmRvSnscyMKhn9a0trQ3c3RXlGKcLvQo2YHJ9g0elw0i2wbsI6fD7hV0LfIND5asJte1ThJOT PsooIuMrZGoJnPnlBcEFgR/IluLtbAT04840/kek7Xeri+8HQckWvPYJcwzdJqniFQcBDydpyj9 E8eqI4imWE6IRBQQ== X-Received: by 2002:a05:600c:4292:b0:40d:3b0a:6edb with SMTP id v18-20020a05600c429200b0040d3b0a6edbmr2873195wmc.183.1705440245834; Tue, 16 Jan 2024 13:24:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPH0F418MaaxHqWGsRsiHW82n61O6XYCpInYdWzMtNn8SVhL7XMy/jSZzcLYXaUojkwmdWuA== X-Received: by 2002:a05:600c:4292:b0:40d:3b0a:6edb with SMTP id v18-20020a05600c429200b0040d3b0a6edbmr2873192wmc.183.1705440245390; Tue, 16 Jan 2024 13:24:05 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id o8-20020a05600c510800b0040e624995f1sm19196122wms.8.2024.01.16.13.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 13:24:04 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/5] gdb: remove skip_quoted and skip_quoted_chars Date: Tue, 16 Jan 2024 21:23:58 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org The function skip_quoted_chars (completer.c) is only used by skip_quoted (also completer.c), so could be made static. The function skip_quoted just calls directly to skip_quoted_chars but fills in some default arguments. The function skip_quoted is only used by the Pascal expression parser, and is only used in one place. The skip_quoted_chars function skips a single string; it either looks for a string between matching quotes, or for a string up to a word break character. However, given how the Pascal expression parser calls this function, we know that the first character will always be a single quote, in which case skip_quoted_chars will looks for a string between matching single quotes. The skip_quoted_chars doesn't do any escaped character handling, it will just stop at the next single quote character. In this commit I propose to remove skip_quoted and skip_quoted_chars, and replace these with a smaller function pascal_skip_string which I've placed in p-exp.y. This new function only skips a string between matching single quotes, which is exactly the use case that we need. The benefit of this change is to remove (some) code duplication. It feels like skip_quoted is similar in some ways to extract_string_maybe_quoted, however, there are some differences; skip_quoted uses the quotes and word break characters from the completion engine which extract_string_maybe_quoted does not. However, I'm currently working on improving filename completion, one part of this is that I'm looking at allowing filenames to be quoted with single or double quotes, while the default string quoting in GDB (for expressions) can only use single quotes. If I do end up allowing single and double quotes in some cases, but we retain the single quotes only for expressions then skip_quoted starts to become a problem, should it accept both quote types, or only one? But given how skip_quoted is used, I can avoid worrying about this by simply removing skip_quoted. The Pascal tests do still pass. The code that called skip_quoted is called at least once in the Pascal tests (adding an abort() call causes gdb.pascal/types.exp to fail), but I doubt the testing is extensive. Not sure how widely used GDB for Pascal actually is though. --- gdb/completer.c | 55 ------------------------------------------------- gdb/completer.h | 5 ----- gdb/p-exp.y | 26 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 61 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 168fab74d14..8168f79de0e 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -2371,61 +2371,6 @@ gdb_rl_attempted_completion_function (const char *text, int start, int end) return NULL; } -/* Skip over the possibly quoted word STR (as defined by the quote - characters QUOTECHARS and the word break characters BREAKCHARS). - Returns pointer to the location after the "word". If either - QUOTECHARS or BREAKCHARS is NULL, use the same values used by the - completer. */ - -const char * -skip_quoted_chars (const char *str, const char *quotechars, - const char *breakchars) -{ - char quote_char = '\0'; - const char *scan; - - if (quotechars == NULL) - quotechars = gdb_completer_quote_characters; - - if (breakchars == NULL) - breakchars = current_language->word_break_characters (); - - for (scan = str; *scan != '\0'; scan++) - { - if (quote_char != '\0') - { - /* Ignore everything until the matching close quote char. */ - if (*scan == quote_char) - { - /* Found matching close quote. */ - scan++; - break; - } - } - else if (strchr (quotechars, *scan)) - { - /* Found start of a quoted string. */ - quote_char = *scan; - } - else if (strchr (breakchars, *scan)) - { - break; - } - } - - return (scan); -} - -/* Skip over the possibly quoted word STR (as defined by the quote - characters and word break characters used by the completer). - Returns pointer to the location after the "word". */ - -const char * -skip_quoted (const char *str) -{ - return skip_quoted_chars (str, NULL, NULL); -} - /* Return a message indicating that the maximum number of completions has been reached and that there may be more. */ diff --git a/gdb/completer.h b/gdb/completer.h index f0b9e68e120..f604a95011f 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -662,11 +662,6 @@ extern void complete_expression (completion_tracker &tracker, extern void complete_nested_command_line (completion_tracker &tracker, const char *text); -extern const char *skip_quoted_chars (const char *, const char *, - const char *); - -extern const char *skip_quoted (const char *); - /* Called from command completion function to skip over /FMT specifications, allowing the rest of the line to be completed. Returns true if the /FMT is at the end of the current line and there is nothing diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 2b5eb6f3026..726166a7a5e 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -76,6 +76,8 @@ static void yyerror (const char *); static char *uptok (const char *, int); +static const char *pascal_skip_string (const char *str); + using namespace expr; %} @@ -1041,6 +1043,28 @@ uptok (const char *tokstart, int namelen) return uptokstart; } +/* Skip over a Pascal string. STR must point to the opening single quote + character. This function returns a pointer to the character after the + closing single quote character. + + This function does not support embedded, escaped single quotes, which + is done by placing two consecutive single quotes into a string. + Support for this would be easy to add, but this function is only used + from the Python expression parser, and if we did skip over escaped + quotes then the rest of the expression parser wouldn't handle them + correctly. */ +static const char * +pascal_skip_string (const char *str) +{ + gdb_assert (*str == '\''); + + do + ++str; + while (*str != '\0' && *str != '\''); + + return str; +} + /* Read one token, getting characters through lexptr. */ static int @@ -1119,7 +1143,7 @@ yylex (void) c = *pstate->lexptr++; if (c != '\'') { - namelen = skip_quoted (tokstart) - tokstart; + namelen = pascal_skip_string (tokstart) - tokstart; if (namelen > 2) { pstate->lexptr = tokstart + namelen; -- 2.25.4