]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Pull advance_pc() in file scope
authorTimm Bäder <tbaeder@redhat.com>
Thu, 18 Mar 2021 09:25:24 +0000 (10:25 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 15 Jul 2021 12:06:52 +0000 (14:06 +0200)
Make advance_pc() a static function so we can get rid of another nested
function. Rename it to run_advance_pc() and use a local advance_pc()
macro to pass all the local variables. This is similar to what the
equivalent code in libdw/dwarf_getsrclines.c is doing.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
src/ChangeLog
src/readelf.c

index cfbcfd48bbfb6a5c7e1da1ee221218ff7ab8fb6b..312bc50339b4d0b43be00bf090bb126e7295b7d7 100644 (file)
@@ -1,3 +1,10 @@
+2021-03-18  Timm Bäder  <tbaeder@redhat.com>
+
+       * readelf.c (run_advance_pc): New static inline function
+       lifted from...
+       (print_debug_line_section): ... here. Define advance_pc
+       using run_advance_pc.
+
 2021-07-03  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (compare_listptr): Fix dwarf_attr_name argument.
index 161d7e655c47d1643d068e542d945f9b36631eb0..8191bde251ddb2a22d6014b442f2d62bddd32476 100644 (file)
@@ -8373,6 +8373,23 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp,
   return readp;
 }
 
+/* Only used via run_advance_pc() macro */
+static inline void
+run_advance_pc (unsigned int op_advance,
+                unsigned int minimum_instr_len,
+                unsigned int max_ops_per_instr,
+                unsigned int *op_addr_advance,
+                Dwarf_Word *address,
+                unsigned int *op_index)
+{
+  const unsigned int advanced_op_index = (*op_index) + op_advance;
+
+  *op_addr_advance = minimum_instr_len * (advanced_op_index
+                                         / max_ops_per_instr);
+  *address = *address + *op_addr_advance;
+  *op_index = advanced_op_index % 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)
@@ -8763,13 +8780,8 @@ 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;
-      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;
-       op_index = (op_index + op_advance) % max_ops_per_instr;
-      }
+#define advance_pc(op_advance) run_advance_pc(op_advance, minimum_instr_len, \
+                      max_ops_per_instr, &op_addr_advance, &address, &op_index)
 
       if (max_ops_per_instr == 0)
        {