[PATCH, RFC] Add support for choosing disassembler cpu in GDB for POWER.

Ulrich Weigand uweigand@de.ibm.com
Fri Oct 28 12:32:00 GMT 2016


Peter Bergner wrote:
> > Another option might be to refactor the way disassembler options
> > output is done in opcodes, e.g. by having platform-specific code
> > only provide an array of tuples of option names and explanatory
> > strings, and move the actual printing to common code.  Then those
> > arrays could be exported to and reused by GDB.  (In particular,
> > there's really no way to do a completer without such information.)
> 
> How about what I implemented below?

Mostly yes.  However, I had been thinking of moving more of this
stuff to common code.  In particular, once the gdbarch has provided
a list of supported options, then all this:

> +static void
> +set_disassembler_options (char *args, int from_tty, struct cmd_list_element *c)
> +{
> +  struct gdbarch *gdbarch = get_current_arch ();
> +  if (gdbarch_set_disassembler_options_p (gdbarch))
> +    {
> +      gdbarch_set_disassembler_options (gdbarch, args, from_tty, c);
> +      return;
> +    }
> +  fprintf_filtered (gdb_stdlog, _("\
> +'set disassembler' is not supported on this architecture.\n"));
> +}
> +
> +static void
> +show_disassembler_options (struct ui_file *file, int from_tty,
> +			   struct cmd_list_element *c, const char *value)
> +{
> +  struct gdbarch *gdbarch = get_current_arch ();
> +  if (gdbarch_show_disassembler_options_p (gdbarch))
> +    {
> +      gdbarch_show_disassembler_options (gdbarch, file, from_tty, c, value);
> +      return;
> +    }
> +  fprintf_filtered (gdb_stdlog, _("\
> +'show disassembler' is not supported on this architecture.\n"));
> +}
> +
> +/* A completion function for "set disassembler".  */
> +
> +static VEC (char_ptr) *
> +disassembler_options_completer (struct cmd_list_element *ignore,
> +                                const char *text, const char *word)
> +{
> +  struct gdbarch *gdbarch = get_current_arch ();
> +  if (gdbarch_disassembler_options_completer_p (gdbarch))
> +    return gdbarch_disassembler_options_completer (gdbarch, ignore, text, word);
> +  return NULL;
> +}

really can be handled generically in common code, right?  I.e.
set_disassembler_options verifies the string is a comma-separated
list of words from the supported option list, show_disassembler_options
simply displays the supported option list, etc.

In fact, once the option processing is done in common code, we don't
even really need the per-gdbarch disassemble_init_for_target option
any more, since common code could simply set the disassembler_options
string before calling disassemble_init_for_target.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com



More information about the Binutils mailing list