From: Timm Bäder Date: Tue, 2 Feb 2021 10:23:24 +0000 (+0100) Subject: readelf: Remove show_op_index variable X-Git-Tag: elfutils-0.183~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f36ac0f291356912106d06bb851b36baf0351e0f;p=thirdparty%2Felfutils.git readelf: Remove show_op_index variable advance_pc() uses show_op_index to save whether the current op_index is > 0 OR the new op_index is > 0. The new op index is calculated via new_op_index = (op_index + op_advance) % max_ops_per_instr; since all of the variables involved are unsigned, new_op_index >= op_index is always true. So... if op_index > 0, then new_op_index > 0 if op_index == 0, then new_op_index >= 0 and if the new_op_index is > 0, then the old one was as well. In any case, we only need to check the new_op_index, since show_op_index used to OR the two comparisons. In other words: op_index > 0 | new_op_index > 0 || show_op_index ------------------------------------------------ true true true false true true true false true xx false false false ... but since the third line (marked with xx) is not possible, the table becomes: op_index > 0 | new_op_index > 0 || show_op_index ------------------------------------------------ true true true false true true false false false ... and show_op_index is equal to (new_op_index > 0). So, remove the show_op_index variable and simply replace it by comparing the new op_index > 0. --- diff --git a/src/ChangeLog b/src/ChangeLog index 1f53ca7bc..9e30df31c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2021-02-02 Timm Bäder + + * readelf.c (print_debug_line_section): Remove unnecessary + show_op_index variable, replace with (op_index > 0). + 2021-01-08 Timm Bäder * readelf.c (print_cfa_program): Lift regname function to... diff --git a/src/readelf.c b/src/readelf.c index 9943c2114..11692bb5b 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -8752,14 +8752,11 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, /* Apply the "operation advance" from a special opcode or DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */ unsigned int op_addr_advance; - bool show_op_index; inline void advance_pc (unsigned int op_advance) { op_addr_advance = minimum_instr_len * ((op_index + op_advance) / max_ops_per_instr); address += op_addr_advance; - show_op_index = (op_index > 0 || - (op_index + op_advance) % max_ops_per_instr > 0); op_index = (op_index + op_advance) % max_ops_per_instr; } @@ -8803,7 +8800,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, printf (_(" special opcode %u: address+%u = "), opcode, op_addr_advance); print_dwarf_addr (dwflmod, 0, address, address); - if (show_op_index) + if (op_index > 0) printf (_(", op_index = %u, line%+d = %zu\n"), op_index, line_increment, line); else @@ -8921,7 +8918,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, printf (_(" advance address by %u to "), op_addr_advance); print_dwarf_addr (dwflmod, 0, address, address); - if (show_op_index) + if (op_index > 0) printf (_(", op_index to %u"), op_index); printf ("\n"); } @@ -8982,7 +8979,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, printf (_(" advance address by constant %u to "), op_addr_advance); print_dwarf_addr (dwflmod, 0, address, address); - if (show_op_index) + if (op_index > 0) printf (_(", op_index to %u"), op_index); printf ("\n"); }