[PATCH 02/14] segment_report_module: Pull segment_read into file scope

Timm Bäder tbaeder@redhat.com
Thu Nov 12 15:04:00 GMT 2020


In preparation of getting rid of nested functions

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 libdwfl/dwfl_segment_report_module.c | 30 +++++++++++++++++-----------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index dd3fdb9e..9f06672a 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -232,6 +232,16 @@ invalid_elf (Elf *elf, bool disk_file_has_build_id,
   return false;
 }
 
+static inline bool
+segment_read (Dwfl *dwfl,
+              Dwfl_Memory_Callback *memory_callback, void *memory_callback_arg,
+              int segndx, void **buffer, size_t *buffer_available,
+              GElf_Addr addr, size_t minread)
+{
+  return ! (*memory_callback) (dwfl, segndx, buffer, buffer_available,
+                               addr, minread, memory_callback_arg);
+}
+
 int
 dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 			    Dwfl_Memory_Callback *memory_callback,
@@ -257,18 +267,11 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 
   GElf_Addr start = dwfl->lookup_addr[segment];
 
-  inline bool segment_read (int segndx,
-			    void **buffer, size_t *buffer_available,
-			    GElf_Addr addr, size_t minread)
-  {
-    return ! (*memory_callback) (dwfl, segndx, buffer, buffer_available,
-				 addr, minread, memory_callback_arg);
-  }
-
   inline void release_buffer (void **buffer, size_t *buffer_available)
   {
     if (*buffer != NULL)
-      (void) segment_read (-1, buffer, buffer_available, 0, 0);
+      (void) segment_read (dwfl, memory_callback, memory_callback_arg,
+                           -1, buffer, buffer_available, 0, 0);
   }
 
   /* First read in the file header and check its sanity.  */
@@ -293,7 +296,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
     return ndx;
   }
 
-  if (segment_read (ndx, &buffer, &buffer_available,
+  if (segment_read (dwfl, memory_callback, memory_callback_arg,
+                    ndx, &buffer, &buffer_available,
 		    start, sizeof (Elf64_Ehdr))
       || memcmp (buffer, ELFMAG, SELFMAG) != 0)
     return finish ();
@@ -312,7 +316,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       {
 	*data = NULL;
 	*data_size = filesz;
-	return segment_read (addr_segndx (dwfl, segment, vaddr, false),
+	return segment_read (dwfl, memory_callback, memory_callback_arg,
+                             addr_segndx (dwfl, segment, vaddr, false),
 			     data, data_size, vaddr, filesz);
       }
 
@@ -919,7 +924,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       {
 	void *into = contents + offset;
 	size_t read_size = size;
-	(void) segment_read (addr_segndx (dwfl, segment, vaddr, false),
+	(void) segment_read (dwfl, memory_callback, memory_callback_arg,
+                             addr_segndx (dwfl, segment, vaddr, false),
 			     &into, &read_size, vaddr, size);
       }
 
-- 
2.26.2



More information about the Elfutils-devel mailing list