mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-25 16:57:52 +00:00
gdb: PR 33384 invalid disassembler option message
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.
This commit is contained in:
@@ -9641,13 +9641,20 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
|
|||||||
const char *options = get_disassembler_options (gdbarch);
|
const char *options = get_disassembler_options (gdbarch);
|
||||||
const char *style = "";
|
const char *style = "";
|
||||||
int len = 0;
|
int len = 0;
|
||||||
const char *opt;
|
const char *opt = options;
|
||||||
|
|
||||||
FOR_EACH_DISASSEMBLER_OPTION (opt, options)
|
if (opt)
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
const char *opt_end = strchr (opt, ',');
|
||||||
if (startswith (opt, "reg-names-"))
|
if (startswith (opt, "reg-names-"))
|
||||||
{
|
{
|
||||||
style = &opt[strlen ("reg-names-")];
|
style = &opt[strlen ("reg-names-")];
|
||||||
len = strcspn (style, ",");
|
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);
|
gdb_printf (file, "The disassembly style is \"%.*s\".\n", len, style);
|
||||||
|
|||||||
16
gdb/disasm.c
16
gdb/disasm.c
@@ -1269,7 +1269,6 @@ set_disassembler_options (const char *prospective_options)
|
|||||||
= make_unique_xstrdup (prospective_options);
|
= make_unique_xstrdup (prospective_options);
|
||||||
char *options = remove_whitespace_and_extra_commas
|
char *options = remove_whitespace_and_extra_commas
|
||||||
(prospective_options_local.get ());
|
(prospective_options_local.get ());
|
||||||
const char *opt;
|
|
||||||
|
|
||||||
/* Allow all architectures, even ones that do not support 'set disassembler',
|
/* Allow all architectures, even ones that do not support 'set disassembler',
|
||||||
to reset their disassembler options to NULL. */
|
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;
|
valid_options = &valid_options_and_args->options;
|
||||||
|
|
||||||
/* Verify we have valid disassembler options. */
|
/* Verify we have valid disassembler options. */
|
||||||
FOR_EACH_DISASSEMBLER_OPTION (opt, options)
|
char *opt = options;
|
||||||
|
while (1)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
char *opt_end = strchr (opt, ',');
|
||||||
|
if (opt_end)
|
||||||
|
*opt_end = 0;
|
||||||
for (i = 0; valid_options->name[i] != NULL; i++)
|
for (i = 0; valid_options->name[i] != NULL; i++)
|
||||||
if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
|
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)
|
if (valid_options->arg[i]->values == NULL)
|
||||||
break;
|
break;
|
||||||
for (j = 0; valid_options->arg[i]->values[j] != NULL; j++)
|
for (j = 0; valid_options->arg[i]->values[j] != NULL; j++)
|
||||||
if (disassembler_options_cmp
|
if (strcmp (arg, valid_options->arg[i]->values[j]) == 0)
|
||||||
(arg, valid_options->arg[i]->values[j]) == 0)
|
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@@ -1317,7 +1319,7 @@ set_disassembler_options (const char *prospective_options)
|
|||||||
if (found)
|
if (found)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (disassembler_options_cmp (opt, valid_options->name[i]) == 0)
|
else if (strcmp (opt, valid_options->name[i]) == 0)
|
||||||
break;
|
break;
|
||||||
if (valid_options->name[i] == NULL)
|
if (valid_options->name[i] == NULL)
|
||||||
{
|
{
|
||||||
@@ -1326,6 +1328,10 @@ set_disassembler_options (const char *prospective_options)
|
|||||||
opt);
|
opt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!opt_end)
|
||||||
|
break;
|
||||||
|
*opt_end = ',';
|
||||||
|
opt = opt_end + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*disassembler_options = options;
|
*disassembler_options = options;
|
||||||
|
|||||||
Reference in New Issue
Block a user