From 65b48a81404cb058c75c562f7dfdeb74f07eba72 Mon Sep 17 00:00:00 2001 From: Peter Bergner Date: Tue, 28 Feb 2017 12:32:07 -0600 Subject: [PATCH] GDB: Add support for the new set/show disassembler-options commands. This commit adds support to GDB so that it can modify the disassembler-options value that is passed to the disassembler, similar to objdump's -M option. Currently, the only supported targets are ARM, PowerPC and S/390, but adding support for a new target(s) is not difficult. include/ * dis-asm.h (disasm_options_t): New typedef. (parse_arm_disassembler_option): Remove prototype. (set_arm_regname_option): Likewise. (get_arm_regnames): Likewise. (get_arm_regname_num_options): Likewise. (disassemble_init_s390): New prototype. (disassembler_options_powerpc): Likewise. (disassembler_options_arm): Likewise. (disassembler_options_s390): Likewise. (remove_whitespace_and_extra_commas): Likewise. (disassembler_options_cmp): Likewise. (next_disassembler_option): New inline function. (FOR_EACH_DISASSEMBLER_OPTION): New macro. opcodes/ * disassemble.c Include "safe-ctype.h". (disassemble_init_for_target): Handle s390 init. (remove_whitespace_and_extra_commas): New function. (disassembler_options_cmp): Likewise. * arm-dis.c: Include "libiberty.h". (NUM_ELEM): Delete. (regnames): Use long disassembler style names. Add force-thumb and no-force-thumb options. (NUM_ARM_REGNAMES): Rename from this... (NUM_ARM_OPTIONS): ...to this. Use ARRAY_SIZE. (get_arm_regname_num_options): Delete. (set_arm_regname_option): Likewise. (get_arm_regnames): Likewise. (parse_disassembler_options): Likewise. (parse_arm_disassembler_option): Rename from this... (parse_arm_disassembler_options): ...to this. Make static. Use new FOR_EACH_DISASSEMBLER_OPTION macro to scan over options. (print_insn): Use parse_arm_disassembler_options. (disassembler_options_arm): New function. (print_arm_disassembler_options): Handle updated regnames. * ppc-dis.c: Include "libiberty.h". (ppc_opts): Add "32" and "64" entries. (ppc_parse_cpu): Use ARRAY_SIZE and disassembler_options_cmp. (powerpc_init_dialect): Add break to switch statement. Use new FOR_EACH_DISASSEMBLER_OPTION macro. (disassembler_options_powerpc): New function. (print_ppc_disassembler_options): Use ARRAY_SIZE. Remove printing of "32" and "64". * s390-dis.c: Include "libiberty.h". (init_flag): Remove unneeded variable. (struct s390_options_t): New structure type. (options): New structure. (init_disasm): Rename from this... (disassemble_init_s390): ...to this. Add initializations for current_arch_mask and option_use_insn_len_bits_p. Remove init_flag. (print_insn_s390): Delete call to init_disasm. (disassembler_options_s390): New function. (print_s390_disassembler_options): Print using information from struct 'options'. * po/opcodes.pot: Regenerate. binutils/ * objdump.c (main): Use remove_whitespace_and_extra_commas. gdb/ * NEWS: Mention new set/show disassembler-options commands. * doc/gdb.texinfo: Document new set/show disassembler-options commands. * disasm.c: Include "arch-utils.h", "gdbcmd.h" and "safe-ctype.h". (prospective_options): New static variable. (gdb_disassembler::gdb_disassembler): Initialize m_di.disassembler_options. (gdb_buffered_insn_length_init_dis): Initilize di->disassembler_options. (get_disassembler_options): New function. (set_disassembler_options): Likewise. (set_disassembler_options_sfunc): Likewise. (show_disassembler_options_sfunc): Likewise. (disassembler_options_completer): Likewise. (_initialize_disasm): Likewise. * disasm.h (get_disassembler_options): New prototype. (set_disassembler_options): Likewise. * gdbarch.sh (gdbarch_disassembler_options): New variable. (gdbarch_verify_disassembler_options): Likewise. * gdbarch.c: Regenerate. * gdbarch.h: Likewise. * arm-tdep.c (num_disassembly_options): Delete. (set_disassembly_style): Likewise. (arm_disassembler_options): New static variable. (set_disassembly_style_sfunc): Convert short style name into long option name. Call set_disassembler_options. (show_disassembly_style_sfunc): New function. (arm_gdbarch_init): Call set_gdbarch_disassembler_options and set_gdbarch_verify_disassembler_options. (_initialize_arm_tdep): Delete regnames variable and update callers. (arm_disassembler_options): Initialize. (disasm_options): New variable. (num_disassembly_options): Rename from this... (num_disassembly_styles): ...to this. Compute by scanning through disasm_options. (valid_disassembly_styles): Initialize using disasm_options. Remove calls to parse_arm_disassembler_option, get_arm_regnames and set_arm_regname_option. Pass show_disassembly_style_sfunc to the "disassembler" setshow command. * rs6000-tdep.c (powerpc_disassembler_options): New static variable. (rs6000_gdbarch_init): Call set_gdbarch_disassembler_options and set_gdbarch_verify_disassembler_options. * s390-tdep.c (s390_disassembler_options): New static variable. (s390_gdbarch_init):all set_gdbarch_disassembler_options and set_gdbarch_verify_disassembler_options. gdb/testsuite/ * gdb.arch/powerpc-power.exp: Delete test. * gdb.arch/powerpc-power.s: Likewise. * gdb.disasm/disassembler-options.exp: New test. * gdb.arch/powerpc-altivec.exp: Likewise. * gdb.arch/powerpc-altivec.s: Likewise. * gdb.arch/powerpc-altivec2.exp: Likewise. * gdb.arch/powerpc-altivec2.s: Likewise. * gdb.arch/powerpc-altivec3.exp: Likewise. * gdb.arch/powerpc-altivec3.s: Likewise. * gdb.arch/powerpc-power7.exp: Likewise. * gdb.arch/powerpc-power7.s: Likewise. * gdb.arch/powerpc-power8.exp: Likewise. * gdb.arch/powerpc-power8.s: Likewise. * gdb.arch/powerpc-power9.exp: Likewise. * gdb.arch/powerpc-power9.s: Likewise. * gdb.arch/powerpc-vsx.exp: Likewise. * gdb.arch/powerpc-vsx.s: Likewise. * gdb.arch/powerpc-vsx2.exp: Likewise. * gdb.arch/powerpc-vsx2.s: Likewise. * gdb.arch/powerpc-vsx3.exp: Likewise. * gdb.arch/powerpc-vsx3.s: Likewise. * gdb.arch/arm-disassembler-options.exp: Likewise. * gdb.arch/powerpc-disassembler-options.exp: Likewise. * gdb.arch/s390-disassembler-options.exp: Likewise. --- binutils/ChangeLog | 4 + binutils/objdump.c | 16 +- gdb/ChangeLog | 46 + gdb/NEWS | 10 + gdb/arm-tdep.c | 106 +- gdb/disasm.c | 179 +++ gdb/disasm.h | 8 + gdb/doc/gdb.texinfo | 21 + gdb/gdbarch.c | 44 + gdb/gdbarch.h | 9 + gdb/gdbarch.sh | 5 + gdb/rs6000-tdep.c | 7 + gdb/s390-linux-tdep.c | 7 + gdb/testsuite/ChangeLog | 27 + .../gdb.arch/arm-disassembler-options.exp | 56 + gdb/testsuite/gdb.arch/powerpc-altivec.exp | 261 +++ gdb/testsuite/gdb.arch/powerpc-altivec.s | 217 +++ gdb/testsuite/gdb.arch/powerpc-altivec2.exp | 178 ++ gdb/testsuite/gdb.arch/powerpc-altivec2.s | 135 ++ gdb/testsuite/gdb.arch/powerpc-altivec3.exp | 131 ++ gdb/testsuite/gdb.arch/powerpc-altivec3.s | 88 + .../gdb.arch/powerpc-disassembler-options.exp | 56 + gdb/testsuite/gdb.arch/powerpc-power.exp | 1429 ----------------- gdb/testsuite/gdb.arch/powerpc-power.s | 1389 ---------------- gdb/testsuite/gdb.arch/powerpc-power7.exp | 164 ++ gdb/testsuite/gdb.arch/powerpc-power7.s | 121 ++ gdb/testsuite/gdb.arch/powerpc-power8.exp | 248 +++ gdb/testsuite/gdb.arch/powerpc-power8.s | 205 +++ gdb/testsuite/gdb.arch/powerpc-power9.exp | 445 +++++ gdb/testsuite/gdb.arch/powerpc-power9.s | 402 +++++ gdb/testsuite/gdb.arch/powerpc-vsx.exp | 225 +++ gdb/testsuite/gdb.arch/powerpc-vsx.s | 182 +++ gdb/testsuite/gdb.arch/powerpc-vsx2.exp | 118 ++ gdb/testsuite/gdb.arch/powerpc-vsx2.s | 75 + gdb/testsuite/gdb.arch/powerpc-vsx3.exp | 184 +++ gdb/testsuite/gdb.arch/powerpc-vsx3.s | 141 ++ .../gdb.arch/s390-disassembler-options.exp | 56 + .../gdb.disasm/disassembler-options.exp | 34 + include/ChangeLog | 16 + include/dis-asm.h | 41 +- opcodes/ChangeLog | 43 + opcodes/arm-dis.c | 169 +- opcodes/disassemble.c | 70 + opcodes/po/opcodes.pot | 199 ++- opcodes/ppc-dis.c | 59 +- opcodes/s390-dis.c | 72 +- 46 files changed, 4603 insertions(+), 3095 deletions(-) create mode 100644 gdb/testsuite/gdb.arch/arm-disassembler-options.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-altivec.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-altivec.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-altivec2.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-altivec2.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-altivec3.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-altivec3.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-disassembler-options.exp delete mode 100644 gdb/testsuite/gdb.arch/powerpc-power.exp delete mode 100644 gdb/testsuite/gdb.arch/powerpc-power.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-power7.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-power7.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-power8.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-power8.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-power9.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-power9.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-vsx.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-vsx.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-vsx2.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-vsx2.s create mode 100644 gdb/testsuite/gdb.arch/powerpc-vsx3.exp create mode 100644 gdb/testsuite/gdb.arch/powerpc-vsx3.s create mode 100644 gdb/testsuite/gdb.arch/s390-disassembler-options.exp create mode 100644 gdb/testsuite/gdb.disasm/disassembler-options.exp diff --git a/binutils/ChangeLog b/binutils/ChangeLog index f54c12d923b..7004b0b9a9b 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,7 @@ +2017-02-28 Peter Bergner + + * objdump.c (main): Use remove_whitespace_and_extra_commas. + 2017-02-27 Jan Kratochvil Fix compilation with GCC 4.4.7. diff --git a/binutils/objdump.c b/binutils/objdump.c index b9fecefca5a..4609858f9e3 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -3728,12 +3728,16 @@ main (int argc, char **argv) machine = optarg; break; case 'M': - if (disassembler_options) - /* Ignore potential memory leak for now. */ - disassembler_options = concat (disassembler_options, ",", - optarg, (const char *) NULL); - else - disassembler_options = optarg; + { + char *options; + if (disassembler_options) + /* Ignore potential memory leak for now. */ + options = concat (disassembler_options, ",", + optarg, (const char *) NULL); + else + options = optarg; + disassembler_options = remove_whitespace_and_extra_commas (options); + } break; case 'j': add_only (optarg); diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fafa10c84e4..b06029154fd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,49 @@ +2017-02-28 Peter Bergner + + * NEWS: Mention new set/show disassembler-options commands. + * doc/gdb.texinfo: Document new set/show disassembler-options commands. + * disasm.c: Include "arch-utils.h", "gdbcmd.h" and "safe-ctype.h". + (prospective_options): New static variable. + (gdb_disassembler::gdb_disassembler): Initialize + m_di.disassembler_options. + (gdb_buffered_insn_length_init_dis): Initilize di->disassembler_options. + (get_disassembler_options): New function. + (set_disassembler_options): Likewise. + (set_disassembler_options_sfunc): Likewise. + (show_disassembler_options_sfunc): Likewise. + (disassembler_options_completer): Likewise. + (_initialize_disasm): Likewise. + * disasm.h (get_disassembler_options): New prototype. + (set_disassembler_options): Likewise. + * gdbarch.sh (gdbarch_disassembler_options): New variable. + (gdbarch_verify_disassembler_options): Likewise. + * gdbarch.c: Regenerate. + * gdbarch.h: Likewise. + * arm-tdep.c (num_disassembly_options): Delete. + (set_disassembly_style): Likewise. + (arm_disassembler_options): New static variable. + (set_disassembly_style_sfunc): Convert short style name into long + option name. Call set_disassembler_options. + (show_disassembly_style_sfunc): New function. + (arm_gdbarch_init): Call set_gdbarch_disassembler_options and + set_gdbarch_verify_disassembler_options. + (_initialize_arm_tdep): Delete regnames variable and update callers. + (arm_disassembler_options): Initialize. + (disasm_options): New variable. + (num_disassembly_options): Rename from this... + (num_disassembly_styles): ...to this. Compute by scanning through + disasm_options. + (valid_disassembly_styles): Initialize using disasm_options. + Remove calls to parse_arm_disassembler_option, get_arm_regnames and + set_arm_regname_option. + Pass show_disassembly_style_sfunc to the "disassembler" setshow command. + * rs6000-tdep.c (powerpc_disassembler_options): New static variable. + (rs6000_gdbarch_init): Call set_gdbarch_disassembler_options and + set_gdbarch_verify_disassembler_options. + * s390-tdep.c (s390_disassembler_options): New static variable. + (s390_gdbarch_init):all set_gdbarch_disassembler_options and + set_gdbarch_verify_disassembler_options. + 2017-02-27 Simon Marchi * remote.c (remote_add_target_side_condition): Remove "struct" diff --git a/gdb/NEWS b/gdb/NEWS index 76de00e85c2..cf585954d79 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -84,6 +84,16 @@ flash-erase Erases all the flash memory regions reported by the target. This is equivalent to the CLI command flash-erase. +* New commands + +set disassembler-options +show disassembler-options + Controls the passing of target specific information to the disassembler. + If it is necessary to specify more than one disassembler option then + multiple options can be placed together into a comma separated list. + The default value is the empty string. Currently, the only supported + targets are ARM, PowerPC and S/390. + *** Changes in GDB 7.12 * GDB and GDBserver now build with a C++ compiler by default. diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 88ed3917298..3aee7221f34 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -145,9 +145,6 @@ static const char *const arm_mode_strings[] = static const char *arm_fallback_mode_string = "auto"; static const char *arm_force_mode_string = "auto"; -/* Number of different reg name sets (options). */ -static int num_disassembly_options; - /* The standard register names, and all the valid aliases for them. Note that `fp', `sp' and `pc' are not added in this alias list, because they have been added as builtin user registers in @@ -208,6 +205,9 @@ static const char *const arm_register_names[] = "f4", "f5", "f6", "f7", /* 20 21 22 23 */ "fps", "cpsr" }; /* 24 25 */ +/* Holds the current set of options to be passed to the disassembler. */ +static char *arm_disassembler_options; + /* Valid register name styles. */ static const char **valid_disassembly_styles; @@ -218,7 +218,9 @@ static const char *disassembly_style; style. */ static void set_disassembly_style_sfunc(char *, int, struct cmd_list_element *); -static void set_disassembly_style (void); +static void show_disassembly_style_sfunc (struct ui_file *, int, + struct cmd_list_element *, + const char *); static void convert_from_extended (const struct floatformat *, const void *, void *, int); @@ -8539,9 +8541,32 @@ arm_show_force_mode (struct ui_file *file, int from_tty, static void set_disassembly_style_sfunc (char *args, int from_tty, - struct cmd_list_element *c) + struct cmd_list_element *c) { - set_disassembly_style (); + /* Convert the short style name into the long style name (eg, reg-names-*) + before calling the generic set_disassembler_options() function. */ + std::string long_name = std::string ("reg-names-") + disassembly_style; + set_disassembler_options (&long_name[0]); +} + +static void +show_disassembly_style_sfunc (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + struct gdbarch *gdbarch = get_current_arch (); + char *options = get_disassembler_options (gdbarch); + const char *style = ""; + int len = 0; + char *opt; + + FOR_EACH_DISASSEMBLER_OPTION (opt, options) + if (CONST_STRNEQ (opt, "reg-names-")) + { + style = &opt[strlen ("reg-names-")]; + len = strcspn (style, ","); + } + + fprintf_unfiltered (file, "The disassembly style is \"%.*s\".\n", len, style); } /* Return the ARM register name corresponding to register I. */ @@ -8582,21 +8607,6 @@ arm_register_name (struct gdbarch *gdbarch, int i) return arm_register_names[i]; } -static void -set_disassembly_style (void) -{ - int current; - - /* Find the style that the user wants. */ - for (current = 0; current < num_disassembly_options; current++) - if (disassembly_style == valid_disassembly_styles[current]) - break; - gdb_assert (current < num_disassembly_options); - - /* Synchronize the disassembler. */ - set_arm_regname_option (current); -} - /* Test whether the coff symbol specific value corresponds to a Thumb function. */ @@ -9556,6 +9566,9 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) user_reg_add (gdbarch, arm_register_aliases[i].name, value_of_arm_user_reg, &arm_register_aliases[i].regnum); + set_gdbarch_disassembler_options (gdbarch, &arm_disassembler_options); + set_gdbarch_valid_disassembler_options (gdbarch, disassembler_options_arm ()); + return gdbarch; } @@ -9579,8 +9592,7 @@ _initialize_arm_tdep (void) long length; const char *setname; const char *setdesc; - const char *const *regnames; - int i; + int i, j; char regdesc[1024], *rdptr = regdesc; size_t rest = sizeof (regdesc); @@ -9608,9 +9620,6 @@ _initialize_arm_tdep (void) initialize_tdesc_arm_with_vfpv3 (); initialize_tdesc_arm_with_neon (); - /* Get the number of possible sets of register names defined in opcodes. */ - num_disassembly_options = get_arm_regname_num_options (); - /* Add root prefix command for all "set arm"/"show arm" commands. */ add_prefix_cmd ("arm", no_class, set_arm_command, _("Various ARM-specific commands."), @@ -9620,30 +9629,30 @@ _initialize_arm_tdep (void) _("Various ARM-specific commands."), &showarmcmdlist, "show arm ", 0, &showlist); - /* Sync the opcode insn printer with our register viewer. */ - parse_arm_disassembler_option ("reg-names-std"); - /* Initialize the array that will be passed to - add_setshow_enum_cmd(). */ + arm_disassembler_options = xstrdup ("reg-names-std"); + const disasm_options_t *disasm_options = disassembler_options_arm (); + int num_disassembly_styles = 0; + for (i = 0; disasm_options->name[i] != NULL; i++) + if (CONST_STRNEQ (disasm_options->name[i], "reg-names-")) + num_disassembly_styles++; + + /* Initialize the array that will be passed to add_setshow_enum_cmd(). */ valid_disassembly_styles = XNEWVEC (const char *, - num_disassembly_options + 1); - for (i = 0; i < num_disassembly_options; i++) - { - get_arm_regnames (i, &setname, &setdesc, ®names); - valid_disassembly_styles[i] = setname; - length = snprintf (rdptr, rest, "%s - %s\n", setname, setdesc); - rdptr += length; - rest -= length; - /* When we find the default names, tell the disassembler to use - them. */ - if (!strcmp (setname, "std")) - { - disassembly_style = setname; - set_arm_regname_option (i); - } - } + num_disassembly_styles + 1); + for (i = j = 0; disasm_options->name[i] != NULL; i++) + if (CONST_STRNEQ (disasm_options->name[i], "reg-names-")) + { + size_t offset = strlen ("reg-names-"); + const char *style = disasm_options->name[i]; + valid_disassembly_styles[j++] = &style[offset]; + length = snprintf (rdptr, rest, "%s - %s\n", &style[offset], + disasm_options->description[i]); + rdptr += length; + rest -= length; + } /* Mark the end of valid options. */ - valid_disassembly_styles[num_disassembly_options] = NULL; + valid_disassembly_styles[num_disassembly_styles] = NULL; /* Create the help text. */ std::string helptext = string_printf ("%s%s%s", @@ -9657,8 +9666,7 @@ _initialize_arm_tdep (void) _("Show the disassembly style."), helptext.c_str (), set_disassembly_style_sfunc, - NULL, /* FIXME: i18n: The disassembly style is - \"%s\". */ + show_disassembly_style_sfunc, &setarmcmdlist, &showarmcmdlist); add_setshow_boolean_cmd ("apcs32", no_class, &arm_apcs_32, diff --git a/gdb/disasm.c b/gdb/disasm.c index 64d6684b53e..ab080e2690e 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -18,19 +18,26 @@ along with this program. If not, see . */ #include "defs.h" +#include "arch-utils.h" #include "target.h" #include "value.h" #include "ui-out.h" #include "disasm.h" #include "gdbcore.h" +#include "gdbcmd.h" #include "dis-asm.h" #include "source.h" +#include "safe-ctype.h" #include /* Disassemble functions. FIXME: We should get rid of all the duplicate code in gdb that does the same thing: disassemble_command() and the gdbtk variation. */ +/* This variable is used to hold the prospective disassembler_options value + which is set by the "set disassembler_options" command. */ +static char *prospective_options = NULL; + /* This structure is used to store line number information for the deprecated /m option. We need a different sort of line table from the normal one cuz we can't @@ -780,6 +787,7 @@ gdb_disassembler::gdb_disassembler (struct gdbarch *gdbarch, m_di.endian = gdbarch_byte_order (gdbarch); m_di.endian_code = gdbarch_byte_order_for_code (gdbarch); m_di.application_data = this; + m_di.disassembler_options = get_disassembler_options (gdbarch); disassemble_init_for_target (&m_di); } @@ -888,6 +896,7 @@ gdb_buffered_insn_length_init_dis (struct gdbarch *gdbarch, di->endian = gdbarch_byte_order (gdbarch); di->endian_code = gdbarch_byte_order_for_code (gdbarch); + di->disassembler_options = get_disassembler_options (gdbarch); disassemble_init_for_target (di); } @@ -904,3 +913,173 @@ gdb_buffered_insn_length (struct gdbarch *gdbarch, return gdbarch_print_insn (gdbarch, addr, &di); } + +char * +get_disassembler_options (struct gdbarch *gdbarch) +{ + char **disassembler_options = gdbarch_disassembler_options (gdbarch); + if (disassembler_options == NULL) + return NULL; + return *disassembler_options; +} + +void +set_disassembler_options (char *prospective_options) +{ + struct gdbarch *gdbarch = get_current_arch (); + char **disassembler_options = gdbarch_disassembler_options (gdbarch); + const disasm_options_t *valid_options; + char *options = remove_whitespace_and_extra_commas (prospective_options); + char *opt; + + /* Allow all architectures, even ones that do not support 'set disassembler', + to reset their disassembler options to NULL. */ + if (options == NULL) + { + if (disassembler_options != NULL) + { + free (*disassembler_options); + *disassembler_options = NULL; + } + return; + } + + valid_options = gdbarch_valid_disassembler_options (gdbarch); + if (valid_options == NULL) + { + fprintf_filtered (gdb_stdlog, _("\ +'set disassembler-options ...' is not supported on this architecture.\n")); + return; + } + + /* Verify we have valid disassembler options. */ + FOR_EACH_DISASSEMBLER_OPTION (opt, options) + { + size_t i; + for (i = 0; valid_options->name[i] != NULL; i++) + if (disassembler_options_cmp (opt, valid_options->name[i]) == 0) + break; + if (valid_options->name[i] == NULL) + { + fprintf_filtered (gdb_stdlog, + _("Invalid disassembler option value: '%s'.\n"), + opt); + return; + } + } + + free (*disassembler_options); + *disassembler_options = xstrdup (options); +} + +static void +set_disassembler_options_sfunc (char *args, int from_tty, + struct cmd_list_element *c) +{ + set_disassembler_options (prospective_options); +} + +static void +show_disassembler_options_sfunc (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + struct gdbarch *gdbarch = get_current_arch (); + const disasm_options_t *valid_options; + + const char *options = get_disassembler_options (gdbarch); + if (options == NULL) + options = ""; + + fprintf_filtered (file, _("The current disassembler options are '%s'\n"), + options); + + valid_options = gdbarch_valid_disassembler_options (gdbarch); + + if (valid_options == NULL) + return; + + fprintf_filtered (file, _("\n\ +The following disassembler options are supported for use with the\n\ +'set disassembler-options