From: Timm Bäder <tbae...@redhat.com>

Get rid of a nested function this way

Signed-off-by: Timm Bäder <tbae...@redhat.com>
---
 src/readelf.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index e0163891..9758d338 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8356,6 +8356,23 @@ print_form_data (Dwarf *dbg, int form, const unsigned 
char *readp,
   return readp;
 }
 
+static inline void
+advance_pc (unsigned int op_advance,
+           uint_fast8_t max_ops_per_instr,
+           uint_fast8_t minimum_instr_len,
+           Dwarf_Word *address,
+           unsigned int *op_addr_advance,
+           unsigned int *op_index,
+           bool *show_op_index)
+{
+  *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;
+}
+
 static void
 print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
                          Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
@@ -8747,15 +8764,6 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl 
*ebl, GElf_Ehdr *ehdr,
         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;
-      }
 
       if (max_ops_per_instr == 0)
        {
@@ -8792,7 +8800,9 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, 
GElf_Ehdr *ehdr,
 
              /* Perform the increments.  */
              line += line_increment;
-             advance_pc ((opcode - opcode_base) / line_range);
+             advance_pc ((opcode - opcode_base) / line_range,
+                         max_ops_per_instr, minimum_instr_len, &address,
+                         &op_addr_advance, &op_index, &show_op_index);
 
              printf (_(" special opcode %u: address+%u = "),
                      opcode, op_addr_advance);
@@ -8910,7 +8920,9 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, 
GElf_Ehdr *ehdr,
                  if (lineendp - linep < 1)
                    goto invalid_unit;
                  get_uleb128 (u128, linep, lineendp);
-                 advance_pc (u128);
+                 advance_pc (u128, max_ops_per_instr, minimum_instr_len,
+                             &address, &op_addr_advance, &op_index,
+                             &show_op_index);
                  {
                    printf (_(" advance address by %u to "),
                            op_addr_advance);
@@ -8971,7 +8983,10 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl 
*ebl, GElf_Ehdr *ehdr,
                  if (unlikely (line_range == 0))
                    goto invalid_unit;
 
-                 advance_pc ((255 - opcode_base) / line_range);
+                 advance_pc ((255 - opcode_base) / line_range,
+                             max_ops_per_instr, minimum_instr_len,
+                             &address, &op_addr_advance, &op_index,
+                             &show_op_index);
                  {
                    printf (_(" advance address by constant %u to "),
                            op_addr_advance);
-- 
2.26.2

Reply via email to