]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
segment_report_module: Pull finish_portion() into file scope
authorTimm Bäder <tbaeder@redhat.com>
Thu, 26 Nov 2020 14:10:46 +0000 (15:10 +0100)
committerMark Wielaard <mark@klomp.org>
Sat, 28 Nov 2020 01:00:09 +0000 (02:00 +0100)
Use a read_state struct here to minimize the amount of parameters we
pass.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index 889e3ee8d1227007ea6906ca831bf51357895f6f..eb898ec8f798e5eb4961a1456f6962a4ce2c56ff 100644 (file)
@@ -1,3 +1,10 @@
+2020-11-26  Timm Bäder  <tbaeder@redhat.com>
+
+       * dwfl_segment_report_module.c (struct read_state): New.
+       (finish_portion): New static function.
+       (dwfl_segment_report_module): Introduce read_state. Remove
+       finish_portion function. Call static function with read_state.
+
 2020-11-23  Timm Bäder  <tbaeder@redhat.com>
 
        * segment_report_module.c (dwfl_segment_report_module): Remove
index 7e7471847b2fe3948f72f9aed634f338a11cdac9..391fd7617d7002b02fa36432bb8f54c27aa5cdbb 100644 (file)
@@ -61,6 +61,14 @@ struct elf_build_id
   GElf_Addr vaddr;
 };
 
+struct read_state
+{
+  Dwfl *dwfl;
+  Dwfl_Memory_Callback *memory_callback;
+  void *memory_callback_arg;
+  void **buffer;
+  size_t *buffer_available;
+};
 
 /* Return user segment index closest to ADDR but not above it.
    If NEXT, return the closest to ADDR but not below it.  */
@@ -239,6 +247,15 @@ invalid_elf (Elf *elf, bool disk_file_has_build_id,
   return false;
 }
 
+static void
+finish_portion (struct read_state *read_state,
+               void **data, size_t *data_size)
+{
+  if (*data_size != 0 && *data != NULL)
+    (*read_state->memory_callback) (read_state->dwfl, -1, data, data_size,
+                                   0, 0, read_state->memory_callback_arg);
+}
+
 int
 dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
                            Dwfl_Memory_Callback *memory_callback,
@@ -249,6 +266,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
                            const struct r_debug_info *r_debug_info)
 {
   size_t segment = ndx;
+  struct read_state read_state;
 
   if (segment >= dwfl->lookup_elts)
     segment = dwfl->lookup_elts - 1;
@@ -271,6 +289,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   Elf *elf = NULL;
   int fd = -1;
 
+  read_state.dwfl = dwfl;
+  read_state.memory_callback = memory_callback;
+  read_state.memory_callback_arg = memory_callback_arg;
+  read_state.buffer = &buffer;
+  read_state.buffer_available = &buffer_available;
+
   /* We might have to reserve some memory for the phdrs.  Set to NULL
      here so we can always safely free it.  */
   void *phdrsp = NULL;
@@ -306,12 +330,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
     return false;
   }
 
-  inline void finish_portion (void **data, size_t *data_size)
-  {
-    if (*data_size != 0 && *data != NULL)
-      (*memory_callback) (dwfl, -1, data, data_size, 0, 0, memory_callback_arg);
-  }
-
   /* Extract the information we need from the file header.  */
   const unsigned char *e_ident;
   unsigned char ei_class;
@@ -519,7 +537,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   done:
     if (notes != data)
       free (notes);
-    finish_portion (&data, &data_size);
+    finish_portion (&read_state, &data, &data_size);
   }
 
   Elf32_Phdr *p32 = phdrsp;
@@ -609,7 +627,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
         }
     }
 
-  finish_portion (&ph_buffer, &ph_buffer_size);
+  finish_portion (&read_state, &ph_buffer, &ph_buffer_size);
 
   /* We must have seen the segment covering offset 0, or else the ELF
      header we read at START was not produced by these program headers.  */
@@ -787,7 +805,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
         }
       free (dyns);
     }
-  finish_portion (&dyn_data, &dyn_data_size);
+  finish_portion (&read_state, &dyn_data, &dyn_data_size);
 
   /* We'll use the name passed in or a stupid default if not DT_SONAME.  */
   if (name == NULL)
@@ -848,7 +866,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   /* At this point we do not need BUILD_ID or NAME any more.
      They have been copied.  */
   free (build_id.memory);
-  finish_portion (&soname, &soname_size);
+  finish_portion (&read_state, &soname, &soname_size);
 
   if (unlikely (mod == NULL))
     {