public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>,
	Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands
Date: Wed,  7 Oct 2020 21:05:07 +0100	[thread overview]
Message-ID: <e18d0fe2b3f4edcf043afe11fb48d4db183c3b30.1601927355.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1601927355.git.andrew.burgess@embecosm.com>

Small refactor to wrap up executing the scripts and commands passed
using the -x, -ex, -ix, -iex command line flags.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* main.c (execute_cmdargs): New function.
	(captured_main_1): Make use of execute_cmdargs.
---
 gdb/ChangeLog |  5 +++++
 gdb/main.c    | 53 ++++++++++++++++++++-------------------------------
 2 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index f6377f2df28..f85b7dbfdaa 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -515,6 +515,25 @@ struct cmdarg
   char *string;
 };
 
+/* From CMDARG_VEC execute command files (matching FILE_TYPE) or commands
+   (matching CMD_TYPE).  Update the value in *RET.  */
+
+static void
+execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
+		 cmdarg_kind file_type, cmdarg_kind cmd_type,
+		 int *ret)
+{
+  for (const auto &cmdarg_p : *cmdarg_vec)
+    {
+      if (cmdarg_p.type == file_type)
+	*ret = catch_command_errors (source_script, cmdarg_p.string,
+				     !batch_flag);
+      else if (cmdarg_p.type == cmd_type)
+	*ret = catch_command_errors (execute_command, cmdarg_p.string,
+				     !batch_flag);
+    }
+}
+
 static void
 captured_main_1 (struct captured_main_args *context)
 {
@@ -1069,22 +1088,7 @@ captured_main_1 (struct captured_main_args *context)
     ret = catch_command_errors (source_script, home_gdbinit.c_str (), 0);
 
   /* Process '-ix' and '-iex' options early.  */
-  for (i = 0; i < cmdarg_vec.size (); i++)
-    {
-      const struct cmdarg &cmdarg_p = cmdarg_vec[i];
-
-      switch (cmdarg_p.type)
-	{
-	case CMDARG_INIT_FILE:
-	  ret = catch_command_errors (source_script, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	case CMDARG_INIT_COMMAND:
-	  ret = catch_command_errors (execute_command, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	}
-    }
+  execute_cmdargs (&cmdarg_vec, CMDARG_INIT_FILE, CMDARG_INIT_COMMAND, &ret);
 
   /* Now perform all the actions indicated by the arguments.  */
   if (cdarg != NULL)
@@ -1195,22 +1199,7 @@ captured_main_1 (struct captured_main_args *context)
     load_auto_scripts_for_objfile (objfile);
 
   /* Process '-x' and '-ex' options.  */
-  for (i = 0; i < cmdarg_vec.size (); i++)
-    {
-      const struct cmdarg &cmdarg_p = cmdarg_vec[i];
-
-      switch (cmdarg_p.type)
-	{
-	case CMDARG_FILE:
-	  ret = catch_command_errors (source_script, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	case CMDARG_COMMAND:
-	  ret = catch_command_errors (execute_command, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	}
-    }
+  execute_cmdargs (&cmdarg_vec, CMDARG_FILE, CMDARG_COMMAND, &ret);
 
   /* Read in the old history after all the command files have been
      read.  */
-- 
2.25.4


  parent reply	other threads:[~2020-10-07 19:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
2020-10-07 20:05 ` [PATCH 1/7] Add get_standard_config_dir function Andrew Burgess
2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
2020-10-08  6:52   ` Eli Zaretskii
2020-11-02 10:20     ` Andrew Burgess
2020-10-22 19:07   ` Tom Tromey
2020-11-09 13:52   ` Tom Tromey
2020-11-09 13:55     ` Tom Tromey
2020-10-07 20:05 ` Andrew Burgess [this message]
2020-10-08 15:25   ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Aktemur, Tankut Baris
2020-11-02  9:48     ` Andrew Burgess
2020-10-22 19:08   ` Tom Tromey
2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
2020-10-08  6:28   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
2020-10-08  6:36   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
2020-10-08  6:40   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 7/7] Add "set startup-quietly" Andrew Burgess
2020-10-08  6:44   ` Eli Zaretskii
2020-10-08  6:56 ` [PATCH 0/7] Adding startup files to GDB Eli Zaretskii
2020-10-22 19:02 ` Tom Tromey
2020-10-28 15:29   ` Andrew Burgess
2021-01-11 16:45   ` 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=e18d0fe2b3f4edcf043afe11fb48d4db183c3b30.1601927355.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).