public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Marco Barisione <mbarisione@undo.io>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] Move the code to execute a cmd_list_element out from execute_command
Date: Mon, 14 Sep 2020 09:39:24 +0000	[thread overview]
Message-ID: <20200914093925.5442-2-mbarisione@undo.io> (raw)
In-Reply-To: <20200914093925.5442-1-mbarisione@undo.io>

gdb/ChangeLog:

	* gdbcmd.h (execute_cmd_list_command): Add declaration.
	* top.c (execute_command): Move out the code to execute a
	command from a cmd_list_element.
	(execute_cmd_list_command): Add from code originally in
	execute_command.
	* top.h (execute_cmd_list_command): Add declaration.
---
 gdb/gdbcmd.h |  3 +++
 gdb/top.c    | 66 ++++++++++++++++++++++++++++++----------------------
 gdb/top.h    |  2 ++
 3 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
index 4406094ea5..5be474ec1a 100644
--- a/gdb/gdbcmd.h
+++ b/gdb/gdbcmd.h
@@ -134,6 +134,9 @@ extern struct cmd_list_element *save_cmdlist;
 
 extern void execute_command (const char *, int);
 
+extern void execute_cmd_list_command (struct cmd_list_element *,
+				      const char *, int);
+
 /* Execute command P and returns its output.  If TERM_OUT,
    the output is built using terminal output behaviour such
    as cli_styling.  */
diff --git a/gdb/top.c b/gdb/top.c
index acd31afb9a..8eae15a488 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -581,7 +581,6 @@ execute_command (const char *p, int from_tty)
       const char *arg;
       std::string default_args;
       std::string default_args_and_arg;
-      int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
 
       line = p;
 
@@ -641,33 +640,7 @@ execute_command (const char *p, int from_tty)
       if (c->deprecated_warn_user)
 	deprecated_cmd_warning (line);
 
-      /* c->user_commands would be NULL in the case of a python command.  */
-      if (c->theclass == class_user && c->user_commands)
-	execute_user_command (c, arg);
-      else if (c->theclass == class_user
-	       && c->prefixlist && !c->allow_unknown)
-	/* If this is a user defined prefix that does not allow unknown
-	   (in other words, C is a prefix command and not a command
-	   that can be followed by its args), report the list of
-	   subcommands.  */
-	{
-	  printf_unfiltered
-	    ("\"%.*s\" must be followed by the name of a subcommand.\n",
-	     (int) strlen (c->prefixname) - 1, c->prefixname);
-	  help_list (*c->prefixlist, c->prefixname, all_commands, gdb_stdout);
-	}
-      else if (c->type == set_cmd)
-	do_set_command (arg, from_tty, c);
-      else if (c->type == show_cmd)
-	do_show_command (arg, from_tty, c);
-      else if (!cmd_func_p (c))
-	error (_("That is not a command, just a help topic."));
-      else if (deprecated_call_command_hook)
-	deprecated_call_command_hook (c, arg, from_tty);
-      else
-	cmd_func (c, arg, from_tty);
-
-      maybe_wait_sync_command_done (was_sync);
+      execute_cmd_list_command (c, arg, from_tty);
 
       /* If this command has been post-hooked, run the hook last.  */
       execute_cmd_post_hook (c);
@@ -690,6 +663,43 @@ execute_command (const char *p, int from_tty)
   cleanup_if_error.release ();
 }
 
+/* Execute the C command.  */
+
+void
+execute_cmd_list_command (struct cmd_list_element *c, const char *arg,
+			  int from_tty)
+{
+  bool was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
+
+  /* c->user_commands would be NULL in the case of a python command.  */
+  if (c->theclass == class_user && c->user_commands)
+    execute_user_command (c, arg);
+  else if (c->theclass == class_user
+	   && c->prefixlist && !c->allow_unknown)
+    {
+      /* If this is a user defined prefix that does not allow unknown
+	 (in other words, C is a prefix command and not a command
+	 that can be followed by its args), report the list of
+	 subcommands.  */
+      printf_unfiltered
+	("\"%.*s\" must be followed by the name of a subcommand.\n",
+	 (int) strlen (c->prefixname) - 1, c->prefixname);
+      help_list (*c->prefixlist, c->prefixname, all_commands, gdb_stdout);
+    }
+  else if (c->type == set_cmd)
+    do_set_command (arg, from_tty, c);
+  else if (c->type == show_cmd)
+    do_show_command (arg, from_tty, c);
+  else if (!cmd_func_p (c))
+    error (_("That is not a command, just a help topic."));
+  else if (deprecated_call_command_hook)
+    deprecated_call_command_hook (c, arg, from_tty);
+  else
+    cmd_func (c, arg, from_tty);
+
+  maybe_wait_sync_command_done (was_sync);
+}
+
 /* Run execute_command for P and FROM_TTY.  Sends its output to FILE,
    do not display it to the screen.  BATCH_FLAG will be
    temporarily set to true.  */
diff --git a/gdb/top.h b/gdb/top.h
index fd99297715..ba6c596da7 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -241,6 +241,8 @@ extern void quit_force (int *, int);
 extern void quit_command (const char *, int);
 extern void quit_cover (void);
 extern void execute_command (const char *, int);
+extern void execute_cmd_list_command (struct cmd_list_element *,
+				      const char *, int);
 
 /* If the interpreter is in sync mode (we're running a user command's
    list, running command hooks or similars), and we just ran a
-- 
2.20.1


  reply	other threads:[~2020-09-14  9:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14  9:39 Add a way to invoke redefined (overridden) GDB commands Marco Barisione
2020-09-14  9:39 ` Marco Barisione [this message]
2020-10-05  9:08   ` [PATCH 1/2] Move the code to execute a cmd_list_element out from execute_command Andrew Burgess
2020-10-05  9:40     ` Marco Barisione
2020-10-05 17:49       ` Andrew Burgess
2020-09-14  9:39 ` [PATCH 2/2] Add a way to preserve redefined GDB commands for later invocation Marco Barisione
2020-09-14 16:18   ` Eli Zaretskii
2020-09-14 16:51     ` Marco Barisione
2020-10-05 10:24   ` Andrew Burgess
2020-10-05 11:44     ` Marco Barisione
2020-10-05 18:11       ` Andrew Burgess
2020-10-06  7:18         ` Marco Barisione
2020-09-28  7:54 ` [PING] Add a way to invoke redefined (overridden) GDB commands Marco Barisione
2020-10-05  7:42   ` Marco Barisione
2020-10-12 11:50 ` Pedro Alves
2020-10-19 17:41   ` Marco Barisione
2020-10-19 18:05     ` Pedro Alves
2020-10-19 18:47       ` Philippe Waroquiers
2020-10-19 19:28         ` Marco Barisione
2020-10-20 15:06           ` Pedro Alves
2020-10-20 18:19             ` Marco Barisione
2020-10-20 18:32               ` Pedro Alves
2020-10-20 15:15         ` Pedro Alves

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=20200914093925.5442-2-mbarisione@undo.io \
    --to=mbarisione@undo.io \
    --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).