Add casts for legitimate integer to enum conversions

This patch is mostly extracted from Pedro's C++ branch.  It adds explicit
casts from integer to enum types, where it is really the intention to do
so.  This could be because we are ...

 * iterating on enum values (we need to iterate on an equivalent integer)
 * converting from a value read from bytes (dwarf attribute, agent
 expression opcode) to the equivalent enum
 * reading the equivalent integer value from another language (Python/Guile)

An exception to that is the casts in regcache.c.  It seems to me like
struct regcache's register_status field could be a pointer to an array of
enum register_status.  Doing so would waste a bit of memory (4 bytes
used by the enum vs 1 byte used by the current signed char, for each
register).  If we switch to C++11 one day, we can define the underlying
type of an enum type, so we could have the best of both worlds.

gdb/ChangeLog:

	* arm-tdep.c (set_fp_model_sfunc): Add cast from integer to enum.
	(arm_set_abi): Likewise.
	* ax-general.c (ax_print): Likewise.
	* c-exp.y (exp : string_exp): Likewise.
	* compile/compile-loc2c.c (compute_stack_depth_worker): Likewise.
	(do_compile_dwarf_expr_to_c): Likewise.
	* cp-name-parser.y (demangler_special : DEMANGLER_SPECIAL start):
	Likewise.
	* dwarf2expr.c (execute_stack_op): Likewise.
	* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
	(disassemble_dwarf_expression): Likewise.
	* dwarf2read.c (dwarf2_add_member_fn): Likewise.
	(read_array_order): Likewise.
	(abbrev_table_read_table): Likewise.
	(read_attribute_value): Likewise.
	(skip_unknown_opcode): Likewise.
	(dwarf_decode_macro_bytes): Likewise.
	(dwarf_decode_macros): Likewise.
	* eval.c (value_f90_subarray): Likewise.
	* guile/scm-param.c (gdbscm_make_parameter): Likewise.
	* i386-linux-tdep.c (i386_canonicalize_syscall): Likewise.
	* infrun.c (handle_command): Likewise.
	* memory-map.c (memory_map_start_memory): Likewise.
	* osabi.c (set_osabi): Likewise.
	* parse.c (operator_length_standard): Likewise.
	* ppc-linux-tdep.c (ppc_canonicalize_syscall): Likewise, and use
	single return point.
	* python/py-frame.c (gdbpy_frame_stop_reason_string): Likewise.
	* python/py-symbol.c (gdbpy_lookup_symbol): Likewise.
	(gdbpy_lookup_global_symbol): Likewise.
	* record-full.c (record_full_restore): Likewise.
	* regcache.c (regcache_register_status): Likewise.
	(regcache_raw_read): Likewise.
	(regcache_cooked_read): Likewise.
	* rs6000-tdep.c (powerpc_set_vector_abi): Likewise.
	* symtab.c (initialize_ordinary_address_classes): Likewise.
	* target-debug.h (target_debug_print_signals): Likewise.
	* utils.c (do_restore_current_language): Likewise.
This commit is contained in:
Simon Marchi 2015-08-06 17:21:41 -04:00
parent 84da3f0cf9
commit aead7601eb
25 changed files with 119 additions and 57 deletions

View File

@ -1,3 +1,45 @@
2015-08-06 Simon Marchi <simon.marchi@ericsson.com>
Pedro Alves <palves@redhat.com>
* arm-tdep.c (set_fp_model_sfunc): Add cast from integer to enum.
(arm_set_abi): Likewise.
* ax-general.c (ax_print): Likewise.
* c-exp.y (exp : string_exp): Likewise.
* compile/compile-loc2c.c (compute_stack_depth_worker): Likewise.
(do_compile_dwarf_expr_to_c): Likewise.
* cp-name-parser.y (demangler_special : DEMANGLER_SPECIAL start):
Likewise.
* dwarf2expr.c (execute_stack_op): Likewise.
* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
(disassemble_dwarf_expression): Likewise.
* dwarf2read.c (dwarf2_add_member_fn): Likewise.
(read_array_order): Likewise.
(abbrev_table_read_table): Likewise.
(read_attribute_value): Likewise.
(skip_unknown_opcode): Likewise.
(dwarf_decode_macro_bytes): Likewise.
(dwarf_decode_macros): Likewise.
* eval.c (value_f90_subarray): Likewise.
* guile/scm-param.c (gdbscm_make_parameter): Likewise.
* i386-linux-tdep.c (i386_canonicalize_syscall): Likewise.
* infrun.c (handle_command): Likewise.
* memory-map.c (memory_map_start_memory): Likewise.
* osabi.c (set_osabi): Likewise.
* parse.c (operator_length_standard): Likewise.
* ppc-linux-tdep.c (ppc_canonicalize_syscall): Likewise, and use
single return point.
* python/py-frame.c (gdbpy_frame_stop_reason_string): Likewise.
* python/py-symbol.c (gdbpy_lookup_symbol): Likewise.
(gdbpy_lookup_global_symbol): Likewise.
* record-full.c (record_full_restore): Likewise.
* regcache.c (regcache_register_status): Likewise.
(regcache_raw_read): Likewise.
(regcache_cooked_read): Likewise.
* rs6000-tdep.c (powerpc_set_vector_abi): Likewise.
* symtab.c (initialize_ordinary_address_classes): Likewise.
* target-debug.h (target_debug_print_signals): Likewise.
* utils.c (do_restore_current_language): Likewise.
2015-08-06 Clem Dickey <clemd@acm.org>
PR python/17136

View File

@ -9408,7 +9408,7 @@ set_fp_model_sfunc (char *args, int from_tty,
for (fp_model = ARM_FLOAT_AUTO; fp_model != ARM_FLOAT_LAST; fp_model++)
if (strcmp (current_fp_model, fp_model_strings[fp_model]) == 0)
{
arm_fp_model = fp_model;
arm_fp_model = (enum arm_float_model) fp_model;
break;
}
@ -9445,7 +9445,7 @@ arm_set_abi (char *args, int from_tty,
for (arm_abi = ARM_ABI_AUTO; arm_abi != ARM_ABI_LAST; arm_abi++)
if (strcmp (arm_abi_string, arm_abi_strings[arm_abi]) == 0)
{
arm_abi_global = arm_abi;
arm_abi_global = (enum arm_abi_kind) arm_abi;
break;
}

View File

@ -391,7 +391,7 @@ ax_print (struct ui_file *f, struct agent_expr *x)
for (i = 0; i < x->len;)
{
enum agent_op op = x->buf[i];
enum agent_op op = (enum agent_op) x->buf[i];
if (op >= (sizeof (aop_map) / sizeof (aop_map[0]))
|| !aop_map[op].name)

View File

@ -878,7 +878,7 @@ exp : string_exp
if (type != C_STRING
&& type != $1.tokens[i].type)
error (_("Undefined string concatenation."));
type = $1.tokens[i].type;
type = (enum c_string_type) $1.tokens[i].type;
break;
default:
/* internal error */

View File

@ -85,7 +85,7 @@ compute_stack_depth_worker (int start, int *need_tempvar,
while (op_ptr < op_end)
{
enum dwarf_location_atom op = *op_ptr;
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
uint64_t reg;
int64_t offset;
int ndx = op_ptr - base;
@ -667,7 +667,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
while (op_ptr < op_end)
{
enum dwarf_location_atom op = *op_ptr;
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
uint64_t uoffset, reg;
int64_t offset;

View File

@ -432,7 +432,7 @@ function
demangler_special
: DEMANGLER_SPECIAL start
{ $$ = make_empty ($1);
{ $$ = make_empty ((enum demangle_component_type) $1);
d_left ($$) = $2;
d_right ($$) = NULL; }
| CONSTRUCTION_VTABLE start CONSTRUCTION_IN start

View File

@ -654,7 +654,7 @@ execute_stack_op (struct dwarf_expr_context *ctx,
while (op_ptr < op_end)
{
enum dwarf_location_atom op = *op_ptr++;
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr++;
ULONGEST result;
/* Assume the value is not in stack memory.
Code that knows otherwise sets this to 1.

View File

@ -2881,7 +2881,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
while (op_ptr < op_end)
{
enum dwarf_location_atom op = *op_ptr;
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
uint64_t uoffset, reg;
int64_t offset;
int i;
@ -3764,7 +3764,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
&& (all
|| (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
{
enum dwarf_location_atom op = *data++;
enum dwarf_location_atom op = (enum dwarf_location_atom) *data++;
uint64_t ul;
int64_t l;
const char *name;

View File

@ -12897,7 +12897,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
/* Get accessibility. */
attr = dwarf2_attr (die, DW_AT_accessibility, cu);
if (attr)
accessibility = DW_UNSND (attr);
accessibility = (enum dwarf_access_attribute) DW_UNSND (attr);
else
accessibility = dwarf2_default_access_attribute (die, cu);
switch (accessibility)
@ -13812,7 +13812,8 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_ordering, cu);
if (attr) return DW_SND (attr);
if (attr)
return (enum dwarf_array_dim_ordering) DW_SND (attr);
/* GNU F77 is a special case, as at 08/2004 array type info is the
opposite order to the dwarf2 specification, but data is still
@ -15345,7 +15346,8 @@ abbrev_table_read_table (struct dwarf2_section_info *section,
/* read in abbrev header */
cur_abbrev->number = abbrev_number;
cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
cur_abbrev->tag
= (enum dwarf_tag) read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
abbrev_ptr += bytes_read;
cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
abbrev_ptr += 1;
@ -15365,8 +15367,10 @@ abbrev_table_read_table (struct dwarf2_section_info *section,
* sizeof (struct attr_abbrev)));
}
cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
cur_attrs[cur_abbrev->num_attrs].name
= (enum dwarf_attribute) abbrev_name;
cur_attrs[cur_abbrev->num_attrs++].form
= (enum dwarf_form) abbrev_form;
abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
abbrev_ptr += bytes_read;
abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
@ -16210,7 +16214,7 @@ read_attribute_value (const struct die_reader_specs *reader,
unsigned int bytes_read;
struct dwarf_block *blk;
attr->form = form;
attr->form = (enum dwarf_form) form;
switch (form)
{
case DW_FORM_ref_addr:
@ -21170,7 +21174,8 @@ skip_unknown_opcode (unsigned int opcode,
for (i = 0; i < arg; ++i)
{
mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size,
mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end,
(enum dwarf_form) defn[i], offset_size,
section);
if (mac_ptr == NULL)
{
@ -21287,7 +21292,7 @@ dwarf_decode_macro_bytes (bfd *abfd,
break;
}
macinfo_type = read_1_byte (abfd, mac_ptr);
macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr);
mac_ptr++;
/* Note that we rely on the fact that the corresponding GNU and
@ -21427,7 +21432,9 @@ dwarf_decode_macro_bytes (bfd *abfd,
/* We don't increment mac_ptr here, so this is just
a look-ahead. */
next_type = read_1_byte (abfd, mac_ptr);
next_type
= (enum dwarf_macro_record_type) read_1_byte (abfd,
mac_ptr);
if (next_type != 0)
complaint (&symfile_complaints,
_("no terminating 0-type entry for "
@ -21603,7 +21610,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
break;
}
macinfo_type = read_1_byte (abfd, mac_ptr);
macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr);
mac_ptr++;
/* Note that we rely on the fact that the corresponding GNU and

View File

@ -406,7 +406,8 @@ value_f90_subarray (struct value *array,
int pc = (*pos) + 1;
LONGEST low_bound, high_bound;
struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
enum f90_range_type range_type
= (enum f90_range_type) longest_to_int (exp->elts[pc].longconst);
*pos += 3;

View File

@ -939,7 +939,7 @@ gdbscm_make_parameter (SCM name_scm, SCM rest)
/* These are all stored in GC space so that we don't have to worry about
freeing them if we throw an exception. */
p_smob->name = name;
p_smob->cmd_class = cmd_class;
p_smob->cmd_class = (enum command_class) cmd_class;
p_smob->type = (enum var_types) param_type;
p_smob->doc = doc;
p_smob->set_doc = set_doc;

View File

@ -379,7 +379,7 @@ i386_canonicalize_syscall (int syscall)
enum { i386_syscall_max = 499 };
if (syscall <= i386_syscall_max)
return syscall;
return (enum gdb_syscall) syscall;
else
return gdb_sys_no_syscall;
}

View File

@ -7054,7 +7054,7 @@ Are you sure you want to change it? "),
sig_print_header ();
for (; signum < nsigs; signum++)
if (sigs[signum])
sig_print_info (signum);
sig_print_info ((enum gdb_signal) signum);
}
break;

View File

@ -66,7 +66,7 @@ memory_map_start_memory (struct gdb_xml_parser *parser,
mem_region_init (r);
r->lo = *start_p;
r->hi = r->lo + *length_p;
r->attrib.mode = *type_p;
r->attrib.mode = (enum mem_access_mode) *type_p;
r->attrib.blocksize = -1;
}

View File

@ -626,12 +626,16 @@ set_osabi (char *args, int from_tty, struct cmd_list_element *c)
int i;
for (i = 1; i < GDB_OSABI_INVALID; i++)
if (strcmp (set_osabi_string, gdbarch_osabi_name (i)) == 0)
{
user_selected_osabi = i;
user_osabi_state = osabi_user;
break;
}
{
enum gdb_osabi osabi = (enum gdb_osabi) i;
if (strcmp (set_osabi_string, gdbarch_osabi_name (osabi)) == 0)
{
user_selected_osabi = osabi;
user_osabi_state = osabi_user;
break;
}
}
if (i == GDB_OSABI_INVALID)
internal_error (__FILE__, __LINE__,
_("Invalid OS ABI \"%s\" passed to command handler."),

View File

@ -1005,8 +1005,9 @@ operator_length_standard (const struct expression *expr, int endpos,
case OP_F90_RANGE:
oplen = 3;
range_type = (enum f90_range_type)
longest_to_int (expr->elts[endpos - 2].longconst);
range_type = longest_to_int (expr->elts[endpos - 2].longconst);
switch (range_type)
{
case LOW_BOUND_DEFAULT:

View File

@ -765,29 +765,32 @@ static struct linux_record_tdep ppc64_linux_record_tdep;
static enum gdb_syscall
ppc_canonicalize_syscall (int syscall)
{
int result = -1;
if (syscall <= 165)
return syscall;
result = syscall;
else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
return syscall + 1;
result = syscall + 1;
else if (syscall >= 192 && syscall <= 197) /* mmap2 */
return syscall;
result = syscall;
else if (syscall == 208) /* tkill */
return gdb_sys_tkill;
result = gdb_sys_tkill;
else if (syscall >= 207 && syscall <= 220) /* gettid */
return syscall + 224 - 207;
result = syscall + 224 - 207;
else if (syscall >= 234 && syscall <= 239) /* exit_group */
return syscall + 252 - 234;
else if (syscall >= 240 && syscall <=248) /* timer_create */
return syscall += 259 - 240;
else if (syscall >= 250 && syscall <=251) /* tgkill */
return syscall + 270 - 250;
result = syscall + 252 - 234;
else if (syscall >= 240 && syscall <= 248) /* timer_create */
result = syscall += 259 - 240;
else if (syscall >= 250 && syscall <= 251) /* tgkill */
result = syscall + 270 - 250;
else if (syscall == 336)
return gdb_sys_recv;
result = gdb_sys_recv;
else if (syscall == 337)
return gdb_sys_recvfrom;
result = gdb_sys_recvfrom;
else if (syscall == 342)
return gdb_sys_recvmsg;
return -1;
result = gdb_sys_recvmsg;
return (enum gdb_syscall) result;
}
/* Record registers which might be clobbered during system call.

View File

@ -666,7 +666,7 @@ gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
return NULL;
}
str = unwind_stop_reason_to_string (reason);
str = unwind_stop_reason_to_string ((enum unwind_stop_reason) reason);
return PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
}

View File

@ -396,7 +396,8 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
TRY
{
symbol = lookup_symbol (name, block, domain, &is_a_field_of_this).symbol;
symbol = lookup_symbol (name, block, (domain_enum) domain,
&is_a_field_of_this).symbol;
}
CATCH (except, RETURN_MASK_ALL)
{
@ -449,7 +450,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
TRY
{
symbol = lookup_global_symbol (name, NULL, domain).symbol;
symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
}
CATCH (except, RETURN_MASK_ALL)
{

View File

@ -2421,7 +2421,7 @@ record_full_restore (void)
bfdcore_read (core_bfd, osec, &signal,
sizeof (signal), &bfd_offset);
signal = netorder32 (signal);
rec->u.end.sigval = signal;
rec->u.end.sigval = (enum gdb_signal) signal;
/* Get insn count. */
bfdcore_read (core_bfd, osec, &count,

View File

@ -452,7 +452,7 @@ regcache_register_status (const struct regcache *regcache, int regnum)
else
gdb_assert (regnum < regcache->descr->nr_raw_registers);
return regcache->register_status[regnum];
return (enum register_status) regcache->register_status[regnum];
}
void
@ -664,7 +664,7 @@ regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
memcpy (buf, register_buffer (regcache, regnum),
regcache->descr->sizeof_register[regnum]);
return regcache->register_status[regnum];
return (enum register_status) regcache->register_status[regnum];
}
enum register_status
@ -751,7 +751,7 @@ regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
else
memset (buf, 0, regcache->descr->sizeof_register[regnum]);
return regcache->register_status[regnum];
return (enum register_status) regcache->register_status[regnum];
}
else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
{

View File

@ -6060,7 +6060,7 @@ powerpc_set_vector_abi (char *args, int from_tty,
if (strcmp (powerpc_vector_abi_string,
powerpc_vector_strings[vector_abi]) == 0)
{
powerpc_vector_abi_global = vector_abi;
powerpc_vector_abi_global = (enum powerpc_vector_abi) vector_abi;
break;
}

View File

@ -6151,7 +6151,7 @@ initialize_ordinary_address_classes (void)
int i;
for (i = 0; i < LOC_FINAL_VALUE; ++i)
symbol_impl[i].aclass = i;
symbol_impl[i].aclass = (enum address_class) i;
}

View File

@ -192,7 +192,10 @@ target_debug_print_signals (unsigned char *sigs)
for (i = 0; i < GDB_SIGNAL_LAST; i++)
if (sigs[i])
fprintf_unfiltered (gdb_stdlog, " %s", gdb_signal_to_name (i));
{
fprintf_unfiltered (gdb_stdlog, " %s",
gdb_signal_to_name ((enum gdb_signal) i));
}
}
fputs_unfiltered (" }", gdb_stdlog);
}

View File

@ -429,7 +429,7 @@ make_cleanup_free_so (struct so_list *so)
static void
do_restore_current_language (void *p)
{
enum language saved_lang = (uintptr_t) p;
enum language saved_lang = (enum language) (uintptr_t) p;
set_language (saved_lang);
}