From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view
Date: Tue, 10 Mar 2026 13:30:34 -0400 [thread overview]
Message-ID: <20260310173104.676640-3-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260310173104.676640-1-simon.marchi@polymtl.ca>
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
next prev parent reply other threads:[~2026-03-10 17:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` simon.marchi [this message]
2026-03-13 18:25 ` [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260310173104.676640-3-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox