gdb: new function to wrap up executing command line scripts/commands
authorAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 9 Sep 2020 10:26:22 +0000 (11:26 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 2 Nov 2020 17:42:11 +0000 (17:42 +0000)
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
gdb/main.c

index 18b7fb0a53a34edde270c3bd9caedcfcec8cee8e..4356fa75df33de8b8b3fa0f449d8e167c53c81ab 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-02  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * main.c (execute_cmdargs): New function.
+       (captured_main_1): Make use of execute_cmdargs.
+
 2020-11-02  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * NEWS: Mention changes to config file search path.
index 6232ea3f633a48b4ea027941325b669077e91811..d3a6637e8d4f769f8b72a61d79cefbb1efc35688 100644 (file)
@@ -515,6 +515,26 @@ struct cmdarg
   char *string;
 };
 
+/* From CMDARG_VEC execute command files (matching FILE_TYPE) or commands
+   (matching CMD_TYPE).  Update the value in *RET if and scripts or
+   commands are executed.  */
+
+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 +1089,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 +1200,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.  */