From 9a24775b97646827396073d0d7e510b9694331ab Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 4 Sep 2017 18:23:22 +0100 Subject: [PATCH] Introduce gdb_disassembly_flags For some reason I ended up staring at some of the "int flags" in btrace-related code, and I got confused because I had no clue what the flags where supposed to indicate. Fix that by using enum_flags, so that: #1 - it's clear from the type what the flags are about, and #2 - the compiler can catch mismatching mistakes gdb/ChangeLog: 2017-09-04 Pedro Alves * cli/cli-cmds.c (print_disassembly, disassemble_current_function) (disassemble_command): Use gdb_disassembly_flags instead of bare int. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn) (dump_insns, do_mixed_source_and_assembly_deprecated) (do_mixed_source_and_assembly, do_assembly_only, gdb_disassembly): Use gdb_disassembly_flags instead of bare int. * disasm.h (DISASSEMBLY_SOURCE_DEPRECATED, DISASSEMBLY_RAW_INSN) (DISASSEMBLY_OMIT_FNAME, DISASSEMBLY_FILENAME) (DISASSEMBLY_OMIT_PC, DISASSEMBLY_SOURCE) (DISASSEMBLY_SPECULATIVE): No longer macros. Instead they're... (enum gdb_disassembly_flag): ... values of this new enumeration. (gdb_disassembly_flags): Define. (gdb_disassembly) (gdb_pretty_print_disassembler::pretty_print_insn): Use it. * mi/mi-cmd-disas.c (mi_cmd_disassemble): Use gdb_disassembly_flags instead of bare int. * record-btrace.c (btrace_insn_history) (record_btrace_insn_history, record_btrace_insn_history_range) (record_btrace_insn_history_from): Use gdb_disassembly_flags instead of bare int. * record.c (get_insn_history_modifiers, cmd_record_insn_history): Use gdb_disassembly_flags instead of bare int. * target-debug.h (target_debug_print_gdb_disassembly_flags): Define. * target-delegates.c: Regenerate. * target.c (target_insn_history, target_insn_history_from) (target_insn_history_range): Use gdb_disassembly_flags instead of bare int. * target.h: Include "disasm.h". (struct target_ops) : Use gdb_disassembly_flags instead of bare int. (target_insn_history, target_insn_history_from) (target_insn_history_range): Use gdb_disassembly_flags instead of bare int. --- gdb/ChangeLog | 39 +++++++++++++++++++++++++++++++++++++++ gdb/cli/cli-cmds.c | 7 ++++--- gdb/disasm.c | 12 ++++++------ gdb/disasm.h | 25 +++++++++++++++---------- gdb/mi/mi-cmd-disas.c | 3 ++- gdb/record-btrace.c | 22 +++++++++++++--------- gdb/record.c | 10 ++++------ gdb/target-debug.h | 2 ++ gdb/target-delegates.c | 24 ++++++++++++------------ gdb/target.c | 8 +++++--- gdb/target.h | 18 ++++++++++++------ 11 files changed, 114 insertions(+), 56 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 39a47ec..9c9c6b1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,42 @@ +2017-09-04 Pedro Alves + + * cli/cli-cmds.c (print_disassembly, disassemble_current_function) + (disassemble_command): Use gdb_disassembly_flags instead of bare + int. + * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn) + (dump_insns, do_mixed_source_and_assembly_deprecated) + (do_mixed_source_and_assembly, do_assembly_only, gdb_disassembly): + Use gdb_disassembly_flags instead of bare int. + * disasm.h (DISASSEMBLY_SOURCE_DEPRECATED, DISASSEMBLY_RAW_INSN) + (DISASSEMBLY_OMIT_FNAME, DISASSEMBLY_FILENAME) + (DISASSEMBLY_OMIT_PC, DISASSEMBLY_SOURCE) + (DISASSEMBLY_SPECULATIVE): No longer macros. Instead they're... + (enum gdb_disassembly_flag): ... values of this new enumeration. + (gdb_disassembly_flags): Define. + (gdb_disassembly) + (gdb_pretty_print_disassembler::pretty_print_insn): Use it. + * mi/mi-cmd-disas.c (mi_cmd_disassemble): Use + gdb_disassembly_flags instead of bare int. + * record-btrace.c (btrace_insn_history) + (record_btrace_insn_history, record_btrace_insn_history_range) + (record_btrace_insn_history_from): Use gdb_disassembly_flags + instead of bare int. + * record.c (get_insn_history_modifiers, cmd_record_insn_history): + Use gdb_disassembly_flags instead of bare int. + * target-debug.h (target_debug_print_gdb_disassembly_flags): + Define. + * target-delegates.c: Regenerate. + * target.c (target_insn_history, target_insn_history_from) + (target_insn_history_range): Use gdb_disassembly_flags instead of + bare int. + * target.h: Include "disasm.h". + (struct target_ops) : Use gdb_disassembly_flags instead of bare + int. + (target_insn_history, target_insn_history_from) + (target_insn_history_range): Use gdb_disassembly_flags instead of + bare int. + 2017-09-04 Simon Marchi * cli/cli-script.c (build_command_line): For if/while commands, diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 7d7e16a..b79ceb2 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1121,7 +1121,8 @@ list_command (char *arg, int from_tty) static void print_disassembly (struct gdbarch *gdbarch, const char *name, - CORE_ADDR low, CORE_ADDR high, int flags) + CORE_ADDR low, CORE_ADDR high, + gdb_disassembly_flags flags) { #if defined(TUI) if (!tui_is_window_visible (DISASSEM_WIN)) @@ -1152,7 +1153,7 @@ print_disassembly (struct gdbarch *gdbarch, const char *name, Print a disassembly of the current function according to FLAGS. */ static void -disassemble_current_function (int flags) +disassemble_current_function (gdb_disassembly_flags flags) { struct frame_info *frame; struct gdbarch *gdbarch; @@ -1207,7 +1208,7 @@ disassemble_command (char *arg, int from_tty) CORE_ADDR low, high; const char *name; CORE_ADDR pc; - int flags; + gdb_disassembly_flags flags; const char *p; p = arg; diff --git a/gdb/disasm.c b/gdb/disasm.c index 76c4ff3..c3528e0 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -191,7 +191,7 @@ compare_lines (const void *mle1p, const void *mle2p) int gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, const struct disasm_insn *insn, - int flags) + gdb_disassembly_flags flags) { /* parts of the symbolic representation of the address */ int unmapped; @@ -295,7 +295,7 @@ gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, static int dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout, CORE_ADDR low, CORE_ADDR high, - int how_many, int flags, CORE_ADDR *end_pc) + int how_many, gdb_disassembly_flags flags, CORE_ADDR *end_pc) { struct disasm_insn insn; int num_displayed = 0; @@ -338,7 +338,7 @@ do_mixed_source_and_assembly_deprecated (struct gdbarch *gdbarch, struct ui_out *uiout, struct symtab *symtab, CORE_ADDR low, CORE_ADDR high, - int how_many, int flags) + int how_many, gdb_disassembly_flags flags) { int newlines = 0; int nlines; @@ -498,7 +498,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout, struct symtab *main_symtab, CORE_ADDR low, CORE_ADDR high, - int how_many, int flags) + int how_many, gdb_disassembly_flags flags) { const struct linetable_entry *le, *first_le; int i, nlines; @@ -730,7 +730,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, static void do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout, CORE_ADDR low, CORE_ADDR high, - int how_many, int flags) + int how_many, gdb_disassembly_flags flags) { ui_out_emit_list list_emitter (uiout, "asm_insns"); @@ -803,7 +803,7 @@ gdb_disassembler::print_insn (CORE_ADDR memaddr, void gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout, - int flags, int how_many, + gdb_disassembly_flags flags, int how_many, CORE_ADDR low, CORE_ADDR high) { struct symtab *symtab; diff --git a/gdb/disasm.h b/gdb/disasm.h index ad3e8dd..5b79be0 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -20,14 +20,19 @@ #define DISASM_H #include "dis-asm.h" - -#define DISASSEMBLY_SOURCE_DEPRECATED (0x1 << 0) -#define DISASSEMBLY_RAW_INSN (0x1 << 1) -#define DISASSEMBLY_OMIT_FNAME (0x1 << 2) -#define DISASSEMBLY_FILENAME (0x1 << 3) -#define DISASSEMBLY_OMIT_PC (0x1 << 4) -#define DISASSEMBLY_SOURCE (0x1 << 5) -#define DISASSEMBLY_SPECULATIVE (0x1 << 6) +#include "common/enum-flags.h" + +enum gdb_disassembly_flag + { + DISASSEMBLY_SOURCE_DEPRECATED = (0x1 << 0), + DISASSEMBLY_RAW_INSN = (0x1 << 1), + DISASSEMBLY_OMIT_FNAME = (0x1 << 2), + DISASSEMBLY_FILENAME = (0x1 << 3), + DISASSEMBLY_OMIT_PC = (0x1 << 4), + DISASSEMBLY_SOURCE = (0x1 << 5), + DISASSEMBLY_SPECULATIVE = (0x1 << 6), + }; +DEF_ENUM_FLAGS_TYPE (enum gdb_disassembly_flag, gdb_disassembly_flags); struct gdbarch; struct ui_out; @@ -87,7 +92,7 @@ struct disasm_insn }; extern void gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout, - int flags, int how_many, + gdb_disassembly_flags flags, int how_many, CORE_ADDR low, CORE_ADDR high); /* Print the instruction at address MEMADDR in debugged memory, @@ -109,7 +114,7 @@ public: /* Prints the instruction INSN into UIOUT and returns the length of the printed instruction in bytes. */ int pretty_print_insn (struct ui_out *uiout, const struct disasm_insn *insn, - int flags); + gdb_disassembly_flags flags); private: /* Returns the architecture used for disassembling. */ diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c index fa36311..d0f9b0b 100644 --- a/gdb/mi/mi-cmd-disas.c +++ b/gdb/mi/mi-cmd-disas.c @@ -57,7 +57,8 @@ mi_cmd_disassemble (const char *command, char **argv, int argc) struct ui_out *uiout = current_uiout; CORE_ADDR start; - int mode, disasm_flags; + int mode; + gdb_disassembly_flags disasm_flags; struct symtab *s; /* Which options have we processed ... */ diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index d35800b..220b33c 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -630,15 +630,16 @@ static void btrace_insn_history (struct ui_out *uiout, const struct btrace_thread_info *btinfo, const struct btrace_insn_iterator *begin, - const struct btrace_insn_iterator *end, int flags) + const struct btrace_insn_iterator *end, + gdb_disassembly_flags flags) { struct cleanup *cleanups, *ui_item_chain; struct gdbarch *gdbarch; struct btrace_insn_iterator it; struct btrace_line_range last_lines; - DEBUG ("itrace (0x%x): [%u; %u)", flags, btrace_insn_number (begin), - btrace_insn_number (end)); + DEBUG ("itrace (0x%x): [%u; %u)", (unsigned) flags, + btrace_insn_number (begin), btrace_insn_number (end)); flags |= DISASSEMBLY_SPECULATIVE; @@ -720,7 +721,8 @@ btrace_insn_history (struct ui_out *uiout, /* The to_insn_history method of target record-btrace. */ static void -record_btrace_insn_history (struct target_ops *self, int size, int flags) +record_btrace_insn_history (struct target_ops *self, int size, + gdb_disassembly_flags flags) { struct btrace_thread_info *btinfo; struct btrace_insn_history *history; @@ -740,7 +742,7 @@ record_btrace_insn_history (struct target_ops *self, int size, int flags) { struct btrace_insn_iterator *replay; - DEBUG ("insn-history (0x%x): %d", flags, size); + DEBUG ("insn-history (0x%x): %d", (unsigned) flags, size); /* If we're replaying, we start at the replay position. Otherwise, we start at the tail of the trace. */ @@ -772,7 +774,7 @@ record_btrace_insn_history (struct target_ops *self, int size, int flags) begin = history->begin; end = history->end; - DEBUG ("insn-history (0x%x): %d, prev: [%u; %u)", flags, size, + DEBUG ("insn-history (0x%x): %d, prev: [%u; %u)", (unsigned) flags, size, btrace_insn_number (&begin), btrace_insn_number (&end)); if (size < 0) @@ -804,7 +806,8 @@ record_btrace_insn_history (struct target_ops *self, int size, int flags) static void record_btrace_insn_history_range (struct target_ops *self, - ULONGEST from, ULONGEST to, int flags) + ULONGEST from, ULONGEST to, + gdb_disassembly_flags flags) { struct btrace_thread_info *btinfo; struct btrace_insn_history *history; @@ -818,7 +821,7 @@ record_btrace_insn_history_range (struct target_ops *self, low = from; high = to; - DEBUG ("insn-history (0x%x): [%u; %u)", flags, low, high); + DEBUG ("insn-history (0x%x): [%u; %u)", (unsigned) flags, low, high); /* Check for wrap-arounds. */ if (low != from || high != to) @@ -853,7 +856,8 @@ record_btrace_insn_history_range (struct target_ops *self, static void record_btrace_insn_history_from (struct target_ops *self, - ULONGEST from, int size, int flags) + ULONGEST from, int size, + gdb_disassembly_flags flags) { ULONGEST begin, end, context; diff --git a/gdb/record.c b/gdb/record.c index 16e5b03..9ee3560 100644 --- a/gdb/record.c +++ b/gdb/record.c @@ -470,10 +470,10 @@ no_chunk (char *arg) /* Read instruction-history modifiers from an argument string. */ -static int +static gdb_disassembly_flags get_insn_history_modifiers (char **arg) { - int modifiers; + gdb_disassembly_flags modifiers; char *args; modifiers = 0; @@ -551,13 +551,11 @@ command_size_to_target_size (unsigned int size) static void cmd_record_insn_history (char *arg, int from_tty) { - int flags, size; - require_record_target (); - flags = get_insn_history_modifiers (&arg); + gdb_disassembly_flags flags = get_insn_history_modifiers (&arg); - size = command_size_to_target_size (record_insn_history_size); + int size = command_size_to_target_size (record_insn_history_size); if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0) target_insn_history (size, flags); diff --git a/gdb/target-debug.h b/gdb/target-debug.h index 532e98d..7477ce6 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -162,6 +162,8 @@ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_enum_remove_bp_reason(X) \ target_debug_do_print (plongest (X)) +#define target_debug_print_gdb_disassembly_flags(X) \ + target_debug_do_print (plongest (X)) static void target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status) diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 88e3e0b..4fc06ea 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -3854,20 +3854,20 @@ debug_goto_record (struct target_ops *self, ULONGEST arg1) } static void -delegate_insn_history (struct target_ops *self, int arg1, int arg2) +delegate_insn_history (struct target_ops *self, int arg1, gdb_disassembly_flags arg2) { self = self->beneath; self->to_insn_history (self, arg1, arg2); } static void -tdefault_insn_history (struct target_ops *self, int arg1, int arg2) +tdefault_insn_history (struct target_ops *self, int arg1, gdb_disassembly_flags arg2) { tcomplain (); } static void -debug_insn_history (struct target_ops *self, int arg1, int arg2) +debug_insn_history (struct target_ops *self, int arg1, gdb_disassembly_flags arg2) { fprintf_unfiltered (gdb_stdlog, "-> %s->to_insn_history (...)\n", debug_target.to_shortname); debug_target.to_insn_history (&debug_target, arg1, arg2); @@ -3876,25 +3876,25 @@ debug_insn_history (struct target_ops *self, int arg1, int arg2) fputs_unfiltered (", ", gdb_stdlog); target_debug_print_int (arg1); fputs_unfiltered (", ", gdb_stdlog); - target_debug_print_int (arg2); + target_debug_print_gdb_disassembly_flags (arg2); fputs_unfiltered (")\n", gdb_stdlog); } static void -delegate_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, int arg3) +delegate_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, gdb_disassembly_flags arg3) { self = self->beneath; self->to_insn_history_from (self, arg1, arg2, arg3); } static void -tdefault_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, int arg3) +tdefault_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, gdb_disassembly_flags arg3) { tcomplain (); } static void -debug_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, int arg3) +debug_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, gdb_disassembly_flags arg3) { fprintf_unfiltered (gdb_stdlog, "-> %s->to_insn_history_from (...)\n", debug_target.to_shortname); debug_target.to_insn_history_from (&debug_target, arg1, arg2, arg3); @@ -3905,25 +3905,25 @@ debug_insn_history_from (struct target_ops *self, ULONGEST arg1, int arg2, int a fputs_unfiltered (", ", gdb_stdlog); target_debug_print_int (arg2); fputs_unfiltered (", ", gdb_stdlog); - target_debug_print_int (arg3); + target_debug_print_gdb_disassembly_flags (arg3); fputs_unfiltered (")\n", gdb_stdlog); } static void -delegate_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, int arg3) +delegate_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, gdb_disassembly_flags arg3) { self = self->beneath; self->to_insn_history_range (self, arg1, arg2, arg3); } static void -tdefault_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, int arg3) +tdefault_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, gdb_disassembly_flags arg3) { tcomplain (); } static void -debug_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, int arg3) +debug_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, gdb_disassembly_flags arg3) { fprintf_unfiltered (gdb_stdlog, "-> %s->to_insn_history_range (...)\n", debug_target.to_shortname); debug_target.to_insn_history_range (&debug_target, arg1, arg2, arg3); @@ -3934,7 +3934,7 @@ debug_insn_history_range (struct target_ops *self, ULONGEST arg1, ULONGEST arg2, fputs_unfiltered (", ", gdb_stdlog); target_debug_print_ULONGEST (arg2); fputs_unfiltered (", ", gdb_stdlog); - target_debug_print_int (arg3); + target_debug_print_gdb_disassembly_flags (arg3); fputs_unfiltered (")\n", gdb_stdlog); } diff --git a/gdb/target.c b/gdb/target.c index 0624007..3312b89 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3794,7 +3794,7 @@ target_goto_record (ULONGEST insn) /* See target.h. */ void -target_insn_history (int size, int flags) +target_insn_history (int size, gdb_disassembly_flags flags) { current_target.to_insn_history (¤t_target, size, flags); } @@ -3802,7 +3802,8 @@ target_insn_history (int size, int flags) /* See target.h. */ void -target_insn_history_from (ULONGEST from, int size, int flags) +target_insn_history_from (ULONGEST from, int size, + gdb_disassembly_flags flags) { current_target.to_insn_history_from (¤t_target, from, size, flags); } @@ -3810,7 +3811,8 @@ target_insn_history_from (ULONGEST from, int size, int flags) /* See target.h. */ void -target_insn_history_range (ULONGEST begin, ULONGEST end, int flags) +target_insn_history_range (ULONGEST begin, ULONGEST end, + gdb_disassembly_flags flags) { current_target.to_insn_history_range (¤t_target, begin, end, flags); } diff --git a/gdb/target.h b/gdb/target.h index 5971151..796717f 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -74,6 +74,7 @@ struct inferior; #include "btrace.h" #include "record.h" #include "command.h" +#include "disasm.h" #include "break-common.h" /* For enum target_hw_bp_type. */ @@ -1200,7 +1201,8 @@ struct target_ops the current position. If SIZE < 0, disassemble abs (SIZE) preceding instructions; otherwise, disassemble SIZE succeeding instructions. */ - void (*to_insn_history) (struct target_ops *, int size, int flags) + void (*to_insn_history) (struct target_ops *, int size, + gdb_disassembly_flags flags) TARGET_DEFAULT_NORETURN (tcomplain ()); /* Disassemble SIZE instructions in the recorded execution trace around @@ -1208,13 +1210,15 @@ struct target_ops If SIZE < 0, disassemble abs (SIZE) instructions before FROM; otherwise, disassemble SIZE instructions after FROM. */ void (*to_insn_history_from) (struct target_ops *, - ULONGEST from, int size, int flags) + ULONGEST from, int size, + gdb_disassembly_flags flags) TARGET_DEFAULT_NORETURN (tcomplain ()); /* Disassemble a section of the recorded execution trace from instruction BEGIN (inclusive) to instruction END (inclusive). */ void (*to_insn_history_range) (struct target_ops *, - ULONGEST begin, ULONGEST end, int flags) + ULONGEST begin, ULONGEST end, + gdb_disassembly_flags flags) TARGET_DEFAULT_NORETURN (tcomplain ()); /* Print a function trace of the recorded execution trace. @@ -2509,13 +2513,15 @@ extern void target_goto_record_end (void); extern void target_goto_record (ULONGEST insn); /* See to_insn_history. */ -extern void target_insn_history (int size, int flags); +extern void target_insn_history (int size, gdb_disassembly_flags flags); /* See to_insn_history_from. */ -extern void target_insn_history_from (ULONGEST from, int size, int flags); +extern void target_insn_history_from (ULONGEST from, int size, + gdb_disassembly_flags flags); /* See to_insn_history_range. */ -extern void target_insn_history_range (ULONGEST begin, ULONGEST end, int flags); +extern void target_insn_history_range (ULONGEST begin, ULONGEST end, + gdb_disassembly_flags flags); /* See to_call_history. */ extern void target_call_history (int size, int flags); -- 2.7.4