public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 2/7] gdb: option completion for 'save gdb-index' command
Date: Mon, 27 Nov 2023 17:55:56 +0000	[thread overview]
Message-ID: <523e35f23ec81debf21af6a42b148968c73e2ecd.1701107594.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1701107594.git.aburgess@redhat.com>

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<save_gdb_index_options> {
+    "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);
 }
-- 
2.25.4


  parent reply	other threads:[~2023-11-27 17:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27 17:55 [PATCH 0/7] Changes to gdb-index creation Andrew Burgess
2023-11-27 17:55 ` [PATCH 1/7] gdb: allow use of ~ in 'save gdb-index' command Andrew Burgess
2023-11-27 17:55 ` Andrew Burgess [this message]
2023-11-27 18:58   ` [PATCH 2/7] gdb: option completion for " Tom Tromey
2023-11-27 22:20     ` Andrew Burgess
2023-11-27 17:55 ` [PATCH 3/7] gdb/testsuite: small refactor in selftest-support.exp Andrew Burgess
2023-11-27 17:55 ` [PATCH 4/7] gdb: reduce size of generated gdb-index file Andrew Burgess
2023-11-27 17:55 ` [PATCH 5/7] gdb: C++-ify mapped_symtab from dwarf2/index-write.c Andrew Burgess
2023-11-27 19:01   ` Tom Tromey
2023-11-27 22:21     ` Andrew Burgess
2023-11-27 17:56 ` [PATCH 6/7] gdb: generate gdb-index identically regardless of work thread count Andrew Burgess
2023-11-27 17:56 ` [PATCH 7/7] gdb: generate dwarf-5 index identically as worker-thread count changes Andrew Burgess
2023-11-27 19:38 ` [PATCH 0/7] Changes to gdb-index creation Tom Tromey
2023-11-28 10:34   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=523e35f23ec81debf21af6a42b148968c73e2ecd.1701107594.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).