From patchwork Wed Mar 6 10:23:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86859 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27793385801A for ; Wed, 6 Mar 2024 10:24:25 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3052D38582BF for ; Wed, 6 Mar 2024 10:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3052D38582BF 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 3052D38582BF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720636; cv=none; b=tKTauPgkOyFAQtgnkGobWD8S+J71ZKQDfDljbq6Ytwxmbp5Ce6lNIhpXIMEjAh/KL87GAaZYh1OY2C5gLa5BHclIyJQjhtbI4H97yisIs96AsZnwiflM5bJzDskTL29iemp528aB8TM7LZnh8hEQf6PMTNe+uDQURsBq5bQvwGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720636; c=relaxed/simple; bh=OJ58jpkJ+soJBTdmpPml4i8J904C+6STMqlJzS57LE4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=VxSezFOiL5McQatNq87T0iskKTRhW5B1dAWdb301XbRWqy97fm0MwlhGDk2Yd4vrr+/M9BdATUzjofspFCs6ndCOyLIERCjjN7GyAZMQmgAWqQad0IAO06JLKT29Ux2PHs95plc/ArxV+H3fX9VRsCUDx8mhST0d3jKyKUp3+HA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720634; 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=KF0gFreYg4pKo+kQjzj3wUMsibY56I5CrLyvNdjrBug=; b=b0VWXFq47b6nu6z7uM02drirE3Sf0bIJm58aqvxCOGUAyC/PRAqv7hRLFcNcBaJDNscCOZ Uhh5yTXyoJaCBgR/zyOr/oWURxCWbhV5A7UpiNtFAIRB0IckwGxZwRwTURpC5h8+cTQPzI doEpAV7hxwo5gN1p7zuk1qHTTDowg+Y= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-jJ1P3LZ3N-yG_svYHohrRQ-1; Wed, 06 Mar 2024 05:23:53 -0500 X-MC-Unique: jJ1P3LZ3N-yG_svYHohrRQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a4533388b03so189729766b.0 for ; Wed, 06 Mar 2024 02:23:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720632; x=1710325432; 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=KF0gFreYg4pKo+kQjzj3wUMsibY56I5CrLyvNdjrBug=; b=ryU58+UOorpr/J9ywujQI/g/qcgwedc3JONZmt1OFD6UX2MVgEwQIO0RV2Gg9YMpRE 8JVWAAEy6U5g4tfHgJnqIk8oY0D7G1TgZ2KsGksoBIKqs1a1wXoLaD20N+2rxkTH5lco GiEbepJqOAtiteFx8dlSkwpwKaB/US9FQ4y8zUTNbGxZoefcMnWsf45V9nUrUIPnIaZJ PBwyTYIzqHEFo9sler4lgmHi7VKiHKKZkk9zjicBzx9tF9j5tAmPdyOmiNQPUx1v/SzC C0b2FQhxNzyxMooS4RrfGrS4XM7zkPuNF8XDlMOss+PuxnGU+6RvY9SLxaNMWVhVr/b0 mwVQ== X-Gm-Message-State: AOJu0Ywuj3KHtnTG5PLfUwb3jLao/hFgdzGHnc7loG1R4VdOVn6W6+R6 owYuPQMt9QMgcszJQnqmkuhkraD8GgFeE+plgWjIIQwDynnHJshlQA6n8FyAalLVDKGmGwEIPx4 QGXf+4S1uhNvV22s2ruIYVW+f+CX5UvM0HaochVy46osnFEM5fTKaGFLErNui2iy9xWmzn+d8lP gV4vgn9Yvdctwldg/c88oiqhxiY5iG6bw1sO0ECmD/Xzw= X-Received: by 2002:a17:906:37d5:b0:a45:bea5:8063 with SMTP id o21-20020a17090637d500b00a45bea58063mr722272ejc.48.1709720631771; Wed, 06 Mar 2024 02:23:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNAW8e4dHMiNo0mHT+1ztQiaq8UD9Kh72vnensOEVRfDPeOelX4qR0MiI23GjODr8PEm7Kzw== X-Received: by 2002:a17:906:37d5:b0:a45:bea5:8063 with SMTP id o21-20020a17090637d500b00a45bea58063mr722248ejc.48.1709720631230; Wed, 06 Mar 2024 02:23:51 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id y1-20020a1709060bc100b00a43aa27b5f2sm6993425ejg.94.2024.03.06.02.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:23:49 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/7] gdb: remove skip_quoted and skip_quoted_chars Date: Wed, 6 Mar 2024 10:23:33 +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 X-Spam-Status: No, score=-12.2 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+patchwork=sourceware.org@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 ea7eb8c8d7e..bfb1cad60a7 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; %} @@ -1042,6 +1044,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 @@ -1120,7 +1144,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;