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; From patchwork Wed Mar 6 10:23:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86865 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 6E8DB385802F for ; Wed, 6 Mar 2024 10:29:45 +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 E54873858029 for ; Wed, 6 Mar 2024 10:29:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E54873858029 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 E54873858029 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=1709720951; cv=none; b=YSHcIODoOH7xHBp40Ndda+13jpEOTn6uURdokYeArVNy4Z2HFsPmLwiU9F3sjko7hNPY4E7R1leVk3styg/kEMYu6g6Cwt7sWZx5snHJwVgldXc+3XqmkUsnvF4olPpq4ndkNCUWNSgCOpg782nEmyzYrTGGnJ3Pokc0tvfl7B4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720951; c=relaxed/simple; bh=SHgBJ1Z5DpjNUF94EAGELUQvQAk/bMx0KEYtPumGlls=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jmzTWhk6mjWlNC5xTsC38XgkHACf7aLlhBQEIDOED22qrxC3u/x2kvvvcmFSKPtXCF/O4GT33PLg2pNthJ6OyBlPReJ5Zk2wZuo5WSAmUubuPWdZOkh+9VAuUM1tkBxoM+uNofoQXvx/tfkpDCpxGNSe3N1K22ZlBVg64/wRA3c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720948; 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=Ps/DzOdiWY5rI9PxpgIJ3G1NvkScu8mmjx0fQOnxP9A=; b=AAqUpYYr+mvypFkwJ3rCqQAcplGKNk4qP3RsgzU7Y/DbGOxUsbnQ5w3GkvynV4dN/f8dfc IBShqoGRuLjtES0IEe47M4xfzm6y0nAXkiAC3vbQPKopa1MBxsRy1FTdaKKLm9lOEDhe30 0vZ0Fqpoogk1U9uWf4US/BgovsUTqPo= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-uc0wFu7lMxqaAaGv42WWDA-1; Wed, 06 Mar 2024 05:29:07 -0500 X-MC-Unique: uc0wFu7lMxqaAaGv42WWDA-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a3fcf5b93faso436066866b.2 for ; Wed, 06 Mar 2024 02:29:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720634; x=1710325434; 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=bozw9Yio2RMn1fX9HaTA0jiNm3rZBiOhqDHqLaDQkIM=; b=E0hZb12xcd0w9qDQrQJgxbjhpIO6jgSk0b0C068a31ukMsQ9OKVqdkXIuvUHYk4D68 /QApb5AaKZKkaSI7r0dW7vsKt0UpENGVELZwhOTLpg2Us1yfCptgd++GJpOC7m5v0QaL dKcvlY/T2Sg+PRpBtYNRWJBR09qY67sngrbCWA7tGbG/fTv5QV+VYoHwnl+JqU0XVHOy UakH+wsnyBz8yZ5HZXjbLuhxENL5MjFD/9pwuTpxAKCr+r/69iQVJ7ggIVW+OzE6hdq+ AmIROZVO+p0J/DbBw5D4M7EaAE5kTmDfMqmYs14bUvgKitCzLQzv2LPhJ2zdjNUxaM5f M+cw== X-Gm-Message-State: AOJu0YxDK6hmstTG/0bWBkL1RLGlbGOyC9+rmalrMjp6/QyIqxzIKSvY 1NUN+BhKFZfRjBZ57U1Mj1PYnQRX7nGSWOJBkx9+bZ09XLSKfjQMJIhTXC77W5MsqMQX/rkULs/ KAuXAdGuyj490PIS6Qg8dMWk9SDwK1QsGw1d0tC9ZsOVxkNjJqE+PZRK/QQ7qsZVBjYwJMUAZqt C+ak6uwda07t7Nr8FWGB58PhLauEibscPKFSNmbS6yIaU= X-Received: by 2002:a17:906:390e:b0:a44:446b:e99e with SMTP id f14-20020a170906390e00b00a44446be99emr9241303eje.31.1709720633624; Wed, 06 Mar 2024 02:23:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxi/4hxkVJsgy/44eq3x0vXPFoaNrOkUbtc9obJMmiyIInTEH9dLe9MGXlc+ujAcJAmDLxPw== X-Received: by 2002:a17:906:390e:b0:a44:446b:e99e with SMTP id f14-20020a170906390e00b00a44446be99emr9241284eje.31.1709720632870; Wed, 06 Mar 2024 02:23:52 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id sa20-20020a1709076d1400b00a4432543b21sm6934134ejc.198.2024.03.06.02.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:23:52 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 2/7] gdb: fix bug where quote characters would become nullptr Date: Wed, 6 Mar 2024 10:23:34 +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=-11.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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 In gdb_completion_word_break_characters_throw, after calling complete_line_internal, if the completion function chose to use a custom word point then we set rl_completer_quote_characters to NULL. However, nowhere do we set rl_completer_quote_characters back to its default value, which is setup in init_main (top.c). An example of something that uses a custom word point for its completion is 'thread apply all ...'. An example of something that relies on rl_completer_quote_characters would be completion of a quoted filename that contains white space. Consider this shell and GDB session. The markers indicate where I've used tab to trigger completion: $ mkdir /tmp/aaa\ bbb $ touch /tmp/aaa\ bbb/xx\ 11 $ touch /tmp/aaa\ bbb/xx\ 22 $ gdb -q (gdb) file '/tmp/aaa bbb/xx xx 11 xx 22 (gdb) thread apply all hel (gdb) thread apply all help (gdb) file '/tmp/aaa bbb/xx First I create a directory structure which uses white space within file and directory names. Then within GDB I use the 'file' command and use a single quote to quote the filename. When I tab complete GDB correctly offers the two files within the directory '/tmp/aaa bbb/'. This works because rl_completer_quote_characters contains the single quote, and so readline knows that it is trying to complete the string that starts after the single quote: /tmp/aaa bbb/xx Next I invoke the completer for the 'thread apply all' command, to do this I type 'thread apply all hel' and hit tab, this expands to the one completion 'thread apply all help'. We can run this command or not, it doesn't matter (there are no threads, so we'll get no output). Now I repeat the original 'file' completion. This time though I don't get offered any completions. The reason is that the 'thread apply all' completer set rl_completer_quote_characters to nullptr. Now, when readline tries to figure out the word to complete it doesn't see the single quote as the start of a quoted word, so instead readline falls back to the word break characters, and in this case spots the white space. As a result readline tries to complete the string 'bbb/xx' which obviously doesn't have any completions. By setting rl_completer_quote_characters each time completion is invoked this problem is resolved and the second 'file' command completes as expected. I've extended gdb.base/filename-completion.exp to also test with quoted filenames, and added a 'thread apply all' completion at the start to expose this bug. As setting of rl_completer_quote_characters is now all done in the completer.c file the function get_gdb_completer_quote_characters() could be made static. However, as this function is only used one time to initialise rl_completer_quote_characters, I've instead just deleted get_gdb_completer_quote_characters() and used gdb_completer_quote_characters directly. --- gdb/completer.c | 10 +-- gdb/completer.h | 2 - .../gdb.base/filename-completion.exp | 66 +++++++++++++------ gdb/top.c | 1 - 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 8168f79de0e..44da6548eb4 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -181,13 +181,6 @@ static const char gdb_completer_file_name_break_characters[] = sequences as strings. */ static const char gdb_completer_quote_characters[] = "'"; -/* Accessor for some completer data that may interest other files. */ - -const char * -get_gdb_completer_quote_characters (void) -{ - return gdb_completer_quote_characters; -} /* This can be used for functions which don't want to complete on symbols but don't want to complete on anything else either. */ @@ -1269,6 +1262,9 @@ complete_line_internal_1 (completion_tracker &tracker, set_rl_completer_word_break_characters (current_language->word_break_characters ()); + /* Likewise for the quote characters. */ + rl_completer_quote_characters = gdb_completer_quote_characters; + /* Decide whether to complete on a list of gdb commands or on symbols. */ tmp_command = (char *) alloca (point + 1); diff --git a/gdb/completer.h b/gdb/completer.h index f604a95011f..0a95ced8a80 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -619,8 +619,6 @@ extern void reggroup_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); -extern const char *get_gdb_completer_quote_characters (void); - extern char *gdb_completion_word_break_characters (void); /* Set the word break characters array to BREAK_CHARS. This function diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 20ca227f96d..7d8ab1a3350 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -37,6 +37,9 @@ proc setup_directory_tree {} { remote_exec host "mkdir -p ${root}/cc1" remote_exec host "touch ${root}/cc2" + remote_exec host "touch \"${root}/aaa/aa bb\"" + remote_exec host "touch \"${root}/aaa/aa cc\"" + return $root } @@ -45,26 +48,49 @@ proc setup_directory_tree {} { # sub-directory of the user's home directory ROOT might have been # modified to replace the $HOME prefix with a single "~" character. proc run_tests { root } { - test_gdb_complete_none "file ${root}/xx" \ - "expand a non-existent filename" - - test_gdb_complete_unique "file ${root}/a" \ - "file ${root}/aaa/" "" false \ - "expand a unique filename" - - test_gdb_complete_multiple "file ${root}/" \ - "b" "b" { - "bb1/" - "bb2/" - } "" "" false \ - "expand multiple directory names" - - test_gdb_complete_multiple "file ${root}/" \ - "c" "c" { - "cc1/" - "cc2" - } "" "" false \ - "expand mixed directory and file names" + + # Completing 'thread apply all ...' commands uses a custom word + # point. At one point we had a bug where doing this would break + # completion of quoted filenames that contained white space. + test_gdb_complete_unique "thread apply all hel" \ + "thread apply all help" " " false \ + "complete a 'thread apply all' command" + + foreach_with_prefix qc [list "" "'"] { + test_gdb_complete_none "file ${qc}${root}/xx" \ + "expand a non-existent filename" + + test_gdb_complete_unique "file ${qc}${root}/a" \ + "file ${qc}${root}/aaa/" "" false \ + "expand a unique filename" + + test_gdb_complete_multiple "file ${qc}${root}/" \ + "b" "b" { + "bb1/" + "bb2/" + } "" "${qc}" false \ + "expand multiple directory names" + + test_gdb_complete_multiple "file ${qc}${root}/" \ + "c" "c" { + "cc1/" + "cc2" + } "" "${qc}" false \ + "expand mixed directory and file names" + + # GDB does not currently escape word break characters + # (e.g. white space) correctly in unquoted filenames. + if { $qc ne "" } { + set sp " " + + test_gdb_complete_multiple "file ${qc}${root}/aaa/" \ + "a" "a${sp}" { + "aa bb" + "aa cc" + } "" "${qc}" false \ + "expand filenames containing spaces" + } + } } gdb_start diff --git a/gdb/top.c b/gdb/top.c index cf7d3a913ba..8df684ec8b4 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -2142,7 +2142,6 @@ init_main (void) rl_completion_word_break_hook = gdb_completion_word_break_characters; rl_attempted_completion_function = gdb_rl_attempted_completion_function; set_rl_completer_word_break_characters (default_word_break_characters ()); - rl_completer_quote_characters = get_gdb_completer_quote_characters (); rl_completion_display_matches_hook = cli_display_match_list; rl_readline_name = "gdb"; rl_terminal_name = getenv ("TERM"); From patchwork Wed Mar 6 10:23:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86860 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 BDFC03858037 for ; Wed, 6 Mar 2024 10:24:28 +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 D21BF385802B for ; Wed, 6 Mar 2024 10:23:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D21BF385802B 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 D21BF385802B 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=1709720640; cv=none; b=UcZ8D/KnEG8PPubUvFm5VLfHd3Jkz7kSq6iyu18FvZy3Q5a42bkLqtkkE/MNJnkX2CILqZxIM6B3R6MBynirpw9UTtS+ErzY23Q4Yu19TLG8k9Mz9ZNfD5Qlhn+52+o7FDR0Q2aIpQygYWj9t8g1aYYDVD5WhocUWPC7byuqD/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720640; c=relaxed/simple; bh=iWSM2djF3lM9sPrwJfvv+ab6CE/zbPNSl3q5hOIlUu8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=CVXnPdpuHCP/6Kur3KQzhqHntdae9Ybr3R+xoXDymUQMXEb9Blu4KFfG8dWcFvgTTebMD3bh5Hve2ioq89xkTgfvN8w0xrldLOVH2+6rdI9eDx81g1rUyhdTxrwqOsOhtG0RArgMSGPSxrxbd57z5wQmrlHNzcimDf9rtFiKAHU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720638; 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=IVpWDpQxj625l80jIlw6UrI1AoGZRtdaseDX5nde0do=; b=Oe91D4Eqfy+ybCtCesHEyo5JOHvwWkKSMV68NpNyDfU75VCiQG/i1ifvLWkLabAMvyNGiR hHE7V3fO6iz334K0j1/52P5sLmPtzrKc+SNgIjMDBW4EKNBw+0qWlnktpbYHQc1LduJBjL GaKIbanj4MXGsmaRBwm0ze7UPh7wR88= 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-628-ZsTPiJPKOSakzw1DLq2B2Q-1; Wed, 06 Mar 2024 05:23:57 -0500 X-MC-Unique: ZsTPiJPKOSakzw1DLq2B2Q-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a44143c8908so68801566b.1 for ; Wed, 06 Mar 2024 02:23:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720635; x=1710325435; 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=aagEVFf3icx7lUBXSZDTptpPVI+PM9gyCJtR1nuRkvQ=; b=fwKsSJ+r2cVXWU3bdRY8MXM6nY5xXAWwj4DzbGJ+RKlN9iiC4gdLmDbWT8Jhc7JluJ tu93sdhsfiBZuncKlcBzpyOnh9pd77pzQZ1SBasu2WMCS6vbYbdddaKQE1eVT2Rl6J5v lDDAy3O5IZR7Giu5cBP2SX4dLf1HfrSTHt5utUsITY1N/nRPq+aXtV33TV9HRIosIKuj d/eoFYOrB3qEYwvWCgHZ8r4Mpmtl5LQu4Sj3K0adDa5iQwPEcsr4TOsndgKI5n2jxwUs l22sNd7UJC0Hoqgyer+IPjSaavAfz3CYGM/7Zy0MtUNtkBwc+SkVEVNNowXEIyhky0IT HYxQ== X-Gm-Message-State: AOJu0YwYpoIg4YlwxnUzJZz06pTmNIA9o0GBmbOU86ea+r3MvDbgwOlP 0+Oo+cIRjKHwMUZBLQX7/DsOYty+BgoW4rim2IoPah3oyissQc+gxJOTp3KrVsKJaJNAywoRj9Z 04rELOJOi8Bc4Gy2oCxaD2Ts2SGUjm1tsdcneuKMVtKqMF6Qe+INpIMm0KRQ80VD1TdYdW0qBtw 51wDrsmlw56hKdgmn16l4LmZdV7jTifhFFXXSDIi+gC8Q= X-Received: by 2002:a17:906:684d:b0:a45:bde1:a334 with SMTP id a13-20020a170906684d00b00a45bde1a334mr983841ejs.27.1709720634875; Wed, 06 Mar 2024 02:23:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAExBDypaiGXeM7R6oPqvn9nSDqoRPDFqxb8u+3Elz3J7lCpXx6vrqV4J3LWVllwwD0ZJi+A== X-Received: by 2002:a17:906:684d:b0:a45:bde1:a334 with SMTP id a13-20020a170906684d00b00a45bde1a334mr983814ejs.27.1709720634175; Wed, 06 Mar 2024 02:23:54 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id cu5-20020a170906ba8500b00a440ec600e3sm6949519ejd.121.2024.03.06.02.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:23:53 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/7] gdb: allow double quotes for quoting filenames Date: Wed, 6 Mar 2024 10:23:35 +0000 Message-Id: <3fd42ec03923acbf824f5f5318291aa7c92bb751.1709720449.git.aburgess@redhat.com> 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=-11.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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 Currently GDB only supports using single quotes for quoting things, the reason for this, as explained in completer.c (next to the variable gdb_completer_expression_quote_characters) is that double quoted strings need to be treated differently by the C expression parser. But for filenames I don't believe this restriction holds. The file names as passed to things like the 'file' command are not passing through the C expression parser, so it seems like we should be fine to allow double quotes for quoting in this case. And so, this commit extends GDB to allow double quotes for quoting filenames. Maybe in future we might be able to allow double quote quoting in additional places, but this seems enough for now. The testing has been extended to cover double quotes in addition to the existing single quote testing. This change does a number of things: 1. Set rl_completer_quote_characters in filename_completer and filename_completer_handle_brkchars, this overrides the default which is set in complete_line_internal_1, 2. In advance_to_completion_word we now take a set of quote characters as a parameter, the two callers advance_to_expression_complete_word_point and advance_to_filename_complete_word_point now pass in the required set of quote characters, 3. In completion_find_completion_word we now use the currently active set of quote characters, this means we'll use gdb_completer_expression_quote_characters or gdb_completer_file_name_quote_characters depending on what type of things we are completing. --- gdb/completer.c | 34 +++++++++++++------ .../gdb.base/filename-completion.exp | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 44da6548eb4..cefac605a33 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -176,10 +176,15 @@ static const char gdb_completer_file_name_break_characters[] = " \t\n*|\"';:?><"; #endif -/* Characters that can be used to quote completion strings. Note that - we can't include '"' because the gdb C parser treats such quoted +/* Characters that can be used to quote expressions. Note that we can't + include '"' (double quote) because the gdb C parser treats such quoted sequences as strings. */ -static const char gdb_completer_quote_characters[] = "'"; +static const char gdb_completer_expression_quote_characters[] = "'"; + +/* Characters that can be used to quote file names. We do allow '"' + (double quotes) in this set as file names are not passed through the C + expression parser. */ +static const char gdb_completer_file_name_quote_characters[] = "'\""; /* This can be used for functions which don't want to complete on @@ -199,9 +204,9 @@ filename_completer (struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word) { - int subsequent_name; + rl_completer_quote_characters = gdb_completer_file_name_quote_characters; - subsequent_name = 0; + int subsequent_name = 0; while (1) { gdb::unique_xmalloc_ptr p_rl @@ -256,6 +261,8 @@ filename_completer_handle_brkchars (struct cmd_list_element *ignore, { set_rl_completer_word_break_characters (gdb_completer_file_name_break_characters); + + rl_completer_quote_characters = gdb_completer_file_name_quote_characters; } /* Find the bounds of the current word for completion purposes, and @@ -401,12 +408,13 @@ gdb_rl_find_completion_word (struct gdb_rl_completion_word_info *info, static const char * advance_to_completion_word (completion_tracker &tracker, const char *word_break_characters, + const char *quote_characters, const char *text) { gdb_rl_completion_word_info info; info.word_break_characters = word_break_characters; - info.quote_characters = gdb_completer_quote_characters; + info.quote_characters = quote_characters; info.basic_quote_characters = rl_basic_quote_characters; int delimiter; @@ -431,7 +439,8 @@ advance_to_expression_complete_word_point (completion_tracker &tracker, const char *text) { const char *brk_chars = current_language->word_break_characters (); - return advance_to_completion_word (tracker, brk_chars, text); + const char *quote_chars = gdb_completer_expression_quote_characters; + return advance_to_completion_word (tracker, brk_chars, quote_chars, text); } /* See completer.h. */ @@ -441,7 +450,8 @@ advance_to_filename_complete_word_point (completion_tracker &tracker, const char *text) { const char *brk_chars = gdb_completer_file_name_break_characters; - return advance_to_completion_word (tracker, brk_chars, text); + const char *quote_chars = gdb_completer_file_name_quote_characters; + return advance_to_completion_word (tracker, brk_chars, quote_chars, text); } /* See completer.h. */ @@ -1262,8 +1272,10 @@ complete_line_internal_1 (completion_tracker &tracker, set_rl_completer_word_break_characters (current_language->word_break_characters ()); - /* Likewise for the quote characters. */ - rl_completer_quote_characters = gdb_completer_quote_characters; + /* Likewise for the quote characters. If we later find out that we are + completing file names then we can switch to the file name quote + character set (i.e., both single- and double-quotes). */ + rl_completer_quote_characters = gdb_completer_expression_quote_characters; /* Decide whether to complete on a list of gdb commands or on symbols. */ @@ -1988,7 +2000,7 @@ completion_find_completion_word (completion_tracker &tracker, const char *text, gdb_rl_completion_word_info info; info.word_break_characters = rl_completer_word_break_characters; - info.quote_characters = gdb_completer_quote_characters; + info.quote_characters = rl_completer_quote_characters; info.basic_quote_characters = rl_basic_quote_characters; return gdb_rl_find_completion_word (&info, quote_char, NULL, text); diff --git a/gdb/testsuite/gdb.base/filename-completion.exp b/gdb/testsuite/gdb.base/filename-completion.exp index 7d8ab1a3350..b700977cec5 100644 --- a/gdb/testsuite/gdb.base/filename-completion.exp +++ b/gdb/testsuite/gdb.base/filename-completion.exp @@ -56,7 +56,7 @@ proc run_tests { root } { "thread apply all help" " " false \ "complete a 'thread apply all' command" - foreach_with_prefix qc [list "" "'"] { + foreach_with_prefix qc [list "" "'" "\""] { test_gdb_complete_none "file ${qc}${root}/xx" \ "expand a non-existent filename" From patchwork Wed Mar 6 10:23:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86861 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 3994138582AC for ; Wed, 6 Mar 2024 10:25:03 +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 375A438582B6 for ; Wed, 6 Mar 2024 10:24:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 375A438582B6 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 375A438582B6 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=1709720645; cv=none; b=cdsUPp8P6yJBOxC9EkM7ZDTRYvlwSyC+CxYbpBJjkC3k6VW+kXzz0W7fYIpG7LZQgMmlnS6PPbg/PnX0uqWtp/lAj9aIaNGeyGGC56bR24z73j9Eme0c1MAndx7UPpn/cbTrvlCM0jpnG2zaf1a6SA3aGTnHPbjEKbTQ11YQ8ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720645; c=relaxed/simple; bh=fqLrD/J/ZvVXM/i89uLyZZgJxg9yTescFX3Ned9WkPQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=o8NLf9997uPM50c0ZqKqOo7fIKYXTt8I7gft+JMvpBXOQJUWp5UYpmabxehB8RFI5I7YBhknbmCBmjsQi+98rTSMQrmHK8LMe+R22khLkJjydMtBo6DfrsVUZYwWdv72LHQwFEqc7ugLhCcYRgEM0Slex+6/Y1vJXdpVDeYwKjU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720640; 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=5Chr9ZwDKPM07ZObPaDmwHBAVuTJ97EuTvABjrQkukw=; b=gNe0GVKiMVkcipFZ3/QAW14bhNKZY5gcwkVdd6dMFdgfu5+XWvxBbvpiZeTyi0CqT32KM/ igkCIY0k7mMt9KbAvWTepFb32XmQ+elFbVtRS93MzrRoXobxkin6Ytlw314iFwiqzlyI3w JkEosX5ZLnY633LYH9jZYmQQLtBjhG0= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-ADWfGCfRMvCymOXNLAYNuQ-1; Wed, 06 Mar 2024 05:23:59 -0500 X-MC-Unique: ADWfGCfRMvCymOXNLAYNuQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a35ef7abe08so463625066b.2 for ; Wed, 06 Mar 2024 02:23:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720638; x=1710325438; 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=5Chr9ZwDKPM07ZObPaDmwHBAVuTJ97EuTvABjrQkukw=; b=SA6ihm+vReiKZFYxjXje+tbCzGRm2qbtFoC9Kc3YxpgNCRniGA5LevIht9hmZVVz5N kIMhn2Hs8fefn+fmnRna0wK5FJAcfUek3j5yiP7aTfE4XTfcvGWvHWuqbJVgMhFROXXI JgtTERGVeM40nE6uIu8RqZCYKkTzC2hEhLBK6QCChbHrvGY6bWkt6fyfd0F+iGyYIJU6 vyCwKC6mDuGAguYMQXbwC8TI8NstrFXAzBqv/WbS43TY9hMbDpsapYLTHGN0pVxRgQFD gLkMvmZNKXzOc19bjLzGyTmJ60Cvdclxrkpg6sgTnpYiN82bKO0u5xT/HMU1ZXASPDM9 o3Uw== X-Gm-Message-State: AOJu0YxbqwBt2pRk04RZBqkhNUbrGfFVMTNhM+G+iFFB1F5U1rloJ3GH +m6Nrv1bt3kHzb0S1JqqDrE6t/Td2buNLuaWh8C6Sgm48y82s81+5K3A4pKO79VklBABS+k7ZZ8 pYTvc4wnwslI182v0+wiSXnceZLstl7elRgp7qBZnrznbOnig7N31Pc1Yxi8yOb9ubi3X/YgWII RYph0Ht7AD5YpmCVdo6Wc0C1MHZT/ri/cVvE1oqgQX37A= X-Received: by 2002:a17:906:7d3:b0:a45:c027:372 with SMTP id m19-20020a17090607d300b00a45c0270372mr558427ejc.68.1709720637838; Wed, 06 Mar 2024 02:23:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAmIFwCcaY6epfFJJR0rVN3ENK53m65GRKxOTP7Y3XXzuexRtK+b1F6fgjKZ+Orm5mPK9Jfw== X-Received: by 2002:a17:906:7d3:b0:a45:c027:372 with SMTP id m19-20020a17090607d300b00a45c0270372mr558409ejc.68.1709720637340; Wed, 06 Mar 2024 02:23:57 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id z20-20020a170906271400b00a441cb52bfcsm7018887ejc.165.2024.03.06.02.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:23:55 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 4/7] gdb: remove some dead code from completer.c Date: Wed, 6 Mar 2024 10:23:36 +0000 Message-Id: <5fade1ecaf0945d1f3fc3ecd58255c68a874c934.1709720449.git.aburgess@redhat.com> 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 In completer.c there is some code that is surrounded with '#if 0', this code: #if 0 /* There is no way to do this just long enough to affect quote inserting without also affecting the next completion. This should be fixed in readline. FIXME. */ /* Ensure that readline does the right thing with respect to inserting quotes. */ rl_completer_word_break_characters = ""; #endif This code, in some form, and always defined out, has been around since the original import of GDB. Though the comment hints at what the problem might be, it's not really clear what the issue is. And completion within GDB has moved on a long way since this code was written ... but not used. I'm proposing that we just remove this code. If/when a problem comes up then we can look at how to solve it. Maybe this code would be the answer ... but also, I suspect, given all the changes ... maybe not. I'm not sure carrying around this code for another 20+ years adds much value. There should be no user visible changes after this commit. --- gdb/completer.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index cefac605a33..330c39598c5 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -241,14 +241,6 @@ filename_completer (struct cmd_list_element *ignore, tracker.add_completion (make_completion_match_str (std::move (p_rl), text, word)); } -#if 0 - /* There is no way to do this just long enough to affect quote - inserting without also affecting the next completion. This - should be fixed in readline. FIXME. */ - /* Ensure that readline does the right thing - with respect to inserting quotes. */ - rl_completer_word_break_characters = ""; -#endif } /* The corresponding completer_handle_brkchars From patchwork Wed Mar 6 10:23:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86864 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 DB579385801C for ; Wed, 6 Mar 2024 10:25:28 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 21118385843A for ; Wed, 6 Mar 2024 10:24:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21118385843A 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 21118385843A 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=1709720645; cv=none; b=ij/L4H3vZCPvB4vo7+KqkRFEBAoC7SOp/V97oSpkQFTS1H1AY8QFmHv4BKFerAa1AEjthoMj3+hjxBXz/xs3X04bQRh944mfbzUiaWHwWVdTBywaahtMasgpb/3XWj8L2ElNhfBTOOUuoLYZ0EMpXxRQTSmfR+5Aqxw4dHm1FDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720645; c=relaxed/simple; bh=hLBG9jodGnferuNzlYbdSksM67LLA2C5oHtZ0/WUqus=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Nr9o87grI5vNDNDPkMYXxeDK7BmGrF3Hb31yRG6T7ewAKcW5/lYTEzmABIRPnuIBqZBC633lRJld0SwAVNKngxbEiTzgCZBKCWDdFZN2crZUvrtExtClCOwmEY3oEWDseibBH321gEOF6HgHCKXnL3HotXJGbx//XFUHtI9iQ94= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720642; 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=tWbctKYH8AaADxcaY3FrYeL+F5sx9kmshZPKdBe16kE=; b=VnnGD0GhAfZ/d3fziEbLlN7QXrAIF/ZPeYZQMmdpyjCFXMIxL+M1EXzWKtGxCh1PgjO2sP NjZtLpQb76ke36960ZLcQqQSZcyelR6KrOilN4xRKTh3BSqj7Rx7cRjgeGiIUfsZkHGcwG zhFaMNft4N1WPSrxndqeEMmyOdBEOdg= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-jwHs-jA7OJO2cllOk0RF2w-1; Wed, 06 Mar 2024 05:24:01 -0500 X-MC-Unique: jwHs-jA7OJO2cllOk0RF2w-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a4533388b03so189741266b.0 for ; Wed, 06 Mar 2024 02:24:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720640; x=1710325440; 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=tWbctKYH8AaADxcaY3FrYeL+F5sx9kmshZPKdBe16kE=; b=cvxPuWzDSp9tTGWPFLmeMxZBtvk01hd0HNG/Sh/kYXWiEipvxq43xHqg2+ct+SKo5l 2swRsjJugi5oqKlh/nov2istsk2NkyGkOffLBoDeZ949SvjCwNxfW36EVL+8MdnNrz88 eR+J04nYmN1FSOwkIqK0AtgWiBHcdJR2OoheR45bzvZL3h8SBhJr1P3srRM/4BWbm10i V9hWRCTZ4N73N79dCWKL6x7ePGcRBthFzK/gnAS1LwcjUq+xbAo35+thakpgOK71VFlx T4dN9lkcCyBzDvT5kDkKahyV600gPRhyeiH7i6Zu8eGt/ZtvYcCVbxxqVMdtMczyDbrO RcSA== X-Gm-Message-State: AOJu0YzwMVpn6p6xf7dLN0DWcdINMyqs6KmhjWtOw797FH8LDMQ8BK7H TO5zIbI0LSyS6oYeYo0o7sWVvV+9RYA3m/pyiqU2KKMedjNMcikrIzRm4f7mjodi4lAJRj2asSB PSz7CUoA1fUhnwT2USxlyZRoGHUdQRaDEuCirnKiOaCxpglRzEllTTvRg+RlkjBeKqgNBa91uJn axl2qraiLEq9IinKelEfDVgqv5yPWdU4FccfdxSyH0yZE= X-Received: by 2002:a17:906:8c6:b0:a3e:9aa3:7024 with SMTP id o6-20020a17090608c600b00a3e9aa37024mr10033404eje.34.1709720639823; Wed, 06 Mar 2024 02:23:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/U/S883/GPHCCCT3fkSzssmv0r5M4k/vvv6GC46HyOgajuHH8XfNK2f6H7M3x/gRs1rcoyA== X-Received: by 2002:a17:906:8c6:b0:a3e:9aa3:7024 with SMTP id o6-20020a17090608c600b00a3e9aa37024mr10033388eje.34.1709720639251; Wed, 06 Mar 2024 02:23:59 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id pv13-20020a170907208d00b00a451dc6055fsm3832724ejb.212.2024.03.06.02.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:23:58 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 5/7] gdb: remove special case completion word handling for filenames Date: Wed, 6 Mar 2024 10:23:37 +0000 Message-Id: <42a053369278a30fc6502e45eb4e4e9903a8ba3d.1709720449.git.aburgess@redhat.com> 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, 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 This commit removes some code which is special casing the filename completion logic. The code in question relates to finding the beginning of the completion word and was first introduced, or modified into its existing form in commit 7830cf6fb9571c3357b1a0 (from 2001). The code being removed moved the start of the completion word backward until a character in gdb_completer_file_name_break_characters was found, or until we reached the end of the actual command. However, I doubt that this is needed any more. The filename completer has a corresponding filename_completer_handle_brkchars function which provides gdb_completer_file_name_break_characters as the word break characters to readline, and also sets rl_completer_quote_characters. As such, I would expect readline to be able to correctly find the start of the completion word. There is one change which I've needed to make as a consequence of removing the above code, and I think this is a bug fix. In complete_line_internal_normal_command we initialised temporary variable P to the CMD_ARGS; this is the complete text after the command name. Meanwhile, complete_line_internal_normal_command also accepts an argument WORD, which is the completion word that readline found for us. In the code I removed P was updated, it was first set to WORD, and then moved backwards to the "new" start of the completion word. But notice, the default for P is the complete command argument text, and only if we are performing filename completion do we modify P to be the completion word. We then passed P through to the actual commands completion function. If we are doing anything other than filename completion then the value of P passed is the complete argument text. If we are doing filename completion then the value of P passed is the completion word. Thus in filename_completer we get two arguments TEXT and WORD, the TEXT argument gets the value of P which is the "new" completion word, while WORD is the completion word that readline calculated. However, after I removed the special case in complete_line_internal_normal_command, the temporary P is removed, we now always pass through the complete argument text where P was previous used. As such, filename_completer now receives TEXT as the complete argument text, and WORD as the readline calculated completion word. Previously in filename_completer we actually tried to generate completions based on TEXT, which due to the special case, was the completion word. But after my change this is no longer the case. So I've updated filename_completer to generate completions based on WORD, the readline calculated completion word. If I'm correct, then I don't expect to see any user visible changes after this commit. --- gdb/completer.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 330c39598c5..04354120621 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -210,7 +210,7 @@ filename_completer (struct cmd_list_element *ignore, while (1) { gdb::unique_xmalloc_ptr p_rl - (rl_filename_completion_function (text, subsequent_name)); + (rl_filename_completion_function (word, subsequent_name)); if (p_rl == NULL) break; /* We need to set subsequent_name to a non-zero value before the @@ -239,7 +239,7 @@ filename_completer (struct cmd_list_element *ignore, } tracker.add_completion - (make_completion_match_str (std::move (p_rl), text, word)); + (make_completion_match_str (std::move (p_rl), word, word)); } } @@ -1193,23 +1193,6 @@ complete_line_internal_normal_command (completion_tracker &tracker, complete_line_internal_reason reason, struct cmd_list_element *c) { - const char *p = cmd_args; - - if (c->completer == filename_completer) - { - /* Many commands which want to complete on file names accept - several file names, as in "run foo bar >>baz". So we don't - want to complete the entire text after the command, just the - last word. To this end, we need to find the beginning of the - file name by starting at `word' and going backwards. */ - for (p = word; - p > command - && strchr (gdb_completer_file_name_break_characters, - p[-1]) == NULL; - p--) - ; - } - if (reason == handle_brkchars) { completer_handle_brkchars_ftype *brkchars_fn; @@ -1223,11 +1206,11 @@ complete_line_internal_normal_command (completion_tracker &tracker, (c->completer)); } - brkchars_fn (c, tracker, p, word); + brkchars_fn (c, tracker, cmd_args, word); } if (reason != handle_brkchars && c->completer != NULL) - (*c->completer) (c, tracker, p, word); + (*c->completer) (c, tracker, cmd_args, word); } /* Internal function used to handle completions. From patchwork Wed Mar 6 10:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86862 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 560473857C5A for ; Wed, 6 Mar 2024 10:25:11 +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 5FBAF3858032 for ; Wed, 6 Mar 2024 10:24:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FBAF3858032 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 5FBAF3858032 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=1709720647; cv=none; b=rkB8m9Nk+3zbKHfJtjqrJpTxuv0fyD6hpiAW/fU2fK8WhYq81HMEXAA0g3p6whtc21UjxxUOH5X+WvDKqgDR0xfz74lcjRBjvOPYiKH6R7hBKgpp12mpbWnJSyCEE+841ggqYGpM/RPlh10DqK/1u9iJNUgPc+i+1inuprL9u+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720647; c=relaxed/simple; bh=PVnjcS7IzxSnDc7baZve6gpGeulwFBYQwirAC4Lgias=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=aViweMbWjT2H3Bj83IbcgqWfIz+As+dx7c/6NzPNtxHsoffnSB3M4KYEb2S8Hmb8ds6la9YL9l6YPpnxyalJzX0/hQWk0TkhZAqRneAN9VKqeMSVK/sdN59BP3x4mfcEUvHIeAhSB5GyUbVv8kfeDMoj0Q09yXAvov6PuIFHUdk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720645; 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=JHD3E/ia7Bb4ql10ZjRjpuIp8lVPthuoAuZOlntU3CE=; b=OBf/XvDf+RZoVvvUS+Eyuy27aZddDVR0vArr26UQjoQwYWVIS09LEFlLzUjk1bfpRz4atk 0///ydZ79QOzsHyqWtomUjHQ20jAejnwE2Wlc1CS6B+qLu143lY8IMHPM4MxSl5CO1rZKm ctk8i98XVO4WRHNzT1yNGvNDIrsuWFg= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-zRmMFqR4NuuO2ZJT_qyEZA-1; Wed, 06 Mar 2024 05:24:03 -0500 X-MC-Unique: zRmMFqR4NuuO2ZJT_qyEZA-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a449be9db59so283937366b.1 for ; Wed, 06 Mar 2024 02:24:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720641; x=1710325441; 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=JHD3E/ia7Bb4ql10ZjRjpuIp8lVPthuoAuZOlntU3CE=; b=Z+SV9FRwSs/H5I2Ic1321euNxPbLZoX3R3wzbx4nl1GfkMUbwPLZIv7We/WmP3p4Pr oM9eSafwgV9+TqcehaD7SrJvnS+xPhPGG2q5kGj0vK5NIvd82YORGvPNH0I7WhYQNzfV iK0GCh1alLihNtf/YU8Aa7h/MYnPv3xJxCdVvhz9SLX5uemTllDlN5Dk7Yi4ZVv5fFXZ 9WbBH/knju7gXUn+uM8x+cYzdQvg+BXyvwfRalX0+jDJZ/0RTvunb5wUyQqtQJElk3op SBNsb+brtyMrFzLGCZGg4A3pcTH2i2x2ZfS4OfVRBxj8ympEjNUHcsNIcqtQUw0atMsA Fhtg== X-Gm-Message-State: AOJu0YwBKJD/VYAkLW3PT1bPWp17ITw9VXsxbyOae4zi/tfMVKWeo6oL MdbeQVz/WM4T7ntnaogxQrc/bmBb/TP34ghub4PYTu4LrHBfdGzUEqxajKEWairzoOwpZ4CnDxr 7gZp4FzFb+UtINcmnHc/bP+BB7lIdLArZ7I9fw8lIw5Y3aMDAX6TK73uXTRr/GwG+RE/83f3VRw pyh8u7VAA6d2wohYMVdoX14BxNyat8rCEXmStrbR/nRVY= X-Received: by 2002:a17:906:5795:b0:a45:bdd9:c2cc with SMTP id k21-20020a170906579500b00a45bdd9c2ccmr696084ejq.41.1709720641436; Wed, 06 Mar 2024 02:24:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtTBdMB+MZbS8bRTkyRdR1x0dY9B6HLPm4c7r76G6GOt3vfHs+JA0gBM88obRx0ppw/4ClHg== X-Received: by 2002:a17:906:5795:b0:a45:bdd9:c2cc with SMTP id k21-20020a170906579500b00a45bdd9c2ccmr696069ejq.41.1709720640984; Wed, 06 Mar 2024 02:24:00 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id d1-20020a170906544100b00a45bda3cbb8sm403919ejp.134.2024.03.06.02.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:24:00 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 6/7] gdb/completion: make completion_find_completion_word static Date: Wed, 6 Mar 2024 10:23:38 +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 I noticed that completion_find_completion_word is only used within completer.c, so lets make it static. There should be no user visible changes after this commit. --- gdb/completer.c | 14 ++++++++++++-- gdb/completer.h | 11 ----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 04354120621..2fee90503db 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -46,6 +46,11 @@ #include "completer.h" +/* Forward declarations. */ +static const char *completion_find_completion_word (completion_tracker &tracker, + const char *text, + int *quote_char); + /* See completer.h. */ class completion_tracker::completion_hash_entry @@ -1955,9 +1960,14 @@ gdb_completion_word_break_characters () return NULL; } -/* See completer.h. */ +/* Find the bounds of the word in TEXT for completion purposes, and return + a pointer to the end of the word. Calls the completion machinery for a + handle_brkchars phase (using TRACKER) to figure out the right work break + characters for the command in TEXT. QUOTE_CHAR, if non-null, is set to + the opening quote character if we found an unclosed quoted substring, + '\0' otherwise. */ -const char * +static const char * completion_find_completion_word (completion_tracker &tracker, const char *text, int *quote_char) { diff --git a/gdb/completer.h b/gdb/completer.h index 0a95ced8a80..9011ba778a7 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -556,17 +556,6 @@ extern void complete_line (completion_tracker &tracker, extern completion_result complete (const char *line, char const **word, int *quote_char); -/* Find the bounds of the word in TEXT for completion purposes, and - return a pointer to the end of the word. Calls the completion - machinery for a handle_brkchars phase (using TRACKER) to figure out - the right work break characters for the command in TEXT. - QUOTE_CHAR, if non-null, is set to the opening quote character if - we found an unclosed quoted substring, '\0' otherwise. */ -extern const char *completion_find_completion_word (completion_tracker &tracker, - const char *text, - int *quote_char); - - /* Assuming TEXT is an expression in the current language, find the completion word point for TEXT, emulating the algorithm readline uses to find the word point, using the current language's word From patchwork Wed Mar 6 10:23:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86863 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 D951A3857C50 for ; Wed, 6 Mar 2024 10:25:15 +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 498633857C40 for ; Wed, 6 Mar 2024 10:24:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 498633857C40 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 498633857C40 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=1709720649; cv=none; b=X6KRaRvvgJQOVqYh5KpOp1uQKbPx1+l194Ukqq/unIt+XWMTy4tiMEdKr10mMy6BatdCtzx71G7VeD8ra9vOjclOpaWck8U8XIZsN8OpncIM5Xp4LLn9viU8Bt2eKziwIoVtoirEn7CS7RD+Nig6Qll+niHdbty0gyZU7yDSh7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709720649; c=relaxed/simple; bh=bynQki2WHsKRlAND60cxosqY1GCAUIjECwDfEXGInU4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=abHjfauJC/4hVhtCX058F/SUhyNRWI7b9K1AJnQyJ1Ch+O4HtMhowuEPqgdjNTok5iI2GFb7kTCsevUTqOZ+W5sPoV34WZXdfQR1qK1JKPGN6PHzJJIvvH7gJkAWMY77AuyeTFfzHbKGCLnmhMZN0fJ/3PS1h4pX6BpXzmNY8os= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709720647; 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=+vHjBQirvC4tC2VQOxsHQKNKWawnLOF57gSpmjpZObw=; b=cJ04Tqbs6CTuccB6brcsJJSLHyWK1wk2nOoyM4i03SegBG3MMDio7IitPlADjaaJQAuy4T T8oi66w0WdNn1hui2d6vSwHBrWWkcqQLMrqWta08B+81SvPbsT09d1U2g1he1utc/RBwi7 h6lzui1JFpzngt0A+NEbiibT3A3xOq8= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376-kv43d89gPGSbHxhUCuwRUA-1; Wed, 06 Mar 2024 05:24:05 -0500 X-MC-Unique: kv43d89gPGSbHxhUCuwRUA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a45acc7f191so98744066b.0 for ; Wed, 06 Mar 2024 02:24:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709720643; x=1710325443; 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=+vHjBQirvC4tC2VQOxsHQKNKWawnLOF57gSpmjpZObw=; b=VRmiP7qdqFa1s7XV9tgbcAwQ8UpZy+zZmEx3LKGH9mzrPRmr9PSzNdH7fepH1ylnaS +Cx+4AObss/NS5vteaQ9Q87GOdBjdOgCRUXWkEXq5YGaPXQJ8G35UAAdk78ihQsFt/LW qCdpMyq5YTPvtBfpcPAJt53/rCPQIS4U3VZmCMv4Qgjlzs8/3PhKVervP8rdrE9XehfY 6ztRf3jNQAfLy+6IUa5nHTESBzD0CVr8KX+VaECPRN2s0GJ4QwF2sNLSPgd9oYisKcMd ilnSfhMjWsjH5jO0Cl4a8Ton8vI/IB+1Y246pv1fu8lF9Lza/lVqRebFzqby7VaDBL+8 cibA== X-Gm-Message-State: AOJu0YzVAeldreGmySitFDktlQ/5Hh2ySWJ8/yq+u/AHgicWLv9eXF3a 44NM2+Eq1uNFrp8KGAzgNv3hRlYBuvLUvUD9AQBTSvkMmjyAQFvQXs9T+GyA7+GNsURlxjOIZ4R TDizUBKUHqUoW0DnrKR5lMF7LF6k5yZNR+W4VMNw56mlWJlAc8KYECG0MjFmH6QP13XuzkZjhCx Y3Tc/PPtCs379Ib7tQgcP6lLi5GeHHbR1OG+MYDzeZtu4= X-Received: by 2002:a17:907:100a:b0:a3e:b869:11b3 with SMTP id ox10-20020a170907100a00b00a3eb86911b3mr10225882ejb.55.1709720643428; Wed, 06 Mar 2024 02:24:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVUx4fYDT8HHlHQK64ENVae0trnJL6+jf7KyfUAXdbdkYuCcGzyY4E7TKSff4UvANPUCzWSg== X-Received: by 2002:a17:907:100a:b0:a3e:b869:11b3 with SMTP id ox10-20020a170907100a00b00a3eb86911b3mr10225862ejb.55.1709720642842; Wed, 06 Mar 2024 02:24:02 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id l18-20020a1709060e1200b00a459094cf61sm2108709eji.115.2024.03.06.02.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 02:24:01 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 7/7] gdb: move more completion setup into completer.c Date: Wed, 6 Mar 2024 10:23:39 +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 Move more setup of the readline global state relating to tab completion into completer.c out of top.c. Lots of the readline setup is done in init_main (top.c). This commit moves those bits of initialisation that relate to completion, and which are only set the one time, into completer.c. This does mean that readline initialisation is now done in multiple locations, some in init_main (top.c) and some in completer.c, but I think this is OK. The work done in init_main is the general readline setup. I think making static what can be made static, and having it all in one file, makes things easier to reason about. So I'm OK with having this split initialisation. The only completion related thing which is still setup in top.c is rl_completion_display_matches_hook. I've left this where it is for now as rl_completion_display_matches_hook is also updated in the tui code, and the display hook functions are not in completer.c anyway, so moving this initialisation to completer.c would not allow anything else to be made static. There should be no user visible changes after this commit. --- gdb/completer.c | 24 +++++++++++++++++++----- gdb/completer.h | 11 ----------- gdb/top.c | 3 --- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 2fee90503db..8e34e30f46b 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -51,6 +51,8 @@ static const char *completion_find_completion_word (completion_tracker &tracker, const char *text, int *quote_char); +static void set_rl_completer_word_break_characters (const char *break_chars); + /* See completer.h. */ class completion_tracker::completion_hash_entry @@ -1113,9 +1115,12 @@ expression_completer (struct cmd_list_element *ignore, complete_expression (tracker, text, word); } -/* See definition in completer.h. */ +/* Set the word break characters array to BREAK_CHARS. This function is + useful as const-correct alternative to direct assignment to + rl_completer_word_break_characters, which is "char *", not "const + char *". */ -void +static void set_rl_completer_word_break_characters (const char *break_chars) { rl_completer_word_break_characters = (char *) break_chars; @@ -1940,8 +1945,12 @@ gdb_completion_word_break_characters_throw () return (char *) rl_completer_word_break_characters; } -char * -gdb_completion_word_break_characters () +/* Get the list of chars that are considered as word breaks for the current + command. This function does not throw any exceptions and is called from + readline. See gdb_completion_word_break_characters_throw for details. */ + +static char * +gdb_completion_word_break_characters () noexcept { /* New completion starting. */ current_completion.aborted = false; @@ -2336,7 +2345,7 @@ gdb_rl_attempted_completion_function_throw (const char *text, int start, int end hook. Wrapper around gdb_rl_attempted_completion_function_throw that catches C++ exceptions, which can't cross readline. */ -char ** +static char ** gdb_rl_attempted_completion_function (const char *text, int start, int end) { /* Restore globals that might have been tweaked in @@ -3004,6 +3013,11 @@ void _initialize_completer (); void _initialize_completer () { + /* Setup some readline completion globals. */ + rl_completion_word_break_hook = gdb_completion_word_break_characters; + rl_attempted_completion_function = gdb_rl_attempted_completion_function; + set_rl_completer_word_break_characters (default_word_break_characters ()); + add_setshow_zuinteger_unlimited_cmd ("max-completions", no_class, &max_completions, _("\ Set maximum number of completion candidates."), _("\ diff --git a/gdb/completer.h b/gdb/completer.h index 9011ba778a7..98a12f3907c 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -569,9 +569,6 @@ const char *advance_to_expression_complete_word_point extern const char *advance_to_filename_complete_word_point (completion_tracker &tracker, const char *text); -extern char **gdb_rl_attempted_completion_function (const char *text, - int start, int end); - extern void noop_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); @@ -608,14 +605,6 @@ extern void reggroup_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); -extern char *gdb_completion_word_break_characters (void); - -/* Set the word break characters array to BREAK_CHARS. This function - is useful as const-correct alternative to direct assignment to - rl_completer_word_break_characters, which is "char *", - not "const char *". */ -extern void set_rl_completer_word_break_characters (const char *break_chars); - /* Get the matching completer_handle_brkchars_ftype function for FN. FN is one of the core completer functions above (filename, location, symbol, etc.). This function is useful for cases when diff --git a/gdb/top.c b/gdb/top.c index 8df684ec8b4..0aeeb987832 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -2139,9 +2139,6 @@ init_main (void) write_history_p = 0; /* Setup important stuff for command line editing. */ - rl_completion_word_break_hook = gdb_completion_word_break_characters; - rl_attempted_completion_function = gdb_rl_attempted_completion_function; - set_rl_completer_word_break_characters (default_word_break_characters ()); rl_completion_display_matches_hook = cli_display_match_list; rl_readline_name = "gdb"; rl_terminal_name = getenv ("TERM");