summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2020-11-26 15:10:46 +0100
committerMark Wielaard <mark@klomp.org>2020-11-28 02:00:09 +0100
commit6e3e015ae2b1c2b3404edd0b1c976c48dbb3b693 (patch)
tree0dcac8446bee17ec73a8a8edc69bbace472bffbb /libdwfl
parentdebuginfod: correct prometheus metric typo (diff)
downloadelfutils-6e3e015ae2b1c2b3404edd0b1c976c48dbb3b693.tar.gz
elfutils-6e3e015ae2b1c2b3404edd0b1c976c48dbb3b693.tar.bz2
elfutils-6e3e015ae2b1c2b3404edd0b1c976c48dbb3b693.tar.xz
segment_report_module: Pull finish_portion() into file scope
Use a read_state struct here to minimize the amount of parameters we pass. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog7
-rw-r--r--libdwfl/dwfl_segment_report_module.c38
2 files changed, 35 insertions, 10 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 889e3ee8..eb898ec8 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,10 @@
12020-11-26 Timm Bäder <tbaeder@redhat.com>
2
3 * dwfl_segment_report_module.c (struct read_state): New.
4 (finish_portion): New static function.
5 (dwfl_segment_report_module): Introduce read_state. Remove
6 finish_portion function. Call static function with read_state.
7
12020-11-23 Timm Bäder <tbaeder@redhat.com> 82020-11-23 Timm Bäder <tbaeder@redhat.com>
2 9
3 * segment_report_module.c (dwfl_segment_report_module): Remove 10 * segment_report_module.c (dwfl_segment_report_module): Remove
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 7e747184..391fd761 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -61,6 +61,14 @@ struct elf_build_id
61 GElf_Addr vaddr; 61 GElf_Addr vaddr;
62}; 62};
63 63
64struct read_state
65{
66 Dwfl *dwfl;
67 Dwfl_Memory_Callback *memory_callback;
68 void *memory_callback_arg;
69 void **buffer;
70 size_t *buffer_available;
71};
64 72
65/* Return user segment index closest to ADDR but not above it. 73/* Return user segment index closest to ADDR but not above it.
66 If NEXT, return the closest to ADDR but not below it. */ 74 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,
239 return false; 247 return false;
240} 248}
241 249
250static void
251finish_portion (struct read_state *read_state,
252 void **data, size_t *data_size)
253{
254 if (*data_size != 0 && *data != NULL)
255 (*read_state->memory_callback) (read_state->dwfl, -1, data, data_size,
256 0, 0, read_state->memory_callback_arg);
257}
258
242int 259int
243dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, 260dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
244 Dwfl_Memory_Callback *memory_callback, 261 Dwfl_Memory_Callback *memory_callback,
@@ -249,6 +266,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
249 const struct r_debug_info *r_debug_info) 266 const struct r_debug_info *r_debug_info)
250{ 267{
251 size_t segment = ndx; 268 size_t segment = ndx;
269 struct read_state read_state;
252 270
253 if (segment >= dwfl->lookup_elts) 271 if (segment >= dwfl->lookup_elts)
254 segment = dwfl->lookup_elts - 1; 272 segment = dwfl->lookup_elts - 1;
@@ -271,6 +289,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
271 Elf *elf = NULL; 289 Elf *elf = NULL;
272 int fd = -1; 290 int fd = -1;
273 291
292 read_state.dwfl = dwfl;
293 read_state.memory_callback = memory_callback;
294 read_state.memory_callback_arg = memory_callback_arg;
295 read_state.buffer = &buffer;
296 read_state.buffer_available = &buffer_available;
297
274 /* We might have to reserve some memory for the phdrs. Set to NULL 298 /* We might have to reserve some memory for the phdrs. Set to NULL
275 here so we can always safely free it. */ 299 here so we can always safely free it. */
276 void *phdrsp = NULL; 300 void *phdrsp = NULL;
@@ -306,12 +330,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
306 return false; 330 return false;
307 } 331 }
308 332
309 inline void finish_portion (void **data, size_t *data_size)
310 {
311 if (*data_size != 0 && *data != NULL)
312 (*memory_callback) (dwfl, -1, data, data_size, 0, 0, memory_callback_arg);
313 }
314
315 /* Extract the information we need from the file header. */ 333 /* Extract the information we need from the file header. */
316 const unsigned char *e_ident; 334 const unsigned char *e_ident;
317 unsigned char ei_class; 335 unsigned char ei_class;
@@ -519,7 +537,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
519 done: 537 done:
520 if (notes != data) 538 if (notes != data)
521 free (notes); 539 free (notes);
522 finish_portion (&data, &data_size); 540 finish_portion (&read_state, &data, &data_size);
523 } 541 }
524 542
525 Elf32_Phdr *p32 = phdrsp; 543 Elf32_Phdr *p32 = phdrsp;
@@ -609,7 +627,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
609 } 627 }
610 } 628 }
611 629
612 finish_portion (&ph_buffer, &ph_buffer_size); 630 finish_portion (&read_state, &ph_buffer, &ph_buffer_size);
613 631
614 /* We must have seen the segment covering offset 0, or else the ELF 632 /* We must have seen the segment covering offset 0, or else the ELF
615 header we read at START was not produced by these program headers. */ 633 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,
787 } 805 }
788 free (dyns); 806 free (dyns);
789 } 807 }
790 finish_portion (&dyn_data, &dyn_data_size); 808 finish_portion (&read_state, &dyn_data, &dyn_data_size);
791 809
792 /* We'll use the name passed in or a stupid default if not DT_SONAME. */ 810 /* We'll use the name passed in or a stupid default if not DT_SONAME. */
793 if (name == NULL) 811 if (name == NULL)
@@ -848,7 +866,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
848 /* At this point we do not need BUILD_ID or NAME any more. 866 /* At this point we do not need BUILD_ID or NAME any more.
849 They have been copied. */ 867 They have been copied. */
850 free (build_id.memory); 868 free (build_id.memory);
851 finish_portion (&soname, &soname_size); 869 finish_portion (&read_state, &soname, &soname_size);
852 870
853 if (unlikely (mod == NULL)) 871 if (unlikely (mod == NULL))
854 { 872 {