+/* Handle command errors thrown from within
+ catch_command_errors/catch_command_errors_const. */
+
+static int
+handle_command_errors (struct gdb_exception e)
+{
+ if (e.reason < 0)
+ {
+ exception_print (gdb_stderr, e);
+
+ /* If any exception escaped to here, we better enable stdin.
+ Otherwise, any command that calls async_disable_stdin, and
+ then throws, will leave stdin inoperable. */
+ async_enable_stdin ();
+ return 0;
+ }
+ return 1;
+}
+
+/* Type of the command callback passed to catch_command_errors. */
+
+typedef void (catch_command_errors_ftype) (char *, int);
+
+/* Wrap calls to commands run before the event loop is started. */
+
+static int
+catch_command_errors (catch_command_errors_ftype *command,
+ char *arg, int from_tty)
+{
+ TRY
+ {
+ int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
+
+ command (arg, from_tty);
+
+ maybe_wait_sync_command_done (was_sync);
+ }
+ CATCH (e, RETURN_MASK_ALL)
+ {
+ return handle_command_errors (e);
+ }
+ END_CATCH
+
+ return 1;
+}
+
+/* Type of the command callback passed to catch_command_errors_const. */
+
+typedef void (catch_command_errors_const_ftype) (const char *, int);
+
+/* Like catch_command_errors, but works with const command and args. */
+
+static int
+catch_command_errors_const (catch_command_errors_const_ftype *command,
+ const char *arg, int from_tty)
+{
+ TRY
+ {
+ int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
+
+ command (arg, from_tty);
+
+ maybe_wait_sync_command_done (was_sync);
+ }
+ CATCH (e, RETURN_MASK_ALL)
+ {
+ return handle_command_errors (e);
+ }
+ END_CATCH
+
+ return 1;
+}
+
+/* Type of this option. */
+enum cmdarg_kind
+{
+ /* Option type -x. */
+ CMDARG_FILE,
+
+ /* Option type -ex. */
+ CMDARG_COMMAND,
+
+ /* Option type -ix. */
+ CMDARG_INIT_FILE,
+
+ /* Option type -iex. */
+ CMDARG_INIT_COMMAND
+};
+
+/* Arguments of --command option and its counterpart. */
+typedef struct cmdarg {
+ /* Type of this option. */
+ enum cmdarg_kind type;
+
+ /* Value of this option - filename or the GDB command itself. String memory
+ is not owned by this structure despite it is 'const'. */
+ char *string;
+} cmdarg_s;
+
+/* Define type VEC (cmdarg_s). */
+DEF_VEC_O (cmdarg_s);
+