From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2MwrB4tE6GXOyToAWB0awg (envelope-from ) for ; Wed, 06 Mar 2024 05:25:15 -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=cJ04Tqbs; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 196BF1E0D2; Wed, 6 Mar 2024 05:25:15 -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 06D231E092 for ; Wed, 6 Mar 2024 05:25:13 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90F0A3857C42 for ; Wed, 6 Mar 2024 10:25:12 +0000 (GMT) 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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+public-inbox=simark.ca@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"); -- 2.25.4