+/* Parse options to --debug-format= and "monitor set debug-format".
+ ARG is the text after "--debug-format=" or "monitor set debug-format".
+ IS_MONITOR is non-zero if we're invoked via "monitor set debug-format".
+ This triggers calls to monitor_output.
+ The result is NULL if all options were parsed ok, otherwise an error
+ message which the caller must free.
+
+ N.B. These commands affect all debug format settings, they are not
+ cumulative. If a format is not specified, it is turned off.
+ However, we don't go to extra trouble with things like
+ "monitor set debug-format all,none,timestamp".
+ Instead we just parse them one at a time, in order.
+
+ The syntax for "monitor set debug" we support here is not identical
+ to gdb's "set debug foo on|off" because we also use this function to
+ parse "--debug-format=foo,bar". */
+
+static char *
+parse_debug_format_options (const char *arg, int is_monitor)
+{
+ VEC (char_ptr) *options;
+ int ix;
+ char *option;
+
+ /* First turn all debug format options off. */
+ debug_timestamp = 0;
+
+ /* First remove leading spaces, for "monitor set debug-format". */
+ while (isspace (*arg))
+ ++arg;
+
+ options = delim_string_to_char_ptr_vec (arg, ',');
+
+ for (ix = 0; VEC_iterate (char_ptr, options, ix, option); ++ix)
+ {
+ if (strcmp (option, "all") == 0)
+ {
+ debug_timestamp = 1;
+ if (is_monitor)
+ monitor_output ("All extra debug format options enabled.\n");
+ }
+ else if (strcmp (option, "none") == 0)
+ {
+ debug_timestamp = 0;
+ if (is_monitor)
+ monitor_output ("All extra debug format options disabled.\n");
+ }
+ else if (strcmp (option, "timestamp") == 0)
+ {
+ debug_timestamp = 1;
+ if (is_monitor)
+ monitor_output ("Timestamps will be added to debug output.\n");
+ }
+ else if (*option == '\0')
+ {
+ /* An empty option, e.g., "--debug-format=foo,,bar", is ignored. */
+ continue;
+ }
+ else
+ {
+ char *msg = xstrprintf ("Unknown debug-format argument: \"%s\"\n",
+ option);
+
+ free_char_ptr_vec (options);
+ return msg;
+ }
+ }
+
+ free_char_ptr_vec (options);
+ return NULL;
+}
+