* [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback
@ 2026-03-10 17:30 simon.marchi
2026-03-10 17:30 ` [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls simon.marchi
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: simon.marchi @ 2026-03-10 17:30 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
From: Simon Marchi <simon.marchi@polymtl.ca>
I noticed that linux_find_memory_regions_full did not check the return
value of the linux_find_memory_region_ftype callback. I think this is a
mistake. When called from linux_find_memory_regions, the
find_memory_region_ftype callback could return false, in which case we
should stop iterating.
This probably didn't matter in practice, as these callbacks generally
don't return false (only in error cases that never happen).
Change-Id: Iafc5a9aae3d955454420d700a23f18de6f0bc267
---
gdb/linux-tdep.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 495dd0680384..53ee6d9579cc 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1637,15 +1637,12 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
for (const struct smaps_data &map : smaps)
{
/* Invoke the callback function to create the corefile segment. */
- if (should_dump_mapping_p (filterflags, map))
- {
- func (map.start_address, map.end_address - map.start_address,
- map.offset, map.read, map.write, map.exec,
- true, /* MODIFIED is true because we want to dump
- the mapping. */
- map.vmflags.memory_tagging != 0,
- map.filename, obfd);
- }
+ if (should_dump_mapping_p (filterflags, map)
+ && !func (map.start_address, map.end_address - map.start_address,
+ map.offset, map.read, map.write, map.exec,
+ /* MODIFIED is true because we want to dump the mapping. */
+ true, map.vmflags.memory_tagging != 0, map.filename, obfd))
+ return false;
}
return true;
base-commit: 1add703e09f0f8d073cde4af9d11cd59996e9763
--
2.53.0
^ permalink raw reply [flat|nested] 15+ messages in thread* [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls 2026-03-10 17:30 [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback simon.marchi @ 2026-03-10 17:30 ` simon.marchi 2026-03-13 18:21 ` Tom Tromey 2026-03-10 17:30 ` [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view simon.marchi ` (3 subsequent siblings) 4 siblings, 1 reply; 15+ messages in thread From: simon.marchi @ 2026-03-10 17:30 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi From: Simon Marchi <simon.marchi@polymtl.ca> This fixes some spots that didn't check the return value of a find_memory_region_ftype callback. Change-Id: Ic57933ce76709ca16c93bc66c21da97afb3163a2 --- gdb/gcore.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/gdb/gcore.c b/gdb/gcore.c index 7c6d5f8667f7..2bf300c0d29f 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -558,25 +558,27 @@ objfile_find_memory_regions (struct target_ops *self, } /* Make a stack segment. */ - if (derive_stack_segment (&temp_bottom, &temp_top)) - (*func) (temp_bottom, temp_top - temp_bottom, - true, /* Stack section will be readable. */ - true, /* Stack section will be writable. */ - false, /* Stack section will not be executable. */ - true, /* Stack section will be modified. */ - false, /* No memory tags in the object file. */ - obfd); + if (derive_stack_segment (&temp_bottom, &temp_top) + && !func (temp_bottom, temp_top - temp_bottom, + true, /* Stack section will be readable. */ + true, /* Stack section will be writable. */ + false, /* Stack section will not be executable. */ + true, /* Stack section will be modified. */ + false, /* No memory tags in the object file. */ + obfd)) + return false; /* Make a heap segment. */ if (derive_heap_segment (current_program_space->exec_bfd (), &temp_bottom, - &temp_top)) - (*func) (temp_bottom, temp_top - temp_bottom, - true, /* Heap section will be readable. */ - true, /* Heap section will be writable. */ - false, /* Heap section will not be executable. */ - true, /* Heap section will be modified. */ - false, /* No memory tags in the object file. */ - obfd); + &temp_top) + && !func (temp_bottom, temp_top - temp_bottom, + true, /* Heap section will be readable. */ + true, /* Heap section will be writable. */ + false, /* Heap section will not be executable. */ + true, /* Heap section will be modified. */ + false, /* No memory tags in the object file. */ + obfd)) + return false; return true; } -- 2.53.0 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls 2026-03-10 17:30 ` [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls simon.marchi @ 2026-03-13 18:21 ` Tom Tromey 0 siblings, 0 replies; 15+ messages in thread From: Tom Tromey @ 2026-03-13 18:21 UTC (permalink / raw) To: simon.marchi; +Cc: gdb-patches >>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: Simon> From: Simon Marchi <simon.marchi@polymtl.ca> Simon> This fixes some spots that didn't check the return value of a Simon> find_memory_region_ftype callback. Thanks. Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view 2026-03-10 17:30 [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback simon.marchi 2026-03-10 17:30 ` [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls simon.marchi @ 2026-03-10 17:30 ` simon.marchi 2026-03-13 18:25 ` Tom Tromey 2026-03-10 17:30 ` [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef simon.marchi ` (2 subsequent siblings) 4 siblings, 1 reply; 15+ messages in thread From: simon.marchi @ 2026-03-10 17:30 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi From: Simon Marchi <simon.marchi@polymtl.ca> Make it a function_view and eliminate the `void *` callback data. Change the callback functions to lambda functions where they are used. Change-Id: I239b3650783fa06320f85c2a63273346af81344f --- gdb/linux-tdep.c | 153 ++++++++++++----------------------------------- 1 file changed, 39 insertions(+), 114 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 53ee6d9579cc..36b7cc95b4eb 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1365,12 +1365,9 @@ linux_core_xfer_siginfo (struct gdbarch *gdbarch, struct bfd &cbfd, return len; } -typedef bool linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size, - ULONGEST offset, bool read, - bool write, bool exec, - bool modified, bool memory_tagged, - const std::string &filename, - void *data); +using linux_find_memory_region_ftype + = gdb::function_view<bool (ULONGEST, ULONGEST, ULONGEST, bool, bool, bool, + bool, bool, const std::string &)>; typedef bool linux_dump_mapping_p_ftype (filter_flags filterflags, const smaps_data &map); @@ -1580,8 +1577,7 @@ linux_address_in_memtag_page (CORE_ADDR address) static bool linux_find_memory_regions_full (struct gdbarch *gdbarch, linux_dump_mapping_p_ftype *should_dump_mapping_p, - linux_find_memory_region_ftype *func, - void *obfd) + linux_find_memory_region_ftype func) { pid_t pid; /* Default dump behavior of coredump_filter (0x33), according to @@ -1641,111 +1637,29 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, && !func (map.start_address, map.end_address - map.start_address, map.offset, map.read, map.write, map.exec, /* MODIFIED is true because we want to dump the mapping. */ - true, map.vmflags.memory_tagging != 0, map.filename, obfd)) + true, map.vmflags.memory_tagging != 0, map.filename)) return false; } return true; } -/* A structure for passing information through - linux_find_memory_regions_full. */ - -struct linux_find_memory_regions_data -{ - /* The original callback. */ - - find_memory_region_ftype func; - - /* The original datum. */ - - void *obfd; -}; - -/* A callback for linux_find_memory_regions that converts between the - "full"-style callback and find_memory_region_ftype. */ - -static bool -linux_find_memory_regions_thunk (ULONGEST vaddr, ULONGEST size, - ULONGEST offset, - bool read, bool write, bool exec, - bool modified, bool memory_tagged, - const std::string &filename, void *arg) -{ - struct linux_find_memory_regions_data *data - = (struct linux_find_memory_regions_data *) arg; - - return data->func (vaddr, size, read, write, exec, modified, memory_tagged, - data->obfd); -} - /* A variant of linux_find_memory_regions_full that is suitable as the gdbarch find_memory_regions method. */ static bool linux_find_memory_regions (struct gdbarch *gdbarch, - find_memory_region_ftype func, void *obfd) -{ - struct linux_find_memory_regions_data data; - - data.func = func; - data.obfd = obfd; - - return linux_find_memory_regions_full (gdbarch, - dump_mapping_p, - linux_find_memory_regions_thunk, - &data); -} - -/* This is used to pass information from - linux_make_mappings_corefile_notes through - linux_find_memory_regions_full. */ - -struct linux_make_mappings_data -{ - /* Number of files mapped. */ - ULONGEST file_count; - - /* The obstack for the main part of the data. */ - struct obstack *data_obstack; - - /* The filename obstack. */ - struct obstack *filename_obstack; - - /* The architecture's "long" type. */ - struct type *long_type; -}; - -/* A callback for linux_find_memory_regions_full that updates the - mappings data for linux_make_mappings_corefile_notes. - - MEMORY_TAGGED is true if the memory region contains memory tags, false - otherwise. */ - -static bool -linux_make_mappings_callback (ULONGEST vaddr, ULONGEST size, ULONGEST offset, - bool read, bool write, bool exec, bool modified, - bool memory_tagged, const std::string &filename, - void *data) + find_memory_region_ftype func, void *data) { - struct linux_make_mappings_data *map_data - = (struct linux_make_mappings_data *) data; - gdb_byte buf[sizeof (ULONGEST)]; - - gdb_assert (filename.length () > 0); - - ++map_data->file_count; - - pack_long (buf, map_data->long_type, vaddr); - obstack_grow (map_data->data_obstack, buf, map_data->long_type->length ()); - pack_long (buf, map_data->long_type, vaddr + size); - obstack_grow (map_data->data_obstack, buf, map_data->long_type->length ()); - pack_long (buf, map_data->long_type, offset); - obstack_grow (map_data->data_obstack, buf, map_data->long_type->length ()); - - obstack_grow_str0 (map_data->filename_obstack, filename.c_str ()); + auto cb = [&] (ULONGEST vaddr, ULONGEST size, ULONGEST offset, bool read, + bool write, bool exec, bool modified, bool memory_tagged, + const std::string &filename) + { + return func (vaddr, size, read, write, exec, modified, memory_tagged, + data); + }; - return true; + return linux_find_memory_regions_full (gdbarch, dump_mapping_p, cb); } /* Write the file mapping data to the core file, if possible. OBFD is @@ -1757,18 +1671,12 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, gdb::unique_xmalloc_ptr<char> ¬e_data, int *note_size) { - struct linux_make_mappings_data mapping_data; type_allocator alloc (gdbarch); struct type *long_type = init_integer_type (alloc, gdbarch_long_bit (gdbarch), 0, "long"); gdb_byte buf[sizeof (ULONGEST)]; - auto_obstack data_obstack, filename_obstack; - - mapping_data.file_count = 0; - mapping_data.data_obstack = &data_obstack; - mapping_data.filename_obstack = &filename_obstack; - mapping_data.long_type = long_type; + ULONGEST file_count = 0; /* Reserve space for the count. */ obstack_blank (&data_obstack, long_type->length ()); @@ -1777,16 +1685,33 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, pack_long (buf, long_type, 1); obstack_grow (&data_obstack, buf, long_type->length ()); - linux_find_memory_regions_full (gdbarch, - dump_note_entry_p, - linux_make_mappings_callback, - &mapping_data); + auto cb = [&] (ULONGEST vaddr, ULONGEST size, ULONGEST offset, bool read, + bool write, bool exec, bool modified, bool memory_tagged, + const std::string &filename) + { + gdb_assert (filename.length () > 0); + + ++file_count; + + pack_long (buf, long_type, vaddr); + obstack_grow (&data_obstack, buf, long_type->length ()); + pack_long (buf, long_type, vaddr + size); + obstack_grow (&data_obstack, buf, long_type->length ()); + pack_long (buf, long_type, offset); + obstack_grow (&data_obstack, buf, long_type->length ()); + + obstack_grow_str0 (&filename_obstack, filename.c_str ()); + + return true; + }; + + linux_find_memory_regions_full (gdbarch, dump_note_entry_p, cb); - if (mapping_data.file_count != 0) + if (file_count != 0) { /* Write the count to the obstack. */ - pack_long ((gdb_byte *) obstack_base (&data_obstack), - long_type, mapping_data.file_count); + pack_long ((gdb_byte *) obstack_base (&data_obstack), long_type, + file_count); /* Copy the filenames to the data obstack. */ int size = obstack_object_size (&filename_obstack); -- 2.53.0 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view 2026-03-10 17:30 ` [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view simon.marchi @ 2026-03-13 18:25 ` Tom Tromey 0 siblings, 0 replies; 15+ messages in thread From: Tom Tromey @ 2026-03-13 18:25 UTC (permalink / raw) To: simon.marchi; +Cc: gdb-patches >>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: Simon> From: Simon Marchi <simon.marchi@polymtl.ca> Simon> Make it a function_view and eliminate the `void *` callback data. Simon> Change the callback functions to lambda functions where they are used. Thanks, I like how much code this removes. Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef 2026-03-10 17:30 [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback simon.marchi 2026-03-10 17:30 ` [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls simon.marchi 2026-03-10 17:30 ` [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view simon.marchi @ 2026-03-10 17:30 ` simon.marchi 2026-03-13 18:25 ` Tom Tromey 2026-03-10 17:30 ` [PATCH 5/5] gdb: make find_memory_region_ftype a function_view simon.marchi 2026-03-13 18:21 ` [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback Tom Tromey 4 siblings, 1 reply; 15+ messages in thread From: simon.marchi @ 2026-03-10 17:30 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi From: Simon Marchi <simon.marchi@polymtl.ca> It is unused. Change-Id: I4c3ffc6598a12468072cd805ceebca3087e590d9 --- gdb/linux-tdep.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h index 4f74d40075da..92666ea4d978 100644 --- a/gdb/linux-tdep.h +++ b/gdb/linux-tdep.h @@ -59,11 +59,6 @@ struct type *linux_get_siginfo_type_with_fields (struct gdbarch *gdbarch, memory tagging protection. */ bool linux_address_in_memtag_page (CORE_ADDR address); -typedef char *(*linux_collect_thread_registers_ftype) (const struct regcache *, - ptid_t, - bfd *, char *, int *, - enum gdb_signal); - extern enum gdb_signal linux_gdb_signal_from_target (struct gdbarch *gdbarch, int signal); -- 2.53.0 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef 2026-03-10 17:30 ` [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef simon.marchi @ 2026-03-13 18:25 ` Tom Tromey 2026-03-14 18:43 ` Simon Marchi 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2026-03-13 18:25 UTC (permalink / raw) To: simon.marchi; +Cc: gdb-patches >>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: Simon> From: Simon Marchi <simon.marchi@polymtl.ca> Simon> It is unused. Obvious but Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef 2026-03-13 18:25 ` Tom Tromey @ 2026-03-14 18:43 ` Simon Marchi 0 siblings, 0 replies; 15+ messages in thread From: Simon Marchi @ 2026-03-14 18:43 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches On 2026-03-13 14:25, Tom Tromey wrote: >>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: > > Simon> From: Simon Marchi <simon.marchi@polymtl.ca> > Simon> It is unused. > > Obvious but > Approved-By: Tom Tromey <tom@tromey.com> > > Tom I pushed up to here. Simon ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 5/5] gdb: make find_memory_region_ftype a function_view 2026-03-10 17:30 [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback simon.marchi ` (2 preceding siblings ...) 2026-03-10 17:30 ` [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef simon.marchi @ 2026-03-10 17:30 ` simon.marchi 2026-03-13 18:46 ` Tom Tromey 2026-03-14 19:06 ` [PATCH v2] " simon.marchi 2026-03-13 18:21 ` [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback Tom Tromey 4 siblings, 2 replies; 15+ messages in thread From: simon.marchi @ 2026-03-10 17:30 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi From: Simon Marchi <simon.marchi@polymtl.ca> Make it a function_view and remove the `void *` parameter. Convert the callers (in gcore.c) to use lambda functions that capture `obfd`. One thing is that I am not sure how to implement target_debug_print_find_memory_region_ftype now... right now I made it return a constant "<function_view>" string. To make target.h see find_memory_region_ftype, I added an include of gdbarch.h in target.h, I'm not sure if this is undesirable, possibly causing some circular include problem in the future. find_memory_region_ftype was previously in defs.h. Leaving it there would require including gdbsupport/function-view.h inside defs.h, which I would prefer not to do. An alternative would be to place find_memory_region_ftype in a smaller (perhaps a new) header file, but I don't really know which one. Change-Id: I9d24d31da31e5fe0439124cec1a9757ad226b222 --- gdb/defs.h | 18 -------------- gdb/exec.c | 6 ++--- gdb/fbsd-nat.c | 8 +++--- gdb/fbsd-nat.h | 2 +- gdb/gcore.c | 51 ++++++++++++++++++++++---------------- gdb/gcore.h | 4 +-- gdb/gdbarch-gen.c | 4 +-- gdb/gdbarch-gen.h | 4 +-- gdb/gdbarch.h | 14 +++++++++++ gdb/gdbarch_components.py | 2 +- gdb/gnu-nat.c | 9 +++---- gdb/linux-tdep.c | 7 ++---- gdb/netbsd-nat.c | 8 +++--- gdb/netbsd-nat.h | 2 +- gdb/procfs.c | 20 ++++++--------- gdb/target-debug.h | 6 +---- gdb/target-delegates-gen.c | 19 +++++++------- gdb/target.c | 7 +++--- gdb/target.h | 7 +++--- 19 files changed, 89 insertions(+), 109 deletions(-) diff --git a/gdb/defs.h b/gdb/defs.h index 2d9c23cf232b..6029a2144d02 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -212,24 +212,6 @@ extern int print_address_symbolic (struct gdbarch *, CORE_ADDR, extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *); extern const char *pc_prefix (CORE_ADDR); -/* From exec.c */ - -/* Process memory area starting at ADDR with length SIZE. Area is readable iff - READ is true, writable if WRITE is true, executable if EXEC is true. Area - is possibly changed against its original file based copy if MODIFIED is true. - - MEMORY_TAGGED is true if the memory region contains memory tags, false - otherwise. - - DATA is passed without changes from a caller. - - Return true on success, false otherwise. */ - -typedef bool (*find_memory_region_ftype) (CORE_ADDR addr, unsigned long size, - bool read, bool write, bool exec, - bool modified, bool memory_tagged, - void *data); - /* * Possible lvalue types. Like enum language, this should be in value.h, but needs to be here for the same reason. */ diff --git a/gdb/exec.c b/gdb/exec.c index 94051ddab232..913580f5ed99 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -77,7 +77,7 @@ struct exec_target final : public target_ops bool has_memory () override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) override; - bool find_memory_regions (find_memory_region_ftype func, void *data) override; + bool find_memory_regions (find_memory_region_ftype func) override; }; static exec_target exec_ops; @@ -1071,9 +1071,9 @@ exec_target::make_corefile_notes (bfd *obfd, int *note_size) } bool -exec_target::find_memory_regions (find_memory_region_ftype func, void *data) +exec_target::find_memory_regions (find_memory_region_ftype func) { - return objfile_find_memory_regions (this, func, data); + return objfile_find_memory_regions (this, func); } INIT_GDB_FILE (exec) diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 80116553d9be..f4da73efb1d3 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -142,12 +142,10 @@ fbsd_nat_target::pid_to_exec_file (int pid) } /* Iterate over all the memory regions in the current inferior, - calling FUNC for each memory region. DATA is passed as the last - argument to FUNC. */ + calling FUNC for each memory region. */ bool -fbsd_nat_target::find_memory_regions (find_memory_region_ftype func, - void *data) +fbsd_nat_target::find_memory_regions (find_memory_region_ftype func) { pid_t pid = inferior_ptid.pid (); struct kinfo_vmentry *kve; @@ -188,7 +186,7 @@ fbsd_nat_target::find_memory_regions (find_memory_region_ftype func, Pass MODIFIED as true, we do not know the real modification state. */ func (kve->kve_start, size, kve->kve_protection & KVME_PROT_READ, kve->kve_protection & KVME_PROT_WRITE, - kve->kve_protection & KVME_PROT_EXEC, true, false, data); + kve->kve_protection & KVME_PROT_EXEC, true, false); } return true; } diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index fdac024d7bb3..9db5fb200a8d 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -49,7 +49,7 @@ class fbsd_nat_target : public inf_ptrace_target public: const char *pid_to_exec_file (int pid) override; - bool find_memory_regions (find_memory_region_ftype func, void *data) override; + bool find_memory_regions (find_memory_region_ftype func) override; bool info_proc (const char *, enum info_proc_what) override; diff --git a/gdb/gcore.c b/gdb/gcore.c index 2bf300c0d29f..b024f3d0ff3b 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -395,14 +395,13 @@ make_output_phdrs (bfd *obfd, asection *osec) MEMORY_TAGGED is true if the memory region contains memory tags, false otherwise. - DATA is 'bfd *' for the core file GDB is creating. */ + OBFD is the core file GDB is creating. */ static bool gcore_create_callback (CORE_ADDR vaddr, unsigned long size, bool read, - bool write, bool exec, bool modified, bool memory_tagged, - void *data) + bool write, bool exec, bool modified, + bool memory_tagged, bfd *obfd) { - bfd *obfd = (bfd *) data; asection *osec; flagword flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD; @@ -485,20 +484,18 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, bool read, MEMORY_TAGGED is true if the memory region contains memory tags, false otherwise. - DATA is 'bfd *' for the core file GDB is creating. */ + OBFD is the core file GDB is creating. */ static bool gcore_create_memtag_section_callback (CORE_ADDR vaddr, unsigned long size, bool read, bool write, bool exec, bool modified, bool memory_tagged, - void *data) + bfd *obfd) { /* Are there memory tags in this particular memory map entry? */ if (!memory_tagged) return true; - bfd *obfd = (bfd *) data; - /* Ask the architecture to create a memory tag section for this particular memory map entry. It will be populated with contents later, as we can't start writing the contents before we have all the sections sorted out. */ @@ -526,7 +523,7 @@ gcore_create_memtag_section_callback (CORE_ADDR vaddr, unsigned long size, bool objfile_find_memory_regions (struct target_ops *self, - find_memory_region_ftype func, void *obfd) + find_memory_region_ftype func) { /* Use objfile data to create memory sections. */ bfd_vma temp_bottom = 0, temp_top = 0; @@ -550,8 +547,7 @@ objfile_find_memory_regions (struct target_ops *self, (flags & SEC_READONLY) == 0, /* Writable. */ (flags & SEC_CODE) != 0, /* Executable. */ true, /* MODIFIED is unknown, pass it as true. */ - false, /* No memory tags in the object file. */ - obfd); + false /* No memory tags in the object file. */); if (!ret) return ret; } @@ -564,8 +560,7 @@ objfile_find_memory_regions (struct target_ops *self, true, /* Stack section will be writable. */ false, /* Stack section will not be executable. */ true, /* Stack section will be modified. */ - false, /* No memory tags in the object file. */ - obfd)) + false /* No memory tags in the object file. */)) return false; /* Make a heap segment. */ @@ -576,8 +571,7 @@ objfile_find_memory_regions (struct target_ops *self, true, /* Heap section will be writable. */ false, /* Heap section will not be executable. */ true, /* Heap section will be modified. */ - false, /* No memory tags in the object file. */ - obfd)) + false /* No memory tags in the object file. */)) return false; return true; @@ -847,23 +841,36 @@ gcore_copy_memtag_section_callback (bfd *obfd, asection *osec) static bool gcore_memory_sections (bfd *obfd) { + auto cb = [obfd] (CORE_ADDR vaddr, unsigned long size, bool read, bool write, + bool exec, bool modified, bool memory_tagged) + { + return gcore_create_callback (vaddr, size, read, write, exec, modified, + memory_tagged, obfd); + }; + /* Try gdbarch method first, then fall back to target method. */ gdbarch *arch = current_inferior ()->arch (); if (!gdbarch_find_memory_regions_p (arch) - || !gdbarch_find_memory_regions (arch, gcore_create_callback, obfd)) + || !gdbarch_find_memory_regions (arch, cb)) { - if (!target_find_memory_regions (gcore_create_callback, obfd)) + if (!target_find_memory_regions (cb)) return false; /* FIXME: error return/msg? */ } + auto cb_memtag = [obfd] (CORE_ADDR vaddr, unsigned long size, bool read, + bool write, bool exec, bool modified, + bool memory_tagged) + { + return gcore_create_memtag_section_callback (vaddr, size, read, write, + exec, modified, + memory_tagged, obfd); + }; + /* Take care of dumping memory tags, if there are any. */ if (!gdbarch_find_memory_regions_p (arch) - || !gdbarch_find_memory_regions (arch, - gcore_create_memtag_section_callback, - obfd)) + || !gdbarch_find_memory_regions (arch, cb_memtag)) { - if (!target_find_memory_regions (gcore_create_memtag_section_callback, - obfd)) + if (!target_find_memory_regions (cb_memtag)) return false; } diff --git a/gdb/gcore.h b/gdb/gcore.h index 7605b515c1e0..3bbebe33102e 100644 --- a/gdb/gcore.h +++ b/gdb/gcore.h @@ -21,14 +21,14 @@ #define GDB_GCORE_H #include "gdb_bfd.h" +#include "gdbarch.h" struct thread_info; extern gdb_bfd_ref_ptr create_gcore_bfd (const char *filename); extern void write_gcore_file (bfd *obfd); extern bool objfile_find_memory_regions (struct target_ops *self, - find_memory_region_ftype func, - void *obfd); + find_memory_region_ftype func); /* Find the signalled thread. In case there's more than one signalled thread, prefer the current thread, if it is signalled. If no thread was diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c index ddf982ebcf4d..1a8f21091b2f 100644 --- a/gdb/gdbarch-gen.c +++ b/gdb/gdbarch-gen.c @@ -3674,13 +3674,13 @@ gdbarch_find_memory_regions_p (struct gdbarch *gdbarch) } bool -gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data) +gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func) { gdb_assert (gdbarch != nullptr); gdb_assert (gdbarch->find_memory_regions != nullptr); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_find_memory_regions called\n"); - return gdbarch->find_memory_regions (gdbarch, func, data); + return gdbarch->find_memory_regions (gdbarch, func); } void diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index b6ec669ee2b7..c13949785688 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -962,8 +962,8 @@ void set_gdbarch_make_corefile_notes (struct gdbarch *gdbarch, gdbarch_make_core bool gdbarch_find_memory_regions_p (struct gdbarch *gdbarch); -using gdbarch_find_memory_regions_ftype = bool (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data); -bool gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data); +using gdbarch_find_memory_regions_ftype = bool (struct gdbarch *gdbarch, find_memory_region_ftype func); +bool gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func); void set_gdbarch_find_memory_regions (struct gdbarch *gdbarch, gdbarch_find_memory_regions_ftype *find_memory_regions); /* Given a bfd OBFD, segment ADDRESS and SIZE, create a memory tag section to be dumped to a core file */ diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index fe59846b916e..9ce67d5cad52 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -134,6 +134,20 @@ using read_core_file_mappings_loop_ftype = const char *filename, const bfd_build_id *build_id)>; +/* Process memory area starting at ADDR with length SIZE. Area is readable iff + READ is true, writable if WRITE is true, executable if EXEC is true. Area + is possibly changed against its original file based copy if MODIFIED is true. + + MEMORY_TAGGED is true if the memory region contains memory tags, false + otherwise. + + Return true on success, false otherwise. */ + +using find_memory_region_ftype + = gdb::function_view<bool (CORE_ADDR addr, unsigned long size, bool read, + bool write, bool exec, bool modified, + bool memory_tagged)>; + /* Possible values for gdbarch_call_dummy_location. */ enum call_dummy_location_type { diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 424558d6ae08..7a329d921665 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -1636,7 +1636,7 @@ Find core file memory regions """, type="bool", name="find_memory_regions", - params=[("find_memory_region_ftype", "func"), ("void *", "data")], + params=[("find_memory_region_ftype", "func")], predicate=True, ) diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index e5706b75b1cd..43153652d724 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2566,8 +2566,7 @@ gnu_nat_target::xfer_partial (enum target_object object, /* Call FUNC on each memory region in the task. */ bool -gnu_nat_target::find_memory_regions (find_memory_region_ftype func, - void *data) +gnu_nat_target::find_memory_regions (find_memory_region_ftype func) { kern_return_t err; task_t task; @@ -2624,8 +2623,7 @@ gnu_nat_target::find_memory_regions (find_memory_region_ftype func, last_protection & VM_PROT_WRITE, last_protection & VM_PROT_EXECUTE, true, /* MODIFIED is unknown, pass it as true. */ - false, /* No memory tags in the object file. */ - data); + false /* No memory tags in the object file. */); last_region_address = region_address; last_region_end = region_address += region_length; last_protection = protection; @@ -2639,8 +2637,7 @@ gnu_nat_target::find_memory_regions (find_memory_region_ftype func, last_protection & VM_PROT_WRITE, last_protection & VM_PROT_EXECUTE, 1, /* MODIFIED is unknown, pass it as true. */ - false, /* No memory tags in the object file. */ - data); + false /* No memory tags in the object file. */); return true; } diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 36b7cc95b4eb..39e02dec49ca 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1649,15 +1649,12 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, static bool linux_find_memory_regions (struct gdbarch *gdbarch, - find_memory_region_ftype func, void *data) + find_memory_region_ftype func) { auto cb = [&] (ULONGEST vaddr, ULONGEST size, ULONGEST offset, bool read, bool write, bool exec, bool modified, bool memory_tagged, const std::string &filename) - { - return func (vaddr, size, read, write, exec, modified, memory_tagged, - data); - }; + { return func (vaddr, size, read, write, exec, modified, memory_tagged); }; return linux_find_memory_regions_full (gdbarch, dump_mapping_p, cb); } diff --git a/gdb/netbsd-nat.c b/gdb/netbsd-nat.c index b8a8911baf4e..6b9029bf0ef9 100644 --- a/gdb/netbsd-nat.c +++ b/gdb/netbsd-nat.c @@ -209,12 +209,10 @@ nbsd_kinfo_get_vmmap (pid_t pid, size_t *size) } /* Iterate over all the memory regions in the current inferior, - calling FUNC for each memory region. OBFD is passed as the last - argument to FUNC. */ + calling FUNC for each memory region. */ bool -nbsd_nat_target::find_memory_regions (find_memory_region_ftype func, - void *data) +nbsd_nat_target::find_memory_regions (find_memory_region_ftype func) { pid_t pid = inferior_ptid.pid (); @@ -260,7 +258,7 @@ nbsd_nat_target::find_memory_regions (find_memory_region_ftype func, Pass MODIFIED as true, we do not know the real modification state. */ func (kve->kve_start, size, kve->kve_protection & KVME_PROT_READ, kve->kve_protection & KVME_PROT_WRITE, - kve->kve_protection & KVME_PROT_EXEC, true, false, data); + kve->kve_protection & KVME_PROT_EXEC, true, false); } return true; } diff --git a/gdb/netbsd-nat.h b/gdb/netbsd-nat.h index f9b9c9fac122..3470fe103c83 100644 --- a/gdb/netbsd-nat.h +++ b/gdb/netbsd-nat.h @@ -36,7 +36,7 @@ struct nbsd_nat_target : public inf_ptrace_target void update_thread_list () override; std::string pid_to_str (ptid_t ptid) override; - bool find_memory_regions (find_memory_region_ftype func, void *data) override; + bool find_memory_regions (find_memory_region_ftype func) override; bool info_proc (const char *, enum info_proc_what) override; void resume (ptid_t, int, enum gdb_signal) override; diff --git a/gdb/procfs.c b/gdb/procfs.c index e0d49c126b24..3b2ca3f9f603 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -134,8 +134,7 @@ class procfs_target final : public inf_child_target { return tc_schedlock; } /* find_memory_regions support method for gcore */ - bool find_memory_regions (find_memory_region_ftype func, void *data) - override; + bool find_memory_regions (find_memory_region_ftype func) override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) override; @@ -3107,10 +3106,8 @@ procfs_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) static bool iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, - void *data, bool (*func) (struct prmap *map, - find_memory_region_ftype child_func, - void *data)) + find_memory_region_ftype child_func)) { char pathname[MAX_PROC_NAME_SIZE]; struct prmap *prmaps; @@ -3139,7 +3136,7 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, proc_error (pi, "iterate_over_mappings (read)", __LINE__); for (prmap = prmaps; nmap > 0; prmap++, nmap--) - if (!func (prmap, child_func, data)) + if (!func (prmap, child_func)) return false; return true; @@ -3150,8 +3147,7 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, Returns the value returned by the callback. */ static bool -find_memory_regions_callback (struct prmap *map, - find_memory_region_ftype func, void *data) +find_memory_regions_callback (struct prmap *map, find_memory_region_ftype func) { return (*func) ((CORE_ADDR) map->pr_vaddr, map->pr_size, @@ -3159,8 +3155,7 @@ find_memory_regions_callback (struct prmap *map, (map->pr_mflags & MA_WRITE) != 0, (map->pr_mflags & MA_EXEC) != 0, true, /* MODIFIED is unknown, pass it as true. */ - false, - data); + false); } /* External interface. Calls a callback function once for each @@ -3176,12 +3171,11 @@ find_memory_regions_callback (struct prmap *map, the callback. */ bool -procfs_target::find_memory_regions (find_memory_region_ftype func, void *data) +procfs_target::find_memory_regions (find_memory_region_ftype func) { procinfo *pi = find_procinfo_or_die (inferior_ptid.pid (), 0); - return iterate_over_mappings (pi, func, data, - find_memory_regions_callback); + return iterate_over_mappings (pi, func, find_memory_regions_callback); } /* Returns an ascii representation of a memory mapping's flags. */ diff --git a/gdb/target-debug.h b/gdb/target-debug.h index 06b89856fe57..c86affbc8382 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -170,13 +170,9 @@ target_debug_print_const_std_vector_target_section_p (const std::vector<target_section> *vec) { return host_address_to_string (vec->data ()); } -static std::string -target_debug_print_void_p (void *p) -{ return host_address_to_string (p); } - static std::string target_debug_print_find_memory_region_ftype (find_memory_region_ftype func) -{ return host_address_to_string (func); } +{ return "<function_view>"; } static std::string target_debug_print_bfd_p (bfd *bfd) diff --git a/gdb/target-delegates-gen.c b/gdb/target-delegates-gen.c index 258e6de7e126..b39fd7cb33a1 100644 --- a/gdb/target-delegates-gen.c +++ b/gdb/target-delegates-gen.c @@ -109,7 +109,7 @@ struct dummy_target : public target_ops bool supports_set_thread_options (gdb_thread_options arg0) override; bool supports_non_stop () override; bool always_non_stop_p () override; - bool find_memory_regions (find_memory_region_ftype arg0, void *arg1) override; + bool find_memory_regions (find_memory_region_ftype arg0) override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *arg0, int *arg1) override; gdb_byte *get_bookmark (const char *arg0, int arg1) override; void goto_bookmark (const gdb_byte *arg0, int arg1) override; @@ -290,7 +290,7 @@ struct debug_target : public target_ops bool supports_set_thread_options (gdb_thread_options arg0) override; bool supports_non_stop () override; bool always_non_stop_p () override; - bool find_memory_regions (find_memory_region_ftype arg0, void *arg1) override; + bool find_memory_regions (find_memory_region_ftype arg0) override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *arg0, int *arg1) override; gdb_byte *get_bookmark (const char *arg0, int arg1) override; void goto_bookmark (const gdb_byte *arg0, int arg1) override; @@ -2266,27 +2266,26 @@ debug_target::always_non_stop_p () } bool -target_ops::find_memory_regions (find_memory_region_ftype arg0, void *arg1) +target_ops::find_memory_regions (find_memory_region_ftype arg0) { - return this->beneath ()->find_memory_regions (arg0, arg1); + return this->beneath ()->find_memory_regions (arg0); } bool -dummy_target::find_memory_regions (find_memory_region_ftype arg0, void *arg1) +dummy_target::find_memory_regions (find_memory_region_ftype arg0) { - return dummy_find_memory_regions (this, arg0, arg1); + return dummy_find_memory_regions (this, arg0); } bool -debug_target::find_memory_regions (find_memory_region_ftype arg0, void *arg1) +debug_target::find_memory_regions (find_memory_region_ftype arg0) { target_debug_printf_nofunc ("-> %s->find_memory_regions (...)", this->beneath ()->shortname ()); bool result - = this->beneath ()->find_memory_regions (arg0, arg1); - target_debug_printf_nofunc ("<- %s->find_memory_regions (%s, %s) = %s", + = this->beneath ()->find_memory_regions (arg0); + target_debug_printf_nofunc ("<- %s->find_memory_regions (%s) = %s", this->beneath ()->shortname (), target_debug_print_find_memory_region_ftype (arg0).c_str (), - target_debug_print_void_p (arg1).c_str (), target_debug_print_bool (result).c_str ()); return result; } diff --git a/gdb/target.c b/gdb/target.c index 77a562aa919d..925d6458c19b 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -416,9 +416,9 @@ target_thread_architecture (ptid_t ptid) /* See target.h. */ bool -target_find_memory_regions (find_memory_region_ftype func, void *data) +target_find_memory_regions (find_memory_region_ftype func) { - return current_inferior ()->top_target ()->find_memory_regions (func, data); + return current_inferior ()->top_target ()->find_memory_regions (func); } /* See target.h. */ @@ -3686,8 +3686,7 @@ default_pid_to_str (struct target_ops *ops, ptid_t ptid) /* Error-catcher for target_find_memory_regions. */ static bool -dummy_find_memory_regions (struct target_ops *self, - find_memory_region_ftype ignore1, void *ignore2) +dummy_find_memory_regions (target_ops *self, find_memory_region_ftype ignore1) { error (_("Command not implemented for this target.")); } diff --git a/gdb/target.h b/gdb/target.h index a71f750a9d92..2cc47f3e7f5b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -85,8 +85,8 @@ typedef const gdb_byte const_gdb_byte; #include "tracepoint.h" #include "gdbsupport/fileio.h" #include "gdbsupport/x86-xstate.h" - #include "gdbsupport/break-common.h" +#include "gdbarch.h" enum strata { @@ -765,7 +765,7 @@ struct target_ops virtual bool always_non_stop_p () TARGET_DEFAULT_RETURN (false); /* find_memory_regions support method for gcore */ - virtual bool find_memory_regions (find_memory_region_ftype func, void *data) + virtual bool find_memory_regions (find_memory_region_ftype func) TARGET_DEFAULT_FUNC (dummy_find_memory_regions); /* make_corefile_notes support method for gcore */ virtual gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) @@ -2040,8 +2040,7 @@ extern gdbarch *target_thread_architecture (ptid_t ptid); If FUNC ever returns false, stop iterating and return false. Otherwise, return true. */ -extern bool target_find_memory_regions (find_memory_region_ftype func, - void *data); +extern bool target_find_memory_regions (find_memory_region_ftype func); /* * Compose corefile .note section. -- 2.53.0 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 5/5] gdb: make find_memory_region_ftype a function_view 2026-03-10 17:30 ` [PATCH 5/5] gdb: make find_memory_region_ftype a function_view simon.marchi @ 2026-03-13 18:46 ` Tom Tromey 2026-03-14 18:48 ` Simon Marchi 2026-03-14 19:06 ` [PATCH v2] " simon.marchi 1 sibling, 1 reply; 15+ messages in thread From: Tom Tromey @ 2026-03-13 18:46 UTC (permalink / raw) To: simon.marchi; +Cc: gdb-patches >>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: Simon> From: Simon Marchi <simon.marchi@polymtl.ca> Simon> Make it a function_view and remove the `void *` parameter. Convert the Simon> callers (in gcore.c) to use lambda functions that capture `obfd`. Simon> One thing is that I am not sure how to implement Simon> target_debug_print_find_memory_region_ftype now... right now I made it Simon> return a constant "<function_view>" string. I think this is fine. Some of these debug printers are already not really that useful. Simon> To make target.h see find_memory_region_ftype, I added an include of Simon> gdbarch.h in target.h, I'm not sure if this is undesirable, possibly Simon> causing some circular include problem in the future. Simon> find_memory_region_ftype was previously in defs.h. Leaving it there Simon> would require including gdbsupport/function-view.h inside defs.h, which Simon> I would prefer not to do. An alternative would be to place Simon> find_memory_region_ftype in a smaller (perhaps a new) header file, but I Simon> don't really know which one. It's tempting to try to fix it now before it is a problem. Though I somewhat suspect that what you have already is fine. I do think having a new small header just for this type would be completely fine and I think it's a reasonable long-term strategy for handling this kind of "pro forma" typedef. As in, I'd encourage this in other cases where breaking circular dependencies is needed. Anyway I also think this is ok. Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 5/5] gdb: make find_memory_region_ftype a function_view 2026-03-13 18:46 ` Tom Tromey @ 2026-03-14 18:48 ` Simon Marchi 0 siblings, 0 replies; 15+ messages in thread From: Simon Marchi @ 2026-03-14 18:48 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches On 2026-03-13 14:46, Tom Tromey wrote: >>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: > > Simon> From: Simon Marchi <simon.marchi@polymtl.ca> > Simon> Make it a function_view and remove the `void *` parameter. Convert the > Simon> callers (in gcore.c) to use lambda functions that capture `obfd`. > > Simon> One thing is that I am not sure how to implement > Simon> target_debug_print_find_memory_region_ftype now... right now I made it > Simon> return a constant "<function_view>" string. > > I think this is fine. Some of these debug printers are already not > really that useful. > > Simon> To make target.h see find_memory_region_ftype, I added an include of > Simon> gdbarch.h in target.h, I'm not sure if this is undesirable, possibly > Simon> causing some circular include problem in the future. > Simon> find_memory_region_ftype was previously in defs.h. Leaving it there > Simon> would require including gdbsupport/function-view.h inside defs.h, which > Simon> I would prefer not to do. An alternative would be to place > Simon> find_memory_region_ftype in a smaller (perhaps a new) header file, but I > Simon> don't really know which one. > > It's tempting to try to fix it now before it is a problem. > > Though I somewhat suspect that what you have already is fine. > > I do think having a new small header just for this type would be > completely fine and I think it's a reasonable long-term strategy for > handling this kind of "pro forma" typedef. As in, I'd encourage this in > other cases where breaking circular dependencies is needed. > > Anyway I also think this is ok. > Approved-By: Tom Tromey <tom@tromey.com> Well, it does feel wrong to have the typedef in gdbarch.h, because it is not more a "gdbarch.h" thing than it is a "target.h" thing. Both headers are equal users of the typedef. So I think it makes sense for it to be in a third header that they both include. I will send a new patch where the typedef is in a new file called `find-memory-region.h`. Simon ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] gdb: make find_memory_region_ftype a function_view 2026-03-10 17:30 ` [PATCH 5/5] gdb: make find_memory_region_ftype a function_view simon.marchi 2026-03-13 18:46 ` Tom Tromey @ 2026-03-14 19:06 ` simon.marchi 2026-03-19 13:57 ` Tom Tromey 1 sibling, 1 reply; 15+ messages in thread From: simon.marchi @ 2026-03-14 19:06 UTC (permalink / raw) To: gdb-patches; +Cc: Simon Marchi From: Simon Marchi <simon.marchi@polymtl.ca> New in v2: - new header file find-memory-region.h Make it a function_view and remove the `void *` parameter. Convert the callers (in gcore.c) to use lambda functions that capture `obfd`. The target_debug_print_find_memory_region_ftype debug printer isn't terribly useful, but I don't see a good way to print a function_view with what we have right now. Since find_memory_region_ftype needs to be seen by both gdbarch.h and target.h, I chose to move the typedef to a new file (find-memory-region.h), that is included by both. Change-Id: I9d24d31da31e5fe0439124cec1a9757ad226b222 --- gdb/Makefile.in | 1 + gdb/defs.h | 18 -------------- gdb/exec.c | 6 ++--- gdb/fbsd-nat.c | 8 +++--- gdb/fbsd-nat.h | 2 +- gdb/find-memory-region.h | 37 +++++++++++++++++++++++++++ gdb/gcore.c | 51 ++++++++++++++++++++++---------------- gdb/gcore.h | 4 +-- gdb/gdbarch-gen.c | 4 +-- gdb/gdbarch-gen.h | 4 +-- gdb/gdbarch.h | 1 + gdb/gdbarch_components.py | 2 +- gdb/gnu-nat.c | 19 ++++++-------- gdb/linux-tdep.c | 7 ++---- gdb/netbsd-nat.c | 8 +++--- gdb/netbsd-nat.h | 2 +- gdb/procfs.c | 32 ++++++++++-------------- gdb/target-debug.h | 6 +---- gdb/target-delegates-gen.c | 19 +++++++------- gdb/target.c | 7 +++--- gdb/target.h | 7 +++--- 21 files changed, 125 insertions(+), 120 deletions(-) create mode 100644 gdb/find-memory-region.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index ca9e6be47631..429e1684aaf2 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1453,6 +1453,7 @@ HFILES_NO_SRCDIR = \ f-exp.h \ filename-seen-cache.h \ filesystem.h \ + find-memory-region.h \ finish-thread-state.h \ f-lang.h \ frame-base.h \ diff --git a/gdb/defs.h b/gdb/defs.h index 2d9c23cf232b..6029a2144d02 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -212,24 +212,6 @@ extern int print_address_symbolic (struct gdbarch *, CORE_ADDR, extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *); extern const char *pc_prefix (CORE_ADDR); -/* From exec.c */ - -/* Process memory area starting at ADDR with length SIZE. Area is readable iff - READ is true, writable if WRITE is true, executable if EXEC is true. Area - is possibly changed against its original file based copy if MODIFIED is true. - - MEMORY_TAGGED is true if the memory region contains memory tags, false - otherwise. - - DATA is passed without changes from a caller. - - Return true on success, false otherwise. */ - -typedef bool (*find_memory_region_ftype) (CORE_ADDR addr, unsigned long size, - bool read, bool write, bool exec, - bool modified, bool memory_tagged, - void *data); - /* * Possible lvalue types. Like enum language, this should be in value.h, but needs to be here for the same reason. */ diff --git a/gdb/exec.c b/gdb/exec.c index 94051ddab232..913580f5ed99 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -77,7 +77,7 @@ struct exec_target final : public target_ops bool has_memory () override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) override; - bool find_memory_regions (find_memory_region_ftype func, void *data) override; + bool find_memory_regions (find_memory_region_ftype func) override; }; static exec_target exec_ops; @@ -1071,9 +1071,9 @@ exec_target::make_corefile_notes (bfd *obfd, int *note_size) } bool -exec_target::find_memory_regions (find_memory_region_ftype func, void *data) +exec_target::find_memory_regions (find_memory_region_ftype func) { - return objfile_find_memory_regions (this, func, data); + return objfile_find_memory_regions (this, func); } INIT_GDB_FILE (exec) diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 80116553d9be..f4da73efb1d3 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -142,12 +142,10 @@ fbsd_nat_target::pid_to_exec_file (int pid) } /* Iterate over all the memory regions in the current inferior, - calling FUNC for each memory region. DATA is passed as the last - argument to FUNC. */ + calling FUNC for each memory region. */ bool -fbsd_nat_target::find_memory_regions (find_memory_region_ftype func, - void *data) +fbsd_nat_target::find_memory_regions (find_memory_region_ftype func) { pid_t pid = inferior_ptid.pid (); struct kinfo_vmentry *kve; @@ -188,7 +186,7 @@ fbsd_nat_target::find_memory_regions (find_memory_region_ftype func, Pass MODIFIED as true, we do not know the real modification state. */ func (kve->kve_start, size, kve->kve_protection & KVME_PROT_READ, kve->kve_protection & KVME_PROT_WRITE, - kve->kve_protection & KVME_PROT_EXEC, true, false, data); + kve->kve_protection & KVME_PROT_EXEC, true, false); } return true; } diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index fdac024d7bb3..9db5fb200a8d 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -49,7 +49,7 @@ class fbsd_nat_target : public inf_ptrace_target public: const char *pid_to_exec_file (int pid) override; - bool find_memory_regions (find_memory_region_ftype func, void *data) override; + bool find_memory_regions (find_memory_region_ftype func) override; bool info_proc (const char *, enum info_proc_what) override; diff --git a/gdb/find-memory-region.h b/gdb/find-memory-region.h new file mode 100644 index 000000000000..23776caebb2b --- /dev/null +++ b/gdb/find-memory-region.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2026 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef GDB_FIND_MEMORY_REGION_H +#define GDB_FIND_MEMORY_REGION_H + +#include "gdbsupport/function-view.h" + +/* Process memory area starting at ADDR with length SIZE. Area is readable iff + READ is true, writable if WRITE is true, executable if EXEC is true. Area + is possibly changed against its original file based copy if MODIFIED is true. + + MEMORY_TAGGED is true if the memory region contains memory tags, false + otherwise. + + Return true on success, false otherwise. */ + +using find_memory_region_ftype + = gdb::function_view<bool (CORE_ADDR addr, unsigned long size, bool read, + bool write, bool exec, bool modified, + bool memory_tagged)>; + +#endif /* GDB_FIND_MEMORY_REGION_H */ diff --git a/gdb/gcore.c b/gdb/gcore.c index 2bf300c0d29f..b024f3d0ff3b 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -395,14 +395,13 @@ make_output_phdrs (bfd *obfd, asection *osec) MEMORY_TAGGED is true if the memory region contains memory tags, false otherwise. - DATA is 'bfd *' for the core file GDB is creating. */ + OBFD is the core file GDB is creating. */ static bool gcore_create_callback (CORE_ADDR vaddr, unsigned long size, bool read, - bool write, bool exec, bool modified, bool memory_tagged, - void *data) + bool write, bool exec, bool modified, + bool memory_tagged, bfd *obfd) { - bfd *obfd = (bfd *) data; asection *osec; flagword flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD; @@ -485,20 +484,18 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, bool read, MEMORY_TAGGED is true if the memory region contains memory tags, false otherwise. - DATA is 'bfd *' for the core file GDB is creating. */ + OBFD is the core file GDB is creating. */ static bool gcore_create_memtag_section_callback (CORE_ADDR vaddr, unsigned long size, bool read, bool write, bool exec, bool modified, bool memory_tagged, - void *data) + bfd *obfd) { /* Are there memory tags in this particular memory map entry? */ if (!memory_tagged) return true; - bfd *obfd = (bfd *) data; - /* Ask the architecture to create a memory tag section for this particular memory map entry. It will be populated with contents later, as we can't start writing the contents before we have all the sections sorted out. */ @@ -526,7 +523,7 @@ gcore_create_memtag_section_callback (CORE_ADDR vaddr, unsigned long size, bool objfile_find_memory_regions (struct target_ops *self, - find_memory_region_ftype func, void *obfd) + find_memory_region_ftype func) { /* Use objfile data to create memory sections. */ bfd_vma temp_bottom = 0, temp_top = 0; @@ -550,8 +547,7 @@ objfile_find_memory_regions (struct target_ops *self, (flags & SEC_READONLY) == 0, /* Writable. */ (flags & SEC_CODE) != 0, /* Executable. */ true, /* MODIFIED is unknown, pass it as true. */ - false, /* No memory tags in the object file. */ - obfd); + false /* No memory tags in the object file. */); if (!ret) return ret; } @@ -564,8 +560,7 @@ objfile_find_memory_regions (struct target_ops *self, true, /* Stack section will be writable. */ false, /* Stack section will not be executable. */ true, /* Stack section will be modified. */ - false, /* No memory tags in the object file. */ - obfd)) + false /* No memory tags in the object file. */)) return false; /* Make a heap segment. */ @@ -576,8 +571,7 @@ objfile_find_memory_regions (struct target_ops *self, true, /* Heap section will be writable. */ false, /* Heap section will not be executable. */ true, /* Heap section will be modified. */ - false, /* No memory tags in the object file. */ - obfd)) + false /* No memory tags in the object file. */)) return false; return true; @@ -847,23 +841,36 @@ gcore_copy_memtag_section_callback (bfd *obfd, asection *osec) static bool gcore_memory_sections (bfd *obfd) { + auto cb = [obfd] (CORE_ADDR vaddr, unsigned long size, bool read, bool write, + bool exec, bool modified, bool memory_tagged) + { + return gcore_create_callback (vaddr, size, read, write, exec, modified, + memory_tagged, obfd); + }; + /* Try gdbarch method first, then fall back to target method. */ gdbarch *arch = current_inferior ()->arch (); if (!gdbarch_find_memory_regions_p (arch) - || !gdbarch_find_memory_regions (arch, gcore_create_callback, obfd)) + || !gdbarch_find_memory_regions (arch, cb)) { - if (!target_find_memory_regions (gcore_create_callback, obfd)) + if (!target_find_memory_regions (cb)) return false; /* FIXME: error return/msg? */ } + auto cb_memtag = [obfd] (CORE_ADDR vaddr, unsigned long size, bool read, + bool write, bool exec, bool modified, + bool memory_tagged) + { + return gcore_create_memtag_section_callback (vaddr, size, read, write, + exec, modified, + memory_tagged, obfd); + }; + /* Take care of dumping memory tags, if there are any. */ if (!gdbarch_find_memory_regions_p (arch) - || !gdbarch_find_memory_regions (arch, - gcore_create_memtag_section_callback, - obfd)) + || !gdbarch_find_memory_regions (arch, cb_memtag)) { - if (!target_find_memory_regions (gcore_create_memtag_section_callback, - obfd)) + if (!target_find_memory_regions (cb_memtag)) return false; } diff --git a/gdb/gcore.h b/gdb/gcore.h index 7605b515c1e0..2431e123b60e 100644 --- a/gdb/gcore.h +++ b/gdb/gcore.h @@ -20,6 +20,7 @@ #ifndef GDB_GCORE_H #define GDB_GCORE_H +#include "find-memory-region.h" #include "gdb_bfd.h" struct thread_info; @@ -27,8 +28,7 @@ struct thread_info; extern gdb_bfd_ref_ptr create_gcore_bfd (const char *filename); extern void write_gcore_file (bfd *obfd); extern bool objfile_find_memory_regions (struct target_ops *self, - find_memory_region_ftype func, - void *obfd); + find_memory_region_ftype func); /* Find the signalled thread. In case there's more than one signalled thread, prefer the current thread, if it is signalled. If no thread was diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c index ddf982ebcf4d..1a8f21091b2f 100644 --- a/gdb/gdbarch-gen.c +++ b/gdb/gdbarch-gen.c @@ -3674,13 +3674,13 @@ gdbarch_find_memory_regions_p (struct gdbarch *gdbarch) } bool -gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data) +gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func) { gdb_assert (gdbarch != nullptr); gdb_assert (gdbarch->find_memory_regions != nullptr); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_find_memory_regions called\n"); - return gdbarch->find_memory_regions (gdbarch, func, data); + return gdbarch->find_memory_regions (gdbarch, func); } void diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index b6ec669ee2b7..c13949785688 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -962,8 +962,8 @@ void set_gdbarch_make_corefile_notes (struct gdbarch *gdbarch, gdbarch_make_core bool gdbarch_find_memory_regions_p (struct gdbarch *gdbarch); -using gdbarch_find_memory_regions_ftype = bool (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data); -bool gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data); +using gdbarch_find_memory_regions_ftype = bool (struct gdbarch *gdbarch, find_memory_region_ftype func); +bool gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func); void set_gdbarch_find_memory_regions (struct gdbarch *gdbarch, gdbarch_find_memory_regions_ftype *find_memory_regions); /* Given a bfd OBFD, segment ADDRESS and SIZE, create a memory tag section to be dumped to a core file */ diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index fe59846b916e..b0b17afc6af9 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -31,6 +31,7 @@ #include "gdbsupport/gdb-checked-static-cast.h" #include "registry.h" #include "solib.h" +#include "find-memory-region.h" struct floatformat; struct ui_file; diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 424558d6ae08..7a329d921665 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -1636,7 +1636,7 @@ Find core file memory regions """, type="bool", name="find_memory_regions", - params=[("find_memory_region_ftype", "func"), ("void *", "data")], + params=[("find_memory_region_ftype", "func")], predicate=True, ) diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index e5706b75b1cd..aabbf6fc5d5a 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2566,8 +2566,7 @@ gnu_nat_target::xfer_partial (enum target_object object, /* Call FUNC on each memory region in the task. */ bool -gnu_nat_target::find_memory_regions (find_memory_region_ftype func, - void *data) +gnu_nat_target::find_memory_regions (find_memory_region_ftype func) { kern_return_t err; task_t task; @@ -2624,8 +2623,7 @@ gnu_nat_target::find_memory_regions (find_memory_region_ftype func, last_protection & VM_PROT_WRITE, last_protection & VM_PROT_EXECUTE, true, /* MODIFIED is unknown, pass it as true. */ - false, /* No memory tags in the object file. */ - data); + false /* No memory tags in the object file. */); last_region_address = region_address; last_region_end = region_address += region_length; last_protection = protection; @@ -2634,13 +2632,12 @@ gnu_nat_target::find_memory_regions (find_memory_region_ftype func, /* Report the final region. */ if (last_region_end > last_region_address && last_protection != VM_PROT_NONE) - (*func) (last_region_address, last_region_end - last_region_address, - last_protection & VM_PROT_READ, - last_protection & VM_PROT_WRITE, - last_protection & VM_PROT_EXECUTE, - 1, /* MODIFIED is unknown, pass it as true. */ - false, /* No memory tags in the object file. */ - data); + func (last_region_address, last_region_end - last_region_address, + last_protection & VM_PROT_READ, + last_protection & VM_PROT_WRITE, + last_protection & VM_PROT_EXECUTE, + true, /* MODIFIED is unknown, pass it as true. */ + false /* No memory tags in the object file. */); return true; } diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 36b7cc95b4eb..39e02dec49ca 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1649,15 +1649,12 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, static bool linux_find_memory_regions (struct gdbarch *gdbarch, - find_memory_region_ftype func, void *data) + find_memory_region_ftype func) { auto cb = [&] (ULONGEST vaddr, ULONGEST size, ULONGEST offset, bool read, bool write, bool exec, bool modified, bool memory_tagged, const std::string &filename) - { - return func (vaddr, size, read, write, exec, modified, memory_tagged, - data); - }; + { return func (vaddr, size, read, write, exec, modified, memory_tagged); }; return linux_find_memory_regions_full (gdbarch, dump_mapping_p, cb); } diff --git a/gdb/netbsd-nat.c b/gdb/netbsd-nat.c index b8a8911baf4e..6b9029bf0ef9 100644 --- a/gdb/netbsd-nat.c +++ b/gdb/netbsd-nat.c @@ -209,12 +209,10 @@ nbsd_kinfo_get_vmmap (pid_t pid, size_t *size) } /* Iterate over all the memory regions in the current inferior, - calling FUNC for each memory region. OBFD is passed as the last - argument to FUNC. */ + calling FUNC for each memory region. */ bool -nbsd_nat_target::find_memory_regions (find_memory_region_ftype func, - void *data) +nbsd_nat_target::find_memory_regions (find_memory_region_ftype func) { pid_t pid = inferior_ptid.pid (); @@ -260,7 +258,7 @@ nbsd_nat_target::find_memory_regions (find_memory_region_ftype func, Pass MODIFIED as true, we do not know the real modification state. */ func (kve->kve_start, size, kve->kve_protection & KVME_PROT_READ, kve->kve_protection & KVME_PROT_WRITE, - kve->kve_protection & KVME_PROT_EXEC, true, false, data); + kve->kve_protection & KVME_PROT_EXEC, true, false); } return true; } diff --git a/gdb/netbsd-nat.h b/gdb/netbsd-nat.h index f9b9c9fac122..3470fe103c83 100644 --- a/gdb/netbsd-nat.h +++ b/gdb/netbsd-nat.h @@ -36,7 +36,7 @@ struct nbsd_nat_target : public inf_ptrace_target void update_thread_list () override; std::string pid_to_str (ptid_t ptid) override; - bool find_memory_regions (find_memory_region_ftype func, void *data) override; + bool find_memory_regions (find_memory_region_ftype func) override; bool info_proc (const char *, enum info_proc_what) override; void resume (ptid_t, int, enum gdb_signal) override; diff --git a/gdb/procfs.c b/gdb/procfs.c index e0d49c126b24..cea9f823bbca 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -134,8 +134,7 @@ class procfs_target final : public inf_child_target { return tc_schedlock; } /* find_memory_regions support method for gcore */ - bool find_memory_regions (find_memory_region_ftype func, void *data) - override; + bool find_memory_regions (find_memory_region_ftype func) override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) override; @@ -3107,10 +3106,8 @@ procfs_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) static bool iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, - void *data, bool (*func) (struct prmap *map, - find_memory_region_ftype child_func, - void *data)) + find_memory_region_ftype child_func)) { char pathname[MAX_PROC_NAME_SIZE]; struct prmap *prmaps; @@ -3139,7 +3136,7 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, proc_error (pi, "iterate_over_mappings (read)", __LINE__); for (prmap = prmaps; nmap > 0; prmap++, nmap--) - if (!func (prmap, child_func, data)) + if (!func (prmap, child_func)) return false; return true; @@ -3150,17 +3147,15 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func, Returns the value returned by the callback. */ static bool -find_memory_regions_callback (struct prmap *map, - find_memory_region_ftype func, void *data) +find_memory_regions_callback (struct prmap *map, find_memory_region_ftype func) { - return (*func) ((CORE_ADDR) map->pr_vaddr, - map->pr_size, - (map->pr_mflags & MA_READ) != 0, - (map->pr_mflags & MA_WRITE) != 0, - (map->pr_mflags & MA_EXEC) != 0, - true, /* MODIFIED is unknown, pass it as true. */ - false, - data); + return func ((CORE_ADDR) map->pr_vaddr, + map->pr_size, + (map->pr_mflags & MA_READ) != 0, + (map->pr_mflags & MA_WRITE) != 0, + (map->pr_mflags & MA_EXEC) != 0, + true, /* MODIFIED is unknown, pass it as true. */ + false); } /* External interface. Calls a callback function once for each @@ -3176,12 +3171,11 @@ find_memory_regions_callback (struct prmap *map, the callback. */ bool -procfs_target::find_memory_regions (find_memory_region_ftype func, void *data) +procfs_target::find_memory_regions (find_memory_region_ftype func) { procinfo *pi = find_procinfo_or_die (inferior_ptid.pid (), 0); - return iterate_over_mappings (pi, func, data, - find_memory_regions_callback); + return iterate_over_mappings (pi, func, find_memory_regions_callback); } /* Returns an ascii representation of a memory mapping's flags. */ diff --git a/gdb/target-debug.h b/gdb/target-debug.h index 06b89856fe57..c86affbc8382 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -170,13 +170,9 @@ target_debug_print_const_std_vector_target_section_p (const std::vector<target_section> *vec) { return host_address_to_string (vec->data ()); } -static std::string -target_debug_print_void_p (void *p) -{ return host_address_to_string (p); } - static std::string target_debug_print_find_memory_region_ftype (find_memory_region_ftype func) -{ return host_address_to_string (func); } +{ return "<function_view>"; } static std::string target_debug_print_bfd_p (bfd *bfd) diff --git a/gdb/target-delegates-gen.c b/gdb/target-delegates-gen.c index 258e6de7e126..b39fd7cb33a1 100644 --- a/gdb/target-delegates-gen.c +++ b/gdb/target-delegates-gen.c @@ -109,7 +109,7 @@ struct dummy_target : public target_ops bool supports_set_thread_options (gdb_thread_options arg0) override; bool supports_non_stop () override; bool always_non_stop_p () override; - bool find_memory_regions (find_memory_region_ftype arg0, void *arg1) override; + bool find_memory_regions (find_memory_region_ftype arg0) override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *arg0, int *arg1) override; gdb_byte *get_bookmark (const char *arg0, int arg1) override; void goto_bookmark (const gdb_byte *arg0, int arg1) override; @@ -290,7 +290,7 @@ struct debug_target : public target_ops bool supports_set_thread_options (gdb_thread_options arg0) override; bool supports_non_stop () override; bool always_non_stop_p () override; - bool find_memory_regions (find_memory_region_ftype arg0, void *arg1) override; + bool find_memory_regions (find_memory_region_ftype arg0) override; gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *arg0, int *arg1) override; gdb_byte *get_bookmark (const char *arg0, int arg1) override; void goto_bookmark (const gdb_byte *arg0, int arg1) override; @@ -2266,27 +2266,26 @@ debug_target::always_non_stop_p () } bool -target_ops::find_memory_regions (find_memory_region_ftype arg0, void *arg1) +target_ops::find_memory_regions (find_memory_region_ftype arg0) { - return this->beneath ()->find_memory_regions (arg0, arg1); + return this->beneath ()->find_memory_regions (arg0); } bool -dummy_target::find_memory_regions (find_memory_region_ftype arg0, void *arg1) +dummy_target::find_memory_regions (find_memory_region_ftype arg0) { - return dummy_find_memory_regions (this, arg0, arg1); + return dummy_find_memory_regions (this, arg0); } bool -debug_target::find_memory_regions (find_memory_region_ftype arg0, void *arg1) +debug_target::find_memory_regions (find_memory_region_ftype arg0) { target_debug_printf_nofunc ("-> %s->find_memory_regions (...)", this->beneath ()->shortname ()); bool result - = this->beneath ()->find_memory_regions (arg0, arg1); - target_debug_printf_nofunc ("<- %s->find_memory_regions (%s, %s) = %s", + = this->beneath ()->find_memory_regions (arg0); + target_debug_printf_nofunc ("<- %s->find_memory_regions (%s) = %s", this->beneath ()->shortname (), target_debug_print_find_memory_region_ftype (arg0).c_str (), - target_debug_print_void_p (arg1).c_str (), target_debug_print_bool (result).c_str ()); return result; } diff --git a/gdb/target.c b/gdb/target.c index 77a562aa919d..925d6458c19b 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -416,9 +416,9 @@ target_thread_architecture (ptid_t ptid) /* See target.h. */ bool -target_find_memory_regions (find_memory_region_ftype func, void *data) +target_find_memory_regions (find_memory_region_ftype func) { - return current_inferior ()->top_target ()->find_memory_regions (func, data); + return current_inferior ()->top_target ()->find_memory_regions (func); } /* See target.h. */ @@ -3686,8 +3686,7 @@ default_pid_to_str (struct target_ops *ops, ptid_t ptid) /* Error-catcher for target_find_memory_regions. */ static bool -dummy_find_memory_regions (struct target_ops *self, - find_memory_region_ftype ignore1, void *ignore2) +dummy_find_memory_regions (target_ops *self, find_memory_region_ftype ignore1) { error (_("Command not implemented for this target.")); } diff --git a/gdb/target.h b/gdb/target.h index a71f750a9d92..9fb29be01b69 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -85,8 +85,8 @@ typedef const gdb_byte const_gdb_byte; #include "tracepoint.h" #include "gdbsupport/fileio.h" #include "gdbsupport/x86-xstate.h" - #include "gdbsupport/break-common.h" +#include "find-memory-region.h" enum strata { @@ -765,7 +765,7 @@ struct target_ops virtual bool always_non_stop_p () TARGET_DEFAULT_RETURN (false); /* find_memory_regions support method for gcore */ - virtual bool find_memory_regions (find_memory_region_ftype func, void *data) + virtual bool find_memory_regions (find_memory_region_ftype func) TARGET_DEFAULT_FUNC (dummy_find_memory_regions); /* make_corefile_notes support method for gcore */ virtual gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) @@ -2040,8 +2040,7 @@ extern gdbarch *target_thread_architecture (ptid_t ptid); If FUNC ever returns false, stop iterating and return false. Otherwise, return true. */ -extern bool target_find_memory_regions (find_memory_region_ftype func, - void *data); +extern bool target_find_memory_regions (find_memory_region_ftype func); /* * Compose corefile .note section. base-commit: 2a5a674f0c02d95b6ed601eedb366849aaec0c55 -- 2.53.0 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] gdb: make find_memory_region_ftype a function_view 2026-03-14 19:06 ` [PATCH v2] " simon.marchi @ 2026-03-19 13:57 ` Tom Tromey 2026-03-19 14:08 ` Simon Marchi 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2026-03-19 13:57 UTC (permalink / raw) To: simon.marchi; +Cc: gdb-patches >>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: Simon> From: Simon Marchi <simon.marchi@polymtl.ca> Simon> New in v2: Simon> - new header file find-memory-region.h Simon> Make it a function_view and remove the `void *` parameter. Convert the Simon> callers (in gcore.c) to use lambda functions that capture `obfd`. Simon> The target_debug_print_find_memory_region_ftype debug printer isn't Simon> terribly useful, but I don't see a good way to print a function_view Simon> with what we have right now. Simon> Since find_memory_region_ftype needs to be seen by both gdbarch.h and Simon> target.h, I chose to move the typedef to a new file Simon> (find-memory-region.h), that is included by both. Looks good to me. Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] gdb: make find_memory_region_ftype a function_view 2026-03-19 13:57 ` Tom Tromey @ 2026-03-19 14:08 ` Simon Marchi 0 siblings, 0 replies; 15+ messages in thread From: Simon Marchi @ 2026-03-19 14:08 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches On 2026-03-19 09:57, Tom Tromey wrote: >>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: > > Simon> From: Simon Marchi <simon.marchi@polymtl.ca> > Simon> New in v2: > > Simon> - new header file find-memory-region.h > > Simon> Make it a function_view and remove the `void *` parameter. Convert the > Simon> callers (in gcore.c) to use lambda functions that capture `obfd`. > > Simon> The target_debug_print_find_memory_region_ftype debug printer isn't > Simon> terribly useful, but I don't see a good way to print a function_view > Simon> with what we have right now. > > Simon> Since find_memory_region_ftype needs to be seen by both gdbarch.h and > Simon> target.h, I chose to move the typedef to a new file > Simon> (find-memory-region.h), that is included by both. > > Looks good to me. > Approved-By: Tom Tromey <tom@tromey.com> > > Tom Thanks, pushed. Simon ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback 2026-03-10 17:30 [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback simon.marchi ` (3 preceding siblings ...) 2026-03-10 17:30 ` [PATCH 5/5] gdb: make find_memory_region_ftype a function_view simon.marchi @ 2026-03-13 18:21 ` Tom Tromey 4 siblings, 0 replies; 15+ messages in thread From: Tom Tromey @ 2026-03-13 18:21 UTC (permalink / raw) To: simon.marchi; +Cc: gdb-patches >>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes: Simon> From: Simon Marchi <simon.marchi@polymtl.ca> Simon> I noticed that linux_find_memory_regions_full did not check the return Simon> value of the linux_find_memory_region_ftype callback. I think this is a Simon> mistake. When called from linux_find_memory_regions, the Simon> find_memory_region_ftype callback could return false, in which case we Simon> should stop iterating. Simon> This probably didn't matter in practice, as these callbacks generally Simon> don't return false (only in error cases that never happen). Looks reasonable. Approved-By: Tom Tromey <tom@tromey.com> Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-03-19 14:09 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-03-10 17:30 [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback simon.marchi 2026-03-10 17:30 ` [PATCH 2/5] gdb/gcore: check return values of some find_memory_region_ftype calls simon.marchi 2026-03-13 18:21 ` Tom Tromey 2026-03-10 17:30 ` [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view simon.marchi 2026-03-13 18:25 ` Tom Tromey 2026-03-10 17:30 ` [PATCH 4/5] gdb/linux-tdep: remove linux_collect_thread_registers_ftype typedef simon.marchi 2026-03-13 18:25 ` Tom Tromey 2026-03-14 18:43 ` Simon Marchi 2026-03-10 17:30 ` [PATCH 5/5] gdb: make find_memory_region_ftype a function_view simon.marchi 2026-03-13 18:46 ` Tom Tromey 2026-03-14 18:48 ` Simon Marchi 2026-03-14 19:06 ` [PATCH v2] " simon.marchi 2026-03-19 13:57 ` Tom Tromey 2026-03-19 14:08 ` Simon Marchi 2026-03-13 18:21 ` [PATCH 1/5] gdb/linux-tdep: check return value of linux_find_memory_region_ftype callback Tom Tromey
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox