Skip to content

Commit aead760

Browse files
author
Simon Marchi
committed
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.
1 parent 84da3f0 commit aead760

25 files changed

Lines changed: 119 additions & 57 deletions

gdb/ChangeLog

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
2015-08-06 Simon Marchi <[email protected]>
2+
Pedro Alves <[email protected]>
3+
4+
* arm-tdep.c (set_fp_model_sfunc): Add cast from integer to enum.
5+
(arm_set_abi): Likewise.
6+
* ax-general.c (ax_print): Likewise.
7+
* c-exp.y (exp : string_exp): Likewise.
8+
* compile/compile-loc2c.c (compute_stack_depth_worker): Likewise.
9+
(do_compile_dwarf_expr_to_c): Likewise.
10+
* cp-name-parser.y (demangler_special : DEMANGLER_SPECIAL start):
11+
Likewise.
12+
* dwarf2expr.c (execute_stack_op): Likewise.
13+
* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
14+
(disassemble_dwarf_expression): Likewise.
15+
* dwarf2read.c (dwarf2_add_member_fn): Likewise.
16+
(read_array_order): Likewise.
17+
(abbrev_table_read_table): Likewise.
18+
(read_attribute_value): Likewise.
19+
(skip_unknown_opcode): Likewise.
20+
(dwarf_decode_macro_bytes): Likewise.
21+
(dwarf_decode_macros): Likewise.
22+
* eval.c (value_f90_subarray): Likewise.
23+
* guile/scm-param.c (gdbscm_make_parameter): Likewise.
24+
* i386-linux-tdep.c (i386_canonicalize_syscall): Likewise.
25+
* infrun.c (handle_command): Likewise.
26+
* memory-map.c (memory_map_start_memory): Likewise.
27+
* osabi.c (set_osabi): Likewise.
28+
* parse.c (operator_length_standard): Likewise.
29+
* ppc-linux-tdep.c (ppc_canonicalize_syscall): Likewise, and use
30+
single return point.
31+
* python/py-frame.c (gdbpy_frame_stop_reason_string): Likewise.
32+
* python/py-symbol.c (gdbpy_lookup_symbol): Likewise.
33+
(gdbpy_lookup_global_symbol): Likewise.
34+
* record-full.c (record_full_restore): Likewise.
35+
* regcache.c (regcache_register_status): Likewise.
36+
(regcache_raw_read): Likewise.
37+
(regcache_cooked_read): Likewise.
38+
* rs6000-tdep.c (powerpc_set_vector_abi): Likewise.
39+
* symtab.c (initialize_ordinary_address_classes): Likewise.
40+
* target-debug.h (target_debug_print_signals): Likewise.
41+
* utils.c (do_restore_current_language): Likewise.
42+
143
2015-08-06 Clem Dickey <[email protected]>
244

345
PR python/17136

gdb/arm-tdep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9408,7 +9408,7 @@ set_fp_model_sfunc (char *args, int from_tty,
94089408
for (fp_model = ARM_FLOAT_AUTO; fp_model != ARM_FLOAT_LAST; fp_model++)
94099409
if (strcmp (current_fp_model, fp_model_strings[fp_model]) == 0)
94109410
{
9411-
arm_fp_model = fp_model;
9411+
arm_fp_model = (enum arm_float_model) fp_model;
94129412
break;
94139413
}
94149414

@@ -9445,7 +9445,7 @@ arm_set_abi (char *args, int from_tty,
94459445
for (arm_abi = ARM_ABI_AUTO; arm_abi != ARM_ABI_LAST; arm_abi++)
94469446
if (strcmp (arm_abi_string, arm_abi_strings[arm_abi]) == 0)
94479447
{
9448-
arm_abi_global = arm_abi;
9448+
arm_abi_global = (enum arm_abi_kind) arm_abi;
94499449
break;
94509450
}
94519451

gdb/ax-general.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ ax_print (struct ui_file *f, struct agent_expr *x)
391391

392392
for (i = 0; i < x->len;)
393393
{
394-
enum agent_op op = x->buf[i];
394+
enum agent_op op = (enum agent_op) x->buf[i];
395395

396396
if (op >= (sizeof (aop_map) / sizeof (aop_map[0]))
397397
|| !aop_map[op].name)

gdb/c-exp.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ exp : string_exp
878878
if (type != C_STRING
879879
&& type != $1.tokens[i].type)
880880
error (_("Undefined string concatenation."));
881-
type = $1.tokens[i].type;
881+
type = (enum c_string_type) $1.tokens[i].type;
882882
break;
883883
default:
884884
/* internal error */

gdb/compile/compile-loc2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ compute_stack_depth_worker (int start, int *need_tempvar,
8585

8686
while (op_ptr < op_end)
8787
{
88-
enum dwarf_location_atom op = *op_ptr;
88+
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
8989
uint64_t reg;
9090
int64_t offset;
9191
int ndx = op_ptr - base;
@@ -667,7 +667,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
667667

668668
while (op_ptr < op_end)
669669
{
670-
enum dwarf_location_atom op = *op_ptr;
670+
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
671671
uint64_t uoffset, reg;
672672
int64_t offset;
673673

gdb/cp-name-parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function
432432

433433
demangler_special
434434
: DEMANGLER_SPECIAL start
435-
{ $$ = make_empty ($1);
435+
{ $$ = make_empty ((enum demangle_component_type) $1);
436436
d_left ($$) = $2;
437437
d_right ($$) = NULL; }
438438
| CONSTRUCTION_VTABLE start CONSTRUCTION_IN start

gdb/dwarf2expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ execute_stack_op (struct dwarf_expr_context *ctx,
654654

655655
while (op_ptr < op_end)
656656
{
657-
enum dwarf_location_atom op = *op_ptr++;
657+
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr++;
658658
ULONGEST result;
659659
/* Assume the value is not in stack memory.
660660
Code that knows otherwise sets this to 1.

gdb/dwarf2loc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
28812881

28822882
while (op_ptr < op_end)
28832883
{
2884-
enum dwarf_location_atom op = *op_ptr;
2884+
enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
28852885
uint64_t uoffset, reg;
28862886
int64_t offset;
28872887
int i;
@@ -3764,7 +3764,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
37643764
&& (all
37653765
|| (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
37663766
{
3767-
enum dwarf_location_atom op = *data++;
3767+
enum dwarf_location_atom op = (enum dwarf_location_atom) *data++;
37683768
uint64_t ul;
37693769
int64_t l;
37703770
const char *name;

gdb/dwarf2read.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12897,7 +12897,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
1289712897
/* Get accessibility. */
1289812898
attr = dwarf2_attr (die, DW_AT_accessibility, cu);
1289912899
if (attr)
12900-
accessibility = DW_UNSND (attr);
12900+
accessibility = (enum dwarf_access_attribute) DW_UNSND (attr);
1290112901
else
1290212902
accessibility = dwarf2_default_access_attribute (die, cu);
1290312903
switch (accessibility)
@@ -13812,7 +13812,8 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
1381213812

1381313813
attr = dwarf2_attr (die, DW_AT_ordering, cu);
1381413814

13815-
if (attr) return DW_SND (attr);
13815+
if (attr)
13816+
return (enum dwarf_array_dim_ordering) DW_SND (attr);
1381613817

1381713818
/* GNU F77 is a special case, as at 08/2004 array type info is the
1381813819
opposite order to the dwarf2 specification, but data is still
@@ -15345,7 +15346,8 @@ abbrev_table_read_table (struct dwarf2_section_info *section,
1534515346

1534615347
/* read in abbrev header */
1534715348
cur_abbrev->number = abbrev_number;
15348-
cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
15349+
cur_abbrev->tag
15350+
= (enum dwarf_tag) read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
1534915351
abbrev_ptr += bytes_read;
1535015352
cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
1535115353
abbrev_ptr += 1;
@@ -15365,8 +15367,10 @@ abbrev_table_read_table (struct dwarf2_section_info *section,
1536515367
* sizeof (struct attr_abbrev)));
1536615368
}
1536715369

15368-
cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
15369-
cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
15370+
cur_attrs[cur_abbrev->num_attrs].name
15371+
= (enum dwarf_attribute) abbrev_name;
15372+
cur_attrs[cur_abbrev->num_attrs++].form
15373+
= (enum dwarf_form) abbrev_form;
1537015374
abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
1537115375
abbrev_ptr += bytes_read;
1537215376
abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
@@ -16210,7 +16214,7 @@ read_attribute_value (const struct die_reader_specs *reader,
1621016214
unsigned int bytes_read;
1621116215
struct dwarf_block *blk;
1621216216

16213-
attr->form = form;
16217+
attr->form = (enum dwarf_form) form;
1621416218
switch (form)
1621516219
{
1621616220
case DW_FORM_ref_addr:
@@ -21170,7 +21174,8 @@ skip_unknown_opcode (unsigned int opcode,
2117021174

2117121175
for (i = 0; i < arg; ++i)
2117221176
{
21173-
mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size,
21177+
mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end,
21178+
(enum dwarf_form) defn[i], offset_size,
2117421179
section);
2117521180
if (mac_ptr == NULL)
2117621181
{
@@ -21287,7 +21292,7 @@ dwarf_decode_macro_bytes (bfd *abfd,
2128721292
break;
2128821293
}
2128921294

21290-
macinfo_type = read_1_byte (abfd, mac_ptr);
21295+
macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr);
2129121296
mac_ptr++;
2129221297

2129321298
/* Note that we rely on the fact that the corresponding GNU and
@@ -21427,7 +21432,9 @@ dwarf_decode_macro_bytes (bfd *abfd,
2142721432

2142821433
/* We don't increment mac_ptr here, so this is just
2142921434
a look-ahead. */
21430-
next_type = read_1_byte (abfd, mac_ptr);
21435+
next_type
21436+
= (enum dwarf_macro_record_type) read_1_byte (abfd,
21437+
mac_ptr);
2143121438
if (next_type != 0)
2143221439
complaint (&symfile_complaints,
2143321440
_("no terminating 0-type entry for "
@@ -21603,7 +21610,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
2160321610
break;
2160421611
}
2160521612

21606-
macinfo_type = read_1_byte (abfd, mac_ptr);
21613+
macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr);
2160721614
mac_ptr++;
2160821615

2160921616
/* Note that we rely on the fact that the corresponding GNU and

gdb/eval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ value_f90_subarray (struct value *array,
406406
int pc = (*pos) + 1;
407407
LONGEST low_bound, high_bound;
408408
struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
409-
enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
409+
enum f90_range_type range_type
410+
= (enum f90_range_type) longest_to_int (exp->elts[pc].longconst);
410411

411412
*pos += 3;
412413

0 commit comments

Comments
 (0)