mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-29 10:30:46 +00:00
opcodes: PR 33384 invalid disassembler option message
This is the binutils fix for PR 33384. Here we are assuming that no const char* comma-separated option strings are passed in to disassemble_info.disassembler_options. That is true for current usage in gdb and binutils. In fact, there is only one place that passes a string in read-only memory, gdb/tdep-i386.c:disassembly_flavor, and that one is a single option. include/ * dis-asm.h (struct disassemble_info): Comment. (disassembler_options_cmp, next_disassembler_option), (FOR_EACH_DISASSEMBLER_OPTION): Delete. (for_each_disassembler_option): Declare. opcodes/ * disassemble.c (disassembler_options_cmp): Delete. (for_each_disassembler_option): New function. * arc-dis.c (parse_option): Replace disassembler_options_cmp with strcmp. (parse_cpu_option): Likewise. (parse_disassembler_options): Replace FOR_EACH_DISASSEMBLER_OPTION with for_each_disassembler_option, and extract loop body to.. (arc_parse_option): ..this new function. * arm-dis.c (parse_arm_disassembler_options): Delete, extracting loop body to.. (arm_parse_option): ..this new function. (print_insn): Use for_each_disassembler_option. * csky-dis.c (parse_csky_dis_options): Delete, extracting loop body to.. (parse_csky_option): ..this new function. (print_insn_csky): Use for_each_disassembler_option. * nfp-dis.c (parse_disassembler_options): Replace FOR_EACH_DISASSEMBLER_OPTION with for_each_disassembler_option, and extract loop body to.. (nfp_parse_option): ..this new function. Use opcodes_error_handler here rather than info->fprintf_func to print error. * ppc-dis.c (ppc_parse_cpu): Replace disassembler_options_cmp with strcmp. (struct ppc_parse_data): New. (powerpc_init_dialect): Adjust to use new struct. Replace FOR_EACH_DISASSEMBLER_OPTION with for_each_disassembler_option, and extract loop body to.. (ppc_parse_option): ..this new function.
This commit is contained in:
@@ -11904,52 +11904,43 @@ arm_symbol_is_valid (asymbol * sym,
|
||||
return (name && *name != '$' && strncmp (name, "__tagsym$$", 10));
|
||||
}
|
||||
|
||||
/* Parse the string of disassembler options. */
|
||||
/* Parse a disassembler option. */
|
||||
|
||||
static void
|
||||
parse_arm_disassembler_options (const char *options)
|
||||
static bool
|
||||
arm_parse_option (const char *opt, void *data ATTRIBUTE_UNUSED)
|
||||
{
|
||||
const char *opt;
|
||||
|
||||
force_thumb = false;
|
||||
FOR_EACH_DISASSEMBLER_OPTION (opt, options)
|
||||
if (startswith (opt, "reg-names-"))
|
||||
{
|
||||
if (startswith (opt, "reg-names-"))
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < NUM_ARM_OPTIONS; i++)
|
||||
if (disassembler_options_cmp (opt, regnames[i].name) == 0)
|
||||
{
|
||||
regname_selected = i;
|
||||
break;
|
||||
}
|
||||
unsigned int i;
|
||||
for (i = 0; i < NUM_ARM_OPTIONS; i++)
|
||||
if (strcmp (opt, regnames[i].name) == 0)
|
||||
{
|
||||
regname_selected = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= NUM_ARM_OPTIONS)
|
||||
/* xgettext: c-format */
|
||||
opcodes_error_handler (_("unrecognised register name set: %s"),
|
||||
opt);
|
||||
}
|
||||
else if (startswith (opt, "force-thumb"))
|
||||
force_thumb = 1;
|
||||
else if (startswith (opt, "no-force-thumb"))
|
||||
force_thumb = 0;
|
||||
else if (startswith (opt, "coproc"))
|
||||
if (i >= NUM_ARM_OPTIONS)
|
||||
/* xgettext: c-format */
|
||||
opcodes_error_handler (_("unrecognised register name set: %s"),
|
||||
opt);
|
||||
}
|
||||
else if (startswith (opt, "force-thumb"))
|
||||
force_thumb = 1;
|
||||
else if (startswith (opt, "no-force-thumb"))
|
||||
force_thumb = 0;
|
||||
else if (startswith (opt, "coproc"))
|
||||
{
|
||||
const char *procptr = opt + sizeof ("coproc") - 1;
|
||||
char *endptr;
|
||||
uint8_t coproc_number = strtol (procptr, &endptr, 10);
|
||||
if (endptr != procptr + 1 || coproc_number > 7)
|
||||
opcodes_error_handler (_("cde coprocessor not between 0-7: %s"),
|
||||
opt);
|
||||
else if (*endptr != '=')
|
||||
opcodes_error_handler (_("coproc must have an argument: %s"),
|
||||
opt);
|
||||
else
|
||||
{
|
||||
const char *procptr = opt + sizeof ("coproc") - 1;
|
||||
char *endptr;
|
||||
uint8_t coproc_number = strtol (procptr, &endptr, 10);
|
||||
if (endptr != procptr + 1 || coproc_number > 7)
|
||||
{
|
||||
opcodes_error_handler (_("cde coprocessor not between 0-7: %s"),
|
||||
opt);
|
||||
continue;
|
||||
}
|
||||
if (*endptr != '=')
|
||||
{
|
||||
opcodes_error_handler (_("coproc must have an argument: %s"),
|
||||
opt);
|
||||
continue;
|
||||
}
|
||||
endptr += 1;
|
||||
if (startswith (endptr, "generic"))
|
||||
cde_coprocs &= ~(1 << coproc_number);
|
||||
@@ -11957,18 +11948,15 @@ parse_arm_disassembler_options (const char *options)
|
||||
|| startswith (endptr, "CDE"))
|
||||
cde_coprocs |= (1 << coproc_number);
|
||||
else
|
||||
{
|
||||
opcodes_error_handler (
|
||||
_("coprocN argument takes options \"generic\","
|
||||
" \"cde\", or \"CDE\": %s"), opt);
|
||||
}
|
||||
opcodes_error_handler
|
||||
(_("coprocN argument takes options \"generic\","
|
||||
" \"cde\", or \"CDE\": %s"), opt);
|
||||
}
|
||||
else
|
||||
/* xgettext: c-format */
|
||||
opcodes_error_handler (_("unrecognised disassembler option: %s"), opt);
|
||||
}
|
||||
|
||||
return;
|
||||
else
|
||||
/* xgettext: c-format */
|
||||
opcodes_error_handler (_("unrecognised disassembler option: %s"), opt);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -12377,7 +12365,8 @@ print_insn (bfd_vma pc, struct disassemble_info *info, bool little)
|
||||
|
||||
if (info->disassembler_options)
|
||||
{
|
||||
parse_arm_disassembler_options (info->disassembler_options);
|
||||
force_thumb = false;
|
||||
for_each_disassembler_option (info, arm_parse_option, NULL);
|
||||
|
||||
/* To avoid repeated parsing of these options, we remove them here. */
|
||||
info->disassembler_options = NULL;
|
||||
|
||||
Reference in New Issue
Block a user