From patchwork Mon Nov 27 17:55:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 80832 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 A2D22384F98B for ; Mon, 27 Nov 2023 17:56:26 +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 B79CA385802E for ; Mon, 27 Nov 2023 17:56:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B79CA385802E 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 B79CA385802E 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=1701107773; cv=none; b=NYH+zxw6JRI7CYNaX2xOzBhkeBtJt0SieA2hpPSWFercjdEplJHMh5K5jZLDcW8Lytj8Ms+aLZV4ix6TmILp6lAJ76L4cBI0pjB2N9JJtUu1PBDTLHVE/HiVb1Ec0AQtEtb6OuLL23/v7N7vfdrcHhFbvaornwy6yKOQVWA8boY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701107773; c=relaxed/simple; bh=SVWAtogAney9IjuUd2wDZJ6zGevBmlAqcmTECh1OTew=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Il8OvhpbB1JzNhLxSxUR7vPJjuADdpaft2Iova+ktRiWGdHIEG27YC4D/ooyqMSiWhbShjSzn1r+/oNSloABS3HUqglBbpJy9nTD2hp2tR4/IgGTQPTPByc22C8m38CzI7tA70tMlbqAHvDxz39FFReG5bt8iY9Fs1AVnuv+g1M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701107769; 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=V6XOR18/ywhiFjjwyffQB3JvXw7txJ8GkO+YiR7z9LQ=; b=DxRSqfosS/grfvkNxl2mUEv75+3xKCEMfMJ01Wnnzaf8s6c0XSy1x6sWSLRkdNkwyc0o/R vDyiCK8LF4/ZLBsDBK80HmneasbuuA0oazxiurSqwQwOL53xX4GSia5WGQ+cBF1KWdRyhV xZMa9jKxY5XWbthvJU6fP3FR/PInPdw= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-601-zdIP-7HPOgOgVyRvbY9UsQ-1; Mon, 27 Nov 2023 12:56:07 -0500 X-MC-Unique: zdIP-7HPOgOgVyRvbY9UsQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-332fab597afso1169871f8f.3 for ; Mon, 27 Nov 2023 09:56:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701107766; x=1701712566; 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=V6XOR18/ywhiFjjwyffQB3JvXw7txJ8GkO+YiR7z9LQ=; b=qw91ANvmwHWUlg6F5nBy4Fi0rAFcUUQwXtYexp1f/lc2BFJQvfygbwy/1J3f6SYi6S k1MmuYZqJSRu2VC7qt2c+sB/pQdZ9dLMUWmXhECNCIHFktmgBu1i2zT8ICEpriWJLVh0 5avEhOBbvQvrWsMoAb+tyMxwQptSNzlD/IUqIPAhPtZwDK7iMyhZriWiq4LQ2c4WqSNi 9Bprm9n9q/hpGw6QRgUklbWVl1vqiyldbLJ7Wp2dmvwYWj0++g0wB+1J2NH/Sjzg9QVP SK59slNtgUKjb1hRaUze7Ef9/uJ0vOA3KOwYwT6AgXTCYwmwlxCXspg7ocdpFD1Em6NT 5AnQ== X-Gm-Message-State: AOJu0YzlvDiAukYrYELkKZhwgkK5IyAC8I4kuh2mh5bXMF9zX9Pio8Ej ct8hVgyDLrZCPA3ci46Psy32j2uYp1tuT6QfVzLrTZnTfINW/6UFJ27ajBEFpgxWRC/G85NCUfN QVVknvJcu684R1R+ERJarc4fLvjeuBgllWyqK1OyysGfBf2OprqqY/XcpK9dGEJmpOFTAmnDwCu HcN0X3nA== X-Received: by 2002:a5d:4942:0:b0:332:e1e6:eeda with SMTP id r2-20020a5d4942000000b00332e1e6eedamr8101271wrs.69.1701107766336; Mon, 27 Nov 2023 09:56:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJAzI5hBi15iKjn622frk3QtlqYD4t93uG2CVNsRwlms2tutEIBsP0JrOamavo/3FQupafrQ== X-Received: by 2002:a5d:4942:0:b0:332:e1e6:eeda with SMTP id r2-20020a5d4942000000b00332e1e6eedamr8101258wrs.69.1701107765926; Mon, 27 Nov 2023 09:56:05 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id m4-20020adffe44000000b00332f74ffde5sm6709009wrs.5.2023.11.27.09.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 09:56:05 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/7] gdb: option completion for 'save gdb-index' command Date: Mon, 27 Nov 2023 17:55:56 +0000 Message-Id: <523e35f23ec81debf21af6a42b148968c73e2ecd.1701107594.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.8 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 Add proper support for option completion to the 'save gdb-index' command. Update save_gdb_index_command function to make use of the new option_def data structures for parsing the '-dwarf-5' option. --- gdb/dwarf2/index-write.c | 69 ++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 8ee5e420936..c0867799f6d 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1523,6 +1523,48 @@ write_dwarf_index (dwarf2_per_bfd *per_bfd, const char *dir, dwz_index_wip->finalize (); } +/* Options structure for the 'save gdb-index' command. */ + +struct save_gdb_index_options +{ + bool dwarf_5 = false; +}; + +/* The option_def list for the 'save gdb-index' command. */ + +static const gdb::option::option_def save_gdb_index_options_defs[] = { + gdb::option::boolean_option_def { + "dwarf-5", + [] (save_gdb_index_options *opt) { return &opt->dwarf_5; }, + nullptr, /* show_cmd_cb */ + nullptr /* set_doc */ + } +}; + +/* Create an options_def_group for the 'save gdb-index' command. */ + +static gdb::option::option_def_group +make_gdb_save_index_options_def_group (save_gdb_index_options *opts) +{ + return {{save_gdb_index_options_defs}, opts}; +} + +/* Completer for the "save gdb-index" command. */ + +static void +gdb_save_index_cmd_completer (struct cmd_list_element *ignore, + completion_tracker &tracker, + const char *text, const char *word) +{ + auto grp = make_gdb_save_index_options_def_group (nullptr); + if (gdb::option::complete_options + (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp)) + return; + + word = advance_to_filename_complete_word_point (tracker, text); + filename_completer (ignore, tracker, text, word); +} + /* Implementation of the `save gdb-index' command. Note that the .gdb_index file format used by this command is @@ -1530,26 +1572,19 @@ write_dwarf_index (dwarf2_per_bfd *per_bfd, const char *dir, there. */ static void -save_gdb_index_command (const char *arg, int from_tty) +save_gdb_index_command (const char *args, int from_tty) { - const char dwarf5space[] = "-dwarf-5 "; - dw_index_kind index_kind = dw_index_kind::GDB_INDEX; - - if (!arg) - arg = ""; - - arg = skip_spaces (arg); - if (strncmp (arg, dwarf5space, strlen (dwarf5space)) == 0) - { - index_kind = dw_index_kind::DEBUG_NAMES; - arg += strlen (dwarf5space); - arg = skip_spaces (arg); - } + save_gdb_index_options opts; + const auto group = make_gdb_save_index_options_def_group (&opts); + gdb::option::process_options + (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group); - if (!*arg) + if (args == nullptr || *args == '\0') error (_("usage: save gdb-index [-dwarf-5] DIRECTORY")); - std::string directory (gdb_tilde_expand (arg)); + std::string directory (gdb_tilde_expand (args)); + dw_index_kind index_kind + = (opts.dwarf_5 ? dw_index_kind::DEBUG_NAMES : dw_index_kind::GDB_INDEX); for (objfile *objfile : current_program_space->objfiles ()) { @@ -1675,5 +1710,5 @@ No options create one file with .gdb-index extension for pre-DWARF-5\n\ compatible .gdb_index section. With -dwarf-5 creates two files with\n\ extension .debug_names and .debug_str for DWARF-5 .debug_names section."), &save_cmdlist); - set_cmd_completer (c, filename_completer); + set_cmd_completer_handle_brkchars (c, gdb_save_index_cmd_completer); }