]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: PR 33384 invalid disassembler option message
authorAlan Modra <amodra@gmail.com>
Fri, 3 Oct 2025 23:14:58 +0000 (08:44 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 4 Oct 2025 00:09:02 +0000 (09:39 +0930)
This is the gdb part of fixing PR33384, where it is noted that an
error in a disassembler option prints the rest of the comma separated
option string rather than just the option in error.

Removing FOR_EACH_DISASSEMBLER_OPTION seemed a good idea to me, as we
then expose the strchr there which is useful in zero terminating the
option, and in the case of arm-tdep.c, to replace strcspn.  Also, if
the option is zero terminated we don't need disassembler_options_cmp.

Alternatively, you could do similarly to arm-tdep.c in disasm.c by
changing the error message to use %.*s with a length found by strcspn.
I rejected that smaller patch on the grounds that it makes for churn
in message translation.  I also prefer to see code using the standard
string functions.

Regression tested on x86_64-linux.  Message behaviour tested on
powerpc64le-linux and arm-linux-eabi.

* arm-tdep.c (show_disassembly_style_sfunc): Don't use
FOR_EACH_DISASSEMBLER_OPTION.  Use strchr needed for loop
control to size option len.
* disasm.c (set_disassembler_options): Don't use
FOR_EACH_DISASSEMBLER_OPTION.  Overwrite comma in options with
a zero.  Replace disassembler_options_cmp with strcmp.

gdb/arm-tdep.c
gdb/disasm.c

index 940d05f75e6dfed33b2f6034fd18a08ed7cbf880..f4c2e0413f1923b8b1725905d4779479a1f40dc7 100644 (file)
@@ -9641,13 +9641,20 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
   const char *options = get_disassembler_options (gdbarch);
   const char *style = "";
   int len = 0;
-  const char *opt;
+  const char *opt = options;
 
-  FOR_EACH_DISASSEMBLER_OPTION (opt, options)
-    if (startswith (opt, "reg-names-"))
+  if (opt)
+    while (1)
       {
-       style = &opt[strlen ("reg-names-")];
-       len = strcspn (style, ",");
+       const char *opt_end = strchr (opt, ',');
+       if (startswith (opt, "reg-names-"))
+         {
+           style = &opt[strlen ("reg-names-")];
+           len = opt_end ? opt_end - style : 99;
+         }
+       if (!opt_end)
+         break;
+       opt = opt_end + 1;
       }
 
   gdb_printf (file, "The disassembly style is \"%.*s\".\n", len, style);
index c8e830ed471cb66e4f1f102e4c1bd1bab229609b..73b094b11732c9dc1860b12c3e090128f9b4c75b 100644 (file)
@@ -1269,7 +1269,6 @@ set_disassembler_options (const char *prospective_options)
     = make_unique_xstrdup (prospective_options);
   char *options = remove_whitespace_and_extra_commas
     (prospective_options_local.get ());
-  const char *opt;
 
   /* Allow all architectures, even ones that do not support 'set disassembler',
      to reset their disassembler options to NULL.  */
@@ -1291,9 +1290,13 @@ set_disassembler_options (const char *prospective_options)
   valid_options = &valid_options_and_args->options;
 
   /* Verify we have valid disassembler options.  */
-  FOR_EACH_DISASSEMBLER_OPTION (opt, options)
+  char *opt = options;
+  while (1)
     {
       size_t i;
+      char *opt_end = strchr (opt, ',');
+      if (opt_end)
+       *opt_end = 0;
       for (i = 0; valid_options->name[i] != NULL; i++)
        if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
          {
@@ -1308,8 +1311,7 @@ set_disassembler_options (const char *prospective_options)
            if (valid_options->arg[i]->values == NULL)
              break;
            for (j = 0; valid_options->arg[i]->values[j] != NULL; j++)
-             if (disassembler_options_cmp
-                   (arg, valid_options->arg[i]->values[j]) == 0)
+             if (strcmp (arg, valid_options->arg[i]->values[j]) == 0)
                {
                  found = true;
                  break;
@@ -1317,7 +1319,7 @@ set_disassembler_options (const char *prospective_options)
            if (found)
              break;
          }
-       else if (disassembler_options_cmp (opt, valid_options->name[i]) == 0)
+       else if (strcmp (opt, valid_options->name[i]) == 0)
          break;
       if (valid_options->name[i] == NULL)
        {
@@ -1326,6 +1328,10 @@ set_disassembler_options (const char *prospective_options)
                      opt);
          return;
        }
+      if (!opt_end)
+       break;
+      *opt_end = ',';
+      opt = opt_end + 1;
     }
 
   *disassembler_options = options;